peachsim 0.1.1684 → 0.1.1700
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/bridge-flow-runner.ts +61 -39
- package/cli/commands/agent-wrapper.ts +21 -10
- package/cli/commands/control.ts +27 -7
- package/cli/commands/coverage-swift.ts +72 -5
- package/cli/commands/coverage.ts +1 -1
- package/cli/commands/detect.ts +17 -4
- package/cli/commands/inspect/actions.ts +1 -0
- package/cli/commands/maestro-compare.ts +25 -99
- package/cli/commands/screenshot.ts +12 -0
- package/cli/help-core.ts +3 -4
- package/cli/maestro-compare.ts +172 -4
- package/cli/outbound-endpoints.ts +2 -10
- package/detox/index.ts +15 -0
- package/detox/launch-permissions.ts +169 -0
- package/dist-lib/agent-daemon-client.cjs +2 -2
- package/dist-lib/agent-events.cjs +2 -2
- package/dist-lib/attached-projects.cjs +2 -2
- package/dist-lib/auth/shared-session.cjs +2 -2
- package/dist-lib/backend-origin.cjs +2 -2
- package/dist-lib/beta.cjs +2 -2
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +2 -2
- package/dist-lib/bridge-contract-input.cjs +2 -2
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +2 -2
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +6729 -3591
- package/dist-lib/capture-contract.cjs +2 -2
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cloud-contract.cjs +2 -2
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +2 -2
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +2 -2
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +2 -2
- package/dist-lib/config.mjs +1 -1
- package/dist-lib/detox/index.cjs +104 -3
- package/dist-lib/dev-bundle-resolution.cjs +208 -44
- package/dist-lib/expo-swift-bundle.cjs +3475 -2137
- package/dist-lib/expo-swift-metadata.cjs +2 -2
- package/dist-lib/expo-swift-metadata.mjs +1 -1
- package/dist-lib/home-paths.cjs +2 -2
- package/dist-lib/host/bridge-host.cjs +8970 -3652
- package/dist-lib/host/fetch-proxy-handler.cjs +332 -40
- package/dist-lib/host/fetch-proxy-overrides.cjs +2 -2
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +2 -2
- package/dist-lib/host/websocket-proxy.cjs +2 -2
- package/dist-lib/index.cjs +469 -143
- package/dist-lib/jump-to-source-babel.cjs +2 -2
- package/dist-lib/jump-to-source-native.cjs +2 -2
- package/dist-lib/kotlin-host.cjs +2 -2
- package/dist-lib/menu.cjs +2 -2
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +2 -2
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +2 -2
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +465 -139
- package/dist-lib/native-app-identity-project.cjs +209 -86
- package/dist-lib/native-app-identity-project.mjs +251 -116
- package/dist-lib/native-app-identity.cjs +2 -2
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +2 -2
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +2 -2
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +2 -2
- package/dist-lib/public-brand.cjs +2 -2
- package/dist-lib/public-origins-lib-esm.json +27 -23
- package/dist-lib/public-origins-lib.json +221 -88
- package/dist-lib/react-native-host-modules.cjs +2 -2
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/reap-browser.cjs +2 -2
- package/dist-lib/scripts/dev-server-scanner.cjs +206 -31
- package/dist-lib/sdk.cjs +3 -3
- package/dist-lib/sdk.mjs +2 -2
- package/dist-lib/skills.cjs +20997 -16596
- package/dist-lib/swift-compile.cjs +3075 -459
- package/dist-lib/swift-compile.mjs +3028 -415
- package/dist-lib/swift-package.cjs +131 -69
- package/dist-lib/swift-package.mjs +126 -68
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +31 -4
- package/dist-lib/swift.cjs +2 -2
- package/dist-lib/vite-swift.cjs +5049 -1704
- package/dist-lib/vite.cjs +261 -58
- package/dist-lib/worklet-executable.cjs +8 -5
- package/dist-lib/worklet-executable.mjs +7 -4
- package/dist-types/packages/peach-engine/src/engine/clipboardContract.d.ts +15 -1
- package/dist-types/packages/peach-engine/src/engine/font-config.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/engine/node.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/scroll-pan-contacts.d.ts +3 -1
- package/dist-types/packages/peach-engine/src/engine/scroll.d.ts +7 -0
- package/dist-types/packages/peach-engine/src/engine/types.d.ts +2 -1
- package/dist-types/packages/peach-engine/src/remote-stream/cloud-display.d.ts +2 -2
- package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +3 -0
- package/dist-types/packages/peach-engine/src/render-worker/protocol.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/render-worker/scroll-mirror.d.ts +17 -0
- package/dist-types/packages/peach-engine/src/render-worker/worker-input-runtime.d.ts +2 -1
- package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +3 -0
- package/dist-types/packages/peach-globals/src/cameraBridgeContract.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/clipboardBridgeContract.d.ts +6 -0
- package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
- package/dist-types/packages/peach-globals/src/nodeContract.d.ts +3 -2
- package/dist-types/packages/peach-globals/src/replayBridgeContract.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/shellHostBridgeContract.d.ts +3 -0
- package/dist-types/packages/peach-kit/src/capabilities.d.ts +1 -0
- package/dist-types/packages/peach-kit/src/materials/types.d.ts +1 -0
- package/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/scripts/dev-server-scanner.ts +4 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Alpha.h +2282 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/BasicImageTypes.h +55 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Conversion.h +10551 -6
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Convolution.h +4236 -3
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Geometry.h +827 -8
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Histogram.h +1369 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Morphology.h +1243 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/Transform.h +1747 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage.h +291 -2
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage_CVUtilities.h +1283 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage_Types.h +811 -91
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vImage.framework/Headers/vImage_Utilities.h +1342 -25
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/BNNS/bnns.h +2738 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/BNNS/bnns_constants.h +1685 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/BNNS/bnns_graph.h +913 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/BNNS/bnns_structures.h +1917 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/LinearAlgebra.h +23 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/arithmetic.h +209 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/base.h +104 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/linear_systems.h +77 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/matrix.h +554 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/norms.h +58 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/object.h +186 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/splat.h +86 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/LinearAlgebra/vector.h +364 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Quadrature/Integration.h +195 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Quadrature/Quadrature.h +44 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/BLAS/BLAS.h +2330 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/BLAS/Types.h +123 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/Solve.h +8339 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/SolveImplementation.h +520 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/SolveImplementationTyped.h +1893 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/Sparse/Sparse.h +10 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/blas_new.h +1098 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/cblas.h +859 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/cblas_new.h +1134 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/clapack.h +10555 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/fortran_blas.h +695 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/lapack.h +38526 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/lapack_types.h +60 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/lapack_version.h +20 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/thread_api.h +50 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vBasicOps.h +1218 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vBigNum.h +1458 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vDSP.h +10377 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vDSP_translate.h +167 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vForce.h +1243 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vecLib.h +114 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vecLibTypes.h +146 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vectorOps.h +1106 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vfp.h +294 -0
- package/sdk/ios/System/Library/Frameworks/Accelerate.framework/Headers/Accelerate.h +25 -1
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFArray.h +673 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFAvailability.h +232 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFBase.h +827 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFCalendar.h +121 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFCharacterSet.h +387 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFData.h +79 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDate.h +122 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFDictionary.h +674 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFError.h +182 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFLocale.h +213 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFNotificationCenter.h +82 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFNumber.h +129 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFSet.h +491 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFString.h +883 -2
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFTimeZone.h +98 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h +11 -220
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +2 -6
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLAvailability.h +22 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLBackgroundActivitySession.h +145 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLBeaconIdentityCondition.h +113 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLBeaconIdentityConstraint.h +34 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLBeaconRegion.h +225 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLBody.h +26 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLCircularGeographicCondition.h +59 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLCircularRegion.h +64 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLCondition.h +48 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLError.h +52 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLErrorDomain.h +24 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLGeocoder.h +55 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLHeading.h +117 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocation.h +9 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManager+CLVisitExtensions.h +45 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManager.h +877 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManagerDelegate.h +225 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationPushServiceError.h +33 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationPushServiceExtension.h +28 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationUpdater.h +250 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLMonitor.h +140 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLMonitorConfiguration.h +77 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLMonitoringEvent.h +184 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLMonitoringRecord.h +57 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLPlacemark.h +98 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLRegion.h +123 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLServiceSession.h +211 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLVisit.h +66 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CoreLocation.h +46 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Modules/module.modulemap +7 -0
- package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +98 -3
- package/sdk/ios/System/Library/Frameworks/IOSurface.framework/Headers/IOSurfaceBase.h +52 -0
- package/sdk/ios/System/Library/Frameworks/IOSurface.framework/Headers/IOSurfaceObjC.h +240 -0
- package/sdk/ios/System/Library/Frameworks/IOSurface.framework/Headers/IOSurfaceRef.h +474 -0
- package/sdk/ios/System/Library/Frameworks/IOSurface.framework/Headers/IOSurfaceTypes.h +66 -0
- package/sdk/ios/System/Library/Frameworks/IOSurface.framework/Modules/module.modulemap +10 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4AccelerationStructure.h +9 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4Archive.h +16 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4ArgumentTable.h +17 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4BinaryFunction.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4BinaryFunctionDescriptor.h +14 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4BufferRange.h +79 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4CommandAllocator.h +15 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4CommandBuffer.h +17 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4CommandEncoder.h +16 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4CommandQueue.h +19 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4CommitFeedback.h +15 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4Compiler.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4CompilerTask.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4ComputeCommandEncoder.h +19 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4ComputePipeline.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4Counters.h +19 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4FunctionDescriptor.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4LibraryDescriptor.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4LibraryFunctionDescriptor.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4LinkingDescriptor.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4MachineLearningCommandEncoder.h +17 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4MachineLearningPipeline.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4MeshRenderPipeline.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4PipelineDataSetSerializer.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4PipelineState.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4RenderCommandEncoder.h +17 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4RenderPass.h +17 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4RenderPipeline.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4SpecializedFunctionDescriptor.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4StitchedFunctionDescriptor.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTL4TileRenderPipeline.h +13 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLAccelerationStructure.h +1212 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLAccelerationStructureCommandEncoder.h +322 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLAccelerationStructureTypes.h +224 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLAllocation.h +22 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLArgument.h +279 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLArgumentEncoder.h +199 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLBinaryArchive.h +142 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLBlitCommandEncoder.h +266 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLBlitPass.h +82 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLBuffer.h +94 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLCaptureManager.h +113 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLCaptureScope.h +43 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLCommandBuffer.h +449 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLCommandEncoder.h +148 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLCommandQueue.h +102 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLComputeCommandEncoder.h +350 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLComputePass.h +90 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLComputePipeline.h +274 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLCounters.h +225 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDataType.h +232 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDefines.h +39 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDepthStencil.h +93 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDevice.h +1122 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDeviceCertification.h +29 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDrawable.h +36 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLDynamicLibrary.h +81 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLEvent.h +79 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLFence.h +22 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLFunctionConstantValues.h +30 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLFunctionDescriptor.h +95 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLFunctionHandle.h +29 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLFunctionLog.h +37 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLFunctionStitching.h +131 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLGPUAddress.h +19 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLHeap.h +284 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLIOCommandBuffer.h +10 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLIOCommandQueue.h +11 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLIOCompressor.h +10 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLIndirectCommandBuffer.h +157 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLIndirectCommandEncoder.h +110 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLIntersectionFunctionTable.h +186 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLLibrary.h +549 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLLinkedFunctions.h +57 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLLogState.h +65 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLParallelRenderCommandEncoder.h +77 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLPipeline.h +57 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLPixelFormat.h +342 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLRasterizationRate.h +323 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLRenderCommandEncoder.h +1068 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLRenderPass.h +411 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLRenderPipeline.h +788 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLResidencySet.h +141 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLResource.h +307 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLResourceStateCommandEncoder.h +125 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLResourceStatePass.h +85 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLResourceViewPool.h +22 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLSampler.h +252 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLStageInputOutputDescriptor.h +158 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLTensor.h +17 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLTexture.h +460 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLTextureViewPool.h +18 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLTypes.h +125 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLVertexDescriptor.h +153 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/MTLVisibleFunctionTable.h +45 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Headers/Metal.h +94 -0
- package/sdk/ios/System/Library/Frameworks/Metal.framework/Modules/module.modulemap +6 -0
- package/sdk/ios/System/Library/Frameworks/QuartzCore.framework/Headers/QuartzCore.h +1 -0
- package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecBase.h +906 -3
- package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecCertificate.h +613 -0
- package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecItem.h +1284 -29
- package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecPolicy.h +441 -0
- package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/SecTrust.h +845 -0
- package/sdk/ios/System/Library/Frameworks/Security.framework/Headers/Security.h +4 -0
- package/sdk/ios/System/Library/Frameworks/UniformTypeIdentifiers.framework/Headers/UTDefines.h +35 -0
- package/sdk/ios/System/Library/Frameworks/UniformTypeIdentifiers.framework/Headers/UTTagClass.h +33 -0
- package/sdk/ios/System/Library/Frameworks/UniformTypeIdentifiers.framework/Headers/UTType.h +504 -0
- package/sdk/ios/System/Library/Frameworks/_LocationEssentials.framework/Headers/CLEssentialsAvailability.h +14 -0
- package/sdk/ios/System/Library/Frameworks/_LocationEssentials.framework/Headers/CLLocationEssentials.h +444 -0
- package/sdk/ios/System/Library/Frameworks/_LocationEssentials.framework/Headers/LocationEssentials.h +14 -0
- package/sdk/ios/System/Library/Frameworks/_LocationEssentials.framework/Modules/module.modulemap +14 -0
- package/sdk/ios/usr/include/AvailabilityMacros.h +3985 -0
- package/sdk/ios/usr/include/complex.h +167 -0
- package/sdk/ios/usr/include/copyfile.h +143 -0
- package/sdk/ios/usr/include/dispatch/dispatch.h +5 -0
- package/sdk/ios/usr/include/mach/mach_types.h +1 -0
- package/sdk/ios/usr/include/malloc/_malloc.h +143 -0
- package/sdk/ios/usr/include/malloc/_malloc_type.h +153 -0
- package/sdk/ios/usr/include/malloc/_platform.h +80 -0
- package/sdk/ios/usr/include/malloc/_ptrcheck.h +43 -0
- package/sdk/ios/usr/include/malloc/malloc.h +768 -0
- package/sdk/ios/usr/include/math.h +835 -2
- package/sdk/ios/usr/include/os/availability.h +168 -6
- package/sdk/ios/usr/include/os/base.h +351 -0
- package/sdk/ios/usr/include/os/clock.h +18 -0
- package/sdk/ios/usr/include/os/lock.h +232 -10
- package/sdk/ios/usr/include/os/log.h +521 -38
- package/sdk/ios/usr/include/os/object.h +320 -3
- package/sdk/ios/usr/include/os/trace.h +492 -0
- package/sdk/ios/usr/include/os/trace_base.h +167 -0
- package/sdk/ios/usr/include/os/workgroup.h +37 -0
- package/sdk/ios/usr/include/os/workgroup_base.h +91 -0
- package/sdk/ios/usr/include/os/workgroup_interval.h +156 -0
- package/sdk/ios/usr/include/os/workgroup_object.h +359 -0
- package/sdk/ios/usr/include/os/workgroup_parallel.h +76 -0
- package/sdk/ios/usr/include/sys/cdefs.h +38 -1
- package/sdk/ios/wasm/include/unistd.h +3 -0
- package/skills/contrast/SKILL.md +3 -0
- package/src/codex-client.ts +11 -6
- package/src/dev-bundle-resolution.ts +124 -48
- package/src/expo-native-workspace.ts +176 -0
- package/src/expo-swift-host.ts +161 -26
- package/src/expo-swift-ready.ts +14 -28
- package/src/expoSwiftContract.ts +4 -1
- package/src/generated/swift-c-predefines.json +2044 -0
- package/src/host/bridge-host.ts +5 -0
- package/src/installed-package-versions.ts +14 -1
- package/src/metro-project-root.ts +44 -33
- package/src/native-app-identity-project.ts +1 -0
- package/src/nitro-adapter.lock.json +916 -10
- package/src/nitro-adapter.ts +33 -24
- package/src/nitro-bundle.ts +108 -21
- package/src/nitro-compile.ts +36 -5
- package/src/nitro-source.ts +13 -3
- package/src/nitroAdapterContract.ts +100 -20
- package/src/nitroContract.ts +18 -2
- package/src/node-http-fetch.ts +116 -0
- package/src/packageVersionsContract.ts +46 -0
- package/src/serverDiscoveryContract.ts +1 -0
- package/src/settingsContract.ts +0 -30
- package/src/swift-binary-modules.ts +20 -5
- package/src/swift-compile.ts +598 -81
- package/src/swift-coverage/package.ts +3 -1
- package/src/swift-coverage/xcode-assets.ts +66 -5
- package/src/swift-coverage/xcode-packages.ts +11 -6
- package/src/swift-host.ts +347 -60
- package/src/swift-objc-compile.ts +52 -10
- package/src/swift-objc-metadata.ts +2 -2
- package/src/swift-objc-platform.ts +2 -2
- package/src/swift-objc-standin.ts +53 -13
- package/src/swift-package-manifest.ts +151 -28
- package/src/swift-package.ts +158 -75
- package/src/swift-packages.ts +141 -44
- package/src/swift-source-file.ts +10 -15
- package/src/swift-source-pods.ts +126 -41
- package/src/swift-standin-digest.ts +77 -0
- package/src/swift-standin-emit.ts +40 -4
- package/src/swift-standins.ts +154 -31
- package/src/swift-submit.ts +5 -0
- package/src/swift-toolchain.ts +38 -0
- package/src/swiftContract.ts +168 -75
- package/src/target-matcher.ts +15 -2
- package/src/vite-plugin.ts +0 -10
- package/src/worklet-executable.ts +7 -3
- package/src/xcode-json-project.ts +14 -2
- package/src/xcode-project.ts +215 -100
- package/src/settings-flags.ts +0 -107
|
@@ -1,11 +1,4244 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/*!
|
|
2
|
+
* @header Convolution.h
|
|
3
|
+
* vImage_Framework
|
|
4
|
+
*
|
|
5
|
+
* See vImage/vImage.h for more on how to view the headerdoc documentation for functions declared herein.
|
|
6
|
+
*
|
|
7
|
+
* @copyright Copyright (c) 2002-2020 by Apple Inc. All rights reserved.
|
|
8
|
+
*
|
|
9
|
+
* @discussion Convolution is a weighted average between a pixel and its neighboring pixels. By smoothing
|
|
10
|
+
* out high frequency signal, convolution can be used to blur an image. By subtracting out the
|
|
11
|
+
* low frequency signal, it can be used to produce a sharpening effect. Convolution is also used
|
|
12
|
+
* with a variety of filters such as Laplace and Sobel to detect edges in the image. Here we also
|
|
13
|
+
* provide a deconvolution filter that attempts to iteratively undo the effect of a convolution.
|
|
14
|
+
* Where the convolution kernel can be accurately determined, it can be used to remove focus
|
|
15
|
+
* problems, motion blur and distortion introduced by the lens.
|
|
16
|
+
*
|
|
17
|
+
* <pre>@textblock
|
|
18
|
+
* =========================================================================
|
|
19
|
+
* ====== MOST VIMAGE CONVOLUTION FUNCTIONS DO NOT WORK IN PLACE =====
|
|
20
|
+
* =========================================================================
|
|
21
|
+
* @/textblock </pre>
|
|
22
|
+
*
|
|
23
|
+
* Since a weighted average of nearby pixels can for some positions extend off the edge of the
|
|
24
|
+
* input image, a variety of edging modes are provided which specify what happens in such
|
|
25
|
+
* cases:
|
|
26
|
+
* <pre>@textblock
|
|
27
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
28
|
+
* copy the corresponding source pixel to the destination. This
|
|
29
|
+
* will result in a ring off unconvolved content at the edges
|
|
30
|
+
* and convolved content in the middle.
|
|
31
|
+
*
|
|
32
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
33
|
+
* For a blur filter this will look like the edges of the image
|
|
34
|
+
* have been blurred into a particular color. This is usually
|
|
35
|
+
* appropriate when the color of the surface onto which the image
|
|
36
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
37
|
+
* as a background color, and let the downstream image compositor
|
|
38
|
+
* blend in the background color. In this case, the result image
|
|
39
|
+
* should be treated as a premultiplied image.
|
|
40
|
+
*
|
|
41
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
42
|
+
* This is better when the image is drawn into a frame or other
|
|
43
|
+
* context where the background is not expected to contribute to
|
|
44
|
+
* the final content.
|
|
45
|
+
*
|
|
46
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
47
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
48
|
+
* Because of the complication at the edges, this edging mode can
|
|
49
|
+
* be significantly slower than the others. It can be numerically
|
|
50
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
51
|
+
* is zero, which can result in division by zero during the computation.
|
|
52
|
+
* The results for this edging mode are usually quite visually similar
|
|
53
|
+
* to kvImageEdgeExtend.
|
|
54
|
+
* @/textblock </pre>
|
|
55
|
+
* Only one edging mode may be active at a time. Please see the Convolution section in
|
|
56
|
+
* the vImage Programming Guide for a better description of edging modes.
|
|
57
|
+
* (https://developer.apple.com/library/ios/documentation/Performance/Conceptual/vImage/vImage.pdf)
|
|
58
|
+
*
|
|
59
|
+
*
|
|
60
|
+
* When calling these interfaces from within the context of your own tiling engine,
|
|
61
|
+
* it may be necessary to produce a result tile starting from different points in the
|
|
62
|
+
* input image. Simply repackaging the input image by adjusting the height, width and
|
|
63
|
+
* src->data to achieve this affect will not work correctly because it introduces
|
|
64
|
+
* artificial edges into the input image. (See discussion of edging modes above.)
|
|
65
|
+
* Instead, X and Y offset parameters are provided. Simply pass in the whole input image
|
|
66
|
+
* and use the X and Y offsets to adjust the position of the content used to produce
|
|
67
|
+
* the output image. The size of the output tile is given by the dest->height and width.
|
|
68
|
+
*
|
|
69
|
+
* @ignorefuncmacro VIMAGE_NON_NULL
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
#ifndef VIMAGE_CONVOLUTION_H
|
|
74
|
+
#define VIMAGE_CONVOLUTION_H
|
|
75
|
+
|
|
76
|
+
|
|
4
77
|
#ifdef __cplusplus
|
|
5
78
|
extern "C" {
|
|
6
79
|
#endif
|
|
80
|
+
|
|
81
|
+
#include <vImage/vImage_Types.h>
|
|
82
|
+
|
|
83
|
+
/*!
|
|
84
|
+
* @functiongroup General Convolution
|
|
85
|
+
* @discussion A general convolve filter allows you to provide an arbitrary set of weights to use
|
|
86
|
+
* in the weighted average between each pixel and its neighbors. As such, it is a
|
|
87
|
+
* very flexible tool for achieving a variety of image effects, from blurring to sharpening
|
|
88
|
+
* to edge detection to sub-pixel image translation and motion blur.
|
|
89
|
+
*
|
|
90
|
+
* Some filters such as edge detection filters take the first derivative of the image
|
|
91
|
+
* surface. Since a derivative can be either positive or negative and some formats such
|
|
92
|
+
* as Planar8 (unorm8) can only represent positive numbers, the general convolution is also
|
|
93
|
+
* available in a form which allows you to provide a bias to add to the weighted sum before
|
|
94
|
+
* the divisor is applied, to shift the values into the positive. You might provide a
|
|
95
|
+
* bias of 128 * divisor to move the encoding for 0 to 128 so that negative numbers are
|
|
96
|
+
* representable, for example. (In this case, -20 would now be encoded as 128-20=108.)
|
|
97
|
+
*
|
|
98
|
+
* Finally, vImage provides multikernel convolution, which allows a different kernel, bias
|
|
99
|
+
* and divisor to be used for each color channel. This might allow for the position of the
|
|
100
|
+
* different color channels to be shifted independently, or for alpha to be blurred differently
|
|
101
|
+
* from color.
|
|
102
|
+
* <pre>@textblock
|
|
103
|
+
* =========================================================================
|
|
104
|
+
* ====== MOST VIMAGE CONVOLUTION FUNCTIONS DO NOT WORK IN PLACE =====
|
|
105
|
+
* =========================================================================
|
|
106
|
+
* @/textblock </pre>
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
/*!
|
|
110
|
+
* @function vImageConvolve_Planar8
|
|
111
|
+
* @abstract General convolution on a Planar8 image.
|
|
112
|
+
* @discussion This filter applies a convolution filter of your choosing to a Planar8 image.
|
|
113
|
+
* For each pixel:
|
|
114
|
+
* <pre>@textblock
|
|
115
|
+
* for each pixel[y][x] in image{
|
|
116
|
+
* int sum = 0;
|
|
117
|
+
*
|
|
118
|
+
* // Calculate weighted average over kernel area
|
|
119
|
+
* for each kernel_element[i][j] in kernel{
|
|
120
|
+
* sum += kernel_element[i][j] *
|
|
121
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
122
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
123
|
+
* }
|
|
124
|
+
* // Correct for the scaling introduced by multiplying by the weights table
|
|
125
|
+
* sum = (sum + divisor/2) / divisor;
|
|
126
|
+
*
|
|
127
|
+
* // write out result
|
|
128
|
+
* result[y][x] = CLAMP(sum, 0, 255);
|
|
129
|
+
* }
|
|
130
|
+
* @/textblock </pre>
|
|
131
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
132
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
133
|
+
* kernel_width.)
|
|
134
|
+
*
|
|
135
|
+
* This filter does not work in place.
|
|
136
|
+
*
|
|
137
|
+
* @param src The input image
|
|
138
|
+
*
|
|
139
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
140
|
+
* This may not alias the src image.
|
|
141
|
+
*
|
|
142
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
143
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
144
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
145
|
+
* the size is returned instead of an error code from the left hand side.
|
|
146
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
147
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
148
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
149
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
150
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
151
|
+
* concurrently, a different temp buffer should be used for each.
|
|
152
|
+
*
|
|
153
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
154
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
155
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
156
|
+
*
|
|
157
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
158
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
159
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
160
|
+
*
|
|
161
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
162
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
163
|
+
* <pre>@textblock
|
|
164
|
+
* const int16_t kernel[9] = { 1, 2, 1,
|
|
165
|
+
* 2, 4, 2,
|
|
166
|
+
* 1, 2, 1 };
|
|
167
|
+
* @/textblock </pre>
|
|
168
|
+
*
|
|
169
|
+
* The kernel values may not sum in any combination to be outside the range
|
|
170
|
+
* [-2**23, 2**23), or modulo overflow in the accumulator may result.
|
|
171
|
+
*
|
|
172
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
173
|
+
*
|
|
174
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
175
|
+
*
|
|
176
|
+
* @param divisor The weighted sum of nearby pixels is typically a large number, which must be corrected
|
|
177
|
+
* to fit back into the image format of the destination image. The correction factor
|
|
178
|
+
* is passed in as divisor here, and is divided from the sum before the result is
|
|
179
|
+
* returned. Typically, the divisor is the sum over the area of the kernel. If the divisor
|
|
180
|
+
* is 0, 1 will be used instead.
|
|
181
|
+
*
|
|
182
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
183
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
184
|
+
* kernel extends off the edge of the image.
|
|
185
|
+
*
|
|
186
|
+
* @param flags The following flags are allowed:
|
|
187
|
+
* <pre>@textblock
|
|
188
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
189
|
+
* copy the corresponding source pixel to the destination. This
|
|
190
|
+
* will result in a ring off unconvolved content at the edges
|
|
191
|
+
* and convolved content in the middle.
|
|
192
|
+
*
|
|
193
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
194
|
+
* For a blur filter this will look like the edges of the image
|
|
195
|
+
* have been blurred into a particular color. This is usually
|
|
196
|
+
* appropriate when the color of the surface onto which the image
|
|
197
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
198
|
+
* as a background color, and let the downstream image compositor
|
|
199
|
+
* blend in the background color. In this case, the result image
|
|
200
|
+
* should be treated as a premultiplied image.
|
|
201
|
+
*
|
|
202
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
203
|
+
* This is better when the image is drawn into a frame or other
|
|
204
|
+
* context where the background is not expected to contribute to
|
|
205
|
+
* the final content.
|
|
206
|
+
*
|
|
207
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
208
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
209
|
+
* Because of the complication at the edges, this edging mode can
|
|
210
|
+
* be significantly slower than the others. It can be numerically
|
|
211
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
212
|
+
* is zero, which can result in division by zero during the computation.
|
|
213
|
+
* The results for this edging mode are usually quite visually similar
|
|
214
|
+
* to kvImageEdgeExtend.
|
|
215
|
+
*
|
|
216
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
217
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
218
|
+
* not touch the src or dest image.
|
|
219
|
+
*
|
|
220
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
221
|
+
*
|
|
222
|
+
* @/textblock </pre>
|
|
223
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
224
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
225
|
+
* be returned.
|
|
226
|
+
*
|
|
227
|
+
* @return One of the following error codes may be returned:
|
|
228
|
+
* <pre>@textblock
|
|
229
|
+
* kvImageNoError Success.
|
|
230
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
231
|
+
* the temp buffer to use with this function and this set of
|
|
232
|
+
* parameters.
|
|
233
|
+
*
|
|
234
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
235
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
236
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
237
|
+
*
|
|
238
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
239
|
+
* to corresponding dimensions of the source buffer.
|
|
240
|
+
*
|
|
241
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
242
|
+
*
|
|
243
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
244
|
+
*
|
|
245
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
246
|
+
*
|
|
247
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
248
|
+
*
|
|
249
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
250
|
+
* @/textblock </pre>
|
|
251
|
+
*/
|
|
252
|
+
VIMAGE_PF vImage_Error vImageConvolve_Planar8( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const int16_t *kernel, uint32_t kernel_height, uint32_t kernel_width, int32_t divisor, Pixel_8 backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.3), ios(5.0), watchos(1.0), tvos(5.0));
|
|
253
|
+
|
|
254
|
+
/*!
|
|
255
|
+
* @function vImageConvolve_PlanarF
|
|
256
|
+
* @abstract General convolution on a PlanarF image.
|
|
257
|
+
* @discussion This filter applies a convolution filter of your choosing to a PlanarF image.
|
|
258
|
+
* For each pixel:
|
|
259
|
+
* <pre>@textblock
|
|
260
|
+
* for each pixel[y][x] in image{
|
|
261
|
+
* float sum = 0;
|
|
262
|
+
*
|
|
263
|
+
* // Calculate weighted average over kernel area
|
|
264
|
+
* for each kernel_element[i][j] in kernel{
|
|
265
|
+
* sum += kernel_element[i][j] *
|
|
266
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
267
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
268
|
+
* }
|
|
269
|
+
*
|
|
270
|
+
* // write out result
|
|
271
|
+
* result[y][x] = sum;
|
|
272
|
+
* }
|
|
273
|
+
* @/textblock </pre>
|
|
274
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
275
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
276
|
+
* kernel_width.)
|
|
277
|
+
*
|
|
278
|
+
* This filter does not work in place.
|
|
279
|
+
*
|
|
280
|
+
* @param src The input image
|
|
281
|
+
*
|
|
282
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
283
|
+
* This may not alias the src image.
|
|
284
|
+
*
|
|
285
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
286
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
287
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
288
|
+
* the size is returned instead of an error code from the left hand side.
|
|
289
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
290
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
291
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
292
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
293
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
294
|
+
* concurrently, a different temp buffer should be used for each.
|
|
295
|
+
*
|
|
296
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
297
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
298
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
299
|
+
*
|
|
300
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
301
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
302
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
303
|
+
*
|
|
304
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
305
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
306
|
+
* <pre>@textblock
|
|
307
|
+
* const float kernel[9] = { 1./16, 2./16, 1./16,
|
|
308
|
+
* 2./16, 4./16, 2./16,
|
|
309
|
+
* 1./16, 2./16, 1./16 };
|
|
310
|
+
* @/textblock </pre>
|
|
311
|
+
*
|
|
312
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
313
|
+
*
|
|
314
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
315
|
+
*
|
|
316
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
317
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
318
|
+
* kernel extends off the edge of the image.
|
|
319
|
+
*
|
|
320
|
+
* @param flags The following flags are allowed:
|
|
321
|
+
* <pre>@textblock
|
|
322
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
323
|
+
* copy the corresponding source pixel to the destination. This
|
|
324
|
+
* will result in a ring off unconvolved content at the edges
|
|
325
|
+
* and convolved content in the middle.
|
|
326
|
+
*
|
|
327
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
328
|
+
* For a blur filter this will look like the edges of the image
|
|
329
|
+
* have been blurred into a particular color. This is usually
|
|
330
|
+
* appropriate when the color of the surface onto which the image
|
|
331
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
332
|
+
* as a background color, and let the downstream image compositor
|
|
333
|
+
* blend in the background color. In this case, the result image
|
|
334
|
+
* should be treated as a premultiplied image.
|
|
335
|
+
*
|
|
336
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
337
|
+
* This is better when the image is drawn into a frame or other
|
|
338
|
+
* context where the background is not expected to contribute to
|
|
339
|
+
* the final content.
|
|
340
|
+
*
|
|
341
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
342
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
343
|
+
* Because of the complication at the edges, this edging mode can
|
|
344
|
+
* be significantly slower than the others. It can be numerically
|
|
345
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
346
|
+
* is zero, which can result in division by zero during the computation.
|
|
347
|
+
* The results for this edging mode are usually quite visually similar
|
|
348
|
+
* to kvImageEdgeExtend.
|
|
349
|
+
*
|
|
350
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
351
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
352
|
+
* not touch the src or dest image.
|
|
353
|
+
*
|
|
354
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
355
|
+
*
|
|
356
|
+
* @/textblock </pre>
|
|
357
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
358
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
359
|
+
* be returned.
|
|
360
|
+
*
|
|
361
|
+
* @return One of the following error codes may be returned:
|
|
362
|
+
* <pre>@textblock
|
|
363
|
+
* kvImageNoError Success.
|
|
364
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
365
|
+
* the temp buffer to use with this function and this set of
|
|
366
|
+
* parameters.
|
|
367
|
+
*
|
|
368
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
369
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
370
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
371
|
+
*
|
|
372
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
373
|
+
* to corresponding dimensions of the source buffer.
|
|
374
|
+
*
|
|
375
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
376
|
+
*
|
|
377
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
378
|
+
*
|
|
379
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
380
|
+
*
|
|
381
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
382
|
+
*
|
|
383
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
384
|
+
* @/textblock </pre>
|
|
385
|
+
*/
|
|
386
|
+
VIMAGE_PF vImage_Error vImageConvolve_PlanarF( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const float *kernel, uint32_t kernel_height, uint32_t kernel_width, Pixel_F backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.3), ios(5.0), watchos(1.0), tvos(5.0));
|
|
387
|
+
|
|
388
|
+
/*!
|
|
389
|
+
* @function vImageConvolve_Planar16F
|
|
390
|
+
* @abstract General convolution on a Planar16F image.
|
|
391
|
+
* @discussion This filter applies a convolution filter of your choosing to a Planar16F image.
|
|
392
|
+
* The kernel values are specified as 32-bit single-precision floats and the
|
|
393
|
+
* weighted average is also computed in single precision by default. However, if
|
|
394
|
+
* the flag kvImageUseFP16Accumulator is set all internal filtering operations will
|
|
395
|
+
* use 16-bit half-precision floating-point arithmetic when the CPU architecture
|
|
396
|
+
* supports it. This results in up to 2x performance improvements but at the
|
|
397
|
+
* expense of a less precise result; typically 2-3 bits of precision is lost.
|
|
398
|
+
*
|
|
399
|
+
* For each pixel:
|
|
400
|
+
* <pre>@textblock
|
|
401
|
+
* for each pixel[y][x] in image{
|
|
402
|
+
* // sum is declared as type _Float16 when the flag kvImageUseFP16Accumulator is set
|
|
403
|
+
* float sum = 0;
|
|
404
|
+
*
|
|
405
|
+
* // Calculate weighted average over kernel area
|
|
406
|
+
* for each kernel_element[i][j] in kernel{
|
|
407
|
+
* sum += kernel_element[i][j] *
|
|
408
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
409
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
410
|
+
* }
|
|
411
|
+
*
|
|
412
|
+
* // write out result
|
|
413
|
+
* result[y][x] = (_Float16)sum;
|
|
414
|
+
* }
|
|
415
|
+
* @/textblock </pre>
|
|
416
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
417
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
418
|
+
* kernel_width.)
|
|
419
|
+
*
|
|
420
|
+
* This filter does not work in place.
|
|
421
|
+
*
|
|
422
|
+
* @param src The input image
|
|
423
|
+
*
|
|
424
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
425
|
+
* This may not alias the src image.
|
|
426
|
+
*
|
|
427
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
428
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
429
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
430
|
+
* the size is returned instead of an error code from the left hand side.
|
|
431
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
432
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
433
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
434
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
435
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
436
|
+
* concurrently, a different temp buffer should be used for each.
|
|
437
|
+
*
|
|
438
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
439
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
440
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
441
|
+
*
|
|
442
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
443
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
444
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
445
|
+
*
|
|
446
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
447
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
448
|
+
* <pre>@textblock
|
|
449
|
+
* const float kernel[9] = { 1./16, 2./16, 1./16,
|
|
450
|
+
* 2./16, 4./16, 2./16,
|
|
451
|
+
* 1./16, 2./16, 1./16 };
|
|
452
|
+
* @/textblock </pre>
|
|
453
|
+
*
|
|
454
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
455
|
+
*
|
|
456
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
457
|
+
*
|
|
458
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
459
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
460
|
+
* kernel extends off the edge of the image.
|
|
461
|
+
*
|
|
462
|
+
* @param flags The following flags are allowed:
|
|
463
|
+
* <pre>@textblock
|
|
464
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
465
|
+
* copy the corresponding source pixel to the destination. This
|
|
466
|
+
* will result in a ring off unconvolved content at the edges
|
|
467
|
+
* and convolved content in the middle.
|
|
468
|
+
*
|
|
469
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
470
|
+
* For a blur filter this will look like the edges of the image
|
|
471
|
+
* have been blurred into a particular color. This is usually
|
|
472
|
+
* appropriate when the color of the surface onto which the image
|
|
473
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
474
|
+
* as a background color, and let the downstream image compositor
|
|
475
|
+
* blend in the background color. In this case, the result image
|
|
476
|
+
* should be treated as a premultiplied image.
|
|
477
|
+
*
|
|
478
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
479
|
+
* This is better when the image is drawn into a frame or other
|
|
480
|
+
* context where the background is not expected to contribute to
|
|
481
|
+
* the final content.
|
|
482
|
+
*
|
|
483
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
484
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
485
|
+
* Because of the complication at the edges, this edging mode can
|
|
486
|
+
* be significantly slower than the others. It can be numerically
|
|
487
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
488
|
+
* is zero, which can result in division by zero during the computation.
|
|
489
|
+
* The results for this edging mode are usually quite visually similar
|
|
490
|
+
* to kvImageEdgeExtend.
|
|
491
|
+
*
|
|
492
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
493
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
494
|
+
* not touch the src or dest image.
|
|
495
|
+
*
|
|
496
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
497
|
+
*
|
|
498
|
+
* kvImageUseFP16Accumulator Enable 16-bit half-precision floating-point arithmetic when computing the
|
|
499
|
+
* kernel averages when the CPU architecture supports it.
|
|
500
|
+
*
|
|
501
|
+
* @/textblock </pre>
|
|
502
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
503
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
504
|
+
* be returned.
|
|
505
|
+
*
|
|
506
|
+
* @return One of the following error codes may be returned:
|
|
507
|
+
* <pre>@textblock
|
|
508
|
+
* kvImageNoError Success.
|
|
509
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
510
|
+
* the temp buffer to use with this function and this set of
|
|
511
|
+
* parameters.
|
|
512
|
+
*
|
|
513
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
514
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
515
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
516
|
+
*
|
|
517
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
518
|
+
* to corresponding dimensions of the source buffer.
|
|
519
|
+
*
|
|
520
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
521
|
+
*
|
|
522
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
523
|
+
*
|
|
524
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
525
|
+
*
|
|
526
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
527
|
+
*
|
|
528
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
529
|
+
* @/textblock </pre>
|
|
530
|
+
*/
|
|
531
|
+
VIMAGE_PF vImage_Error vImageConvolve_Planar16F( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const float *kernel, uint32_t kernel_height, uint32_t kernel_width, Pixel_16F backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(13.0), ios(16.0), watchos(9.0), tvos(16.0));
|
|
532
|
+
|
|
533
|
+
/*!
|
|
534
|
+
* @function vImageConvolve_ARGB8888
|
|
535
|
+
* @abstract General convolution on a ARGB888 image of any channel order.
|
|
536
|
+
* @discussion This filter applies a convolution filter of your choosing to a ARGB8888 image.
|
|
537
|
+
* This filter will work on any four-channel, 8-bit per component image format, not just ARGB.
|
|
538
|
+
* For each pixel:
|
|
539
|
+
* <pre>@textblock
|
|
540
|
+
* for each pixel[y][x] in image{
|
|
541
|
+
* int sumA = 0;
|
|
542
|
+
* int sumR = 0;
|
|
543
|
+
* int sumG = 0;
|
|
544
|
+
* int sumB = 0;
|
|
545
|
+
*
|
|
546
|
+
* // Calculate weighted average over kernel area
|
|
547
|
+
* for each kernel_element[i][j] in kernel{
|
|
548
|
+
* sumA += kernel_element[i][j] *
|
|
549
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][0];
|
|
550
|
+
* sumR += kernel_element[i][j] *
|
|
551
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][1];
|
|
552
|
+
* sumG += kernel_element[i][j] *
|
|
553
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][2];
|
|
554
|
+
* sumB += kernel_element[i][j] *
|
|
555
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][3];
|
|
556
|
+
* }
|
|
557
|
+
* // Correct for the scaling introduced by multiplying by the weights table
|
|
558
|
+
* sumA = (sumA + divisor/2) / divisor;
|
|
559
|
+
* sumR = (sumR + divisor/2) / divisor;
|
|
560
|
+
* sumG = (sumG + divisor/2) / divisor;
|
|
561
|
+
* sumB = (sumB + divisor/2) / divisor;
|
|
562
|
+
*
|
|
563
|
+
* // write out result
|
|
564
|
+
* result[y][x][0] = CLAMP(sumA, 0, 255);
|
|
565
|
+
* result[y][x][1] = CLAMP(sumR, 0, 255);
|
|
566
|
+
* result[y][x][2] = CLAMP(sumG, 0, 255);
|
|
567
|
+
* result[y][x][3] = CLAMP(sumB, 0, 255);
|
|
568
|
+
* }
|
|
569
|
+
* @/textblock </pre>
|
|
570
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
571
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
572
|
+
* kernel_width.)
|
|
573
|
+
*
|
|
574
|
+
* This filter does not work in place.
|
|
575
|
+
*
|
|
576
|
+
*
|
|
577
|
+
* @param src The input image
|
|
578
|
+
*
|
|
579
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
580
|
+
* This may not alias the src image.
|
|
581
|
+
*
|
|
582
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
583
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
584
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
585
|
+
* the size is returned instead of an error code from the left hand side.
|
|
586
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
587
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
588
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
589
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
590
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
591
|
+
* concurrently, a different temp buffer should be used for each.
|
|
592
|
+
*
|
|
593
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
594
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
595
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
596
|
+
*
|
|
597
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
598
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
599
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
600
|
+
*
|
|
601
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
602
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
603
|
+
* <pre>@textblock
|
|
604
|
+
* const int16_t kernel[9] = { 1, 2, 1,
|
|
605
|
+
* 2, 4, 2,
|
|
606
|
+
* 1, 2, 1 };
|
|
607
|
+
* @/textblock </pre>
|
|
608
|
+
*
|
|
609
|
+
* The kernel values may not sum in any combination to be outside the range
|
|
610
|
+
* [-2**23, 2**23), or modulo overflow in the accumulator may result.
|
|
611
|
+
*
|
|
612
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
613
|
+
*
|
|
614
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
615
|
+
*
|
|
616
|
+
* @param divisor The weighted sum of nearby pixels is typically a large number, which must be corrected
|
|
617
|
+
* to fit back into the image format of the destination image. The correction factor
|
|
618
|
+
* is passed in as divisor here, and is divided from the sum before the result is
|
|
619
|
+
* returned. Typically, the divisor is the sum over the area of the kernel. If the divisor
|
|
620
|
+
* is 0, 1 will be used instead.
|
|
621
|
+
*
|
|
622
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
623
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
624
|
+
* kernel extends off the edge of the image.
|
|
625
|
+
*
|
|
626
|
+
* @param flags The following flags are allowed:
|
|
627
|
+
* <pre>@textblock
|
|
628
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
629
|
+
* copy the corresponding source pixel to the destination. This
|
|
630
|
+
* will result in a ring off unconvolved content at the edges
|
|
631
|
+
* and convolved content in the middle.
|
|
632
|
+
*
|
|
633
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
634
|
+
* For a blur filter this will look like the edges of the image
|
|
635
|
+
* have been blurred into a particular color. This is usually
|
|
636
|
+
* appropriate when the color of the surface onto which the image
|
|
637
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
638
|
+
* as a background color, and let the downstream image compositor
|
|
639
|
+
* blend in the background color. In this case, the result image
|
|
640
|
+
* should be treated as a premultiplied image.
|
|
641
|
+
*
|
|
642
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
643
|
+
* This is better when the image is drawn into a frame or other
|
|
644
|
+
* context where the background is not expected to contribute to
|
|
645
|
+
* the final content.
|
|
646
|
+
*
|
|
647
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
648
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
649
|
+
* Because of the complication at the edges, this edging mode can
|
|
650
|
+
* be significantly slower than the others. It can be numerically
|
|
651
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
652
|
+
* is zero, which can result in division by zero during the computation.
|
|
653
|
+
* The results for this edging mode are usually quite visually similar
|
|
654
|
+
* to kvImageEdgeExtend.
|
|
655
|
+
*
|
|
656
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
657
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
658
|
+
* not touch the src or dest image.
|
|
659
|
+
*
|
|
660
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
661
|
+
*
|
|
662
|
+
* @/textblock </pre>
|
|
663
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
664
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
665
|
+
* be returned.
|
|
666
|
+
*
|
|
667
|
+
* @return One of the following error codes may be returned:
|
|
668
|
+
* <pre>@textblock
|
|
669
|
+
* kvImageNoError Success.
|
|
670
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
671
|
+
* the temp buffer to use with this function and this set of
|
|
672
|
+
* parameters.
|
|
673
|
+
*
|
|
674
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
675
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
676
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
677
|
+
*
|
|
678
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
679
|
+
* to corresponding dimensions of the source buffer.
|
|
680
|
+
*
|
|
681
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
682
|
+
*
|
|
683
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
684
|
+
*
|
|
685
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
686
|
+
*
|
|
687
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
688
|
+
*
|
|
689
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
690
|
+
* @/textblock </pre>
|
|
691
|
+
*/
|
|
692
|
+
VIMAGE_PF vImage_Error vImageConvolve_ARGB8888( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const int16_t *kernel, uint32_t kernel_height, uint32_t kernel_width, int32_t divisor, const Pixel_8888 backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.3), ios(5.0), watchos(1.0), tvos(5.0));
|
|
693
|
+
|
|
694
|
+
/*!
|
|
695
|
+
* @function vImageConvolve_ARGBFFFF
|
|
696
|
+
* @abstract General convolution on a ARGBFFFF image of any channel order.
|
|
697
|
+
* @discussion This filter applies a convolution filter of your choosing to a ARGBFFFF image.
|
|
698
|
+
* This filter will work on any four-channel, float per component image format, not just ARGB.
|
|
699
|
+
* For each pixel:
|
|
700
|
+
* <pre>@textblock
|
|
701
|
+
* for each pixel[y][x] in image{
|
|
702
|
+
* float sumA = 0;
|
|
703
|
+
* float sumR = 0;
|
|
704
|
+
* float sumG = 0;
|
|
705
|
+
* float sumB = 0;
|
|
706
|
+
*
|
|
707
|
+
* // Calculate weighted average over kernel area
|
|
708
|
+
* for each kernel_element[i][j] in kernel{
|
|
709
|
+
* sumA += kernel_element[i][j] *
|
|
710
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][0];
|
|
711
|
+
* sumR += kernel_element[i][j] *
|
|
712
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][1];
|
|
713
|
+
* sumG += kernel_element[i][j] *
|
|
714
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][2];
|
|
715
|
+
* sumB += kernel_element[i][j] *
|
|
716
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][3];
|
|
717
|
+
* }
|
|
718
|
+
*
|
|
719
|
+
* // write out result
|
|
720
|
+
* result[y][x][0] = sumA;
|
|
721
|
+
* result[y][x][1] = sumR;
|
|
722
|
+
* result[y][x][2] = sumG;
|
|
723
|
+
* result[y][x][3] = sumB;
|
|
724
|
+
* }
|
|
725
|
+
* @/textblock </pre>
|
|
726
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
727
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
728
|
+
* kernel_width.)
|
|
729
|
+
*
|
|
730
|
+
* This filter does not work in place.
|
|
731
|
+
*
|
|
732
|
+
* @param src The input image
|
|
733
|
+
*
|
|
734
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
735
|
+
* This may not alias the src image.
|
|
736
|
+
*
|
|
737
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
738
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
739
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
740
|
+
* the size is returned instead of an error code from the left hand side.
|
|
741
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
742
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
743
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
744
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
745
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
746
|
+
* concurrently, a different temp buffer should be used for each.
|
|
747
|
+
*
|
|
748
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
749
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
750
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
751
|
+
*
|
|
752
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
753
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
754
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
755
|
+
*
|
|
756
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
757
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
758
|
+
* <pre>@textblock
|
|
759
|
+
* const float kernel[9] = { 1./16, 2./16, 1./16,
|
|
760
|
+
* 2./16, 4./16, 2./16,
|
|
761
|
+
* 1./16, 2./16, 1./16 };
|
|
762
|
+
* @/textblock </pre>
|
|
763
|
+
*
|
|
764
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
765
|
+
*
|
|
766
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
767
|
+
*
|
|
768
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
769
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
770
|
+
* kernel extends off the edge of the image.
|
|
771
|
+
*
|
|
772
|
+
* @param flags The following flags are allowed:
|
|
773
|
+
* <pre>@textblock
|
|
774
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
775
|
+
* copy the corresponding source pixel to the destination. This
|
|
776
|
+
* will result in a ring off unconvolved content at the edges
|
|
777
|
+
* and convolved content in the middle.
|
|
778
|
+
*
|
|
779
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
780
|
+
* For a blur filter this will look like the edges of the image
|
|
781
|
+
* have been blurred into a particular color. This is usually
|
|
782
|
+
* appropriate when the color of the surface onto which the image
|
|
783
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
784
|
+
* as a background color, and let the downstream image compositor
|
|
785
|
+
* blend in the background color. In this case, the result image
|
|
786
|
+
* should be treated as a premultiplied image.
|
|
787
|
+
*
|
|
788
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
789
|
+
* This is better when the image is drawn into a frame or other
|
|
790
|
+
* context where the background is not expected to contribute to
|
|
791
|
+
* the final content.
|
|
792
|
+
*
|
|
793
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
794
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
795
|
+
* Because of the complication at the edges, this edging mode can
|
|
796
|
+
* be significantly slower than the others. It can be numerically
|
|
797
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
798
|
+
* is zero, which can result in division by zero during the computation.
|
|
799
|
+
* The results for this edging mode are usually quite visually similar
|
|
800
|
+
* to kvImageEdgeExtend.
|
|
801
|
+
*
|
|
802
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
803
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
804
|
+
* not touch the src or dest image.
|
|
805
|
+
*
|
|
806
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
807
|
+
*
|
|
808
|
+
* @/textblock </pre>
|
|
809
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
810
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
811
|
+
* be returned.
|
|
812
|
+
*
|
|
813
|
+
* @return One of the following error codes may be returned:
|
|
814
|
+
* <pre>@textblock
|
|
815
|
+
* kvImageNoError Success.
|
|
816
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
817
|
+
* the temp buffer to use with this function and this set of
|
|
818
|
+
* parameters.
|
|
819
|
+
*
|
|
820
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
821
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
822
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
823
|
+
*
|
|
824
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
825
|
+
* to corresponding dimensions of the source buffer.
|
|
826
|
+
*
|
|
827
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
828
|
+
*
|
|
829
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
830
|
+
*
|
|
831
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
832
|
+
*
|
|
833
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
834
|
+
*
|
|
835
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
836
|
+
* @/textblock </pre>
|
|
837
|
+
*/
|
|
838
|
+
VIMAGE_PF vImage_Error vImageConvolve_ARGBFFFF( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const float *kernel, uint32_t kernel_height, uint32_t kernel_width, const Pixel_FFFF backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.3), ios(5.0), watchos(1.0), tvos(5.0));
|
|
839
|
+
|
|
840
|
+
/*!
|
|
841
|
+
* @function vImageConvolve_ARGB16F
|
|
842
|
+
* @abstract General convolution on a ARGB16F image of any channel order.
|
|
843
|
+
* @discussion This filter applies a convolution filter of your choosing to a ARGB16F image.
|
|
844
|
+
* This filter will work on any four-channel, half-float per component image format, not just ARGB.
|
|
845
|
+
* The kernel values are specified as 32-bit single-precision floats and the
|
|
846
|
+
* weighted average is also computed in single precision by default. However, if
|
|
847
|
+
* the flag kvImageUseFP16Accumulator is set all internal filtering operations will
|
|
848
|
+
* use 16-bit half-precision floating-point arithmetic when the CPU architecture
|
|
849
|
+
* supports it. This results in up to 2x performance improvements but at the
|
|
850
|
+
* expense of a less precise result; typically 2-3 bits of precision is lost.
|
|
851
|
+
*
|
|
852
|
+
* For each pixel:
|
|
853
|
+
* <pre>@textblock
|
|
854
|
+
* for each pixel[y][x] in image{
|
|
855
|
+
* // Sums are declared as type _Float16 when the flag kvImageUseFP16Accumulator is set
|
|
856
|
+
* float sumA = 0;
|
|
857
|
+
* float sumR = 0;
|
|
858
|
+
* float sumG = 0;
|
|
859
|
+
* float sumB = 0;
|
|
860
|
+
*
|
|
861
|
+
* // Calculate weighted average over kernel area
|
|
862
|
+
* for each kernel_element[i][j] in kernel{
|
|
863
|
+
* sumA += kernel_element[i][j] *
|
|
864
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][0];
|
|
865
|
+
* sumR += kernel_element[i][j] *
|
|
866
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][1];
|
|
867
|
+
* sumG += kernel_element[i][j] *
|
|
868
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][2];
|
|
869
|
+
* sumB += kernel_element[i][j] *
|
|
870
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][3];
|
|
871
|
+
* }
|
|
872
|
+
*
|
|
873
|
+
* // write out result
|
|
874
|
+
* result[y][x][0] = (_Float16)sumA;
|
|
875
|
+
* result[y][x][1] = (_Float16)sumR;
|
|
876
|
+
* result[y][x][2] = (_Float16)sumG;
|
|
877
|
+
* result[y][x][3] = (_Float16)sumB;
|
|
878
|
+
* }
|
|
879
|
+
* @/textblock </pre>
|
|
880
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
881
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
882
|
+
* kernel_width.)
|
|
883
|
+
*
|
|
884
|
+
* This filter does not work in place.
|
|
885
|
+
*
|
|
886
|
+
* @param src The input image
|
|
887
|
+
*
|
|
888
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
889
|
+
* This may not alias the src image.
|
|
890
|
+
*
|
|
891
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
892
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
893
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
894
|
+
* the size is returned instead of an error code from the left hand side.
|
|
895
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
896
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
897
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
898
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
899
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
900
|
+
* concurrently, a different temp buffer should be used for each.
|
|
901
|
+
*
|
|
902
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
903
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
904
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
905
|
+
*
|
|
906
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
907
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
908
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
909
|
+
*
|
|
910
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
911
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
912
|
+
* <pre>@textblock
|
|
913
|
+
* const float kernel[9] = { 1./16, 2./16, 1./16,
|
|
914
|
+
* 2./16, 4./16, 2./16,
|
|
915
|
+
* 1./16, 2./16, 1./16 };
|
|
916
|
+
* @/textblock </pre>
|
|
917
|
+
*
|
|
918
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
919
|
+
*
|
|
920
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
921
|
+
*
|
|
922
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
923
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
924
|
+
* kernel extends off the edge of the image.
|
|
925
|
+
*
|
|
926
|
+
* @param flags The following flags are allowed:
|
|
927
|
+
* <pre>@textblock
|
|
928
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
929
|
+
* copy the corresponding source pixel to the destination. This
|
|
930
|
+
* will result in a ring off unconvolved content at the edges
|
|
931
|
+
* and convolved content in the middle.
|
|
932
|
+
*
|
|
933
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
934
|
+
* For a blur filter this will look like the edges of the image
|
|
935
|
+
* have been blurred into a particular color. This is usually
|
|
936
|
+
* appropriate when the color of the surface onto which the image
|
|
937
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
938
|
+
* as a background color, and let the downstream image compositor
|
|
939
|
+
* blend in the background color. In this case, the result image
|
|
940
|
+
* should be treated as a premultiplied image.
|
|
941
|
+
*
|
|
942
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
943
|
+
* This is better when the image is drawn into a frame or other
|
|
944
|
+
* context where the background is not expected to contribute to
|
|
945
|
+
* the final content.
|
|
946
|
+
*
|
|
947
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
948
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
949
|
+
* Because of the complication at the edges, this edging mode can
|
|
950
|
+
* be significantly slower than the others. It can be numerically
|
|
951
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
952
|
+
* is zero, which can result in division by zero during the computation.
|
|
953
|
+
* The results for this edging mode are usually quite visually similar
|
|
954
|
+
* to kvImageEdgeExtend.
|
|
955
|
+
*
|
|
956
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
957
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
958
|
+
* not touch the src or dest image.
|
|
959
|
+
*
|
|
960
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
961
|
+
*
|
|
962
|
+
* kvImageUseFP16Accumulator Enable 16-bit half-precision floating-point arithmetic when computing the
|
|
963
|
+
* kernel averages when the CPU architecture supports it.
|
|
964
|
+
*
|
|
965
|
+
* @/textblock </pre>
|
|
966
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
967
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
968
|
+
* be returned.
|
|
969
|
+
*
|
|
970
|
+
* @return One of the following error codes may be returned:
|
|
971
|
+
* <pre>@textblock
|
|
972
|
+
* kvImageNoError Success.
|
|
973
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
974
|
+
* the temp buffer to use with this function and this set of
|
|
975
|
+
* parameters.
|
|
976
|
+
*
|
|
977
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
978
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
979
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
980
|
+
*
|
|
981
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
982
|
+
* to corresponding dimensions of the source buffer.
|
|
983
|
+
*
|
|
984
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
985
|
+
*
|
|
986
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
987
|
+
*
|
|
988
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
989
|
+
*
|
|
990
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
991
|
+
*
|
|
992
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
993
|
+
* @/textblock </pre>
|
|
994
|
+
*/
|
|
995
|
+
VIMAGE_PF vImage_Error vImageConvolve_ARGB16F( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const float *kernel, uint32_t kernel_height, uint32_t kernel_width, const Pixel_ARGB_16F backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(13.0), ios(16.0), watchos(9.0), tvos(16.0));
|
|
996
|
+
|
|
997
|
+
/*!
|
|
998
|
+
* @function vImageConvolveWithBias_Planar8
|
|
999
|
+
* @abstract General convolution on a Planar8 image with added bias.
|
|
1000
|
+
* @discussion This filter applies a convolution filter of your choosing to a Planar8 image.
|
|
1001
|
+
* For each pixel:
|
|
1002
|
+
* <pre>@textblock
|
|
1003
|
+
* for each pixel[y][x] in image{
|
|
1004
|
+
* int sum = 0;
|
|
1005
|
+
*
|
|
1006
|
+
* // Calculate weighted average over kernel area
|
|
1007
|
+
* for each kernel_element[i][j] in kernel{
|
|
1008
|
+
* sum += kernel_element[i][j] *
|
|
1009
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
1010
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
1011
|
+
* }
|
|
1012
|
+
* // Correct for the scaling introduced by multiplying by the weights table
|
|
1013
|
+
* sum = (sum + bias) / divisor;
|
|
1014
|
+
*
|
|
1015
|
+
* // write out result
|
|
1016
|
+
* result[y][x] = CLAMP(sum, 0, 255);
|
|
1017
|
+
* }
|
|
1018
|
+
* @/textblock </pre>
|
|
1019
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
1020
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
1021
|
+
* kernel_width.)
|
|
1022
|
+
*
|
|
1023
|
+
* This filter does not work in place.
|
|
1024
|
+
*
|
|
1025
|
+
* @param src The input image
|
|
1026
|
+
*
|
|
1027
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
1028
|
+
* This may not alias the src image.
|
|
1029
|
+
*
|
|
1030
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
1031
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
1032
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
1033
|
+
* the size is returned instead of an error code from the left hand side.
|
|
1034
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
1035
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
1036
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
1037
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
1038
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
1039
|
+
* concurrently, a different temp buffer should be used for each.
|
|
1040
|
+
*
|
|
1041
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
1042
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1043
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
1044
|
+
*
|
|
1045
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
1046
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1047
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
1048
|
+
*
|
|
1049
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
1050
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
1051
|
+
* <pre>@textblock
|
|
1052
|
+
* const int16_t kernel[9] = { 1, 2, 1,
|
|
1053
|
+
* 2, 4, 2,
|
|
1054
|
+
* 1, 2, 1 };
|
|
1055
|
+
* @/textblock </pre>
|
|
1056
|
+
*
|
|
1057
|
+
* The kernel values may not sum in any combination to be outside the range
|
|
1058
|
+
* [-2**23, 2**23), or modulo overflow in the accumulator may result.
|
|
1059
|
+
*
|
|
1060
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1061
|
+
*
|
|
1062
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1063
|
+
*
|
|
1064
|
+
* @param divisor The weighted sum of nearby pixels is typically a large number, which must be corrected
|
|
1065
|
+
* to fit back into the image format of the destination image. The correction factor
|
|
1066
|
+
* is passed in as divisor here, and is divided from the sum before the result is
|
|
1067
|
+
* returned. Typically, the divisor is the sum over the area of the kernel. If the divisor
|
|
1068
|
+
* is 0, 1 will be used instead.
|
|
1069
|
+
*
|
|
1070
|
+
* @param bias This value is added to the sum of weighted pixels before the divisor is applied.
|
|
1071
|
+
* It can serve to both control rounding and adjust the brightness of the result.
|
|
1072
|
+
* A large bias (e.g 128 * divisor) may be required for some kernels to return
|
|
1073
|
+
* representable results, such as edge detection filters.
|
|
1074
|
+
*
|
|
1075
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
1076
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
1077
|
+
* kernel extends off the edge of the image.
|
|
1078
|
+
*
|
|
1079
|
+
* @param flags The following flags are allowed:
|
|
1080
|
+
* <pre>@textblock
|
|
1081
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
1082
|
+
* copy the corresponding source pixel to the destination. This
|
|
1083
|
+
* will result in a ring off unconvolved content at the edges
|
|
1084
|
+
* and convolved content in the middle.
|
|
1085
|
+
*
|
|
1086
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
1087
|
+
* For a blur filter this will look like the edges of the image
|
|
1088
|
+
* have been blurred into a particular color. This is usually
|
|
1089
|
+
* appropriate when the color of the surface onto which the image
|
|
1090
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
1091
|
+
* as a background color, and let the downstream image compositor
|
|
1092
|
+
* blend in the background color. In this case, the result image
|
|
1093
|
+
* should be treated as a premultiplied image.
|
|
1094
|
+
*
|
|
1095
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
1096
|
+
* This is better when the image is drawn into a frame or other
|
|
1097
|
+
* context where the background is not expected to contribute to
|
|
1098
|
+
* the final content.
|
|
1099
|
+
*
|
|
1100
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
1101
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
1102
|
+
* Because of the complication at the edges, this edging mode can
|
|
1103
|
+
* be significantly slower than the others. It can be numerically
|
|
1104
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
1105
|
+
* is zero, which can result in division by zero during the computation.
|
|
1106
|
+
* The results for this edging mode are usually quite visually similar
|
|
1107
|
+
* to kvImageEdgeExtend.
|
|
1108
|
+
*
|
|
1109
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
1110
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
1111
|
+
* not touch the src or dest image.
|
|
1112
|
+
*
|
|
1113
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
1114
|
+
*
|
|
1115
|
+
* @/textblock </pre>
|
|
1116
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
1117
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
1118
|
+
* be returned.
|
|
1119
|
+
*
|
|
1120
|
+
* @return One of the following error codes may be returned:
|
|
1121
|
+
* <pre>@textblock
|
|
1122
|
+
* kvImageNoError Success.
|
|
1123
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
1124
|
+
* the temp buffer to use with this function and this set of
|
|
1125
|
+
* parameters.
|
|
1126
|
+
*
|
|
1127
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
1128
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
1129
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
1130
|
+
*
|
|
1131
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
1132
|
+
* to corresponding dimensions of the source buffer.
|
|
1133
|
+
*
|
|
1134
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
1135
|
+
*
|
|
1136
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
1137
|
+
*
|
|
1138
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
1139
|
+
*
|
|
1140
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
1141
|
+
*
|
|
1142
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
1143
|
+
* @/textblock </pre>
|
|
1144
|
+
*/
|
|
1145
|
+
VIMAGE_PF vImage_Error vImageConvolveWithBias_Planar8( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const int16_t *kernel, uint32_t kernel_height, uint32_t kernel_width, int32_t divisor, int32_t bias, Pixel_8 backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
1146
|
+
|
|
1147
|
+
/*!
|
|
1148
|
+
* @function vImageConvolveWithBias_PlanarF
|
|
1149
|
+
* @abstract General convolution on a PlanarF image with added bias.
|
|
1150
|
+
* @discussion This filter applies a convolution filter of your choosing to a PlanarF image.
|
|
1151
|
+
* For each pixel:
|
|
1152
|
+
* <pre>@textblock
|
|
1153
|
+
* for each pixel[y][x] in image{
|
|
1154
|
+
* float sum = bias;
|
|
1155
|
+
*
|
|
1156
|
+
* // Calculate weighted average over kernel area
|
|
1157
|
+
* for each kernel_element[i][j] in kernel{
|
|
1158
|
+
* sum += kernel_element[i][j] *
|
|
1159
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
1160
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
1161
|
+
* }
|
|
1162
|
+
*
|
|
1163
|
+
* // write out result
|
|
1164
|
+
* result[y][x] = sum;
|
|
1165
|
+
* }
|
|
1166
|
+
* @/textblock </pre>
|
|
1167
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
1168
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
1169
|
+
* kernel_width.)
|
|
1170
|
+
*
|
|
1171
|
+
* This filter does not work in place.
|
|
1172
|
+
*
|
|
1173
|
+
* @param src The input image
|
|
1174
|
+
*
|
|
1175
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
1176
|
+
* This may not alias the src image.
|
|
1177
|
+
*
|
|
1178
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
1179
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
1180
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
1181
|
+
* the size is returned instead of an error code from the left hand side.
|
|
1182
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
1183
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
1184
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
1185
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
1186
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
1187
|
+
* concurrently, a different temp buffer should be used for each.
|
|
1188
|
+
*
|
|
1189
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
1190
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1191
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
1192
|
+
*
|
|
1193
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
1194
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1195
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
1196
|
+
*
|
|
1197
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
1198
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
1199
|
+
* <pre>@textblock
|
|
1200
|
+
* const float kernel[9] = { 1./16, 2./16, 1./16,
|
|
1201
|
+
* 2./16, 4./16, 2./16,
|
|
1202
|
+
* 1./16, 2./16, 1./16 };
|
|
1203
|
+
* @/textblock </pre>
|
|
1204
|
+
*
|
|
1205
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1206
|
+
*
|
|
1207
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1208
|
+
*
|
|
1209
|
+
* @param bias This value is added to the sum of weighted pixels.
|
|
1210
|
+
*
|
|
1211
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
1212
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
1213
|
+
* kernel extends off the edge of the image.
|
|
1214
|
+
*
|
|
1215
|
+
* @param flags The following flags are allowed:
|
|
1216
|
+
* <pre>@textblock
|
|
1217
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
1218
|
+
* copy the corresponding source pixel to the destination. This
|
|
1219
|
+
* will result in a ring off unconvolved content at the edges
|
|
1220
|
+
* and convolved content in the middle.
|
|
1221
|
+
*
|
|
1222
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
1223
|
+
* For a blur filter this will look like the edges of the image
|
|
1224
|
+
* have been blurred into a particular color. This is usually
|
|
1225
|
+
* appropriate when the color of the surface onto which the image
|
|
1226
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
1227
|
+
* as a background color, and let the downstream image compositor
|
|
1228
|
+
* blend in the background color. In this case, the result image
|
|
1229
|
+
* should be treated as a premultiplied image.
|
|
1230
|
+
*
|
|
1231
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
1232
|
+
* This is better when the image is drawn into a frame or other
|
|
1233
|
+
* context where the background is not expected to contribute to
|
|
1234
|
+
* the final content.
|
|
1235
|
+
*
|
|
1236
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
1237
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
1238
|
+
* Because of the complication at the edges, this edging mode can
|
|
1239
|
+
* be significantly slower than the others. It can be numerically
|
|
1240
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
1241
|
+
* is zero, which can result in division by zero during the computation.
|
|
1242
|
+
* The results for this edging mode are usually quite visually similar
|
|
1243
|
+
* to kvImageEdgeExtend.
|
|
1244
|
+
*
|
|
1245
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
1246
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
1247
|
+
* not touch the src or dest image.
|
|
1248
|
+
*
|
|
1249
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
1250
|
+
*
|
|
1251
|
+
* @/textblock </pre>
|
|
1252
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
1253
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
1254
|
+
* be returned.
|
|
1255
|
+
*
|
|
1256
|
+
* @return One of the following error codes may be returned:
|
|
1257
|
+
* <pre>@textblock
|
|
1258
|
+
* kvImageNoError Success.
|
|
1259
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
1260
|
+
* the temp buffer to use with this function and this set of
|
|
1261
|
+
* parameters.
|
|
1262
|
+
*
|
|
1263
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
1264
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
1265
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
1266
|
+
*
|
|
1267
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
1268
|
+
* to corresponding dimensions of the source buffer.
|
|
1269
|
+
*
|
|
1270
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
1271
|
+
*
|
|
1272
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
1273
|
+
*
|
|
1274
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
1275
|
+
*
|
|
1276
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
1277
|
+
*
|
|
1278
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
1279
|
+
* @/textblock </pre>
|
|
1280
|
+
*/
|
|
1281
|
+
VIMAGE_PF vImage_Error vImageConvolveWithBias_PlanarF( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const float *kernel, uint32_t kernel_height, uint32_t kernel_width, float bias, Pixel_F backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
1282
|
+
|
|
1283
|
+
/*!
|
|
1284
|
+
* @function vImageConvolveWithBias_Planar16F
|
|
1285
|
+
* @abstract General convolution on a Planar16F image.
|
|
1286
|
+
* @discussion This filter applies a convolution filter of your choosing to a Planar16F image.
|
|
1287
|
+
* The kernel values are specified as 32-bit single-precision floats and the
|
|
1288
|
+
* weighted average is also computed in single precision by default. However, if
|
|
1289
|
+
* the flag kvImageUseFP16Accumulator is set all internal filtering operations will
|
|
1290
|
+
* use 16-bit half-precision floating-point arithmetic when the CPU architecture
|
|
1291
|
+
* supports it. This results in up to 2x performance improvements but at the
|
|
1292
|
+
* expense of a less precise result; typically 2-3 bits of precision is lost.
|
|
1293
|
+
*
|
|
1294
|
+
* For each pixel:
|
|
1295
|
+
* <pre>@textblock
|
|
1296
|
+
* for each pixel[y][x] in image{
|
|
1297
|
+
* // sum is declared as type _Float16 when the flag kvImageUseFP16Accumulator is set
|
|
1298
|
+
* float sum = bias;
|
|
1299
|
+
*
|
|
1300
|
+
* // Calculate weighted average over kernel area
|
|
1301
|
+
* for each kernel_element[i][j] in kernel{
|
|
1302
|
+
* sum += kernel_element[i][j] *
|
|
1303
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
1304
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
1305
|
+
* }
|
|
1306
|
+
*
|
|
1307
|
+
* // write out result
|
|
1308
|
+
* result[y][x] = (_Float16)sum;
|
|
1309
|
+
* }
|
|
1310
|
+
* @/textblock </pre>
|
|
1311
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
1312
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
1313
|
+
* kernel_width.)
|
|
1314
|
+
*
|
|
1315
|
+
* This filter does not work in place.
|
|
1316
|
+
*
|
|
1317
|
+
* @param src The input image
|
|
1318
|
+
*
|
|
1319
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
1320
|
+
* This may not alias the src image.
|
|
1321
|
+
*
|
|
1322
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
1323
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
1324
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
1325
|
+
* the size is returned instead of an error code from the left hand side.
|
|
1326
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
1327
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
1328
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
1329
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
1330
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
1331
|
+
* concurrently, a different temp buffer should be used for each.
|
|
1332
|
+
*
|
|
1333
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
1334
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1335
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
1336
|
+
*
|
|
1337
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
1338
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1339
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
1340
|
+
*
|
|
1341
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
1342
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
1343
|
+
* <pre>@textblock
|
|
1344
|
+
* const float kernel[9] = { 1./16, 2./16, 1./16,
|
|
1345
|
+
* 2./16, 4./16, 2./16,
|
|
1346
|
+
* 1./16, 2./16, 1./16 };
|
|
1347
|
+
* @/textblock </pre>
|
|
1348
|
+
*
|
|
1349
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1350
|
+
*
|
|
1351
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1352
|
+
*
|
|
1353
|
+
* @param bias This value is added to the sum of weighted pixels.
|
|
1354
|
+
*
|
|
1355
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
1356
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
1357
|
+
* kernel extends off the edge of the image.
|
|
1358
|
+
*
|
|
1359
|
+
* @param flags The following flags are allowed:
|
|
1360
|
+
* <pre>@textblock
|
|
1361
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
1362
|
+
* copy the corresponding source pixel to the destination. This
|
|
1363
|
+
* will result in a ring off unconvolved content at the edges
|
|
1364
|
+
* and convolved content in the middle.
|
|
1365
|
+
*
|
|
1366
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
1367
|
+
* For a blur filter this will look like the edges of the image
|
|
1368
|
+
* have been blurred into a particular color. This is usually
|
|
1369
|
+
* appropriate when the color of the surface onto which the image
|
|
1370
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
1371
|
+
* as a background color, and let the downstream image compositor
|
|
1372
|
+
* blend in the background color. In this case, the result image
|
|
1373
|
+
* should be treated as a premultiplied image.
|
|
1374
|
+
*
|
|
1375
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
1376
|
+
* This is better when the image is drawn into a frame or other
|
|
1377
|
+
* context where the background is not expected to contribute to
|
|
1378
|
+
* the final content.
|
|
1379
|
+
*
|
|
1380
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
1381
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
1382
|
+
* Because of the complication at the edges, this edging mode can
|
|
1383
|
+
* be significantly slower than the others. It can be numerically
|
|
1384
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
1385
|
+
* is zero, which can result in division by zero during the computation.
|
|
1386
|
+
* The results for this edging mode are usually quite visually similar
|
|
1387
|
+
* to kvImageEdgeExtend.
|
|
1388
|
+
*
|
|
1389
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
1390
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
1391
|
+
* not touch the src or dest image.
|
|
1392
|
+
*
|
|
1393
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
1394
|
+
*
|
|
1395
|
+
* kvImageUseFP16Accumulator Enable 16-bit half-precision floating-point arithmetic when computing the
|
|
1396
|
+
* kernel averages when the CPU architecture supports it.
|
|
1397
|
+
*
|
|
1398
|
+
* @/textblock </pre>
|
|
1399
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
1400
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
1401
|
+
* be returned.
|
|
1402
|
+
*
|
|
1403
|
+
* @return One of the following error codes may be returned:
|
|
1404
|
+
* <pre>@textblock
|
|
1405
|
+
* kvImageNoError Success.
|
|
1406
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
1407
|
+
* the temp buffer to use with this function and this set of
|
|
1408
|
+
* parameters.
|
|
1409
|
+
*
|
|
1410
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
1411
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
1412
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
1413
|
+
*
|
|
1414
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
1415
|
+
* to corresponding dimensions of the source buffer.
|
|
1416
|
+
*
|
|
1417
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
1418
|
+
*
|
|
1419
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
1420
|
+
*
|
|
1421
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
1422
|
+
*
|
|
1423
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
1424
|
+
*
|
|
1425
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
1426
|
+
* @/textblock </pre>
|
|
1427
|
+
*/
|
|
1428
|
+
VIMAGE_PF vImage_Error vImageConvolveWithBias_Planar16F( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const float *kernel, uint32_t kernel_height, uint32_t kernel_width, float bias, Pixel_16F backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(13.0), ios(16.0), watchos(9.0), tvos(16.0));
|
|
1429
|
+
|
|
1430
|
+
/*!
|
|
1431
|
+
* @function vImageConvolveWithBias_ARGB8888
|
|
1432
|
+
* @abstract General convolution on a ARGB888 image of any channel order with bias.
|
|
1433
|
+
* @discussion This filter applies a convolution filter of your choosing to a ARGB8888 image.
|
|
1434
|
+
* This filter will work on any four-channel, 8-bit per component image format, not just ARGB.
|
|
1435
|
+
* For each pixel:
|
|
1436
|
+
* <pre>@textblock
|
|
1437
|
+
* for each pixel[y][x] in image{
|
|
1438
|
+
* int sumA = 0;
|
|
1439
|
+
* int sumR = 0;
|
|
1440
|
+
* int sumG = 0;
|
|
1441
|
+
* int sumB = 0;
|
|
1442
|
+
*
|
|
1443
|
+
* // Calculate weighted average over kernel area
|
|
1444
|
+
* for each kernel_element[i][j] in kernel{
|
|
1445
|
+
* sumA += kernel_element[i][j] *
|
|
1446
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][0];
|
|
1447
|
+
* sumR += kernel_element[i][j] *
|
|
1448
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][1];
|
|
1449
|
+
* sumG += kernel_element[i][j] *
|
|
1450
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][2];
|
|
1451
|
+
* sumB += kernel_element[i][j] *
|
|
1452
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][3];
|
|
1453
|
+
* }
|
|
1454
|
+
* // Correct for the scaling introduced by multiplying by the weights table
|
|
1455
|
+
* sumA = (sumA + bias[0]) / divisor;
|
|
1456
|
+
* sumR = (sumR + bias[1]) / divisor;
|
|
1457
|
+
* sumG = (sumG + bias[2]) / divisor;
|
|
1458
|
+
* sumB = (sumB + bias[3]) / divisor;
|
|
1459
|
+
*
|
|
1460
|
+
* // write out result
|
|
1461
|
+
* result[y][x][0] = CLAMP(sumA, 0, 255);
|
|
1462
|
+
* result[y][x][1] = CLAMP(sumR, 0, 255);
|
|
1463
|
+
* result[y][x][2] = CLAMP(sumG, 0, 255);
|
|
1464
|
+
* result[y][x][3] = CLAMP(sumB, 0, 255);
|
|
1465
|
+
* }
|
|
1466
|
+
* @/textblock </pre>
|
|
1467
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
1468
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
1469
|
+
* kernel_width.)
|
|
1470
|
+
*
|
|
1471
|
+
* This filter does not work in place.
|
|
1472
|
+
*
|
|
1473
|
+
*
|
|
1474
|
+
* @param src The input image
|
|
1475
|
+
*
|
|
1476
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
1477
|
+
* This may not alias the src image.
|
|
1478
|
+
*
|
|
1479
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
1480
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
1481
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
1482
|
+
* the size is returned instead of an error code from the left hand side.
|
|
1483
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
1484
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
1485
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
1486
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
1487
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
1488
|
+
* concurrently, a different temp buffer should be used for each.
|
|
1489
|
+
*
|
|
1490
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
1491
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1492
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
1493
|
+
*
|
|
1494
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
1495
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1496
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
1497
|
+
*
|
|
1498
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
1499
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
1500
|
+
* <pre>@textblock
|
|
1501
|
+
* const int16_t kernel[9] = { 1, 2, 1,
|
|
1502
|
+
* 2, 4, 2,
|
|
1503
|
+
* 1, 2, 1 };
|
|
1504
|
+
* @/textblock </pre>
|
|
1505
|
+
*
|
|
1506
|
+
* The kernel values may not sum in any combination to be outside the range
|
|
1507
|
+
* [-2**23, 2**23), or modulo overflow in the accumulator may result.
|
|
1508
|
+
*
|
|
1509
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1510
|
+
*
|
|
1511
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1512
|
+
*
|
|
1513
|
+
* @param divisor The weighted sum of nearby pixels is typically a large number, which must be corrected
|
|
1514
|
+
* to fit back into the image format of the destination image. The correction factor
|
|
1515
|
+
* is passed in as divisor here, and is divided from the sum before the result is
|
|
1516
|
+
* returned. Typically, the divisor is the sum over the area of the kernel. If the divisor
|
|
1517
|
+
* is 0, 1 will be used instead.
|
|
1518
|
+
*
|
|
1519
|
+
* @param bias This value is added to the sum of weighted pixels before the divisor is applied.
|
|
1520
|
+
* It can serve to both control rounding and adjust the brightness of the result.
|
|
1521
|
+
* A large bias (e.g 128 * divisor) may be required for some kernels, such as edge
|
|
1522
|
+
* detection filters, to return representable results.
|
|
1523
|
+
*
|
|
1524
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
1525
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
1526
|
+
* kernel extends off the edge of the image.
|
|
1527
|
+
*
|
|
1528
|
+
* @param flags The following flags are allowed:
|
|
1529
|
+
* <pre>@textblock
|
|
1530
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
1531
|
+
* copy the corresponding source pixel to the destination. This
|
|
1532
|
+
* will result in a ring off unconvolved content at the edges
|
|
1533
|
+
* and convolved content in the middle.
|
|
1534
|
+
*
|
|
1535
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
1536
|
+
* For a blur filter this will look like the edges of the image
|
|
1537
|
+
* have been blurred into a particular color. This is usually
|
|
1538
|
+
* appropriate when the color of the surface onto which the image
|
|
1539
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
1540
|
+
* as a background color, and let the downstream image compositor
|
|
1541
|
+
* blend in the background color. In this case, the result image
|
|
1542
|
+
* should be treated as a premultiplied image.
|
|
1543
|
+
*
|
|
1544
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
1545
|
+
* This is better when the image is drawn into a frame or other
|
|
1546
|
+
* context where the background is not expected to contribute to
|
|
1547
|
+
* the final content.
|
|
1548
|
+
*
|
|
1549
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
1550
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
1551
|
+
* Because of the complication at the edges, this edging mode can
|
|
1552
|
+
* be significantly slower than the others. It can be numerically
|
|
1553
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
1554
|
+
* is zero, which can result in division by zero during the computation.
|
|
1555
|
+
* The results for this edging mode are usually quite visually similar
|
|
1556
|
+
* to kvImageEdgeExtend.
|
|
1557
|
+
*
|
|
1558
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
1559
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
1560
|
+
* not touch the src or dest image.
|
|
1561
|
+
*
|
|
1562
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
1563
|
+
*
|
|
1564
|
+
* @/textblock </pre>
|
|
1565
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
1566
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
1567
|
+
* be returned.
|
|
1568
|
+
*
|
|
1569
|
+
* @return One of the following error codes may be returned:
|
|
1570
|
+
* <pre>@textblock
|
|
1571
|
+
* kvImageNoError Success.
|
|
1572
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
1573
|
+
* the temp buffer to use with this function and this set of
|
|
1574
|
+
* parameters.
|
|
1575
|
+
*
|
|
1576
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
1577
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
1578
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
1579
|
+
*
|
|
1580
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
1581
|
+
* to corresponding dimensions of the source buffer.
|
|
1582
|
+
*
|
|
1583
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
1584
|
+
*
|
|
1585
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
1586
|
+
*
|
|
1587
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
1588
|
+
*
|
|
1589
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
1590
|
+
*
|
|
1591
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
1592
|
+
* @/textblock </pre>
|
|
1593
|
+
*/
|
|
1594
|
+
VIMAGE_PF vImage_Error vImageConvolveWithBias_ARGB8888( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const int16_t *kernel, uint32_t kernel_height, uint32_t kernel_width, int32_t divisor, int32_t bias, const Pixel_8888 backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
1595
|
+
|
|
1596
|
+
/*!
|
|
1597
|
+
* @function vImageConvolveFloatKernel_ARGB8888
|
|
1598
|
+
* @abstract General convolution on a ARGB888 image of any channel order with a kernel with floating-point weights.
|
|
1599
|
+
* @discussion Performs a filtering operation just like vImageConvolveWithBias_ARGB8888 but with a float rather than an integer (with divisor) kernel.
|
|
1600
|
+
*
|
|
1601
|
+
*/
|
|
1602
|
+
VIMAGE_PF vImage_Error vImageConvolveFloatKernel_ARGB8888( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const float *kernel, uint32_t kernelHeight, uint32_t kernelWidth, float bias, const Pixel_8888 backgroundColor, vImage_Flags flags)
|
|
1603
|
+
VIMAGE_NON_NULL(1,2) __API_AVAILABLE(macos(14.0), ios(17.0), watchos(10.0), tvos(17.0));
|
|
1604
|
+
|
|
1605
|
+
/*!
|
|
1606
|
+
* @function vImageConvolveWithBias_ARGBFFFF
|
|
1607
|
+
* @abstract General convolution on a ARGBFFFF image of any channel order with bias.
|
|
1608
|
+
* @discussion This filter applies a convolution filter of your choosing to a ARGBFFFF image.
|
|
1609
|
+
* This filter will work on any four-channel, float per component image format, not just ARGB.
|
|
1610
|
+
* For each pixel:
|
|
1611
|
+
* <pre>@textblock
|
|
1612
|
+
* for each pixel[y][x] in image{
|
|
1613
|
+
* float sumA = bias[0];
|
|
1614
|
+
* float sumR = bias[1];
|
|
1615
|
+
* float sumG = bias[2];
|
|
1616
|
+
* float sumB = bias[3];
|
|
1617
|
+
*
|
|
1618
|
+
* // Calculate weighted average over kernel area
|
|
1619
|
+
* for each kernel_element[i][j] in kernel{
|
|
1620
|
+
* sumA += kernel_element[i][j] *
|
|
1621
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][0];
|
|
1622
|
+
* sumR += kernel_element[i][j] *
|
|
1623
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][1];
|
|
1624
|
+
* sumG += kernel_element[i][j] *
|
|
1625
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][2];
|
|
1626
|
+
* sumB += kernel_element[i][j] *
|
|
1627
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][3];
|
|
1628
|
+
* }
|
|
1629
|
+
*
|
|
1630
|
+
* // write out result
|
|
1631
|
+
* result[y][x][0] = sumA;
|
|
1632
|
+
* result[y][x][1] = sumR;
|
|
1633
|
+
* result[y][x][2] = sumG;
|
|
1634
|
+
* result[y][x][3] = sumB;
|
|
1635
|
+
* }
|
|
1636
|
+
* @/textblock </pre>
|
|
1637
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
1638
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
1639
|
+
* kernel_width.)
|
|
1640
|
+
*
|
|
1641
|
+
* This filter does not work in place.
|
|
1642
|
+
*
|
|
1643
|
+
* @param src The input image
|
|
1644
|
+
*
|
|
1645
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
1646
|
+
* This may not alias the src image.
|
|
1647
|
+
*
|
|
1648
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
1649
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
1650
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
1651
|
+
* the size is returned instead of an error code from the left hand side.
|
|
1652
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
1653
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
1654
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
1655
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
1656
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
1657
|
+
* concurrently, a different temp buffer should be used for each.
|
|
1658
|
+
*
|
|
1659
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
1660
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1661
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
1662
|
+
*
|
|
1663
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
1664
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1665
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
1666
|
+
*
|
|
1667
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
1668
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
1669
|
+
* <pre>@textblock
|
|
1670
|
+
* const float kernel[9] = { 1./16, 2./16, 1./16,
|
|
1671
|
+
* 2./16, 4./16, 2./16,
|
|
1672
|
+
* 1./16, 2./16, 1./16 };
|
|
1673
|
+
* @/textblock </pre>
|
|
1674
|
+
*
|
|
1675
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1676
|
+
*
|
|
1677
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1678
|
+
*
|
|
1679
|
+
* @param bias This value is added to the sum of weighted pixels.
|
|
1680
|
+
*
|
|
1681
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
1682
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
1683
|
+
* kernel extends off the edge of the image.
|
|
1684
|
+
*
|
|
1685
|
+
* @param flags The following flags are allowed:
|
|
1686
|
+
* <pre>@textblock
|
|
1687
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
1688
|
+
* copy the corresponding source pixel to the destination. This
|
|
1689
|
+
* will result in a ring off unconvolved content at the edges
|
|
1690
|
+
* and convolved content in the middle.
|
|
1691
|
+
*
|
|
1692
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
1693
|
+
* For a blur filter this will look like the edges of the image
|
|
1694
|
+
* have been blurred into a particular color. This is usually
|
|
1695
|
+
* appropriate when the color of the surface onto which the image
|
|
1696
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
1697
|
+
* as a background color, and let the downstream image compositor
|
|
1698
|
+
* blend in the background color. In this case, the result image
|
|
1699
|
+
* should be treated as a premultiplied image.
|
|
1700
|
+
*
|
|
1701
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
1702
|
+
* This is better when the image is drawn into a frame or other
|
|
1703
|
+
* context where the background is not expected to contribute to
|
|
1704
|
+
* the final content.
|
|
1705
|
+
*
|
|
1706
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
1707
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
1708
|
+
* Because of the complication at the edges, this edging mode can
|
|
1709
|
+
* be significantly slower than the others. It can be numerically
|
|
1710
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
1711
|
+
* is zero, which can result in division by zero during the computation.
|
|
1712
|
+
* The results for this edging mode are usually quite visually similar
|
|
1713
|
+
* to kvImageEdgeExtend.
|
|
1714
|
+
*
|
|
1715
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
1716
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
1717
|
+
* not touch the src or dest image.
|
|
1718
|
+
*
|
|
1719
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
1720
|
+
*
|
|
1721
|
+
* @/textblock </pre>
|
|
1722
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
1723
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
1724
|
+
* be returned.
|
|
1725
|
+
*
|
|
1726
|
+
* @return One of the following error codes may be returned:
|
|
1727
|
+
* <pre>@textblock
|
|
1728
|
+
* kvImageNoError Success.
|
|
1729
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
1730
|
+
* the temp buffer to use with this function and this set of
|
|
1731
|
+
* parameters.
|
|
1732
|
+
*
|
|
1733
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
1734
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
1735
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
1736
|
+
*
|
|
1737
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
1738
|
+
* to corresponding dimensions of the source buffer.
|
|
1739
|
+
*
|
|
1740
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
1741
|
+
*
|
|
1742
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
1743
|
+
*
|
|
1744
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
1745
|
+
*
|
|
1746
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
1747
|
+
*
|
|
1748
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
1749
|
+
* @/textblock </pre>
|
|
1750
|
+
*/
|
|
1751
|
+
VIMAGE_PF vImage_Error vImageConvolveWithBias_ARGBFFFF( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const float *kernel, uint32_t kernel_height, uint32_t kernel_width, float bias, const Pixel_FFFF backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
1752
|
+
|
|
1753
|
+
/*!
|
|
1754
|
+
* @function vImageConvolveWithBias_ARGB16F
|
|
1755
|
+
* @abstract General convolution on a ARGB16F image of any channel order.
|
|
1756
|
+
* @discussion This filter applies a convolution filter of your choosing to a ARGB16F image.
|
|
1757
|
+
* This filter will work on any four-channel, half-float per component image format, not just ARGB.
|
|
1758
|
+
* The kernel values are specified as 32-bit single-precision floats and the
|
|
1759
|
+
* weighted average is also computed in single precision by default. However, if
|
|
1760
|
+
* the flag kvImageUseFP16Accumulator is set all internal filtering operations will
|
|
1761
|
+
* use 16-bit half-precision floating-point arithmetic when the CPU architecture
|
|
1762
|
+
* supports it. This results in up to 2x performance improvements but at the
|
|
1763
|
+
* expense of a less precise result; typically 2-3 bits of precision is lost.
|
|
1764
|
+
*
|
|
1765
|
+
* For each pixel:
|
|
1766
|
+
* <pre>@textblock
|
|
1767
|
+
* for each pixel[y][x] in image{
|
|
1768
|
+
* // Sums are declared as type _Float16 when the flag kvImageUseFP16Accumulator is set
|
|
1769
|
+
* float sumA = bias;
|
|
1770
|
+
* float sumR = bias;
|
|
1771
|
+
* float sumG = bias;
|
|
1772
|
+
* float sumB = bias;
|
|
1773
|
+
*
|
|
1774
|
+
* // Calculate weighted average over kernel area
|
|
1775
|
+
* for each kernel_element[i][j] in kernel{
|
|
1776
|
+
* sumA += kernel_element[i][j] *
|
|
1777
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][0];
|
|
1778
|
+
* sumR += kernel_element[i][j] *
|
|
1779
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][1];
|
|
1780
|
+
* sumG += kernel_element[i][j] *
|
|
1781
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][2];
|
|
1782
|
+
* sumB += kernel_element[i][j] *
|
|
1783
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][3];
|
|
1784
|
+
* }
|
|
1785
|
+
*
|
|
1786
|
+
* // write out result
|
|
1787
|
+
* result[y][x][0] = (_Float16)sumA;
|
|
1788
|
+
* result[y][x][1] = (_Float16)sumR;
|
|
1789
|
+
* result[y][x][2] = (_Float16)sumG;
|
|
1790
|
+
* result[y][x][3] = (_Float16)sumB;
|
|
1791
|
+
* }
|
|
1792
|
+
* @/textblock </pre>
|
|
1793
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
1794
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
1795
|
+
* kernel_width.)
|
|
1796
|
+
*
|
|
1797
|
+
* This filter does not work in place.
|
|
1798
|
+
*
|
|
1799
|
+
* @param src The input image
|
|
1800
|
+
*
|
|
1801
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
1802
|
+
* This may not alias the src image.
|
|
1803
|
+
*
|
|
1804
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
1805
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
1806
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
1807
|
+
* the size is returned instead of an error code from the left hand side.
|
|
1808
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
1809
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
1810
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
1811
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
1812
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
1813
|
+
* concurrently, a different temp buffer should be used for each.
|
|
1814
|
+
*
|
|
1815
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
1816
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1817
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
1818
|
+
*
|
|
1819
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
1820
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1821
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
1822
|
+
*
|
|
1823
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
1824
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
1825
|
+
* <pre>@textblock
|
|
1826
|
+
* const float kernel[9] = { 1./16, 2./16, 1./16,
|
|
1827
|
+
* 2./16, 4./16, 2./16,
|
|
1828
|
+
* 1./16, 2./16, 1./16 };
|
|
1829
|
+
* @/textblock </pre>
|
|
1830
|
+
*
|
|
1831
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1832
|
+
*
|
|
1833
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1834
|
+
*
|
|
1835
|
+
* @param bias This value is added to the sum of weighted pixels.
|
|
1836
|
+
*
|
|
1837
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
1838
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
1839
|
+
* kernel extends off the edge of the image.
|
|
1840
|
+
*
|
|
1841
|
+
* @param flags The following flags are allowed:
|
|
1842
|
+
* <pre>@textblock
|
|
1843
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
1844
|
+
* copy the corresponding source pixel to the destination. This
|
|
1845
|
+
* will result in a ring off unconvolved content at the edges
|
|
1846
|
+
* and convolved content in the middle.
|
|
1847
|
+
*
|
|
1848
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
1849
|
+
* For a blur filter this will look like the edges of the image
|
|
1850
|
+
* have been blurred into a particular color. This is usually
|
|
1851
|
+
* appropriate when the color of the surface onto which the image
|
|
1852
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
1853
|
+
* as a background color, and let the downstream image compositor
|
|
1854
|
+
* blend in the background color. In this case, the result image
|
|
1855
|
+
* should be treated as a premultiplied image.
|
|
1856
|
+
*
|
|
1857
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
1858
|
+
* This is better when the image is drawn into a frame or other
|
|
1859
|
+
* context where the background is not expected to contribute to
|
|
1860
|
+
* the final content.
|
|
1861
|
+
*
|
|
1862
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
1863
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
1864
|
+
* Because of the complication at the edges, this edging mode can
|
|
1865
|
+
* be significantly slower than the others. It can be numerically
|
|
1866
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
1867
|
+
* is zero, which can result in division by zero during the computation.
|
|
1868
|
+
* The results for this edging mode are usually quite visually similar
|
|
1869
|
+
* to kvImageEdgeExtend.
|
|
1870
|
+
*
|
|
1871
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
1872
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
1873
|
+
* not touch the src or dest image.
|
|
1874
|
+
*
|
|
1875
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
1876
|
+
*
|
|
1877
|
+
* kvImageUseFP16Accumulator Enable 16-bit half-precision floating-point arithmetic when computing the
|
|
1878
|
+
* kernel averages when the CPU architecture supports it.
|
|
1879
|
+
*
|
|
1880
|
+
* @/textblock </pre>
|
|
1881
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
1882
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
1883
|
+
* be returned.
|
|
1884
|
+
*
|
|
1885
|
+
* @return One of the following error codes may be returned:
|
|
1886
|
+
* <pre>@textblock
|
|
1887
|
+
* kvImageNoError Success.
|
|
1888
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
1889
|
+
* the temp buffer to use with this function and this set of
|
|
1890
|
+
* parameters.
|
|
1891
|
+
*
|
|
1892
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
1893
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
1894
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
1895
|
+
*
|
|
1896
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
1897
|
+
* to corresponding dimensions of the source buffer.
|
|
1898
|
+
*
|
|
1899
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
1900
|
+
*
|
|
1901
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
1902
|
+
*
|
|
1903
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
1904
|
+
*
|
|
1905
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
1906
|
+
*
|
|
1907
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
1908
|
+
* @/textblock </pre>
|
|
1909
|
+
*/
|
|
1910
|
+
VIMAGE_PF vImage_Error vImageConvolveWithBias_ARGB16F( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const float *kernel, uint32_t kernel_height, uint32_t kernel_width, float bias, const Pixel_ARGB_16F backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(13.0), ios(16.0), watchos(9.0), tvos(16.0));
|
|
1911
|
+
|
|
1912
|
+
/*!
|
|
1913
|
+
* @function vImageConvolveMultiKernel_ARGB8888
|
|
1914
|
+
* @abstract General convolution on a ARGB8888 image of any channel order with separate bias, kernel and divisor for each channel.
|
|
1915
|
+
* @discussion This filter applies a convolution filter of your choosing to a ARGB8888 image.
|
|
1916
|
+
* This filter will work on any four-channel, 8-bit per component image format, not just ARGB.
|
|
1917
|
+
* For each pixel:
|
|
1918
|
+
* <pre>@textblock
|
|
1919
|
+
* for each pixel[y][x] in image{
|
|
1920
|
+
* int sumA = 0;
|
|
1921
|
+
* int sumR = 0;
|
|
1922
|
+
* int sumG = 0;
|
|
1923
|
+
* int sumB = 0;
|
|
1924
|
+
* const int16_t *kA = kernel[0];
|
|
1925
|
+
* const int16_t *kR = kernel[1];
|
|
1926
|
+
* const int16_t *kG = kernel[2];
|
|
1927
|
+
* const int16_t *kB = kernel[3];
|
|
1928
|
+
*
|
|
1929
|
+
* // Calculate weighted average over kernel area
|
|
1930
|
+
* for each kernel_element[i][j] in kernel{
|
|
1931
|
+
* sumA += kA[i*kernel_width+j] *
|
|
1932
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][0];
|
|
1933
|
+
* sumR += kR[i*kernel_width+j] *
|
|
1934
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][1];
|
|
1935
|
+
* sumG += kG[i*kernel_width+j] *
|
|
1936
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][2];
|
|
1937
|
+
* sumB += kB[i*kernel_width+j] *
|
|
1938
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][3];
|
|
1939
|
+
* }
|
|
1940
|
+
* // Correct for the scaling introduced by multiplying by the weights table
|
|
1941
|
+
* sumA = (sumA + bias[0]) / divisor[0];
|
|
1942
|
+
* sumR = (sumR + bias[1]) / divisor[1];
|
|
1943
|
+
* sumG = (sumG + bias[2]) / divisor[2];
|
|
1944
|
+
* sumB = (sumB + bias[3]) / divisor[3];
|
|
1945
|
+
*
|
|
1946
|
+
* // write out result
|
|
1947
|
+
* result[y][x][0] = CLAMP(sumA, 0, 255);
|
|
1948
|
+
* result[y][x][1] = CLAMP(sumR, 0, 255);
|
|
1949
|
+
* result[y][x][2] = CLAMP(sumG, 0, 255);
|
|
1950
|
+
* result[y][x][3] = CLAMP(sumB, 0, 255);
|
|
1951
|
+
* }
|
|
1952
|
+
* @/textblock </pre>
|
|
1953
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
1954
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
1955
|
+
* kernel_width.)
|
|
1956
|
+
*
|
|
1957
|
+
* This filter does not work in place.
|
|
1958
|
+
*
|
|
1959
|
+
*
|
|
1960
|
+
* @param src The input image
|
|
1961
|
+
*
|
|
1962
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
1963
|
+
* This may not alias the src image.
|
|
1964
|
+
*
|
|
1965
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
1966
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
1967
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
1968
|
+
* the size is returned instead of an error code from the left hand side.
|
|
1969
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
1970
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
1971
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
1972
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
1973
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
1974
|
+
* concurrently, a different temp buffer should be used for each.
|
|
1975
|
+
*
|
|
1976
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
1977
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1978
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
1979
|
+
*
|
|
1980
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
1981
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
1982
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
1983
|
+
*
|
|
1984
|
+
* @param kernel An array of 4 pointers to weights of dimension kernel_height x kernel_width.
|
|
1985
|
+
* The kernel values in each array may not sum in any combination to be outside the range
|
|
1986
|
+
* [-2**23, 2**23), or modulo overflow in the accumulator may result.
|
|
1987
|
+
*
|
|
1988
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1989
|
+
*
|
|
1990
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
1991
|
+
*
|
|
1992
|
+
* @param divisor The weighted sum of nearby pixels is typically a large number, which must be corrected
|
|
1993
|
+
* to fit back into the image format of the destination image. The correction factor
|
|
1994
|
+
* is passed in as divisor here, and is divided from the sum before the result is
|
|
1995
|
+
* returned. Typically, the divisor is the sum over the area of the kernel. If the divisor
|
|
1996
|
+
* is 0, 1 will be used instead.
|
|
1997
|
+
*
|
|
1998
|
+
* @param bias This array of values is added to the sum of weighted pixels for each channel respectively
|
|
1999
|
+
* before the divisor is applied. It can serve to both control rounding and adjust the
|
|
2000
|
+
* brightness of the result. A large bias (e.g 128 * divisor) may be required for some
|
|
2001
|
+
* kernels, such as edge detection filters, to return representable results.
|
|
2002
|
+
*
|
|
2003
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
2004
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
2005
|
+
* kernel extends off the edge of the image.
|
|
2006
|
+
*
|
|
2007
|
+
* @param flags The following flags are allowed:
|
|
2008
|
+
* <pre>@textblock
|
|
2009
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
2010
|
+
* copy the corresponding source pixel to the destination. This
|
|
2011
|
+
* will result in a ring off unconvolved content at the edges
|
|
2012
|
+
* and convolved content in the middle.
|
|
2013
|
+
*
|
|
2014
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
2015
|
+
* For a blur filter this will look like the edges of the image
|
|
2016
|
+
* have been blurred into a particular color. This is usually
|
|
2017
|
+
* appropriate when the color of the surface onto which the image
|
|
2018
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
2019
|
+
* as a background color, and let the downstream image compositor
|
|
2020
|
+
* blend in the background color. In this case, the result image
|
|
2021
|
+
* should be treated as a premultiplied image.
|
|
2022
|
+
*
|
|
2023
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
2024
|
+
* This is better when the image is drawn into a frame or other
|
|
2025
|
+
* context where the background is not expected to contribute to
|
|
2026
|
+
* the final content.
|
|
2027
|
+
*
|
|
2028
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
2029
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
2030
|
+
* Because of the complication at the edges, this edging mode can
|
|
2031
|
+
* be significantly slower than the others. It can be numerically
|
|
2032
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
2033
|
+
* is zero, which can result in division by zero during the computation.
|
|
2034
|
+
* The results for this edging mode are usually quite visually similar
|
|
2035
|
+
* to kvImageEdgeExtend.
|
|
2036
|
+
*
|
|
2037
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
2038
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
2039
|
+
* not touch the src or dest image.
|
|
2040
|
+
*
|
|
2041
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
2042
|
+
*
|
|
2043
|
+
* @/textblock </pre>
|
|
2044
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
2045
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
2046
|
+
* be returned.
|
|
2047
|
+
*
|
|
2048
|
+
* @return One of the following error codes may be returned:
|
|
2049
|
+
* <pre>@textblock
|
|
2050
|
+
* kvImageNoError Success.
|
|
2051
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
2052
|
+
* the temp buffer to use with this function and this set of
|
|
2053
|
+
* parameters.
|
|
2054
|
+
*
|
|
2055
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
2056
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
2057
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
2058
|
+
*
|
|
2059
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
2060
|
+
* to corresponding dimensions of the source buffer.
|
|
2061
|
+
*
|
|
2062
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
2063
|
+
*
|
|
2064
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
2065
|
+
*
|
|
2066
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
2067
|
+
*
|
|
2068
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
2069
|
+
*
|
|
2070
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
2071
|
+
* @/textblock </pre>
|
|
2072
|
+
*/
|
|
2073
|
+
VIMAGE_PF vImage_Error vImageConvolveMultiKernel_ARGB8888( const vImage_Buffer *src,
|
|
2074
|
+
const vImage_Buffer *dest,
|
|
2075
|
+
void *tempBuffer,
|
|
2076
|
+
vImagePixelCount srcOffsetToROI_X,
|
|
2077
|
+
vImagePixelCount srcOffsetToROI_Y,
|
|
2078
|
+
const int16_t *kernels[4],
|
|
2079
|
+
uint32_t kernel_height,
|
|
2080
|
+
uint32_t kernel_width,
|
|
2081
|
+
const int32_t divisors[4],
|
|
2082
|
+
const int32_t biases[4],
|
|
2083
|
+
const Pixel_8888 backgroundColor,
|
|
2084
|
+
vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
2085
|
+
|
|
2086
|
+
|
|
2087
|
+
/*!
|
|
2088
|
+
* @function vImageConvolveMultiKernel_ARGBFFFF
|
|
2089
|
+
* @abstract General convolution on a ARGBFFFF image of any channel order with separate bias and kernel for each channel.
|
|
2090
|
+
* @discussion This filter applies a convolution filter of your choosing to a ARGBFFFF image.
|
|
2091
|
+
* This filter will work on any four-channel, float per component image format, not just ARGB.
|
|
2092
|
+
* For each pixel:
|
|
2093
|
+
* <pre>@textblock
|
|
2094
|
+
* for each pixel[y][x] in image{
|
|
2095
|
+
* float sumA = bias[0];
|
|
2096
|
+
* float sumR = bias[1];
|
|
2097
|
+
* float sumG = bias[2];
|
|
2098
|
+
* float sumB = bias[3];
|
|
2099
|
+
* const float *kA = kernel[0];
|
|
2100
|
+
* const float *kR = kernel[1];
|
|
2101
|
+
* const float *kG = kernel[2];
|
|
2102
|
+
* const float *kB = kernel[3];
|
|
2103
|
+
*
|
|
2104
|
+
* // Calculate weighted average over kernel area
|
|
2105
|
+
* for each kernel_element[i][j] in kernel{
|
|
2106
|
+
* sumA += kA[i*kernel_width+j] *
|
|
2107
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][0];
|
|
2108
|
+
* sumR += kR[i*kernel_width+j] *
|
|
2109
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][1];
|
|
2110
|
+
* sumG += kG[i*kernel_width+j] *
|
|
2111
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][2];
|
|
2112
|
+
* sumB += kB[i*kernel_width+j] *
|
|
2113
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2] [x+j+srcOffsetToROI_X- kernel_width/2][3];
|
|
2114
|
+
* }
|
|
2115
|
+
*
|
|
2116
|
+
* // write out result
|
|
2117
|
+
* result[y][x][0] = sumA;
|
|
2118
|
+
* result[y][x][1] = sumR;
|
|
2119
|
+
* result[y][x][2] = sumG;
|
|
2120
|
+
* result[y][x][3] = sumB;
|
|
2121
|
+
* }
|
|
2122
|
+
* @/textblock </pre>
|
|
2123
|
+
* (Above, we imagine the kernel to be a 2D array of size kernel_height by kernel_width.
|
|
2124
|
+
* However, in practice it is passed in as a contiguous 1D array of size kernel_height *
|
|
2125
|
+
* kernel_width.)
|
|
2126
|
+
*
|
|
2127
|
+
* This filter does not work in place.
|
|
2128
|
+
*
|
|
2129
|
+
* @param src The input image
|
|
2130
|
+
*
|
|
2131
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
2132
|
+
* This may not alias the src image.
|
|
2133
|
+
*
|
|
2134
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
2135
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
2136
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
2137
|
+
* the size is returned instead of an error code from the left hand side.
|
|
2138
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
2139
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
2140
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
2141
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
2142
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
2143
|
+
* concurrently, a different temp buffer should be used for each.
|
|
2144
|
+
*
|
|
2145
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
2146
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
2147
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
2148
|
+
*
|
|
2149
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
2150
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
2151
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
2152
|
+
*
|
|
2153
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
2154
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
2155
|
+
* <pre>@textblock
|
|
2156
|
+
* const float kernel[9] = { 1./16, 2./16, 1./16,
|
|
2157
|
+
* 2./16, 4./16, 2./16,
|
|
2158
|
+
* 1./16, 2./16, 1./16 };
|
|
2159
|
+
* @/textblock </pre>
|
|
2160
|
+
*
|
|
2161
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
2162
|
+
*
|
|
2163
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
2164
|
+
*
|
|
2165
|
+
* @param bias This value is added to the sum of weighted pixels.
|
|
2166
|
+
*
|
|
2167
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
2168
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
2169
|
+
* kernel extends off the edge of the image.
|
|
2170
|
+
*
|
|
2171
|
+
* @param flags The following flags are allowed:
|
|
2172
|
+
* <pre>@textblock
|
|
2173
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
2174
|
+
* copy the corresponding source pixel to the destination. This
|
|
2175
|
+
* will result in a ring off unconvolved content at the edges
|
|
2176
|
+
* and convolved content in the middle.
|
|
2177
|
+
*
|
|
2178
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
2179
|
+
* For a blur filter this will look like the edges of the image
|
|
2180
|
+
* have been blurred into a particular color. This is usually
|
|
2181
|
+
* appropriate when the color of the surface onto which the image
|
|
2182
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
2183
|
+
* as a background color, and let the downstream image compositor
|
|
2184
|
+
* blend in the background color. In this case, the result image
|
|
2185
|
+
* should be treated as a premultiplied image.
|
|
2186
|
+
*
|
|
2187
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
2188
|
+
* This is better when the image is drawn into a frame or other
|
|
2189
|
+
* context where the background is not expected to contribute to
|
|
2190
|
+
* the final content.
|
|
2191
|
+
*
|
|
2192
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
2193
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
2194
|
+
* Because of the complication at the edges, this edging mode can
|
|
2195
|
+
* be significantly slower than the others. It can be numerically
|
|
2196
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
2197
|
+
* is zero, which can result in division by zero during the computation.
|
|
2198
|
+
* The results for this edging mode are usually quite visually similar
|
|
2199
|
+
* to kvImageEdgeExtend.
|
|
2200
|
+
*
|
|
2201
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
2202
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
2203
|
+
* not touch the src or dest image.
|
|
2204
|
+
*
|
|
2205
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
2206
|
+
*
|
|
2207
|
+
* @/textblock </pre>
|
|
2208
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
2209
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
2210
|
+
* be returned.
|
|
2211
|
+
*
|
|
2212
|
+
* @return One of the following error codes may be returned:
|
|
2213
|
+
* <pre>@textblock
|
|
2214
|
+
* kvImageNoError Success.
|
|
2215
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
2216
|
+
* the temp buffer to use with this function and this set of
|
|
2217
|
+
* parameters.
|
|
2218
|
+
*
|
|
2219
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
2220
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
2221
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
2222
|
+
*
|
|
2223
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
2224
|
+
* to corresponding dimensions of the source buffer.
|
|
2225
|
+
*
|
|
2226
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
2227
|
+
*
|
|
2228
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
2229
|
+
*
|
|
2230
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
2231
|
+
*
|
|
2232
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
2233
|
+
*
|
|
2234
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
2235
|
+
* @/textblock </pre>
|
|
2236
|
+
*/
|
|
2237
|
+
VIMAGE_PF vImage_Error vImageConvolveMultiKernel_ARGBFFFF( const vImage_Buffer *src,
|
|
2238
|
+
const vImage_Buffer *dest,
|
|
2239
|
+
void *tempBuffer,
|
|
2240
|
+
vImagePixelCount srcOffsetToROI_X,
|
|
2241
|
+
vImagePixelCount srcOffsetToROI_Y,
|
|
2242
|
+
const float *kernels[4],
|
|
2243
|
+
uint32_t kernel_height,
|
|
2244
|
+
uint32_t kernel_width,
|
|
2245
|
+
const float biases[4],
|
|
2246
|
+
const Pixel_FFFF backgroundColor,
|
|
2247
|
+
vImage_Flags flags ) VIMAGE_NON_NULL(1,2,6,9,10) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
2248
|
+
|
|
2249
|
+
|
|
2250
|
+
|
|
2251
|
+
|
|
2252
|
+
/*!
|
|
2253
|
+
* @functiongroup Richardson-Lucy Deconvolution
|
|
2254
|
+
*
|
|
2255
|
+
* @discussion Richardson-Lucy deconvolution (a.k.a. Lucy-Richardson) is an iterative procedure for estimating what an original image
|
|
2256
|
+
* probably was before a convolution, given the convolution end result and the kernel used to create it. It is typically used to fix blurring caused
|
|
2257
|
+
* by lens distortion, most famously for the Hubble telescope, but also to improve images in confocal microscopy and other uses. When used
|
|
2258
|
+
* to correct loss of signal due to physical limitations of the imaging system, the point spread function (kernel) is estimated from known
|
|
2259
|
+
* parameters associated with the lensing system. It can also be used to sharpen images that have been digitally blurred, as long as the
|
|
2260
|
+
* original convolution kernel is known or can be estimated.
|
|
2261
|
+
*
|
|
2262
|
+
* This routine iteratively uses the following formula:
|
|
2263
|
+
* <pre>@textblock
|
|
2264
|
+
* e[i+1] = e[i] x (psf0 * ( e[0] / (psf1 * e[i]) ) )
|
|
2265
|
+
*
|
|
2266
|
+
* where:
|
|
2267
|
+
* e[0] = the observed image (src parameter)
|
|
2268
|
+
* e[n] = the result of the nth iteration
|
|
2269
|
+
* psf = point spread function (kernel for call to convolution)
|
|
2270
|
+
* x = multiply operator
|
|
2271
|
+
* '*' = convolution operator
|
|
2272
|
+
* @/textblock </pre>
|
|
2273
|
+
* As with any sharpening operation, Richardson-Lucy amplifies noise, and at some number of iterations the noise becomes noticeable as artifacts.
|
|
2274
|
+
* <pre>@textblock
|
|
2275
|
+
* =========================================================================
|
|
2276
|
+
* ====== MOST VIMAGE CONVOLUTION FUNCTIONS DO NOT WORK IN PLACE =====
|
|
2277
|
+
* =========================================================================
|
|
2278
|
+
* @/textblock </pre>
|
|
2279
|
+
*/
|
|
2280
|
+
|
|
2281
|
+
|
|
2282
|
+
/*!
|
|
2283
|
+
* @function vImageRichardsonLucyDeConvolve_Planar8
|
|
2284
|
+
* @abstract Perform N iterations of a Lucy-Richardson deconvolution on Planar8 data
|
|
2285
|
+
* @discussion
|
|
2286
|
+
* This routine iteratively uses the following formula:
|
|
2287
|
+
* <pre>@textblock
|
|
2288
|
+
* e[i+1] = e[i] x (psf0 * ( e[0] / (psf1 * e[i]) ) )
|
|
2289
|
+
*
|
|
2290
|
+
* where:
|
|
2291
|
+
* e[0] = the observed image (src parameter)
|
|
2292
|
+
* e[n] = the result of the nth iteration
|
|
2293
|
+
* psf = point spread function (kernel for call to convolution)
|
|
2294
|
+
* x = multiply operator
|
|
2295
|
+
* '*' = convolution operator
|
|
2296
|
+
* @/textblock </pre>
|
|
2297
|
+
*
|
|
2298
|
+
* The work in these functions is currently done internally with floating point precision. If you plan to call this function multiple times
|
|
2299
|
+
* (rather than with iterationCount > 1) on 8-bit per channel images, you can save some computation by converting the 8-bit image data to
|
|
2300
|
+
* single precision floating-point yourself using something like vImageConvert_Planar8toPlanarF and iterating on the appropriate
|
|
2301
|
+
* floating-point Richardson Lucy variant. Convert back, when you are done.
|
|
2302
|
+
*
|
|
2303
|
+
* Does not work in place.
|
|
2304
|
+
* @param src The input image
|
|
2305
|
+
*
|
|
2306
|
+
* @param dest A preallocated buffer to receive the result image.
|
|
2307
|
+
* This may not alias the src image.
|
|
2308
|
+
*
|
|
2309
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
2310
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
2311
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
2312
|
+
* the size is returned instead of an error code from the left hand side.
|
|
2313
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
2314
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
2315
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
2316
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
2317
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
2318
|
+
* concurrently, a different temp buffer should be used for each.
|
|
2319
|
+
*
|
|
2320
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
2321
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
2322
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
2323
|
+
*
|
|
2324
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
2325
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
2326
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
2327
|
+
*
|
|
2328
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
2329
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
2330
|
+
* <pre>@textblock
|
|
2331
|
+
* const int16_t kernel[9] = { 1, 2, 1,
|
|
2332
|
+
* 2, 4, 2,
|
|
2333
|
+
* 1, 2, 1 };
|
|
2334
|
+
* @/textblock </pre>
|
|
2335
|
+
*
|
|
2336
|
+
* This is psf0 in the formula given in the discussion.
|
|
2337
|
+
*
|
|
2338
|
+
* @param kernel2 A pointer to a second 1D array of weights of dimension kernel_height2 x kernel_width2.
|
|
2339
|
+
* This is psf1 in the formula given in the discussion.
|
|
2340
|
+
*
|
|
2341
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel1. It must be an odd number.
|
|
2342
|
+
*
|
|
2343
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel1. It must be an odd number.
|
|
2344
|
+
*
|
|
2345
|
+
* @param kernel_height2 The height of the 2D table of weights passed in as kernel2. It must be an odd number.
|
|
2346
|
+
*
|
|
2347
|
+
* @param kernel_width2 The width of the 2D table of weights passed in as kernel2. It must be an odd number.
|
|
2348
|
+
*
|
|
2349
|
+
* @param divisor The divisor to use to correct for the volume under kernel.
|
|
2350
|
+
*
|
|
2351
|
+
* @param divisor2 The divisor to use to correct for the volume under kernel2.
|
|
2352
|
+
*
|
|
2353
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
2354
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
2355
|
+
* kernel extends off the edge of the image.
|
|
2356
|
+
*
|
|
2357
|
+
* @param iterationCount The number of Richardson-Lucy iterations to perform on the data before returning.
|
|
2358
|
+
* If 0, the src buffer is coped to dest.
|
|
2359
|
+
*
|
|
2360
|
+
*
|
|
2361
|
+
* @param flags The following flags are allowed:
|
|
2362
|
+
* <pre>@textblock
|
|
2363
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
2364
|
+
* copy the corresponding source pixel to the destination. This
|
|
2365
|
+
* will result in a ring off unconvolved content at the edges
|
|
2366
|
+
* and convolved content in the middle.
|
|
2367
|
+
*
|
|
2368
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
2369
|
+
* For a blur filter this will look like the edges of the image
|
|
2370
|
+
* have been blurred into a particular color. This is usually
|
|
2371
|
+
* appropriate when the color of the surface onto which the image
|
|
2372
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
2373
|
+
* as a background color, and let the downstream image compositor
|
|
2374
|
+
* blend in the background color. In this case, the result image
|
|
2375
|
+
* should be treated as a premultiplied image.
|
|
2376
|
+
*
|
|
2377
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
2378
|
+
* This is better when the image is drawn into a frame or other
|
|
2379
|
+
* context where the background is not expected to contribute to
|
|
2380
|
+
* the final content.
|
|
2381
|
+
*
|
|
2382
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
2383
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
2384
|
+
* Because of the complication at the edges, this edging mode can
|
|
2385
|
+
* be significantly slower than the others. It can be numerically
|
|
2386
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
2387
|
+
* is zero, which can result in division by zero during the computation.
|
|
2388
|
+
* The results for this edging mode are usually quite visually similar
|
|
2389
|
+
* to kvImageEdgeExtend.
|
|
2390
|
+
*
|
|
2391
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
2392
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
2393
|
+
* not touch the src or dest image.
|
|
2394
|
+
*
|
|
2395
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
2396
|
+
*
|
|
2397
|
+
* @/textblock </pre>
|
|
2398
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
2399
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
2400
|
+
* be returned.
|
|
2401
|
+
*
|
|
2402
|
+
* @return One of the following error codes may be returned:
|
|
2403
|
+
* <pre>@textblock
|
|
2404
|
+
* kvImageNoError Success.
|
|
2405
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
2406
|
+
* the temp buffer to use with this function and this set of
|
|
2407
|
+
* parameters.
|
|
2408
|
+
*
|
|
2409
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
2410
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
2411
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
2412
|
+
*
|
|
2413
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
2414
|
+
* to corresponding dimensions of the source buffer.
|
|
2415
|
+
*
|
|
2416
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
2417
|
+
*
|
|
2418
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
2419
|
+
*
|
|
2420
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
2421
|
+
*
|
|
2422
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
2423
|
+
*
|
|
2424
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
2425
|
+
* @/textblock </pre>
|
|
2426
|
+
*/
|
|
2427
|
+
VIMAGE_PF vImage_Error vImageRichardsonLucyDeConvolve_Planar8( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const int16_t *kernel, const int16_t *kernel2, uint32_t kernel_height, uint32_t kernel_width, uint32_t kernel_height2, uint32_t kernel_width2, int32_t divisor, int32_t divisor2, Pixel_8 backgroundColor, uint32_t iterationCount, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
2428
|
+
|
|
2429
|
+
/*!
|
|
2430
|
+
* @function vImageRichardsonLucyDeConvolve_PlanarF
|
|
2431
|
+
* @abstract Perform N iterations of a Lucy-Richardson deconvolution on PlanarF data
|
|
2432
|
+
* @discussion
|
|
2433
|
+
* This routine iteratively uses the following formula:
|
|
2434
|
+
* <pre>@textblock
|
|
2435
|
+
* e[i+1] = e[i] x (psf0 * ( e[0] / (psf1 * e[i]) ) )
|
|
2436
|
+
*
|
|
2437
|
+
* where:
|
|
2438
|
+
* e[0] = the observed image (src parameter)
|
|
2439
|
+
* e[n] = the result of the nth iteration
|
|
2440
|
+
* psf = point spread function (kernel for call to convolution)
|
|
2441
|
+
* x = multiply operator
|
|
2442
|
+
* '*' = convolution operator
|
|
2443
|
+
* @/textblock </pre>
|
|
2444
|
+
*
|
|
2445
|
+
* Does not work in place.
|
|
2446
|
+
* @param src The input image
|
|
2447
|
+
*
|
|
2448
|
+
* @param dest A preallocated buffer to receive the result image.
|
|
2449
|
+
* This may not alias the src image.
|
|
2450
|
+
*
|
|
2451
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
2452
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
2453
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
2454
|
+
* the size is returned instead of an error code from the left hand side.
|
|
2455
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
2456
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
2457
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
2458
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
2459
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
2460
|
+
* concurrently, a different temp buffer should be used for each.
|
|
2461
|
+
*
|
|
2462
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
2463
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
2464
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
2465
|
+
*
|
|
2466
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
2467
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
2468
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
2469
|
+
*
|
|
2470
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
2471
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
2472
|
+
* <pre>@textblock
|
|
2473
|
+
* const float kernel[9] = { 1./16, 2./16, 1./16,
|
|
2474
|
+
* 2./16, 4./16, 2./16,
|
|
2475
|
+
* 1./16, 2./16, 1./16 };
|
|
2476
|
+
* @/textblock </pre>
|
|
2477
|
+
*
|
|
2478
|
+
* This is psf0 in the formula given in the discussion.
|
|
2479
|
+
*
|
|
2480
|
+
* @param kernel2 A pointer to a second 1D array of weights of dimension kernel_height2 x kernel_width2.
|
|
2481
|
+
* This is psf1 in the formula given in the discussion.
|
|
2482
|
+
*
|
|
2483
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel1. It must be an odd number.
|
|
2484
|
+
*
|
|
2485
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel1. It must be an odd number.
|
|
2486
|
+
*
|
|
2487
|
+
* @param kernel_height2 The height of the 2D table of weights passed in as kernel2. It must be an odd number.
|
|
2488
|
+
*
|
|
2489
|
+
* @param kernel_width2 The width of the 2D table of weights passed in as kernel2. It must be an odd number.
|
|
2490
|
+
*
|
|
2491
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
2492
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
2493
|
+
* kernel extends off the edge of the image.
|
|
2494
|
+
*
|
|
2495
|
+
* @param iterationCount The number of Richardson-Lucy iterations to perform on the data before returning.
|
|
2496
|
+
* If 0, the src buffer is coped to dest.
|
|
2497
|
+
*
|
|
2498
|
+
*
|
|
2499
|
+
* @param flags The following flags are allowed:
|
|
2500
|
+
* <pre>@textblock
|
|
2501
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
2502
|
+
* copy the corresponding source pixel to the destination. This
|
|
2503
|
+
* will result in a ring off unconvolved content at the edges
|
|
2504
|
+
* and convolved content in the middle.
|
|
2505
|
+
*
|
|
2506
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
2507
|
+
* For a blur filter this will look like the edges of the image
|
|
2508
|
+
* have been blurred into a particular color. This is usually
|
|
2509
|
+
* appropriate when the color of the surface onto which the image
|
|
2510
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
2511
|
+
* as a background color, and let the downstream image compositor
|
|
2512
|
+
* blend in the background color. In this case, the result image
|
|
2513
|
+
* should be treated as a premultiplied image.
|
|
2514
|
+
*
|
|
2515
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
2516
|
+
* This is better when the image is drawn into a frame or other
|
|
2517
|
+
* context where the background is not expected to contribute to
|
|
2518
|
+
* the final content.
|
|
2519
|
+
*
|
|
2520
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
2521
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
2522
|
+
* Because of the complication at the edges, this edging mode can
|
|
2523
|
+
* be significantly slower than the others. It can be numerically
|
|
2524
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
2525
|
+
* is zero, which can result in division by zero during the computation.
|
|
2526
|
+
* The results for this edging mode are usually quite visually similar
|
|
2527
|
+
* to kvImageEdgeExtend.
|
|
2528
|
+
*
|
|
2529
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
2530
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
2531
|
+
* not touch the src or dest image.
|
|
2532
|
+
*
|
|
2533
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
2534
|
+
*
|
|
2535
|
+
* @/textblock </pre>
|
|
2536
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
2537
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
2538
|
+
* be returned.
|
|
2539
|
+
*
|
|
2540
|
+
* @return One of the following error codes may be returned:
|
|
2541
|
+
* <pre>@textblock
|
|
2542
|
+
* kvImageNoError Success.
|
|
2543
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
2544
|
+
* the temp buffer to use with this function and this set of
|
|
2545
|
+
* parameters.
|
|
2546
|
+
*
|
|
2547
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
2548
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
2549
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
2550
|
+
*
|
|
2551
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
2552
|
+
* to corresponding dimensions of the source buffer.
|
|
2553
|
+
*
|
|
2554
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
2555
|
+
*
|
|
2556
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
2557
|
+
*
|
|
2558
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
2559
|
+
*
|
|
2560
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
2561
|
+
*
|
|
2562
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
2563
|
+
* @/textblock </pre>
|
|
2564
|
+
*/
|
|
2565
|
+
VIMAGE_PF vImage_Error vImageRichardsonLucyDeConvolve_PlanarF( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const float *kernel, const float *kernel2, uint32_t kernel_height, uint32_t kernel_width, uint32_t kernel_height2, uint32_t kernel_width2, Pixel_F backgroundColor, uint32_t iterationCount, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
2566
|
+
|
|
2567
|
+
/*!
|
|
2568
|
+
* @function vImageRichardsonLucyDeConvolve_ARGB8888
|
|
2569
|
+
* @abstract Perform N iterations of a Lucy-Richardson deconvolution on ARGB8888 data.
|
|
2570
|
+
* @discussion
|
|
2571
|
+
* This routine iteratively uses the following formula:
|
|
2572
|
+
* <pre>@textblock
|
|
2573
|
+
* e[i+1] = e[i] x (psf0 * ( e[0] / (psf1 * e[i]) ) )
|
|
2574
|
+
*
|
|
2575
|
+
* where:
|
|
2576
|
+
* e[0] = the observed image (src parameter)
|
|
2577
|
+
* e[n] = the result of the nth iteration
|
|
2578
|
+
* psf = point spread function (kernel for call to convolution)
|
|
2579
|
+
* x = multiply operator
|
|
2580
|
+
* '*' = convolution operator
|
|
2581
|
+
* @/textblock </pre>
|
|
2582
|
+
* The channels are operated on independently of one another. Consequently, this function will work on
|
|
2583
|
+
* any 4-channel interleaved 8-bit per component format (e.g. RGBA, BGRA...), not just ARGB.
|
|
2584
|
+
*
|
|
2585
|
+
* The work in these functions is currently done internally with floating point precision. If you plan to call this function multiple times
|
|
2586
|
+
* (rather than with iterationCount > 1) on 8-bit per channel images, you can save some computation by converting the 8-bit image data to
|
|
2587
|
+
* single precision floating-point yourself using something like vImageConvert_Planar8toPlanarF and iterating on the appropriate
|
|
2588
|
+
* floating-point Richardson Lucy variant. Convert back, when you are done.
|
|
2589
|
+
*
|
|
2590
|
+
* Does not work in place.
|
|
2591
|
+
*
|
|
2592
|
+
* @param src The input image
|
|
2593
|
+
*
|
|
2594
|
+
* @param dest A preallocated buffer to receive the result image.
|
|
2595
|
+
* This may not alias the src image.
|
|
2596
|
+
*
|
|
2597
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
2598
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
2599
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
2600
|
+
* the size is returned instead of an error code from the left hand side.
|
|
2601
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
2602
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
2603
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
2604
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
2605
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
2606
|
+
* concurrently, a different temp buffer should be used for each.
|
|
2607
|
+
*
|
|
2608
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
2609
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
2610
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
2611
|
+
*
|
|
2612
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
2613
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
2614
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
2615
|
+
*
|
|
2616
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
2617
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
2618
|
+
* <pre>@textblock
|
|
2619
|
+
* const int16_t kernel[9] = { 1, 2, 1,
|
|
2620
|
+
* 2, 4, 2,
|
|
2621
|
+
* 1, 2, 1 };
|
|
2622
|
+
* @/textblock </pre>
|
|
2623
|
+
*
|
|
2624
|
+
* This is psf0 in the formula given in the discussion.
|
|
2625
|
+
*
|
|
2626
|
+
* @param kernel2 A pointer to a second 1D array of weights of dimension kernel_height2 x kernel_width2.
|
|
2627
|
+
* This is psf1 in the formula given in the discussion.
|
|
2628
|
+
*
|
|
2629
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel1. It must be an odd number.
|
|
2630
|
+
*
|
|
2631
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel1. It must be an odd number.
|
|
2632
|
+
*
|
|
2633
|
+
* @param kernel_height2 The height of the 2D table of weights passed in as kernel2. It must be an odd number.
|
|
2634
|
+
*
|
|
2635
|
+
* @param kernel_width2 The width of the 2D table of weights passed in as kernel2. It must be an odd number.
|
|
2636
|
+
*
|
|
2637
|
+
* @param divisor The divisor to use to correct for the volume under kernel.
|
|
2638
|
+
*
|
|
2639
|
+
* @param divisor2 The divisor to use to correct for the volume under kernel2.
|
|
2640
|
+
*
|
|
2641
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
2642
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
2643
|
+
* kernel extends off the edge of the image.
|
|
2644
|
+
*
|
|
2645
|
+
* @param iterationCount The number of Richardson-Lucy iterations to perform on the data before returning.
|
|
2646
|
+
* If 0, the src buffer is coped to dest.
|
|
2647
|
+
*
|
|
2648
|
+
*
|
|
2649
|
+
* @param flags The following flags are allowed:
|
|
2650
|
+
* <pre>@textblock
|
|
2651
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
2652
|
+
* copy the corresponding source pixel to the destination. This
|
|
2653
|
+
* will result in a ring off unconvolved content at the edges
|
|
2654
|
+
* and convolved content in the middle.
|
|
2655
|
+
*
|
|
2656
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
2657
|
+
* For a blur filter this will look like the edges of the image
|
|
2658
|
+
* have been blurred into a particular color. This is usually
|
|
2659
|
+
* appropriate when the color of the surface onto which the image
|
|
2660
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
2661
|
+
* as a background color, and let the downstream image compositor
|
|
2662
|
+
* blend in the background color. In this case, the result image
|
|
2663
|
+
* should be treated as a premultiplied image.
|
|
2664
|
+
*
|
|
2665
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
2666
|
+
* This is better when the image is drawn into a frame or other
|
|
2667
|
+
* context where the background is not expected to contribute to
|
|
2668
|
+
* the final content.
|
|
2669
|
+
*
|
|
2670
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
2671
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
2672
|
+
* Because of the complication at the edges, this edging mode can
|
|
2673
|
+
* be significantly slower than the others. It can be numerically
|
|
2674
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
2675
|
+
* is zero, which can result in division by zero during the computation.
|
|
2676
|
+
* The results for this edging mode are usually quite visually similar
|
|
2677
|
+
* to kvImageEdgeExtend.
|
|
2678
|
+
*
|
|
2679
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
2680
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
2681
|
+
* not touch the src or dest image.
|
|
2682
|
+
*
|
|
2683
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
2684
|
+
*
|
|
2685
|
+
* kvImageLeaveAlphaUnchanged Operate only on the last 3 channels in memory. Leave the first channel
|
|
2686
|
+
* unmodified.
|
|
2687
|
+
*
|
|
2688
|
+
* @/textblock </pre>
|
|
2689
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
2690
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
2691
|
+
* be returned.
|
|
2692
|
+
*
|
|
2693
|
+
* @return One of the following error codes may be returned:
|
|
2694
|
+
* <pre>@textblock
|
|
2695
|
+
* kvImageNoError Success.
|
|
2696
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
2697
|
+
* the temp buffer to use with this function and this set of
|
|
2698
|
+
* parameters.
|
|
2699
|
+
*
|
|
2700
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
2701
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
2702
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
2703
|
+
*
|
|
2704
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
2705
|
+
* to corresponding dimensions of the source buffer.
|
|
2706
|
+
*
|
|
2707
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
2708
|
+
*
|
|
2709
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
2710
|
+
*
|
|
2711
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
2712
|
+
*
|
|
2713
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
2714
|
+
*
|
|
2715
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
2716
|
+
* @/textblock </pre>
|
|
2717
|
+
*/
|
|
2718
|
+
VIMAGE_PF vImage_Error vImageRichardsonLucyDeConvolve_ARGB8888( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const int16_t *kernel, const int16_t *kernel2, uint32_t kernel_height, uint32_t kernel_width, uint32_t kernel_height2, uint32_t kernel_width2, int32_t divisor, int32_t divisor2, const Pixel_8888 backgroundColor, uint32_t iterationCount, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
2719
|
+
|
|
2720
|
+
/*!
|
|
2721
|
+
* @function vImageRichardsonLucyDeConvolve_ARGBFFFF
|
|
2722
|
+
* @abstract Perform N iterations of a Lucy-Richardson deconvolution on ARGBFFFF data
|
|
2723
|
+
* @discussion
|
|
2724
|
+
* This routine iteratively uses the following formula:
|
|
2725
|
+
* <pre>@textblock
|
|
2726
|
+
* e[i+1] = e[i] x (psf0 * ( e[0] / (psf1 * e[i]) ) )
|
|
2727
|
+
*
|
|
2728
|
+
* where:
|
|
2729
|
+
* e[0] = the observed image (src parameter)
|
|
2730
|
+
* e[n] = the result of the nth iteration
|
|
2731
|
+
* psf = point spread function (kernel for call to convolution)
|
|
2732
|
+
* x = multiply operator
|
|
2733
|
+
* '*' = convolution operator
|
|
2734
|
+
* @/textblock </pre>
|
|
2735
|
+
*
|
|
2736
|
+
* The channels are operated on independently of one another. Consequently, this function will work on
|
|
2737
|
+
* any 4-channel interleaved 8-bit per component format (e.g. RGBA, BGRA...), not just ARGB.
|
|
2738
|
+
*
|
|
2739
|
+
* Does not work in place.
|
|
2740
|
+
* @param src The input image
|
|
2741
|
+
*
|
|
2742
|
+
* @param dest A preallocated buffer to receive the result image.
|
|
2743
|
+
* This may not alias the src image.
|
|
2744
|
+
*
|
|
2745
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
2746
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
2747
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
2748
|
+
* the size is returned instead of an error code from the left hand side.
|
|
2749
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
2750
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
2751
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
2752
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
2753
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
2754
|
+
* concurrently, a different temp buffer should be used for each.
|
|
2755
|
+
*
|
|
2756
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
2757
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
2758
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
2759
|
+
*
|
|
2760
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
2761
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
2762
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
2763
|
+
*
|
|
2764
|
+
* @param kernel A pointer to a 1D array of weights of dimension kernel_height x kernel_width.
|
|
2765
|
+
* For example, for a simple 3x3 blur, it might be:
|
|
2766
|
+
* <pre>@textblock
|
|
2767
|
+
* const float kernel[9] = { 1./16, 2./16, 1./16,
|
|
2768
|
+
* 2./16, 4./16, 2./16,
|
|
2769
|
+
* 1./16, 2./16, 1./16 };
|
|
2770
|
+
* @/textblock </pre>
|
|
2771
|
+
*
|
|
2772
|
+
* This is psf0 in the formula given in the discussion.
|
|
2773
|
+
*
|
|
2774
|
+
* @param kernel2 A pointer to a second 1D array of weights of dimension kernel_height2 x kernel_width2.
|
|
2775
|
+
* This is psf1 in the formula given in the discussion.
|
|
2776
|
+
*
|
|
2777
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel1. It must be an odd number.
|
|
2778
|
+
*
|
|
2779
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel1. It must be an odd number.
|
|
2780
|
+
*
|
|
2781
|
+
* @param kernel_height2 The height of the 2D table of weights passed in as kernel2. It must be an odd number.
|
|
2782
|
+
*
|
|
2783
|
+
* @param kernel_width2 The width of the 2D table of weights passed in as kernel2. It must be an odd number.
|
|
2784
|
+
*
|
|
2785
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
2786
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
2787
|
+
* kernel extends off the edge of the image.
|
|
2788
|
+
*
|
|
2789
|
+
* @param iterationCount The number of Richardson-Lucy iterations to perform on the data before returning.
|
|
2790
|
+
* If 0, the src buffer is coped to dest.
|
|
2791
|
+
*
|
|
2792
|
+
*
|
|
2793
|
+
* @param flags The following flags are allowed:
|
|
2794
|
+
* <pre>@textblock
|
|
2795
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
2796
|
+
* copy the corresponding source pixel to the destination. This
|
|
2797
|
+
* will result in a ring off unconvolved content at the edges
|
|
2798
|
+
* and convolved content in the middle.
|
|
2799
|
+
*
|
|
2800
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
2801
|
+
* For a blur filter this will look like the edges of the image
|
|
2802
|
+
* have been blurred into a particular color. This is usually
|
|
2803
|
+
* appropriate when the color of the surface onto which the image
|
|
2804
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
2805
|
+
* as a background color, and let the downstream image compositor
|
|
2806
|
+
* blend in the background color. In this case, the result image
|
|
2807
|
+
* should be treated as a premultiplied image.
|
|
2808
|
+
*
|
|
2809
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
2810
|
+
* This is better when the image is drawn into a frame or other
|
|
2811
|
+
* context where the background is not expected to contribute to
|
|
2812
|
+
* the final content.
|
|
2813
|
+
*
|
|
2814
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
2815
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
2816
|
+
* Because of the complication at the edges, this edging mode can
|
|
2817
|
+
* be significantly slower than the others. It can be numerically
|
|
2818
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
2819
|
+
* is zero, which can result in division by zero during the computation.
|
|
2820
|
+
* The results for this edging mode are usually quite visually similar
|
|
2821
|
+
* to kvImageEdgeExtend.
|
|
2822
|
+
*
|
|
2823
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
2824
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
2825
|
+
* not touch the src or dest image.
|
|
2826
|
+
*
|
|
2827
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
2828
|
+
*
|
|
2829
|
+
* kvImageLeaveAlphaUnchanged Operate only on the last 3 channels in memory. Leave the first channel
|
|
2830
|
+
* unmodified.
|
|
2831
|
+
*
|
|
2832
|
+
* @/textblock </pre>
|
|
2833
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
2834
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
2835
|
+
* be returned.
|
|
2836
|
+
*
|
|
2837
|
+
* @return One of the following error codes may be returned:
|
|
2838
|
+
* <pre>@textblock
|
|
2839
|
+
* kvImageNoError Success.
|
|
2840
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
2841
|
+
* the temp buffer to use with this function and this set of
|
|
2842
|
+
* parameters.
|
|
2843
|
+
*
|
|
2844
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
2845
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
2846
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
2847
|
+
*
|
|
2848
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
2849
|
+
* to corresponding dimensions of the source buffer.
|
|
2850
|
+
*
|
|
2851
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
2852
|
+
*
|
|
2853
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
2854
|
+
*
|
|
2855
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
2856
|
+
*
|
|
2857
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
2858
|
+
*
|
|
2859
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
2860
|
+
* @/textblock </pre>
|
|
2861
|
+
*/
|
|
2862
|
+
VIMAGE_PF vImage_Error vImageRichardsonLucyDeConvolve_ARGBFFFF( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, const float *kernel, const float *kernel2, uint32_t kernel_height, uint32_t kernel_width, uint32_t kernel_height2, uint32_t kernel_width2, const Pixel_FFFF backgroundColor, uint32_t iterationCount, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
2863
|
+
|
|
2864
|
+
/*!
|
|
2865
|
+
* @functiongroup Box Convolve
|
|
2866
|
+
* @discussion A box convolve is a special case of the standard convolution, which has a much faster algorithm.
|
|
2867
|
+
* A box kernel is a kernel populated with all 1's. This returns the unweighted average of the pixels
|
|
2868
|
+
* near the result pixel. Unlike general purpose convolution, the cost of a box convolve algorithm
|
|
2869
|
+
* is theoretically constant regardless of kernel size, so it can be an inexpensive choice for very
|
|
2870
|
+
* large blurs. The box convolve behavior may not be as desired, however, because the blur effect is
|
|
2871
|
+
* rectangular in appearance, whereas most expect it to be gaussian or roughly circular. A tent blur has
|
|
2872
|
+
* similar rectangular character, but because the weighting is non uniform, it is less obvious. A
|
|
2873
|
+
* tent blur is also constant cost per pixel, but larger constant cost.
|
|
2874
|
+
*
|
|
2875
|
+
* Two box blur passes of the same kernel size results in a tent blur. To see this we can take a 1-d starting image:
|
|
2876
|
+
* <pre> @textblock
|
|
2877
|
+
* p0 p1 p2 p3 p4 p5 p6
|
|
2878
|
+
* @/textblock </pre>
|
|
2879
|
+
* and blur it once with a 3 wide box blur, ignoring for the moment what happens at the edges:
|
|
2880
|
+
* <pre> @textblock
|
|
2881
|
+
* (edge) p0+p1+p2 p1+p2+p3 p2+p3+p4 p3+p4+p5 p4+p5+p6 p5+p6+p7
|
|
2882
|
+
* @/textblock </pre>
|
|
2883
|
+
* and a second time:
|
|
2884
|
+
* <pre> @textblock
|
|
2885
|
+
* (edge) p0+2p1+3p2+2p3+p4 p2+2p3+3p4+2p5+p6 p4+2p5+3p6+2p7+p8 .....
|
|
2886
|
+
* (edge) p1+2p2+3p3+2p4+p5 p3+2p4+3p5+2p6+p7
|
|
2887
|
+
* @/textblock </pre>
|
|
2888
|
+
*
|
|
2889
|
+
* If this process is continued, the shape converges towards a gaussian over multiple passes.
|
|
2890
|
+
* <pre>@textblock
|
|
2891
|
+
* =========================================================================
|
|
2892
|
+
* ====== MOST VIMAGE CONVOLUTION FUNCTIONS DO NOT WORK IN PLACE =====
|
|
2893
|
+
* =========================================================================
|
|
2894
|
+
* @/textblock </pre>
|
|
2895
|
+
*/
|
|
2896
|
+
|
|
2897
|
+
/*!
|
|
2898
|
+
* @function vImageBoxConvolve_Planar8
|
|
2899
|
+
* @abstract Special purpose box convolution on a Planar8 image.
|
|
2900
|
+
* @discussion This filter applies a box filter to a Planar8 image. A box filter uses a much faster algorithm
|
|
2901
|
+
* than a standard convolution, and may be a good solution for real time application of large blur
|
|
2902
|
+
* radii against images.
|
|
2903
|
+
* For each pixel:
|
|
2904
|
+
* <pre>@textblock
|
|
2905
|
+
* vImagePixelCount kernel_area = kernel_height * kernel_width;
|
|
2906
|
+
* for each pixel[y][x] in image{
|
|
2907
|
+
* int sum = 0;
|
|
2908
|
+
*
|
|
2909
|
+
* // Calculate unweighted average over kernel area
|
|
2910
|
+
* for each kernel_element[i][j] in kernel{
|
|
2911
|
+
* sum += pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
2912
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
2913
|
+
* }
|
|
2914
|
+
* // Correct for the scaling introduced by multiplying by the weights table
|
|
2915
|
+
* sum = (sum + kernel_area/2) / kernel_area;
|
|
2916
|
+
*
|
|
2917
|
+
* // write out result
|
|
2918
|
+
* result[y][x] = CLAMP(sum, 0, 255);
|
|
2919
|
+
* }
|
|
2920
|
+
* @/textblock </pre>
|
|
2921
|
+
*
|
|
2922
|
+
* This filter does not work in place.
|
|
2923
|
+
*
|
|
2924
|
+
* @param src The input image
|
|
2925
|
+
*
|
|
2926
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
2927
|
+
* This may not alias the src image.
|
|
2928
|
+
*
|
|
2929
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
2930
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
2931
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
2932
|
+
* the size is returned instead of an error code from the left hand side.
|
|
2933
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
2934
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
2935
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
2936
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
2937
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
2938
|
+
* concurrently, a different temp buffer should be used for each.
|
|
2939
|
+
*
|
|
2940
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
2941
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
2942
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
2943
|
+
*
|
|
2944
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
2945
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
2946
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
2947
|
+
*
|
|
2948
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
2949
|
+
*
|
|
2950
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
2951
|
+
*
|
|
2952
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
2953
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
2954
|
+
* kernel extends off the edge of the image.
|
|
2955
|
+
*
|
|
2956
|
+
* @param flags The following flags are allowed:
|
|
2957
|
+
* <pre>@textblock
|
|
2958
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
2959
|
+
* copy the corresponding source pixel to the destination. This
|
|
2960
|
+
* will result in a ring off unconvolved content at the edges
|
|
2961
|
+
* and convolved content in the middle.
|
|
2962
|
+
*
|
|
2963
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
2964
|
+
* For a blur filter this will look like the edges of the image
|
|
2965
|
+
* have been blurred into a particular color. This is usually
|
|
2966
|
+
* appropriate when the color of the surface onto which the image
|
|
2967
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
2968
|
+
* as a background color, and let the downstream image compositor
|
|
2969
|
+
* blend in the background color. In this case, the result image
|
|
2970
|
+
* should be treated as a premultiplied image.
|
|
2971
|
+
*
|
|
2972
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
2973
|
+
* This is better when the image is drawn into a frame or other
|
|
2974
|
+
* context where the background is not expected to contribute to
|
|
2975
|
+
* the final content.
|
|
2976
|
+
*
|
|
2977
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
2978
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
2979
|
+
* Because of the complication at the edges, this edging mode can
|
|
2980
|
+
* be significantly slower than the others. It can be numerically
|
|
2981
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
2982
|
+
* is zero, which can result in division by zero during the computation.
|
|
2983
|
+
* The results for this edging mode are usually quite visually similar
|
|
2984
|
+
* to kvImageEdgeExtend.
|
|
2985
|
+
*
|
|
2986
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
2987
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
2988
|
+
* not touch the src or dest image.
|
|
2989
|
+
*
|
|
2990
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
2991
|
+
*
|
|
2992
|
+
* @/textblock </pre>
|
|
2993
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
2994
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
2995
|
+
* be returned.
|
|
2996
|
+
*
|
|
2997
|
+
* @return One of the following error codes may be returned:
|
|
2998
|
+
* <pre>@textblock
|
|
2999
|
+
* kvImageNoError Success.
|
|
3000
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
3001
|
+
* the temp buffer to use with this function and this set of
|
|
3002
|
+
* parameters.
|
|
3003
|
+
*
|
|
3004
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
3005
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
3006
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
3007
|
+
*
|
|
3008
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
3009
|
+
* to corresponding dimensions of the source buffer.
|
|
3010
|
+
*
|
|
3011
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
3012
|
+
*
|
|
3013
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
3014
|
+
*
|
|
3015
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
3016
|
+
*
|
|
3017
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
3018
|
+
* @/textblock </pre>
|
|
3019
|
+
*/
|
|
3020
|
+
VIMAGE_PF vImage_Error vImageBoxConvolve_Planar8( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, uint32_t kernel_height, uint32_t kernel_width, Pixel_8 backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
3021
|
+
|
|
3022
|
+
/*!
|
|
3023
|
+
* @function vImageBoxConvolve_ARGB8888
|
|
3024
|
+
* @abstract Special purpose box convolution on a 4-channel interleaved, 8-bit per channel image.
|
|
3025
|
+
* @discussion This filter applies a box filter to a 4-channel interleaved, 8-bit per channel imagee.
|
|
3026
|
+
* A box filter uses a much faster algorithm than a standard convolution, and may be a good
|
|
3027
|
+
* solution for real time application of large blur radii against images.
|
|
3028
|
+
* For each pixel:
|
|
3029
|
+
* <pre>@textblock
|
|
3030
|
+
* vImagePixelCount kernel_area = kernel_height * kernel_width;
|
|
3031
|
+
* for each pixel[y][x] in image{
|
|
3032
|
+
* int sumA = 0;
|
|
3033
|
+
* int sumR = 0;
|
|
3034
|
+
* int sumG = 0;
|
|
3035
|
+
* int sumB = 0;
|
|
3036
|
+
*
|
|
3037
|
+
* // Calculate unweighted average over kernel area
|
|
3038
|
+
* for each kernel_element[i][j] in kernel{
|
|
3039
|
+
* sumA += pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
3040
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2][0];
|
|
3041
|
+
* sumR += pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
3042
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2][1];
|
|
3043
|
+
* sumG += pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
3044
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2][2];
|
|
3045
|
+
* sumB += pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
3046
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2][3];
|
|
3047
|
+
* }
|
|
3048
|
+
* // Correct for the scaling introduced by multiplying by the weights table
|
|
3049
|
+
* sumA = (sumA + kernel_area/2) / kernel_area;
|
|
3050
|
+
* sumR = (sumR + kernel_area/2) / kernel_area;
|
|
3051
|
+
* sumG = (sumG + kernel_area/2) / kernel_area;
|
|
3052
|
+
* sumB = (sumB + kernel_area/2) / kernel_area;
|
|
3053
|
+
*
|
|
3054
|
+
* // write out result
|
|
3055
|
+
* result[y][x][0] = CLAMP(sumA, 0, 255);
|
|
3056
|
+
* result[y][x][1] = CLAMP(sumR, 0, 255);
|
|
3057
|
+
* result[y][x][2] = CLAMP(sumG, 0, 255);
|
|
3058
|
+
* result[y][x][3] = CLAMP(sumB, 0, 255);
|
|
3059
|
+
* }
|
|
3060
|
+
* @/textblock </pre>
|
|
3061
|
+
*
|
|
3062
|
+
* This filter does not work in place.
|
|
3063
|
+
*
|
|
3064
|
+
* This filter will work without modification for other byte orders such as RGBA, BGRA, AGBR, CMYK, etc.
|
|
3065
|
+
* The image should be non-premultiplied to avoid odd results in non-opaque regions.
|
|
3066
|
+
*
|
|
3067
|
+
* @param src The input image
|
|
3068
|
+
*
|
|
3069
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
3070
|
+
* This may not alias the src image.
|
|
3071
|
+
*
|
|
3072
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
3073
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
3074
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
3075
|
+
* the size is returned instead of an error code from the left hand side.
|
|
3076
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
3077
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
3078
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
3079
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
3080
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
3081
|
+
* concurrently, a different temp buffer should be used for each.
|
|
3082
|
+
*
|
|
3083
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
3084
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3085
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
3086
|
+
*
|
|
3087
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
3088
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3089
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
3090
|
+
*
|
|
3091
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
3092
|
+
*
|
|
3093
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
3094
|
+
*
|
|
3095
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
3096
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
3097
|
+
* kernel extends off the edge of the image.
|
|
3098
|
+
*
|
|
3099
|
+
* @param flags The following flags are allowed:
|
|
3100
|
+
* <pre>@textblock
|
|
3101
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
3102
|
+
* copy the corresponding source pixel to the destination. This
|
|
3103
|
+
* will result in a ring off unconvolved content at the edges
|
|
3104
|
+
* and convolved content in the middle.
|
|
3105
|
+
*
|
|
3106
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
3107
|
+
* For a blur filter this will look like the edges of the image
|
|
3108
|
+
* have been blurred into a particular color. This is usually
|
|
3109
|
+
* appropriate when the color of the surface onto which the image
|
|
3110
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
3111
|
+
* as a background color, and let the downstream image compositor
|
|
3112
|
+
* blend in the background color. In this case, the result image
|
|
3113
|
+
* should be treated as a premultiplied image.
|
|
3114
|
+
*
|
|
3115
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
3116
|
+
* This is better when the image is drawn into a frame or other
|
|
3117
|
+
* context where the background is not expected to contribute to
|
|
3118
|
+
* the final content.
|
|
3119
|
+
*
|
|
3120
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
3121
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
3122
|
+
* Because of the complication at the edges, this edging mode can
|
|
3123
|
+
* be significantly slower than the others. It can be numerically
|
|
3124
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
3125
|
+
* is zero, which can result in division by zero during the computation.
|
|
3126
|
+
* The results for this edging mode are usually quite visually similar
|
|
3127
|
+
* to kvImageEdgeExtend.
|
|
3128
|
+
*
|
|
3129
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
3130
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
3131
|
+
* not touch the src or dest image.
|
|
3132
|
+
*
|
|
3133
|
+
* kvImageLeaveAlphaUnchanged Apply the convolution to the last three channels in memory, only.
|
|
3134
|
+
*
|
|
3135
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
3136
|
+
*
|
|
3137
|
+
* @/textblock </pre>
|
|
3138
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
3139
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
3140
|
+
* be returned.
|
|
3141
|
+
*
|
|
3142
|
+
* @return One of the following error codes may be returned:
|
|
3143
|
+
* <pre>@textblock
|
|
3144
|
+
* kvImageNoError Success.
|
|
3145
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
3146
|
+
* the temp buffer to use with this function and this set of
|
|
3147
|
+
* parameters.
|
|
3148
|
+
*
|
|
3149
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
3150
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
3151
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
3152
|
+
*
|
|
3153
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
3154
|
+
* to corresponding dimensions of the source buffer.
|
|
3155
|
+
*
|
|
3156
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
3157
|
+
*
|
|
3158
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
3159
|
+
*
|
|
3160
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
3161
|
+
*
|
|
3162
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
3163
|
+
* @/textblock </pre>
|
|
3164
|
+
*/
|
|
7
3165
|
VIMAGE_PF vImage_Error vImageBoxConvolve_ARGB8888( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, uint32_t kernel_height, uint32_t kernel_width, const Pixel_8888 backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
3166
|
+
|
|
3167
|
+
/*!
|
|
3168
|
+
* @functiongroup Tent Convolve
|
|
3169
|
+
* @discussion A tent convolve is a special case of the standard convolution, which has a much faster algorithm.
|
|
3170
|
+
* A tent kernel is a kernel populated with slope of 1 rising towards the center. 2D kernels
|
|
3171
|
+
* are calculated as the product of the appropriate 1D kernels. e.g.
|
|
3172
|
+
* <pre> @textblock
|
|
3173
|
+
* {1,2,3,2,1}
|
|
3174
|
+
* @/textblock </pre>
|
|
3175
|
+
* or
|
|
3176
|
+
* <pre> @textblock
|
|
3177
|
+
* |1| { {1,2,1},
|
|
3178
|
+
* |2| * {1,2,1} = {2,4,2},
|
|
3179
|
+
* |1| {1,2,1} }
|
|
3180
|
+
* @/textblock </pre>
|
|
3181
|
+
* This returns a blur that is more heavily weighted towards the center pixel than a box blur.
|
|
3182
|
+
*
|
|
3183
|
+
* Unlike general purpose convolution, the cost of a tent convolve algorithm is theoretically constant
|
|
3184
|
+
* regardless of kernel size, so it can be an inexpensive choice for very large blurs. The tent convolve
|
|
3185
|
+
* behavior may not be as desired, however, because the blur effect is rectangular in appearance, whereas
|
|
3186
|
+
* most expect a blurring effect to be gaussian or roughly circular. The rectangularity of the tent blur
|
|
3187
|
+
* is less obvious than the box blur. A tent blur has somewhat larger constant cost than a box blur.
|
|
3188
|
+
*
|
|
3189
|
+
* <pre>@textblock
|
|
3190
|
+
* =========================================================================
|
|
3191
|
+
* ====== MOST VIMAGE CONVOLUTION FUNCTIONS DO NOT WORK IN PLACE =====
|
|
3192
|
+
* =========================================================================
|
|
3193
|
+
* @/textblock </pre>
|
|
3194
|
+
*/
|
|
3195
|
+
|
|
3196
|
+
/*!
|
|
3197
|
+
* @function vImageTentConvolve_Planar8
|
|
3198
|
+
* @abstract Special purpose tent convolution on a Planar8 image.
|
|
3199
|
+
* @discussion This filter applies a tent filter to a Planar8 image. A tent filter uses a much faster algorithm
|
|
3200
|
+
* than a standard convolution, and may be a good solution for real time application of large blur
|
|
3201
|
+
* radii against images.
|
|
3202
|
+
* For each pixel:
|
|
3203
|
+
* <pre>@textblock
|
|
3204
|
+
* for each pixel[y][x] in image{
|
|
3205
|
+
* int sum = 0;
|
|
3206
|
+
* int divisor = 0;
|
|
3207
|
+
*
|
|
3208
|
+
* // Calculate weighted average over kernel area
|
|
3209
|
+
* for each kernel_element[i][j] in kernel{
|
|
3210
|
+
* sum += kernel_element[i][j] *
|
|
3211
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
3212
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
3213
|
+
* divisor += kernel_element[i][j];
|
|
3214
|
+
* }
|
|
3215
|
+
*
|
|
3216
|
+
* // Correct for the scaling introduced by multiplying by the weights table
|
|
3217
|
+
* sum = (sum + divisor/2) / divisor;
|
|
3218
|
+
*
|
|
3219
|
+
* // write out result
|
|
3220
|
+
* result[y][x] = CLAMP(sum, 0, 255);
|
|
3221
|
+
* }
|
|
3222
|
+
* @/textblock </pre>
|
|
3223
|
+
*
|
|
3224
|
+
* This filter does not work in place.
|
|
3225
|
+
*
|
|
3226
|
+
* @param src The input image
|
|
3227
|
+
*
|
|
3228
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
3229
|
+
* This may not alias the src image.
|
|
3230
|
+
*
|
|
3231
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
3232
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
3233
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
3234
|
+
* the size is returned instead of an error code from the left hand side.
|
|
3235
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
3236
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
3237
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
3238
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
3239
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
3240
|
+
* concurrently, a different temp buffer should be used for each.
|
|
3241
|
+
*
|
|
3242
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
3243
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3244
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
3245
|
+
*
|
|
3246
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
3247
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3248
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
3249
|
+
*
|
|
3250
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
3251
|
+
*
|
|
3252
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
3253
|
+
*
|
|
3254
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
3255
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
3256
|
+
* kernel extends off the edge of the image.
|
|
3257
|
+
*
|
|
3258
|
+
* @param flags The following flags are allowed:
|
|
3259
|
+
* <pre>@textblock
|
|
3260
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
3261
|
+
* copy the corresponding source pixel to the destination. This
|
|
3262
|
+
* will result in a ring off unconvolved content at the edges
|
|
3263
|
+
* and convolved content in the middle.
|
|
3264
|
+
*
|
|
3265
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
3266
|
+
* For a blur filter this will look like the edges of the image
|
|
3267
|
+
* have been blurred into a particular color. This is usually
|
|
3268
|
+
* appropriate when the color of the surface onto which the image
|
|
3269
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
3270
|
+
* as a background color, and let the downstream image compositor
|
|
3271
|
+
* blend in the background color. In this case, the result image
|
|
3272
|
+
* should be treated as a premultiplied image.
|
|
3273
|
+
*
|
|
3274
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
3275
|
+
* This is better when the image is drawn into a frame or other
|
|
3276
|
+
* context where the background is not expected to contribute to
|
|
3277
|
+
* the final content.
|
|
3278
|
+
*
|
|
3279
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
3280
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
3281
|
+
* Because of the complication at the edges, this edging mode can
|
|
3282
|
+
* be significantly slower than the others. It can be numerically
|
|
3283
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
3284
|
+
* is zero, which can result in division by zero during the computation.
|
|
3285
|
+
* The results for this edging mode are usually quite visually similar
|
|
3286
|
+
* to kvImageEdgeExtend.
|
|
3287
|
+
*
|
|
3288
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
3289
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
3290
|
+
* not touch the src or dest image.
|
|
3291
|
+
*
|
|
3292
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
3293
|
+
*
|
|
3294
|
+
* @/textblock </pre>
|
|
3295
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
3296
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
3297
|
+
* be returned.
|
|
3298
|
+
*
|
|
3299
|
+
* @return One of the following error codes may be returned:
|
|
3300
|
+
* <pre>@textblock
|
|
3301
|
+
* kvImageNoError Success.
|
|
3302
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
3303
|
+
* the temp buffer to use with this function and this set of
|
|
3304
|
+
* parameters.
|
|
3305
|
+
*
|
|
3306
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
3307
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
3308
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
3309
|
+
*
|
|
3310
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
3311
|
+
* to corresponding dimensions of the source buffer.
|
|
3312
|
+
*
|
|
3313
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
3314
|
+
*
|
|
3315
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
3316
|
+
*
|
|
3317
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
3318
|
+
*
|
|
3319
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
3320
|
+
*
|
|
3321
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
3322
|
+
* @/textblock </pre>
|
|
3323
|
+
*/
|
|
3324
|
+
VIMAGE_PF vImage_Error vImageTentConvolve_Planar8( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, uint32_t kernel_height, uint32_t kernel_width, Pixel_8 backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
3325
|
+
|
|
3326
|
+
|
|
3327
|
+
|
|
3328
|
+
|
|
3329
|
+
/*!
|
|
3330
|
+
* @function vImageTentConvolve_ARGB8888
|
|
3331
|
+
* @abstract Special purpose tent convolution on a 4-channel interleaved, 8-bit per channel image.
|
|
3332
|
+
* @discussion This filter applies a tent filter to a 4-channel interleaved, 8-bit per channel imagee.
|
|
3333
|
+
* A tent filter uses a much faster algorithm than a standard convolution, and may be a good
|
|
3334
|
+
* solution for real time application of large blur radii against images.
|
|
3335
|
+
* For each pixel:
|
|
3336
|
+
* <pre>@textblock
|
|
3337
|
+
* for each pixel[y][x] in image{
|
|
3338
|
+
* int sumA = 0;
|
|
3339
|
+
* int sumR = 0;
|
|
3340
|
+
* int sumG = 0;
|
|
3341
|
+
* int sumB = 0;
|
|
3342
|
+
* int divisor = 0;
|
|
3343
|
+
*
|
|
3344
|
+
* // Calculate weighted average over kernel area
|
|
3345
|
+
* for each kernel_element[i][j] in kernel{
|
|
3346
|
+
* sumA += kernel_element[i][j] *
|
|
3347
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][0];
|
|
3348
|
+
* sumR += kernel_element[i][j] *
|
|
3349
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][1];
|
|
3350
|
+
* sumG += kernel_element[i][j] *
|
|
3351
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][2];
|
|
3352
|
+
* sumB += kernel_element[i][j] *
|
|
3353
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2][x+j+srcOffsetToROI_X- kernel_width/2][3];
|
|
3354
|
+
* divisor += kernel_element[i][j];
|
|
3355
|
+
* }
|
|
3356
|
+
* // Correct for the scaling introduced by multiplying by the weights table
|
|
3357
|
+
* sumA = (sumA + divisor/2) / divisor;
|
|
3358
|
+
* sumR = (sumR + divisor/2) / divisor;
|
|
3359
|
+
* sumG = (sumG + divisor/2) / divisor;
|
|
3360
|
+
* sumB = (sumB + divisor/2) / divisor;
|
|
3361
|
+
*
|
|
3362
|
+
* // write out result
|
|
3363
|
+
* result[y][x][0] = CLAMP(sumA, 0, 255);
|
|
3364
|
+
* result[y][x][1] = CLAMP(sumR, 0, 255);
|
|
3365
|
+
* result[y][x][2] = CLAMP(sumG, 0, 255);
|
|
3366
|
+
* result[y][x][3] = CLAMP(sumB, 0, 255);
|
|
3367
|
+
* }
|
|
3368
|
+
* @/textblock </pre>
|
|
3369
|
+
*
|
|
3370
|
+
* This filter does not work in place.
|
|
3371
|
+
*
|
|
3372
|
+
* This filter will work without modification for other byte orders such as RGBA, BGRA, AGBR, CMYK, etc.
|
|
3373
|
+
* The image should be non-premultiplied to avoid odd results in non-opaque regions.
|
|
3374
|
+
*
|
|
3375
|
+
* @param src The input image
|
|
3376
|
+
*
|
|
3377
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
3378
|
+
* This may not alias the src image.
|
|
3379
|
+
*
|
|
3380
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
3381
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
3382
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
3383
|
+
* the size is returned instead of an error code from the left hand side.
|
|
3384
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
3385
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
3386
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
3387
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
3388
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
3389
|
+
* concurrently, a different temp buffer should be used for each.
|
|
3390
|
+
*
|
|
3391
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
3392
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3393
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
3394
|
+
*
|
|
3395
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
3396
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3397
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
3398
|
+
*
|
|
3399
|
+
* @param kernel_height The height of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
3400
|
+
*
|
|
3401
|
+
* @param kernel_width The width of the 2D table of weights passed in as kernel. It must be an odd number.
|
|
3402
|
+
*
|
|
3403
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
3404
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
3405
|
+
* kernel extends off the edge of the image.
|
|
3406
|
+
*
|
|
3407
|
+
* @param flags The following flags are allowed:
|
|
3408
|
+
* <pre>@textblock
|
|
3409
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
3410
|
+
* copy the corresponding source pixel to the destination. This
|
|
3411
|
+
* will result in a ring off unconvolved content at the edges
|
|
3412
|
+
* and convolved content in the middle.
|
|
3413
|
+
*
|
|
3414
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
3415
|
+
* For a blur filter this will look like the edges of the image
|
|
3416
|
+
* have been blurred into a particular color. This is usually
|
|
3417
|
+
* appropriate when the color of the surface onto which the image
|
|
3418
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
3419
|
+
* as a background color, and let the downstream image compositor
|
|
3420
|
+
* blend in the background color. In this case, the result image
|
|
3421
|
+
* should be treated as a premultiplied image.
|
|
3422
|
+
*
|
|
3423
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
3424
|
+
* This is better when the image is drawn into a frame or other
|
|
3425
|
+
* context where the background is not expected to contribute to
|
|
3426
|
+
* the final content.
|
|
3427
|
+
*
|
|
3428
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
3429
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
3430
|
+
* Because of the complication at the edges, this edging mode can
|
|
3431
|
+
* be significantly slower than the others. It can be numerically
|
|
3432
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
3433
|
+
* is zero, which can result in division by zero during the computation.
|
|
3434
|
+
* The results for this edging mode are usually quite visually similar
|
|
3435
|
+
* to kvImageEdgeExtend.
|
|
3436
|
+
*
|
|
3437
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
3438
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
3439
|
+
* not touch the src or dest image.
|
|
3440
|
+
*
|
|
3441
|
+
* kvImageLeaveAlphaUnchanged Apply the convolution to the last three channels in memory, only.
|
|
3442
|
+
*
|
|
3443
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
3444
|
+
*
|
|
3445
|
+
* @/textblock </pre>
|
|
3446
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
3447
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
3448
|
+
* be returned.
|
|
3449
|
+
*
|
|
3450
|
+
* @return One of the following error codes may be returned:
|
|
3451
|
+
* <pre>@textblock
|
|
3452
|
+
* kvImageNoError Success.
|
|
3453
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
3454
|
+
* the temp buffer to use with this function and this set of
|
|
3455
|
+
* parameters.
|
|
3456
|
+
*
|
|
3457
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
3458
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
3459
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
3460
|
+
*
|
|
3461
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
3462
|
+
* to corresponding dimensions of the source buffer.
|
|
3463
|
+
*
|
|
3464
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
3465
|
+
*
|
|
3466
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
3467
|
+
*
|
|
3468
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
3469
|
+
*
|
|
3470
|
+
* kvImageInvalidKernelSize The kernel height and width must be odd numbers.
|
|
3471
|
+
* @/textblock </pre>
|
|
3472
|
+
*/
|
|
3473
|
+
VIMAGE_PF vImage_Error vImageTentConvolve_ARGB8888( const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer, vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y, uint32_t kernel_height, uint32_t kernel_width, const Pixel_8888 backgroundColor, vImage_Flags flags ) VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(10.4), ios(5.0), watchos(1.0), tvos(5.0));
|
|
3474
|
+
|
|
3475
|
+
/*!
|
|
3476
|
+
* @functiongroup Separable Convolution
|
|
3477
|
+
*
|
|
3478
|
+
* @discussion A separable convolution applies two separate 1D filters along the rows and columns
|
|
3479
|
+
* of an image in succession. This allows for a faster implementation compared to
|
|
3480
|
+
* applying the corresponding 2D convolution filter, which is the outer product of the
|
|
3481
|
+
* two 1D filters. An example is the Sobel filter for approximating the image gradient.
|
|
3482
|
+
* The Sobel filter is composed of the averaging filter {1,2,1} and the differentiation
|
|
3483
|
+
* filter {-1,0,1}. For the image x-derivative, this results in the general 2D filter:
|
|
3484
|
+
* <pre> @textblock
|
|
3485
|
+
* |1| { {-1,0,1},
|
|
3486
|
+
* |2| * {-1,0,1} = {-2,0,2},
|
|
3487
|
+
* |1| {-1,0,1} }
|
|
3488
|
+
* @/textblock </pre>
|
|
3489
|
+
* The specialized tent convolve filter vImageTentConvolve_Planar8() is a particular
|
|
3490
|
+
* example of a separable filter.
|
|
3491
|
+
*
|
|
3492
|
+
* There are functions for separable convolution of Planar8 (8-bit integer) and
|
|
3493
|
+
* PlanarF (float) images, just as for the general 2D convolutions functions above.
|
|
3494
|
+
* In addition, there are functions for separable convolution of Planar16U (16-bit
|
|
3495
|
+
* integer) images and Planar8 to Planar16U images. These 16-bit versions can be used
|
|
3496
|
+
* to, for example, implement scale-space filtering where several layers of Gaussian
|
|
3497
|
+
* smoothed images, with increasing sigma, are generated. The initial image is often
|
|
3498
|
+
* 8-bit and the Gaussian smoothed images are represented with 16 bits of precision.
|
|
3499
|
+
*
|
|
3500
|
+
* A difference in the API of these separable convolution functions, compared to the
|
|
3501
|
+
* general 2D functions above, is that all planar integer versions uses floating point
|
|
3502
|
+
* kernels, just as the PlanarF version. This allows for increased precision while
|
|
3503
|
+
* still being fast on modern processors. The general convolution function
|
|
3504
|
+
* vImageConvolve_Planar8() is using 16-bit kernels with a 32-bit integer accumulator
|
|
3505
|
+
* becasue at the time it was first implemented this allowed for faster execution.
|
|
3506
|
+
*
|
|
3507
|
+
* All separable convolution functions also support a bias which is added to the
|
|
3508
|
+
* weighted sum of the pixels. This can be used to control the range of planar integer
|
|
3509
|
+
* images and effectively treating the 8-bit and 16-bit versions as signed ranges.
|
|
3510
|
+
* Since all separable functions support a bias as input parameter the WithBias string
|
|
3511
|
+
* has not been added to the functions names.
|
|
3512
|
+
*
|
|
3513
|
+
*/
|
|
3514
|
+
|
|
3515
|
+
/*!
|
|
3516
|
+
* @function vImageSepConvolve_Planar8
|
|
3517
|
+
* @abstract Separable convolution on a Planar8 image.
|
|
3518
|
+
* @discussion This filter applies two separate 1D filters along the rows and columns of
|
|
3519
|
+
* a Planar8 image.
|
|
3520
|
+
*
|
|
3521
|
+
* For each pixel:
|
|
3522
|
+
* <pre>@textblock
|
|
3523
|
+
* for each pixel[y][x] in image {
|
|
3524
|
+
* float sum = bias;
|
|
3525
|
+
*
|
|
3526
|
+
* // Calculate weighted average over kernel area
|
|
3527
|
+
* for each kernelY_element[i] in kernelY {
|
|
3528
|
+
* for each kernelX_element[j] in kernelX {
|
|
3529
|
+
* sum += kernelY_element[i] * kernelX_element[j] *
|
|
3530
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
3531
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
3532
|
+
* }
|
|
3533
|
+
* }
|
|
3534
|
+
* // Add 0.5 to round to nearest int when converting float to uint8_t
|
|
3535
|
+
* sum = sum + 0.5f;
|
|
3536
|
+
*
|
|
3537
|
+
* // write out result
|
|
3538
|
+
* result[y][x] = (uint8_t)CLAMP(sum, 0, 255);
|
|
3539
|
+
* }
|
|
3540
|
+
* @/textblock </pre>
|
|
3541
|
+
*
|
|
3542
|
+
* This filter does not work in place.
|
|
3543
|
+
*
|
|
3544
|
+
* @param src The input image
|
|
3545
|
+
*
|
|
3546
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
3547
|
+
* This may not alias the src image.
|
|
3548
|
+
*
|
|
3549
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
3550
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
3551
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
3552
|
+
* the size is returned instead of an error code from the left hand side.
|
|
3553
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
3554
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
3555
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
3556
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
3557
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
3558
|
+
* concurrently, a different temp buffer should be used for each.
|
|
3559
|
+
*
|
|
3560
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
3561
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3562
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
3563
|
+
*
|
|
3564
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
3565
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3566
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
3567
|
+
*
|
|
3568
|
+
* @param kernelX A pointer to a 1D array of weights of dimension kernelX_width.
|
|
3569
|
+
* For example, for a simple 3x3 Sobel x-derivative filter it's {-1.0, 0.0, 1.0}.
|
|
3570
|
+
*
|
|
3571
|
+
* @param kernelX_width The width of the 1D array of weights passed in as kernelX. It must be an odd number.
|
|
3572
|
+
*
|
|
3573
|
+
* @param kernelY A pointer to a 1D array of weights of dimension kernelY_width.
|
|
3574
|
+
* For example, for a simple 3x3 Sobel x-derivative filter it's {1.0, 2.0, 1.0}.
|
|
3575
|
+
*
|
|
3576
|
+
* @param kernelY_width The width of the 1D array of weights passed in as kernelY. It must be an odd number.
|
|
3577
|
+
*
|
|
3578
|
+
* @param bias This value is added to the sum of weighted pixels.
|
|
3579
|
+
* You might provide a bias of 128 to move the encoding for 0 to 128 so that
|
|
3580
|
+
* negative numbers are representable, such as Sobel derivative filters.
|
|
3581
|
+
*
|
|
3582
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
3583
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
3584
|
+
* kernel extends off the edge of the image.
|
|
3585
|
+
*
|
|
3586
|
+
* @param flags The following flags are allowed:
|
|
3587
|
+
* <pre>@textblock
|
|
3588
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
3589
|
+
* copy the corresponding source pixel to the destination. This
|
|
3590
|
+
* will result in a ring off unconvolved content at the edges
|
|
3591
|
+
* and convolved content in the middle.
|
|
3592
|
+
*
|
|
3593
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
3594
|
+
* For a blur filter this will look like the edges of the image
|
|
3595
|
+
* have been blurred into a particular color. This is usually
|
|
3596
|
+
* appropriate when the color of the surface onto which the image
|
|
3597
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
3598
|
+
* as a background color, and let the downstream image compositor
|
|
3599
|
+
* blend in the background color. In this case, the result image
|
|
3600
|
+
* should be treated as a premultiplied image.
|
|
3601
|
+
*
|
|
3602
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
3603
|
+
* This is better when the image is drawn into a frame or other
|
|
3604
|
+
* context where the background is not expected to contribute to
|
|
3605
|
+
* the final content.
|
|
3606
|
+
*
|
|
3607
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
3608
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
3609
|
+
* Because of the complication at the edges, this edging mode can
|
|
3610
|
+
* be significantly slower than the others. It can be numerically
|
|
3611
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
3612
|
+
* is zero, which can result in division by zero during the computation.
|
|
3613
|
+
* The results for this edging mode are usually quite visually similar
|
|
3614
|
+
* to kvImageEdgeExtend.
|
|
3615
|
+
*
|
|
3616
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
3617
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
3618
|
+
* not touch the src or dest image.
|
|
3619
|
+
*
|
|
3620
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
3621
|
+
*
|
|
3622
|
+
* @/textblock </pre>
|
|
3623
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
3624
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
3625
|
+
* be returned.
|
|
3626
|
+
*
|
|
3627
|
+
* @return One of the following error codes may be returned:
|
|
3628
|
+
* <pre>@textblock
|
|
3629
|
+
* kvImageNoError Success.
|
|
3630
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
3631
|
+
* the temp buffer to use with this function and this set of
|
|
3632
|
+
* parameters.
|
|
3633
|
+
*
|
|
3634
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
3635
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
3636
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
3637
|
+
*
|
|
3638
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
3639
|
+
* to corresponding dimensions of the source buffer.
|
|
3640
|
+
*
|
|
3641
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
3642
|
+
*
|
|
3643
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
3644
|
+
*
|
|
3645
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
3646
|
+
*
|
|
3647
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
3648
|
+
*
|
|
3649
|
+
* kvImageInvalidKernelSize The kernel sizes must be odd numbers.
|
|
3650
|
+
* @/textblock </pre>
|
|
3651
|
+
*/
|
|
3652
|
+
VIMAGE_PF vImage_Error
|
|
3653
|
+
vImageSepConvolve_Planar8(const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer,
|
|
3654
|
+
vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y,
|
|
3655
|
+
const float *kernelX, uint32_t kernelX_width, const float *kernelY, uint32_t kernelY_width,
|
|
3656
|
+
float bias, Pixel_16U backgroundColor, vImage_Flags flags)
|
|
3657
|
+
VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0));
|
|
3658
|
+
|
|
3659
|
+
/*!
|
|
3660
|
+
* @function vImageSepConvolve_PlanarF
|
|
3661
|
+
* @abstract Separable convolution on a PlanarF image.
|
|
3662
|
+
* @discussion This filter applies two separate 1D filters along the rows and columns of
|
|
3663
|
+
* a PlanarF image.
|
|
3664
|
+
*
|
|
3665
|
+
* For each pixel:
|
|
3666
|
+
* <pre>@textblock
|
|
3667
|
+
* for each pixel[y][x] in image {
|
|
3668
|
+
* float sum = bias;
|
|
3669
|
+
*
|
|
3670
|
+
* // Calculate weighted average over kernel area
|
|
3671
|
+
* for each kernelY_element[i] in kernelY {
|
|
3672
|
+
* for each kernelX_element[j] in kernelX {
|
|
3673
|
+
* sum += kernelY_element[i] * kernelX_element[j] *
|
|
3674
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
3675
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
3676
|
+
* }
|
|
3677
|
+
* }
|
|
3678
|
+
*
|
|
3679
|
+
* // write out result
|
|
3680
|
+
* result[y][x] = sum;
|
|
3681
|
+
* }
|
|
3682
|
+
* @/textblock </pre>
|
|
3683
|
+
*
|
|
3684
|
+
* This filter does not work in place.
|
|
3685
|
+
*
|
|
3686
|
+
* @param src The input image
|
|
3687
|
+
*
|
|
3688
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
3689
|
+
* This may not alias the src image.
|
|
3690
|
+
*
|
|
3691
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
3692
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
3693
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
3694
|
+
* the size is returned instead of an error code from the left hand side.
|
|
3695
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
3696
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
3697
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
3698
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
3699
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
3700
|
+
* concurrently, a different temp buffer should be used for each.
|
|
3701
|
+
*
|
|
3702
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
3703
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3704
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
3705
|
+
*
|
|
3706
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
3707
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3708
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
3709
|
+
*
|
|
3710
|
+
* @param kernelX A pointer to a 1D array of weights of dimension kernelX_width.
|
|
3711
|
+
*
|
|
3712
|
+
* @param kernelX_width The width of the 1D array of weights passed in as kernelX. It must be an odd number.
|
|
3713
|
+
*
|
|
3714
|
+
* @param kernelY A pointer to a 1D array of weights of dimension kernelY_width.
|
|
3715
|
+
*
|
|
3716
|
+
* @param kernelY_width The width of the 1D array of weights passed in as kernelY. It must be an odd number.
|
|
3717
|
+
*
|
|
3718
|
+
* @param bias This value is added to the sum of weighted pixels.
|
|
3719
|
+
*
|
|
3720
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
3721
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
3722
|
+
* kernel extends off the edge of the image.
|
|
3723
|
+
*
|
|
3724
|
+
* @param flags The following flags are allowed:
|
|
3725
|
+
* <pre>@textblock
|
|
3726
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
3727
|
+
* copy the corresponding source pixel to the destination. This
|
|
3728
|
+
* will result in a ring off unconvolved content at the edges
|
|
3729
|
+
* and convolved content in the middle.
|
|
3730
|
+
*
|
|
3731
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
3732
|
+
* For a blur filter this will look like the edges of the image
|
|
3733
|
+
* have been blurred into a particular color. This is usually
|
|
3734
|
+
* appropriate when the color of the surface onto which the image
|
|
3735
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
3736
|
+
* as a background color, and let the downstream image compositor
|
|
3737
|
+
* blend in the background color. In this case, the result image
|
|
3738
|
+
* should be treated as a premultiplied image.
|
|
3739
|
+
*
|
|
3740
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
3741
|
+
* This is better when the image is drawn into a frame or other
|
|
3742
|
+
* context where the background is not expected to contribute to
|
|
3743
|
+
* the final content.
|
|
3744
|
+
*
|
|
3745
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
3746
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
3747
|
+
* Because of the complication at the edges, this edging mode can
|
|
3748
|
+
* be significantly slower than the others. It can be numerically
|
|
3749
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
3750
|
+
* is zero, which can result in division by zero during the computation.
|
|
3751
|
+
* The results for this edging mode are usually quite visually similar
|
|
3752
|
+
* to kvImageEdgeExtend.
|
|
3753
|
+
*
|
|
3754
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
3755
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
3756
|
+
* not touch the src or dest image.
|
|
3757
|
+
*
|
|
3758
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
3759
|
+
*
|
|
3760
|
+
* @/textblock </pre>
|
|
3761
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
3762
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
3763
|
+
* be returned.
|
|
3764
|
+
*
|
|
3765
|
+
* @return One of the following error codes may be returned:
|
|
3766
|
+
* <pre>@textblock
|
|
3767
|
+
* kvImageNoError Success.
|
|
3768
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
3769
|
+
* the temp buffer to use with this function and this set of
|
|
3770
|
+
* parameters.
|
|
3771
|
+
*
|
|
3772
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
3773
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
3774
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
3775
|
+
*
|
|
3776
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
3777
|
+
* to corresponding dimensions of the source buffer.
|
|
3778
|
+
*
|
|
3779
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
3780
|
+
*
|
|
3781
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
3782
|
+
*
|
|
3783
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
3784
|
+
*
|
|
3785
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
3786
|
+
*
|
|
3787
|
+
* kvImageInvalidKernelSize The kernel sizes must be odd numbers.
|
|
3788
|
+
* @/textblock </pre>
|
|
3789
|
+
*/
|
|
3790
|
+
VIMAGE_PF vImage_Error
|
|
3791
|
+
vImageSepConvolve_PlanarF(const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer,
|
|
3792
|
+
vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y,
|
|
3793
|
+
const float *kernelX, uint32_t kernelX_width, const float *kernelY, uint32_t kernelY_width,
|
|
3794
|
+
float bias, Pixel_F backgroundColor, vImage_Flags flags)
|
|
3795
|
+
VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0));
|
|
3796
|
+
|
|
3797
|
+
/*!
|
|
3798
|
+
* @function vImageSepConvolve_Planar16F
|
|
3799
|
+
* @abstract Separable convolution on a Planar16F image.
|
|
3800
|
+
* @discussion This filter applies two separate 1D filters along the rows and columns of a Planar16F image.
|
|
3801
|
+
* The weighted average is computed with single-precision floating-point kernel values. However, if
|
|
3802
|
+
* the flag kvImageUseFP16Accumulator is set all internal filtering operations will
|
|
3803
|
+
* use 16-bit half-precision floating-point arithmetic when the CPU architecture
|
|
3804
|
+
* supports it. This results in up to 2x performance improvements but at the
|
|
3805
|
+
* expense of a less precise result; typically 2-3 bits of precision is lost.
|
|
3806
|
+
*
|
|
3807
|
+
* For each pixel:
|
|
3808
|
+
* <pre>@textblock
|
|
3809
|
+
* for each pixel[y][x] in image {
|
|
3810
|
+
* float sum = bias;
|
|
3811
|
+
*
|
|
3812
|
+
* // Calculate weighted average over kernel area
|
|
3813
|
+
* for each kernelY_element[i] in kernelY {
|
|
3814
|
+
* for each kernelX_element[j] in kernelX {
|
|
3815
|
+
* sum += kernelY_element[i] * kernelX_element[j] *
|
|
3816
|
+
* (float)pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
3817
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
3818
|
+
* }
|
|
3819
|
+
* }
|
|
3820
|
+
*
|
|
3821
|
+
* // Convert to half precisio and write out result
|
|
3822
|
+
* result[y][x] = (_Float16)sum;
|
|
3823
|
+
* }
|
|
3824
|
+
* @/textblock </pre>
|
|
3825
|
+
*
|
|
3826
|
+
* This filter does not work in place.
|
|
3827
|
+
*
|
|
3828
|
+
* @param src The input image
|
|
3829
|
+
*
|
|
3830
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
3831
|
+
* This may not alias the src image.
|
|
3832
|
+
*
|
|
3833
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
3834
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
3835
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
3836
|
+
* the size is returned instead of an error code from the left hand side.
|
|
3837
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
3838
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
3839
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
3840
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
3841
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
3842
|
+
* concurrently, a different temp buffer should be used for each.
|
|
3843
|
+
*
|
|
3844
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
3845
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3846
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
3847
|
+
*
|
|
3848
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
3849
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3850
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
3851
|
+
*
|
|
3852
|
+
* @param kernelX A pointer to a 1D array of weights of dimension kernelX_width.
|
|
3853
|
+
*
|
|
3854
|
+
* @param kernelX_width The width of the 1D array of weights passed in as kernelX. It must be an odd number.
|
|
3855
|
+
*
|
|
3856
|
+
* @param kernelY A pointer to a 1D array of weights of dimension kernelY_width.
|
|
3857
|
+
*
|
|
3858
|
+
* @param kernelY_width The width of the 1D array of weights passed in as kernelY. It must be an odd number.
|
|
3859
|
+
*
|
|
3860
|
+
* @param bias This value is added to the sum of weighted pixels.
|
|
3861
|
+
*
|
|
3862
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
3863
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
3864
|
+
* kernel extends off the edge of the image.
|
|
3865
|
+
*
|
|
3866
|
+
* @param flags The following flags are allowed:
|
|
3867
|
+
* <pre>@textblock
|
|
3868
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
3869
|
+
* copy the corresponding source pixel to the destination. This
|
|
3870
|
+
* will result in a ring off unconvolved content at the edges
|
|
3871
|
+
* and convolved content in the middle.
|
|
3872
|
+
*
|
|
3873
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
3874
|
+
* For a blur filter this will look like the edges of the image
|
|
3875
|
+
* have been blurred into a particular color. This is usually
|
|
3876
|
+
* appropriate when the color of the surface onto which the image
|
|
3877
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
3878
|
+
* as a background color, and let the downstream image compositor
|
|
3879
|
+
* blend in the background color. In this case, the result image
|
|
3880
|
+
* should be treated as a premultiplied image.
|
|
3881
|
+
*
|
|
3882
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
3883
|
+
* This is better when the image is drawn into a frame or other
|
|
3884
|
+
* context where the background is not expected to contribute to
|
|
3885
|
+
* the final content.
|
|
3886
|
+
*
|
|
3887
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
3888
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
3889
|
+
* Because of the complication at the edges, this edging mode can
|
|
3890
|
+
* be significantly slower than the others. It can be numerically
|
|
3891
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
3892
|
+
* is zero, which can result in division by zero during the computation.
|
|
3893
|
+
* The results for this edging mode are usually quite visually similar
|
|
3894
|
+
* to kvImageEdgeExtend.
|
|
3895
|
+
*
|
|
3896
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
3897
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
3898
|
+
* not touch the src or dest image.
|
|
3899
|
+
*
|
|
3900
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
3901
|
+
*
|
|
3902
|
+
* kvImageUseFP16Accumulator Enable 16-bit half-precision floating-point arithmetic when computing the
|
|
3903
|
+
* kernel averages when the CPU architecture supports it.
|
|
3904
|
+
*
|
|
3905
|
+
* @/textblock </pre>
|
|
3906
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
3907
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
3908
|
+
* be returned.
|
|
3909
|
+
*
|
|
3910
|
+
* @return One of the following error codes may be returned:
|
|
3911
|
+
* <pre>@textblock
|
|
3912
|
+
* kvImageNoError Success.
|
|
3913
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
3914
|
+
* the temp buffer to use with this function and this set of
|
|
3915
|
+
* parameters.
|
|
3916
|
+
*
|
|
3917
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
3918
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
3919
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
3920
|
+
*
|
|
3921
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
3922
|
+
* to corresponding dimensions of the source buffer.
|
|
3923
|
+
*
|
|
3924
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
3925
|
+
*
|
|
3926
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
3927
|
+
*
|
|
3928
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
3929
|
+
*
|
|
3930
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
3931
|
+
*
|
|
3932
|
+
* kvImageInvalidKernelSize The kernel sizes must be odd numbers.
|
|
3933
|
+
* @/textblock </pre>
|
|
3934
|
+
*/
|
|
3935
|
+
VIMAGE_PF vImage_Error
|
|
3936
|
+
vImageSepConvolve_Planar16F(const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer,
|
|
3937
|
+
vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y,
|
|
3938
|
+
const float *kernelX, uint32_t kernelX_width, const float *kernelY, uint32_t kernelY_width,
|
|
3939
|
+
float bias, Pixel_16F backgroundColor, vImage_Flags flags)
|
|
3940
|
+
VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(13.0), ios(16.0), watchos(9.0), tvos(16.0));
|
|
3941
|
+
|
|
3942
|
+
/*!
|
|
3943
|
+
* @function vImageSepConvolve_Planar16U
|
|
3944
|
+
* @abstract Separable convolution on a Planar16U image.
|
|
3945
|
+
* @discussion This filter applies two separate 1D filters along the rows and columns of
|
|
3946
|
+
* a Planar16U image.
|
|
3947
|
+
*
|
|
3948
|
+
* For each pixel:
|
|
3949
|
+
* <pre>@textblock
|
|
3950
|
+
* for each pixel[y][x] in image {
|
|
3951
|
+
* float sum = bias;
|
|
3952
|
+
*
|
|
3953
|
+
* // Calculate weighted average over kernel area
|
|
3954
|
+
* for each kernelY_element[i] in kernelY {
|
|
3955
|
+
* for each kernelX_element[j] in kernelX {
|
|
3956
|
+
* sum += kernelY_element[i] * kernelX_element[j] *
|
|
3957
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
3958
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
3959
|
+
* }
|
|
3960
|
+
* }
|
|
3961
|
+
* // Add 0.5 to round to nearest int when converting float to uint16_t
|
|
3962
|
+
* sum = sum + 0.5f;
|
|
3963
|
+
*
|
|
3964
|
+
* // write out result
|
|
3965
|
+
* result[y][x] = (uint16_t)CLAMP(sum, 0, 65535);
|
|
3966
|
+
* }
|
|
3967
|
+
* @/textblock </pre>
|
|
3968
|
+
*
|
|
3969
|
+
* This filter does not work in place.
|
|
3970
|
+
*
|
|
3971
|
+
* @param src The input image
|
|
3972
|
+
*
|
|
3973
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
3974
|
+
* This may not alias the src image.
|
|
3975
|
+
*
|
|
3976
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
3977
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
3978
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
3979
|
+
* the size is returned instead of an error code from the left hand side.
|
|
3980
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
3981
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
3982
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
3983
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
3984
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
3985
|
+
* concurrently, a different temp buffer should be used for each.
|
|
3986
|
+
*
|
|
3987
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
3988
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3989
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
3990
|
+
*
|
|
3991
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
3992
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
3993
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
3994
|
+
*
|
|
3995
|
+
* @param kernelX A pointer to a 1D array of weights of dimension kernelX_width.
|
|
3996
|
+
*
|
|
3997
|
+
* @param kernelX_width The width of the 1D array of weights passed in as kernelX. It must be an odd number.
|
|
3998
|
+
*
|
|
3999
|
+
* @param kernelY A pointer to a 1D array of weights of dimension kernelY_width.
|
|
4000
|
+
*
|
|
4001
|
+
* @param kernelY_width The width of the 1D array of weights passed in as kernelY. It must be an odd number.
|
|
4002
|
+
*
|
|
4003
|
+
* @param bias This value is added to the sum of weighted pixels.
|
|
4004
|
+
* You might provide a bias of 2 ** 15 = 32768 to move the encoding so that
|
|
4005
|
+
* negative numbers are representable.
|
|
4006
|
+
*
|
|
4007
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
4008
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
4009
|
+
* kernel extends off the edge of the image.
|
|
4010
|
+
*
|
|
4011
|
+
* @param flags The following flags are allowed:
|
|
4012
|
+
* <pre>@textblock
|
|
4013
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
4014
|
+
* copy the corresponding source pixel to the destination. This
|
|
4015
|
+
* will result in a ring off unconvolved content at the edges
|
|
4016
|
+
* and convolved content in the middle.
|
|
4017
|
+
*
|
|
4018
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
4019
|
+
* For a blur filter this will look like the edges of the image
|
|
4020
|
+
* have been blurred into a particular color. This is usually
|
|
4021
|
+
* appropriate when the color of the surface onto which the image
|
|
4022
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
4023
|
+
* as a background color, and let the downstream image compositor
|
|
4024
|
+
* blend in the background color. In this case, the result image
|
|
4025
|
+
* should be treated as a premultiplied image.
|
|
4026
|
+
*
|
|
4027
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
4028
|
+
* This is better when the image is drawn into a frame or other
|
|
4029
|
+
* context where the background is not expected to contribute to
|
|
4030
|
+
* the final content.
|
|
4031
|
+
*
|
|
4032
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
4033
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
4034
|
+
* Because of the complication at the edges, this edging mode can
|
|
4035
|
+
* be significantly slower than the others. It can be numerically
|
|
4036
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
4037
|
+
* is zero, which can result in division by zero during the computation.
|
|
4038
|
+
* The results for this edging mode are usually quite visually similar
|
|
4039
|
+
* to kvImageEdgeExtend.
|
|
4040
|
+
*
|
|
4041
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
4042
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
4043
|
+
* not touch the src or dest image.
|
|
4044
|
+
*
|
|
4045
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
4046
|
+
*
|
|
4047
|
+
* @/textblock </pre>
|
|
4048
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
4049
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
4050
|
+
* be returned.
|
|
4051
|
+
*
|
|
4052
|
+
* @return One of the following error codes may be returned:
|
|
4053
|
+
* <pre>@textblock
|
|
4054
|
+
* kvImageNoError Success.
|
|
4055
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
4056
|
+
* the temp buffer to use with this function and this set of
|
|
4057
|
+
* parameters.
|
|
4058
|
+
*
|
|
4059
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
4060
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
4061
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
4062
|
+
*
|
|
4063
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
4064
|
+
* to corresponding dimensions of the source buffer.
|
|
4065
|
+
*
|
|
4066
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
4067
|
+
*
|
|
4068
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
4069
|
+
*
|
|
4070
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
4071
|
+
*
|
|
4072
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
4073
|
+
*
|
|
4074
|
+
* kvImageInvalidKernelSize The kernel sizes must be odd numbers.
|
|
4075
|
+
* @/textblock </pre>
|
|
4076
|
+
*/
|
|
4077
|
+
VIMAGE_PF vImage_Error
|
|
4078
|
+
vImageSepConvolve_Planar16U(const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer,
|
|
4079
|
+
vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y,
|
|
4080
|
+
const float *kernelX, uint32_t kernelX_width, const float *kernelY, uint32_t kernelY_width,
|
|
4081
|
+
float bias, Pixel_16U backgroundColor, vImage_Flags flags)
|
|
4082
|
+
VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0));
|
|
4083
|
+
|
|
4084
|
+
/*!
|
|
4085
|
+
* @function vImageSepConvolve_Planar8to16U
|
|
4086
|
+
* @abstract Separable convolution on a Planar8 image.
|
|
4087
|
+
* @discussion This filter applies two separate 1D filters along the rows and columns of
|
|
4088
|
+
* a Planar8 source image and writing the result to a Planar16U destination image.
|
|
4089
|
+
* Both a bias and scale factor can be specified to control the range of the result.
|
|
4090
|
+
*
|
|
4091
|
+
* For each pixel:
|
|
4092
|
+
* <pre>@textblock
|
|
4093
|
+
* for each pixel[y][x] in image {
|
|
4094
|
+
* float sum = 0.0f;
|
|
4095
|
+
*
|
|
4096
|
+
* // Calculate weighted average over kernel area
|
|
4097
|
+
* for each kernelY_element[i] in kernelY {
|
|
4098
|
+
* for each kernelX_element[j] in kernelX {
|
|
4099
|
+
* sum += kernelY_element[i] * kernelX_element[j] *
|
|
4100
|
+
* pixel[y+i+srcOffsetToROI_Y-kernel_height/2]
|
|
4101
|
+
* [x+j+srcOffsetToROI_X- kernel_width/2];
|
|
4102
|
+
* }
|
|
4103
|
+
* }
|
|
4104
|
+
* // Scale sum and add bias and 0.5 to round float to uint16_t
|
|
4105
|
+
* sum = scale * sum + bias + 0.5f;
|
|
4106
|
+
*
|
|
4107
|
+
* // write out result
|
|
4108
|
+
* result[y][x] = (uint16_t)CLAMP(sum, 0, 65535);
|
|
4109
|
+
* }
|
|
4110
|
+
* @/textblock </pre>
|
|
4111
|
+
*
|
|
4112
|
+
* This filter does not work in place.
|
|
4113
|
+
*
|
|
4114
|
+
* @param src The input image
|
|
4115
|
+
*
|
|
4116
|
+
* @param dest A pointer to a preallocated vImage_Buffer to receive the result image.
|
|
4117
|
+
* This may not alias the src image.
|
|
4118
|
+
*
|
|
4119
|
+
* @param tempBuffer An optional pointer to a region of memory to use as a working area during
|
|
4120
|
+
* computation. The size of the tempBuffer is given by calling the function
|
|
4121
|
+
* with the same parameters and the kvImageGetTempBufferSize flag, in which case
|
|
4122
|
+
* the size is returned instead of an error code from the left hand side.
|
|
4123
|
+
* You may pass NULL here, in which case a region of memory of similar size
|
|
4124
|
+
* will be allocated by the function and freed before it returns. Temp Buffers
|
|
4125
|
+
* are a way of avoiding lost time due to VM faults to initialize newly allocated
|
|
4126
|
+
* buffers. If you will be calling this function repeatedly with similar parameters
|
|
4127
|
+
* you should use a temp buffer. If the function is called from different threads
|
|
4128
|
+
* concurrently, a different temp buffer should be used for each.
|
|
4129
|
+
*
|
|
4130
|
+
* @param srcOffsetToROI_X An offset used in tiling to shift the position of the destination image
|
|
4131
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
4132
|
+
* when the destination tile is not aligned with the left edge of the image.
|
|
4133
|
+
*
|
|
4134
|
+
* @param srcOffsetToROI_Y An offset used in tiling to shift the position of the destination image
|
|
4135
|
+
* relative to the src image. Typically this is 0. Non-Zero values are needed
|
|
4136
|
+
* when the destination tile is not aligned with the top edge of the image.
|
|
4137
|
+
*
|
|
4138
|
+
* @param kernelX A pointer to a 1D array of weights of dimension kernelX_width.
|
|
4139
|
+
*
|
|
4140
|
+
* @param kernelX_width The width of the 1D array of weights passed in as kernelX. It must be an odd number.
|
|
4141
|
+
*
|
|
4142
|
+
* @param kernelY A pointer to a 1D array of weights of dimension kernelY_width.
|
|
4143
|
+
*
|
|
4144
|
+
* @param kernelY_width The width of the 1D array of weights passed in as kernelY. It must be an odd number.
|
|
4145
|
+
*
|
|
4146
|
+
* @param scale This value is multiplied with the sum of weighted pixels, before the bias
|
|
4147
|
+
* is applied. For example, for normalized kernels, where the weights add to 1.0,
|
|
4148
|
+
* specifying a scale of 257 ( = 65535 / 255 ) would expand the 8-bit input
|
|
4149
|
+
* range to a full 16-bit output range.
|
|
4150
|
+
*
|
|
4151
|
+
* @param bias This value is added to the sum of weighted pixels.
|
|
4152
|
+
*
|
|
4153
|
+
* @param backgroundColor When the kvImageBackgroundColorFill edging mode is active, the backgroundColor
|
|
4154
|
+
* parameter provides the background color to be used for missing pixels when the
|
|
4155
|
+
* kernel extends off the edge of the image.
|
|
4156
|
+
*
|
|
4157
|
+
* @param flags The following flags are allowed:
|
|
4158
|
+
* <pre>@textblock
|
|
4159
|
+
* kvImageCopyInPlace If any pixels covered by the kernel do no not exist, simply
|
|
4160
|
+
* copy the corresponding source pixel to the destination. This
|
|
4161
|
+
* will result in a ring off unconvolved content at the edges
|
|
4162
|
+
* and convolved content in the middle.
|
|
4163
|
+
*
|
|
4164
|
+
* kvImageBackgroundColorFill Substitute in the provided background color for missing pixels.
|
|
4165
|
+
* For a blur filter this will look like the edges of the image
|
|
4166
|
+
* have been blurred into a particular color. This is usually
|
|
4167
|
+
* appropriate when the color of the surface onto which the image
|
|
4168
|
+
* will be drawn is known. You can also use {Alpha = 0, color = 0}
|
|
4169
|
+
* as a background color, and let the downstream image compositor
|
|
4170
|
+
* blend in the background color. In this case, the result image
|
|
4171
|
+
* should be treated as a premultiplied image.
|
|
4172
|
+
*
|
|
4173
|
+
* kvImageEdgeExtend Substitute in the nearest defined pixel for missing pixels.
|
|
4174
|
+
* This is better when the image is drawn into a frame or other
|
|
4175
|
+
* context where the background is not expected to contribute to
|
|
4176
|
+
* the final content.
|
|
4177
|
+
*
|
|
4178
|
+
* kvImageTruncateKernel This is similar to kvImageEdgeExtend, except that edge pixels are
|
|
4179
|
+
* simply ignored, and the bias and divisor are adjusted accordingly.
|
|
4180
|
+
* Because of the complication at the edges, this edging mode can
|
|
4181
|
+
* be significantly slower than the others. It can be numerically
|
|
4182
|
+
* unstable if the sum over any rectangular subsection of the kernel
|
|
4183
|
+
* is zero, which can result in division by zero during the computation.
|
|
4184
|
+
* The results for this edging mode are usually quite visually similar
|
|
4185
|
+
* to kvImageEdgeExtend.
|
|
4186
|
+
*
|
|
4187
|
+
* kvImageGetTempBufferSize Instead of calculating the convolution of the image, return the
|
|
4188
|
+
* size of the temp buffer needed for this set of parameters. Does
|
|
4189
|
+
* not touch the src or dest image.
|
|
4190
|
+
*
|
|
4191
|
+
* kvImageDoNotTile Disable internal multithreading.
|
|
4192
|
+
*
|
|
4193
|
+
* @/textblock </pre>
|
|
4194
|
+
* The first four flags listed are edging modes. One and only one edging mode must be
|
|
4195
|
+
* provided. If no edging mode is provided (e.g. kvImageNoFlags), then an error will
|
|
4196
|
+
* be returned.
|
|
4197
|
+
*
|
|
4198
|
+
* @return One of the following error codes may be returned:
|
|
4199
|
+
* <pre>@textblock
|
|
4200
|
+
* kvImageNoError Success.
|
|
4201
|
+
* >= 0 If kvImageGetTempBufferSize is passed, this is the size of
|
|
4202
|
+
* the temp buffer to use with this function and this set of
|
|
4203
|
+
* parameters.
|
|
4204
|
+
*
|
|
4205
|
+
* kvImageInvalidEdgeStyle One and only one of the following flags must be provided:
|
|
4206
|
+
* { kvImageCopyInPlace, kvImageBackgroundColorFill,
|
|
4207
|
+
* kvImageEdgeExtend, kvImageTruncateKernel }
|
|
4208
|
+
*
|
|
4209
|
+
* kvImageRoiLargerThanInputBuffer The dest->width and height must be less than or equal
|
|
4210
|
+
* to corresponding dimensions of the source buffer.
|
|
4211
|
+
*
|
|
4212
|
+
* kvImageInvalidOffset_X The destination width + srcOffsetToROI_X > src->width
|
|
4213
|
+
*
|
|
4214
|
+
* kvImageInvalidOffset_Y The destination height + srcOffsetToROI_Y > src->height
|
|
4215
|
+
*
|
|
4216
|
+
* kvImageNullPointerArgument kernel may not be NULL
|
|
4217
|
+
*
|
|
4218
|
+
* kvImageMemoryAllocationError Could not allocate memory to serve as a temp buffer.
|
|
4219
|
+
*
|
|
4220
|
+
* kvImageInvalidKernelSize The kernel sizes must be odd numbers.
|
|
4221
|
+
* @/textblock </pre>
|
|
4222
|
+
*/
|
|
4223
|
+
VIMAGE_PF vImage_Error
|
|
4224
|
+
vImageSepConvolve_Planar8to16U(const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer,
|
|
4225
|
+
vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y,
|
|
4226
|
+
const float *kernelX, uint32_t kernelX_width, const float *kernelY, uint32_t kernelY_width,
|
|
4227
|
+
float scale, float bias, Pixel_8 backgroundColor, vImage_Flags flags)
|
|
4228
|
+
VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(11.0), ios(14.0), watchos(7.0), tvos(14.0));
|
|
4229
|
+
|
|
4230
|
+
|
|
4231
|
+
VIMAGE_PF vImage_Error
|
|
4232
|
+
vImageSepConvolve_ARGB8888(const vImage_Buffer *src, const vImage_Buffer *dest, void *tempBuffer,
|
|
4233
|
+
vImagePixelCount srcOffsetToROI_X, vImagePixelCount srcOffsetToROI_Y,
|
|
4234
|
+
const float *kernelX, uint32_t kernelX_width, const float *kernelY, uint32_t kernelY_width,
|
|
4235
|
+
float bias, const Pixel_8888 backgroundColor, vImage_Flags flags)
|
|
4236
|
+
VIMAGE_NON_NULL(1,2) API_AVAILABLE(macos(14.0), ios(17.0), watchos(10.0), tvos(17.0));
|
|
4237
|
+
|
|
8
4238
|
#ifdef __cplusplus
|
|
9
4239
|
}
|
|
10
4240
|
#endif
|
|
4241
|
+
|
|
11
4242
|
#endif
|
|
4243
|
+
|
|
4244
|
+
|