515 developing core image filters for ios df · 2016. 7. 8. · developing core image filters for...

324
© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. #WWDC14 Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer Tony Chu General Specialist

Upload: others

Post on 25-Feb-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

© 2014 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

#WWDC14

Developing Core Image Filters for iOS

Media

Session 515 Alexandre Naaman Lead Customizer

!

Tony Chu General Specialist

Page 2: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

New to iOS 8Write your own kernels

Introduced on OS X 10.4, now on iOS • Main motivation—unable to write kernels as a combination of existing filters

• Use cases

- “Per pixel effects” (e.g., hot pixels, vignette)

- Distortions that cannot be represented as a matrix (Droste)

Page 3: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Agenda

Concepts

Page 4: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Agenda

Concepts

Examples of writing custom kernels

Page 5: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Agenda

Concepts

Examples of writing custom kernels

Platform differences

Page 6: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Key Concepts

Page 7: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Key ConceptsFilters perform per pixel operations on an image

Original Result

SepiaFilter

Page 8: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Key ConceptsFilters can be chained together for complex effects

ResultOriginal

SepiaFilter

Hue AdjustFilter

ContrastFilter

Page 9: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Hue AdjustFilter

Key ConceptsIntermediate images are lightweight objects

ResultOriginal

ContrastFilter

SepiaFilter

Page 10: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

ResultOriginal

Key ConceptsEach filter has one or more kernel functions

ContrastFilter

SepiaFilter

kernel vec4 sepia (… kernel vec4 hue (… kernel vec4 contrast (…

Hue AdjustFilter

Page 11: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Key ConceptsKernels concatenated into programs to minimize buffers

ResultOriginal

kernel vec4 sepia (…

kernel vec4 hue (…

kernel vec4 contrast (…

ContrastFilterSepiaFilter

Concat’dFilter

Page 12: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Key ConceptsKernels concatenated into programs to minimize buffers

ResultOriginal

kernel vec4 sepia (…

kernel vec4 hue (…

kernel vec4 contrast (…

kernel vec4 sepia (…

kernel vec4 hue (…

kernel vec4 contrast (…

ContrastFilterSepiaFilter

Concat’dFilter

Page 13: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Core Image Classes

Page 14: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Core Image Classes

CIKernel • Represents a program written in Core Image’s kernel language

Page 15: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Core Image Classes

CIKernel • Represents a program written in Core Image’s kernel language

CIFilter • Has mutable input parameters

• Uses one or more CIKernels to make a new image based on inputs

Page 16: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Core Image Classes

CIKernel • Represents a program written in Core Image’s kernel language

CIFilter • Has mutable input parameters

• Uses one or more CIKernels to make a new image based on inputs

CIImage • An immutable object that represents the recipe for an image

• Non zero origin (lower left) and possibly infinite bounds

Page 17: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Core Image Classes

CIKernel • Represents a program written in Core Image’s kernel language

CIFilter • Has mutable input parameters

• Uses one or more CIKernels to make a new image based on inputs

CIImage • An immutable object that represents the recipe for an image

• Non zero origin (lower left) and possibly infinite bounds

CIContext • A object through which Core Image draws results

Page 18: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

void *inputBuffer={ !

!

!

!

};

ConceptsStarting assumptions

Page 19: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

void *inputBuffer={ !

!

!

!

};

void *outputBuffer={ !

!

!

!

};

ConceptsStarting assumptions

Page 20: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

void *inputBuffer={ !

!

!

!

};

for (j=0;j<height;j++){

}

void *outputBuffer={ !

!

!

!

};

ConceptsStarting assumptions

Page 21: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

void *inputBuffer={ !

!

!

!

};

for (j=0;j<height;j++){

}

for (i=0;i<width;i++){

}

void *outputBuffer={ !

!

!

!

};

ConceptsStarting assumptions

Page 22: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

void *inputBuffer={ !

!

!

!

};

for (j=0;j<height;j++){

}

for (i=0;i<width;i++){

}

void *outputBuffer={ !

!

!

!

};

outputBuffer[i][j]= processPixel (inputBuffer[i][j]);

ConceptsStarting assumptions

Page 23: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

void *inputBuffer={ !

!

!

!

};

for (j=0;j<height;j++){

}

for (i=0;i<width;i++){

}

void *outputBuffer={ !

!

!

!

};

outputBuffer[i][j]= processPixel (inputBuffer[i][j]);

ConceptsStarting assumptions

Page 24: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

void *inputBuffer={ !

!

!

!

};

for (j=0;j<height;j++){

}

for (i=0;i<width;i++){

}

void *outputBuffer={ !

!

!

!

};

outputBuffer[i][j]= processPixel (inputBuffer[i][j]);

ConceptsStarting assumptions

CIKernel: processPixel

Page 25: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

void *inputBuffer={ !

!

!

!

};

for (j=0;j<height;j++){

}

for (i=0;i<width;i++){

}

void *outputBuffer={ !

!

!

!

};

!!!

CIFilter subclass

outputBuffer[i][j]= processPixel (inputBuffer[i][j]);

ConceptsStarting assumptions

CIKernel: processPixel

Page 26: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

void *inputBuffer={ !

!

!

!

};

for (j=0;j<height;j++){

}

for (i=0;i<width;i++){

}

void *outputBuffer={ !

!

!

!

};

!!!

CIFilter subclass

outputBuffer[i][j]= processPixel (inputBuffer[i][j]);

ConceptsStarting assumptions

CIImageCIKernel: processPixel

Page 27: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

void *inputBuffer={ !

!

!

!

};

for (j=0;j<height;j++){

}

for (i=0;i<width;i++){

}

void *outputBuffer={ !

!

!

!

};

!!!

CIFilter subclass

outputBuffer[i][j]= processPixel (inputBuffer[i][j]);

ConceptsStarting assumptions

CIImageCIKernel: processPixel

other input params

Page 28: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

void *inputBuffer={ !

!

!

!

};

for (j=0;j<height;j++){

}

for (i=0;i<width;i++){

}

void *outputBuffer={ !

!

!

!

};

!!!

CIFilter subclass

outputBuffer[i][j]= processPixel (inputBuffer[i][j]);

ConceptsStarting assumptions

CIImage

CIImageCIKernel: processPixel

other input params

Page 29: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

WorkflowUsing Core Image on iOS

Page 30: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

WorkflowUsing Core Image on iOS

Create input CIImages

Page 31: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

WorkflowUsing Core Image on iOS

Create input CIImages

Subclass CIFilter

Page 32: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

WorkflowUsing Core Image on iOS

Create input CIImages

Subclass CIFilter

Get output CIImage

Page 33: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

WorkflowUsing Core Image on iOS

Create input CIImages

Subclass CIFilter

Get output CIImage

Use CIContext to render output image (to CGImageRef, EAGL context, etc.)

Page 34: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Create input CIImages

Subclass CIFilter • Create kernel

• Apply kernel to input image(s) and pass parameters from filter

WorkflowUsing Core Image on iOS

Create input CIImages

Subclass CIFilter

Get output CIImage

Use CIContext to render output image (to CGImageRef, EAGL context, etc.)

Page 35: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

115 Built-in CIFilters on iOSCIAccordianFoldTransition CIAdditionCompositing CIAffineClamp CIAffineTile CIAffineTransform CIAreaHistogram CIBarsSwipeTransition CIBlendWithMask CIBloom CIBumpDistortion CIBumpDistortionLinear CICheckerboardGenerator CICircleSplashDistortion CICircularScreen CICode128BarcodeGenerator CIColorBlendMode CIColorBurnBlendMode CIColorControls CIColorCube CIColorDodgeBlendMode CIColorInvert CIColorMap CIColorMatrix

CIColorMonochrome CIColorClamp CIColorCrossPolynomial CIColorPolynomial CIColorPosterize CIConstantColorGenerator CIConvolution3X3 CIConvolution5X5 CIConvolution9Horizontal CIConvolution9Vertical CICopyMachineTransition CICrop CIDarkenBlendMode CIDifferenceBlendMode CIDisintegrateWithMask CIDissolveTransition CIDivideBlendMode CIDotScreen CIEightfoldReflectedTile CIExclusionBlendMode CIExposureAdjust CIFalseColor CIFlashTransition

CIFourfoldReflectedTile CIFourfoldTranslatedTile CIGammaAdjust CIGaussianBlur CIGaussianGradient CIGlassDistortion CIGlideReflectedTile CIGloom CIHardLightBlendMode CIHatchedScreen CIHighlightShadowAdjust CIHistogramDisplayFilter CIHoleDistortion CIHueAdjust CIHueBlendMode CILanczosScaleTransform CILightenBlendMode CILightTunnel CILinearBurnBlendMode CILinearDodgeBlendMode CILinearGradient CILineScreen CILuminosityBlendMode

CIMaskToAlpha CIMaximumComponent CIMaximumCompositing CIMinimumComponent CIMinimumCompositing CIModTransition CIMultiplyBlendMode CIMultiplyCompositing CIOverlayBlendMode CIPerspectiveCorrection CIPerspectiveTile CIPerspectiveTransform CIPinchDistortion CIPinLightBlendMode CIPixellate CIRadialGradient CIRandomGenerator CISaturationBlendMode CIScreenBlendMode CISepiaTone CISharpenLuminance CISixfoldReflectedTile CISixfoldRotatedTile

CISoftLightBlendMode CISourceAtopCompositing CILinearToSRGBToneCurve CISRGBToneCurveToLinear CISourceInCompositing CISourceOutCompositing CISourceOverCompositing CIStarShineGenerator CIStraightenFilter CIStripesGenerator CISubtractBlendMode CISwipeTransition CITemperatureAndTint CIToneCurve CITriangleKaleidoscope CITwelvefoldReflectedTile CITwirlDistortion CIUnsharpMask CIVibrance CIVignette CIVortexDistortion CIWhitePointAdjust CIQRCodeGenerator

Page 36: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

115 Built-in CIFilters on iOS (78 Color)CIAccordianFoldTransition CIAdditionCompositing CIAffineClamp CIAffineTile CIAffineTransform CIAreaHistogram CIBarsSwipeTransition CIBlendWithMask CIBloom CIBumpDistortion CIBumpDistortionLinear CICheckerboardGenerator CICircleSplashDistortion CICircularScreen CICode128BarcodeGenerator CIColorBlendMode CIColorBurnBlendMode CIColorControls CIColorCube CIColorDodgeBlendMode CIColorInvert CIColorMap CIColorMatrix

CIColorMonochrome CIColorClamp CIColorCrossPolynomial CIColorPolynomial CIColorPosterize CIConstantColorGenerator CIConvolution3X3 CIConvolution5X5 CIConvolution9Horizontal CIConvolution9Vertical CICopyMachineTransition CICrop CIDarkenBlendMode CIDifferenceBlendMode CIDisintegrateWithMask CIDissolveTransition CIDivideBlendMode CIDotScreen CIEightfoldReflectedTile CIExclusionBlendMode CIExposureAdjust CIFalseColor CIFlashTransition

CIFourfoldReflectedTile CIFourfoldTranslatedTile CIGammaAdjust CIGaussianBlur CIGaussianGradient CIGlassDistortion CIGlideReflectedTile CIGloom CIHardLightBlendMode CIHatchedScreen CIHighlightShadowAdjust CIHistogramDisplayFilter CIHoleDistortion CIHueAdjust CIHueBlendMode CILanczosScaleTransform CILightenBlendMode CILightTunnel CILinearBurnBlendMode CILinearDodgeBlendMode CILinearGradient CILineScreen CILuminosityBlendMode

CIMaskToAlpha CIMaximumComponent CIMaximumCompositing CIMinimumComponent CIMinimumCompositing CIModTransition CIMultiplyBlendMode CIMultiplyCompositing CIOverlayBlendMode CIPerspectiveCorrection CIPerspectiveTile CIPerspectiveTransform CIPinchDistortion CIPinLightBlendMode CIPixellate CIRadialGradient CIRandomGenerator CISaturationBlendMode CIScreenBlendMode CISepiaTone CISharpenLuminance CISixfoldReflectedTile CISixfoldRotatedTile

CISoftLightBlendMode CISourceAtopCompositing CILinearToSRGBToneCurve CISRGBToneCurveToLinear CISourceInCompositing CISourceOutCompositing CISourceOverCompositing CIStarShineGenerator CIStraightenFilter CIStripesGenerator CISubtractBlendMode CISwipeTransition CITemperatureAndTint CIToneCurve CITriangleKaleidoscope CITwelvefoldReflectedTile CITwirlDistortion CIUnsharpMask CIVibrance CIVignette CIVortexDistortion CIWhitePointAdjust CIQRCodeGenerator

Page 37: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

115 Built-in CIFilters on iOS (27 Warps)CIAccordianFoldTransition CIAdditionCompositing CIAffineClamp CIAffineTile CIAffineTransform CIAreaHistogram CIBarsSwipeTransition CIBlendWithMask CIBloom CIBumpDistortion CIBumpDistortionLinear CICheckerboardGenerator CICircleSplashDistortion CICircularScreen CICode128BarcodeGenerator CIColorBlendMode CIColorBurnBlendMode CIColorControls CIColorCube CIColorDodgeBlendMode CIColorInvert CIColorMap CIColorMatrix

CIColorMonochrome CIColorClamp CIColorCrossPolynomial CIColorPolynomial CIColorPosterize CIConstantColorGenerator CIConvolution3X3 CIConvolution5X5 CIConvolution9Horizontal CIConvolution9Vertical CICopyMachineTransition CICrop CIDarkenBlendMode CIDifferenceBlendMode CIDisintegrateWithMask CIDissolveTransition CIDivideBlendMode CIDotScreen CIEightfoldReflectedTile CIExclusionBlendMode CIExposureAdjust CIFalseColor CIFlashTransition

CIFourfoldReflectedTile CIFourfoldTranslatedTile CIGammaAdjust CIGaussianBlur CIGaussianGradient CIGlassDistortion CIGlideReflectedTile CIGloom CIHardLightBlendMode CIHatchedScreen CIHighlightShadowAdjust CIHistogramDisplayFilter CIHoleDistortion CIHueAdjust CIHueBlendMode CILanczosScaleTransform CILightenBlendMode CILightTunnel CILinearBurnBlendMode CILinearDodgeBlendMode CILinearGradient CILineScreen CILuminosityBlendMode

CIMaskToAlpha CIMaximumComponent CIMaximumCompositing CIMinimumComponent CIMinimumCompositing CIModTransition CIMultiplyBlendMode CIMultiplyCompositing CIOverlayBlendMode CIPerspectiveCorrection CIPerspectiveTile CIPerspectiveTransform CIPinchDistortion CIPinLightBlendMode CIPixellate CIRadialGradient CIRandomGenerator CISaturationBlendMode CIScreenBlendMode CISepiaTone CISharpenLuminance CISixfoldReflectedTile CISixfoldRotatedTile

CISoftLightBlendMode CISourceAtopCompositing CILinearToSRGBToneCurve CISRGBToneCurveToLinear CISourceInCompositing CISourceOutCompositing CISourceOverCompositing CIStarShineGenerator CIStraightenFilter CIStripesGenerator CISubtractBlendMode CISwipeTransition CITemperatureAndTint CIToneCurve CITriangleKaleidoscope CITwelvefoldReflectedTile CITwirlDistortion CIUnsharpMask CIVibrance CIVignette CIVortexDistortion CIWhitePointAdjust CIQRCodeGenerator

Page 38: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

115 Built-in CIFilters on iOS (7 Convolution)CIAccordianFoldTransition CIAdditionCompositing CIAffineClamp CIAffineTile CIAffineTransform CIAreaHistogram CIBarsSwipeTransition CIBlendWithMask CIBloom CIBumpDistortion CIBumpDistortionLinear CICheckerboardGenerator CICircleSplashDistortion CICircularScreen CICode128BarcodeGenerator CIColorBlendMode CIColorBurnBlendMode CIColorControls CIColorCube CIColorDodgeBlendMode CIColorInvert CIColorMap CIColorMatrix

CIColorMonochrome CIColorClamp CIColorCrossPolynomial CIColorPolynomial CIColorPosterize CIConstantColorGenerator CIConvolution3X3 CIConvolution5X5 CIConvolution9Horizontal CIConvolution9Vertical CICopyMachineTransition CICrop CIDarkenBlendMode CIDifferenceBlendMode CIDisintegrateWithMask CIDissolveTransition CIDivideBlendMode CIDotScreen CIEightfoldReflectedTile CIExclusionBlendMode CIExposureAdjust CIFalseColor CIFlashTransition

CIFourfoldReflectedTile CIFourfoldTranslatedTile CIGammaAdjust CIGaussianBlur CIGaussianGradient CIGlassDistortion CIGlideReflectedTile CIGloom CIHardLightBlendMode CIHatchedScreen CIHighlightShadowAdjust CIHistogramDisplayFilter CIHoleDistortion CIHueAdjust CIHueBlendMode CILanczosScaleTransform CILightenBlendMode CILightTunnel CILinearBurnBlendMode CILinearDodgeBlendMode CILinearGradient CILineScreen CILuminosityBlendMode

CIMaskToAlpha CIMaximumComponent CIMaximumCompositing CIMinimumComponent CIMinimumCompositing CIModTransition CIMultiplyBlendMode CIMultiplyCompositing CIOverlayBlendMode CIPerspectiveCorrection CIPerspectiveTile CIPerspectiveTransform CIPinchDistortion CIPinLightBlendMode CIPixellate CIRadialGradient CIRandomGenerator CISaturationBlendMode CIScreenBlendMode CISepiaTone CISharpenLuminance CISixfoldReflectedTile CISixfoldRotatedTile

CISoftLightBlendMode CISourceAtopCompositing CILinearToSRGBToneCurve CISRGBToneCurveToLinear CISourceInCompositing CISourceOutCompositing CISourceOverCompositing CIStarShineGenerator CIStraightenFilter CIStripesGenerator CISubtractBlendMode CISwipeTransition CITemperatureAndTint CIToneCurve CITriangleKaleidoscope CITwelvefoldReflectedTile CITwirlDistortion CIUnsharpMask CIVibrance CIVignette CIVortexDistortion CIWhitePointAdjust CIQRCodeGenerator

Page 39: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Anatomy of CIKernel

!OS X and iOS

CIKernel

Page 40: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

iOS Only

Anatomy of CIKernel

!OS X and iOS

CIKernel

Page 41: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

iOS Only

Anatomy of CIKernel

!

CIColorKernel CIWarpKernel

OS X and iOS

CIKernel

Page 42: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Anatomy of CIKernel

@interface CIKernel + (CIKernel *) kernelWithString:(NSString *);- (CIImage *) applyWithExtent:(CGRect)extent roiCallback:(CIKernelROICallback)callback arguments:(NSArray *)arguments;@end

Performs no actual work

Page 43: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Anatomy of CIKernel

@interface CIKernel + (CIKernel *) kernelWithString:(NSString *);- (CIImage *) applyWithExtent:(CGRect)extent roiCallback:(CIKernelROICallback)callback arguments:(NSArray *)arguments;@end

GLSL + extensions for imaging

Inputs and outputs are floats

Performs no actual work

Page 44: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color KernelsCIColorKernel

Page 45: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of Color KernelsCIColorKernel

Input Image(s)

CIImage (RGBA8, ARGB8, RGBA Float, RGBA16, etc)

CIColorKernel(everything is read

as RGBA floats)

Output Image

CIImage (RGBA Float)

Page 46: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Example

kernel vec4 doNothing ( __sample s ) { return s.rgba; }

Page 47: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Example

kernel vec4 doNothing ( __sample s ) { return s.rgba; }

Page 48: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Example

kernel vec4 swapRedAndGreen ( __sample s ) { return s.grba; }kernel vec4 doNothing ( __sample s ) { return s.rgba; }

Page 49: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Example

kernel vec4 swapRedAndGreen ( __sample s ) { return s.grba; }kernel vec4 doNothing ( __sample s ) { return s.rgba; }

Page 50: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Example

kernel vec4 swapRedAndGreen ( __sample s ) { return s.grba; }kernel vec4 doNothing ( __sample s ) { return s.rgba; }

Page 51: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Example

kernel vec4 swapRedAndGreen ( __sample s ) { return s.grba; }kernel vec4 doNothing ( __sample s ) { return s.rgba; }

Page 52: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Example

kernel vec4 swapRedAndGreen ( __sample s ) { return s.grba; }kernel vec4 doNothing ( __sample s ) { return s.rgba; }

kernel vec4 swapRedAndGreenAmount ( __sample s, float amount ) { return mix(s.rgba, s.grba, amount); }

Page 53: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Example

kernel vec4 swapRedAndGreen ( __sample s ) { return s.grba; }kernel vec4 doNothing ( __sample s ) { return s.rgba; }

kernel vec4 swapRedAndGreenAmount ( __sample s, float amount ) { return mix(s.rgba, s.grba, amount); }

Page 54: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Example

kernel vec4 swapRedAndGreen ( __sample s ) { return s.grba; }kernel vec4 doNothing ( __sample s ) { return s.rgba; }

kernel vec4 swapRedAndGreenAmount ( __sample s, float amount ) { return mix(s.rgba, s.grba, amount); }

Page 55: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Example

kernel vec4 swapRedAndGreen ( __sample s ) { return s.grba; }kernel vec4 doNothing ( __sample s ) { return s.rgba; }

kernel vec4 swapRedAndGreenAmount ( __sample s, float amount ) { return mix(s.rgba, s.grba, amount); }

Page 56: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 doNothing ( __sample s ) { return s.rgba; }

Color Kernel Example

kernel vec4 swapRedAndGreen ( __sample s ) { return s.grba; }kernel vec4 swapRedAndGreenAmount ( __sample s, float amount ) { return mix(s.rgba, s.grba, amount); }

Page 57: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 swapRedAndGreenAmount ( __sample s, float amount ) { return mix(s.rgba, s.grba, amount); }

kernel vec4 doNothing ( __sample s ) { return s.rgba; }

Color Kernel Example

kernel vec4 swapRedAndGreen ( __sample s ) { return s.grba; }

Page 58: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 swapRedAndGreenAmount ( __sample s, float amount ) { return mix(s.rgba, s.grba, amount); }

kernel vec4 doNothing ( __sample s ) { return s.rgba; }

Color Kernel Example

kernel vec4 swapRedAndGreen ( __sample s ) { return s.grba; }

Page 59: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel ExampleSubclassing CIFilter

Page 60: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel ExampleSubclassing CIFilter

@interface SwapRedGreenFilter : CIFilter @property (retain, nonatomic) CIImage *inputImage;@property (copy, nonatomic) NSNumber *inputAmount;@end

Page 61: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel ExampleSubclassing CIFilter

@interface SwapRedGreenFilter : CIFilter @property (retain, nonatomic) CIImage *inputImage;@property (copy, nonatomic) NSNumber *inputAmount;@end

@implementation SwapRedGreenFilter-(CIKernel *)myKernel { … } // convenience+(NSDictionary *)customAttributes { … }-(CIImage *)outputImage { … }@end

Page 62: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel ExampleApplying the kernel inside of a CIFilter

- (CIKernel *) myKernel { static CIColorKernel *kernel = nil; static dispatch_once_t once; dispatch_once(&once, ^{ kernel = [CIColorKernel kernelWithString: @“kernel vec4 swapRedAndGreenAmount ( __sample s, float amount ) { return mix(s.rgba, s.grba, amount); }” ]; }); return kernel;} - (CIImage *)outputImage { CGRect dod = inputImage.extent ; return [ [self myKernel] applyWithExtent : dod arguments : @[inputImage, inputAmount]];}

Page 63: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel ExampleApplying the kernel inside of a CIFilter

- (CIKernel *) myKernel { static CIColorKernel *kernel = nil; static dispatch_once_t once; dispatch_once(&once, ^{ kernel = [CIColorKernel kernelWithString: @“kernel vec4 swapRedAndGreenAmount ( __sample s, float amount ) { return mix(s.rgba, s.grba, amount); }” ]; }); return kernel;} - (CIImage *)outputImage { CGRect dod = inputImage.extent ; return [ [self myKernel] applyWithExtent : dod arguments : @[inputImage, inputAmount]];}

Page 64: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel ExampleApplying the kernel inside of a CIFilter

- (CIKernel *) myKernel { static CIColorKernel *kernel = nil; static dispatch_once_t once; dispatch_once(&once, ^{ kernel = [CIColorKernel kernelWithString: @“kernel vec4 swapRedAndGreenAmount ( __sample s, float amount ) { return mix(s.rgba, s.grba, amount); }” ]; }); return kernel;} - (CIImage *)outputImage { CGRect dod = inputImage.extent ; return [ [self myKernel] applyWithExtent : dod arguments : @[inputImage, inputAmount]];}

Page 65: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel ExampleApplying the kernel inside of a CIFilter

- (CIKernel *) myKernel { static CIColorKernel *kernel = nil; static dispatch_once_t once; dispatch_once(&once, ^{ kernel = [CIColorKernel kernelWithString: @“kernel vec4 swapRedAndGreenAmount ( __sample s, float amount ) { return mix(s.rgba, s.grba, amount); }” ]; }); return kernel;} - (CIImage *)outputImage { CGRect dod = inputImage.extent ; return [ [self myKernel] applyWithExtent : dod arguments : @[inputImage, inputAmount]];}

Page 66: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel ExampleApplying the kernel inside of a CIFilter

- (CIKernel *) myKernel { static CIColorKernel *kernel = nil; static dispatch_once_t once; dispatch_once(&once, ^{ kernel = [CIColorKernel kernelWithString: @“kernel vec4 swapRedAndGreenAmount ( __sample s, float amount ) { return mix(s.rgba, s.grba, amount); }” ]; }); return kernel;} - (CIImage *)outputImage { CGRect dod = inputImage.extent ; return [ [self myKernel] applyWithExtent : dod arguments : @[inputImage, inputAmount]]; }

Page 67: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette effect

Page 68: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette effect

Page 69: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette effect

1.0

Page 70: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette effect

1.0

0.0

Page 71: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette effect

1.0

0.0

Page 72: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette effect

1.0

0.0

Page 73: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette effect

1.0

0.0

Page 74: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette effect

1.0

0.0

Page 75: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette effect

x = 1.0

0.0

Page 76: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

{

}

Color Kernel Which Depends on PositionVignette kernel code

Page 77: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

{

}

Color Kernel Which Depends on PositionVignette kernel code

Page 78: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

{

}

Color Kernel Which Depends on PositionVignette kernel code

extent.originx

Page 79: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

{

}

Color Kernel Which Depends on PositionVignette kernel code

extent.originx

Page 80: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

Color Kernel Which Depends on PositionVignette kernel code

extent.originx

{

}

Page 81: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

Color Kernel Which Depends on PositionVignette kernel code

extent.size/ 2.0

extent.originx

{

}

Page 82: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

Color Kernel Which Depends on PositionVignette kernel code

extent.size/ 2.0

centerOffset

extent.originx

{

}

Page 83: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

Color Kernel Which Depends on PositionVignette kernel code

centerOffset

centerOffset = extent.origin + extent.size/2.0

{

}

Page 84: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

Color Kernel Which Depends on PositionVignette kernel code

centerOffset

centerOffset = extent.origin + extent.size/2.0radius = length ( extent.size )/2.0

{

}

Page 85: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

Color Kernel Which Depends on PositionVignette kernel code

centerOffset

centerOffset = extent.origin + extent.size/2.0radius = length ( extent.size )/2.0

{

}

Page 86: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

Color Kernel Which Depends on PositionVignette kernel code

centerOffset

centerOffset = extent.origin + extent.size/2.0radius = length ( extent.size )/2.0

destCoord()

{

}

Page 87: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

Color Kernel Which Depends on PositionVignette kernel code

centerOffset

centerOffset = extent.origin + extent.size/2.0radius = length ( extent.size )/2.0

destCoord()

vecFromCenter

{

}

Page 88: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

Color Kernel Which Depends on PositionVignette kernel code

centerOffset

centerOffset = extent.origin + extent.size/2.0radius = length ( extent.size )/2.0

destCoord()

vecFromCenter

vec2 vecFromCenter = destCoord () - centerOffset;

{

}

Page 89: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

Color Kernel Which Depends on PositionVignette kernel code

centerOffset

centerOffset = extent.origin + extent.size/2.0radius = length ( extent.size )/2.0

destCoord()

vecFromCenter

vec2 vecFromCenter = destCoord () - centerOffset; float distance = length ( vecFromCenter ) ;

{

}

Page 90: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

Color Kernel Which Depends on PositionVignette kernel code

centerOffset

centerOffset = extent.origin + extent.size/2.0radius = length ( extent.size )/2.0

destCoord()

vecFromCenter

vec2 vecFromCenter = destCoord () - centerOffset; float distance = length ( vecFromCenter ) ; float darken = 1.0 - ( distance / radius ) ;

{

}

Page 91: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 vignette ( __sample s , vec2 centerOffset , float radius ){ !

!

!

!

}

Color Kernel Which Depends on PositionVignette kernel code

centerOffset

centerOffset = extent.origin + extent.size/2.0radius = length ( extent.size )/2.0

destCoord()

vecFromCenter

return vec4 ( s.rgb * darken, s.a ) ;

vec2 vecFromCenter = destCoord () - centerOffset; float distance = length ( vecFromCenter ) ; float darken = 1.0 - ( distance / radius ) ;

{

}

Page 92: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette outputImage method

- (CIImage *)outputImage { CGRect dod = inputImage.extent; double radius = 0.5 * hypot ( dod.size.width, dod.size.height ); CIVector *centerOffset = [CIVector vectorWithX : dod.size.width * 0.5 + dod.origin.x Y : dod.size.height * 0.5 + dod.origin.y]; return [[self myKernel] applyWithExtent : dod arguments : @[inputImage, centerOffset, @(radius)]];}

Page 93: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette outputImage method

- (CIImage *)outputImage { CGRect dod = inputImage.extent; double radius = 0.5 * hypot ( dod.size.width, dod.size.height ); CIVector *centerOffset = [CIVector vectorWithX : dod.size.width * 0.5 + dod.origin.x Y : dod.size.height * 0.5 + dod.origin.y]; return [[self myKernel] applyWithExtent : dod arguments : @[inputImage, centerOffset, @(radius)]];}

Page 94: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette outputImage method

- (CIImage *)outputImage { CGRect dod = inputImage.extent; double radius = 0.5 * hypot ( dod.size.width, dod.size.height ); CIVector *centerOffset = [CIVector vectorWithX : dod.size.width * 0.5 + dod.origin.x Y : dod.size.height * 0.5 + dod.origin.y]; return [[self myKernel] applyWithExtent : dod arguments : @[inputImage, centerOffset, @(radius)]];}

Page 95: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette outputImage method

- (CIImage *)outputImage { CGRect dod = inputImage.extent; double radius = 0.5 * hypot ( dod.size.width, dod.size.height ); CIVector *centerOffset = [CIVector vectorWithX : dod.size.width * 0.5 + dod.origin.x Y : dod.size.height * 0.5 + dod.origin.y]; return [[self myKernel] applyWithExtent : dod arguments : @[inputImage, centerOffset, @(radius)]];}

Page 96: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette outputImage method

- (CIImage *)outputImage { CGRect dod = inputImage.extent; double radius = 0.5 * hypot ( dod.size.width, dod.size.height ); CIVector *centerOffset = [CIVector vectorWithX : dod.size.width * 0.5 + dod.origin.x Y : dod.size.height * 0.5 + dod.origin.y]; return [[self myKernel] applyWithExtent : dod arguments : @[inputImage, centerOffset, @(radius)]];}

Page 97: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette outputImage method

- (CIImage *)outputImage { CGRect dod = inputImage.extent; double radius = 0.5 * hypot ( dod.size.width, dod.size.height ); CIVector *centerOffset = [CIVector vectorWithX : dod.size.width * 0.5 + dod.origin.x Y : dod.size.height * 0.5 + dod.origin.y]; return [[self myKernel] applyWithExtent : dod arguments : @[inputImage, centerOffset, @(radius)]];}kernel vec4 vignette ( __sample s ,vec2 centerOffset ,float radius){ … }

Page 98: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette outputImage method

- (CIImage *)outputImage { CGRect dod = inputImage.extent; double radius = 0.5 * hypot ( dod.size.width, dod.size.height ); CIVector *centerOffset = [CIVector vectorWithX : dod.size.width * 0.5 + dod.origin.x Y : dod.size.height * 0.5 + dod.origin.y]; return [[self myKernel] applyWithExtent : dod arguments : @[inputImage, centerOffset, @(radius)]]; } kernel vec4 vignette ( __sample s ,vec2 centerOffset ,float radius){ … }

Page 99: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette outputImage method

- (CIImage *)outputImage { CGRect dod = inputImage.extent; double radius = 0.5 * hypot ( dod.size.width, dod.size.height ); CIVector *centerOffset = [CIVector vectorWithX : dod.size.width * 0.5 + dod.origin.x Y : dod.size.height * 0.5 + dod.origin.y]; return [[self myKernel] applyWithExtent : dod arguments : @[inputImage, centerOffset, @(radius)]]; } kernel vec4 vignette ( __sample s ,vec2 centerOffset ,float radius){ … }

Page 100: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Color Kernel Which Depends on PositionVignette outputImage method

- (CIImage *)outputImage { CGRect dod = inputImage.extent; double radius = 0.5 * hypot ( dod.size.width, dod.size.height ); CIVector *centerOffset = [CIVector vectorWithX : dod.size.width * 0.5 + dod.origin.x Y : dod.size.height * 0.5 + dod.origin.y]; return [[self myKernel] applyWithExtent : dod arguments : @[inputImage, centerOffset, @(radius)]]; } kernel vec4 vignette ( __sample s ,vec2 centerOffset ,float radius){ … }

Page 101: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Non zero pixelsDOD for Source over Compositing Kernel

CGRect dod = CGRectUnion ( inputImage.extent, inputBackgroundImage.extent )

kernel vec4 sourceOver( __sample src , __sample dest ) { return src + (1.0-src.a)*dest; }

Page 102: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Non zero pixelsDOD for Source over Compositing Kernel

CGRect dod = CGRectUnion ( inputImage.extent, inputBackgroundImage.extent )

kernel vec4 sourceOver( __sample src , __sample dest ) { return src + (1.0-src.a)*dest; }

Page 103: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Warp KernelsCIWarpKernel

Page 104: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of Warp KernelsCIWarpKernel

Specify DOD and ROI block callback

Input Position(vec2) CIWarpKernel Output Position

(vec2)

Page 105: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec2 doNothing () { return destCoord(); }

Basic Principles of Warp KernelsCIWarpKernel—think backwards

x

y input image

Page 106: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec2 doNothing () { return destCoord(); }

x

y

Basic Principles of Warp KernelsCIWarpKernel—think backwards

x

y input image output image

Page 107: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec2 doNothing () { return destCoord(); }

x

y

Basic Principles of Warp KernelsCIWarpKernel—think backwards

x

y

destCoord()

input image output image

Page 108: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec2 doNothing () { return destCoord(); }

x

y

Basic Principles of Warp KernelsCIWarpKernel—think backwards

x

y

destCoord()

input image output image

Page 109: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of Warp KernelsCIWarpKernel—think backwards

x

y

x

y

kernel vec2 mirrorX ( float imageWidth ) { vec2 input = destCoord(); return vec2 ( imageWidth - input.x , input.y ); }

Page 110: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of Warp KernelsCIWarpKernel—think backwards

x

y

x

y

kernel vec2 mirrorX ( float imageWidth ) { vec2 input = destCoord(); return vec2 ( imageWidth - input.x , input.y ); }

Page 111: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of Warp KernelsCIWarpKernel—think backwards

x

y

x

y

destCoord()

kernel vec2 mirrorX ( float imageWidth ) { vec2 input = destCoord(); return vec2 ( imageWidth - input.x , input.y ); }

Page 112: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of Warp KernelsCIWarpKernel—think backwards

x

y

x

y

destCoord()

kernel vec2 mirrorX ( float imageWidth ) { vec2 input = destCoord(); return vec2 ( imageWidth - input.x , input.y ); }

Page 113: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of Warp KernelsCIWarpKernel—think backwards

x

y

x

y

destCoord()

x

kernel vec2 mirrorX ( float imageWidth ) { vec2 input = destCoord(); return vec2 ( imageWidth - input.x , input.y ); }

Page 114: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of Warp KernelsCIWarpKernel—think backwards

x

y

x

y

imageWidth

destCoord()

x

kernel vec2 mirrorX ( float imageWidth ) { vec2 input = destCoord(); return vec2 ( imageWidth - input.x , input.y ); }

Page 115: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of Warp KernelsCIWarpKernel—think backwards

x

y

x

y

imageWidth imageWidth-x

destCoord()

x

kernel vec2 mirrorX ( float imageWidth ) { vec2 input = destCoord(); return vec2 ( imageWidth - input.x , input.y ); }

Page 116: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of Warp KernelsCIWarpKernel—think backwards

x

y

x

y

imageWidth imageWidth-x

destCoord()

imageWidth-x x

kernel vec2 mirrorX ( float imageWidth ) { vec2 input = destCoord(); return vec2 ( imageWidth - input.x , input.y ); }

Page 117: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Invoking MirrorX Kernel

CIWarpKernel *kernel = [CIWarpKernel kernelWithString:kernelSourceCode]; !

- (CIImage *) outputImage { CGFloat inputWidth = inputImage.extent.size.width; !

CIImage *result = [[self myKernel] applyWithExtent: inputImage.extent roiCallback: ^( int index, CGRect r ) { … } inputImage: inputImage arguments: @[@(inputWidth)]]; return result; }

Page 118: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Invoking MirrorX Kernel

CIWarpKernel *kernel = [CIWarpKernel kernelWithString:kernelSourceCode]; !

- (CIImage *) outputImage { CGFloat inputWidth = inputImage.extent.size.width; !

CIImage *result = [[self myKernel] applyWithExtent: inputImage.extent roiCallback: ^( int index, CGRect r ) { … } inputImage: inputImage arguments: @[@(inputWidth)]]; return result; }

Page 119: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of Warp KernelsFor output rect, what part of input rect do we need—ROI

5

Page 120: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

7

5

1

4

32

6

8 9

Basic Principles of Warp KernelsFor output rect, what part of input rect do we need—ROI

5

Page 121: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

5

Basic Principles of Warp KernelsFor output rect, what part of input rect do we need—ROI

5

Page 122: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

5

CGRectMake ( , , , );

Basic Principles of Warp KernelsFor output rect, what part of input rect do we need—ROI

5

Page 123: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

5

CGRectMake ( , , , );

Basic Principles of Warp KernelsFor output rect, what part of input rect do we need—ROI

x

y

x

y

5

Page 124: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

5

CGRectMake ( , , , );r.size.width

Basic Principles of Warp KernelsFor output rect, what part of input rect do we need—ROI

r.size.widthx

y

x

y

5

Page 125: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

5

CGRectMake ( , , , );r.size.width

Basic Principles of Warp KernelsFor output rect, what part of input rect do we need—ROI

r.size.height

r.size.width

r.size.height

x

y

x

y

5

Page 126: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

5

CGRectMake ( , , , );r.size.widthr.origin.y

Basic Principles of Warp KernelsFor output rect, what part of input rect do we need—ROI

r.size.height

r.size.width

r.origin.y

r.size.height

x

y

x

y

5

Page 127: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

5

CGRectMake ( , , , );r.size.widthr.origin.ynewOrigin

Basic Principles of Warp KernelsFor output rect, what part of input rect do we need—ROI

r.size.height

r.size.widthnewOrigin

r.origin.y

r.size.height

x

y

x

y

5

Page 128: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

5

CGRectMake ( , , , );r.size.widthr.origin.ynewOrigin

Basic Principles of Warp KernelsFor output rect, what part of input rect do we need—ROI

newOrigin =

r.size.height

r.size.widthnewOrigin

r.origin.y

r.size.height

x

y

x

y

5

Page 129: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

5

CGRectMake ( , , , );r.size.widthr.origin.ynewOrigin

Basic Principles of Warp KernelsFor output rect, what part of input rect do we need—ROI

newOrigin =

r.size.height

inputImage.extent.size.width

r.size.widthnewOrigin

r.origin.y

inputImage.extent.size.width

r.size.height

x

y

x

y

5

Page 130: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

5

CGRectMake ( , , , );r.size.widthr.origin.ynewOrigin

Basic Principles of Warp KernelsFor output rect, what part of input rect do we need—ROI

newOrigin =

r.size.height

- ( r.origin.x + r.size.width );inputImage.extent.size.width

r.origin.x r.size.widthnewOrigin

r.origin.y

inputImage.extent.size.width

r.size.height

x

y

x

y

5

Page 131: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Invoking MirrorX Kernel

- (CIImage *) outputImage { if ( CGRectIsInfinite ( inputImage.extent ) ) return nil; !

CGPoint o = inputImage.extent.origin; CGFloat inputWidth = inputImage.extent.size.width;

CGAffineTransform to = CGAffineTransformMakeTranslation ( -o.x, -o.y ); !

CIImage *result = [inputImage imageByApplyingTransform:to]; !

result = [[self myKernel] applyWithExtent: … ]; // same as before CGAffineTransform from = CGAffineTransformMakeTranslation ( o.x, o.y );

return [result imageByApplyingTransform:from]; }

Page 132: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Invoking MirrorX Kernel

- (CIImage *) outputImage { if ( CGRectIsInfinite ( inputImage.extent ) ) return nil; !

CGPoint o = inputImage.extent.origin; CGFloat inputWidth = inputImage.extent.size.width;

CGAffineTransform to = CGAffineTransformMakeTranslation ( -o.x, -o.y ); !

CIImage *result = [inputImage imageByApplyingTransform:to]; !

result = [[self myKernel] applyWithExtent: … ]; // same as before CGAffineTransform from = CGAffineTransformMakeTranslation ( o.x, o.y );

return [result imageByApplyingTransform:from]; }

Page 133: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Invoking MirrorX Kernel

- (CIImage *) outputImage { if ( CGRectIsInfinite ( inputImage.extent ) ) return nil; !

CGPoint o = inputImage.extent.origin; CGFloat inputWidth = inputImage.extent.size.width;

CGAffineTransform to = CGAffineTransformMakeTranslation ( -o.x, -o.y ); !

CIImage *result = [inputImage imageByApplyingTransform:to]; !

result = [[self myKernel] applyWithExtent: … ]; // same as before CGAffineTransform from = CGAffineTransformMakeTranslation ( o.x, o.y );

return [result imageByApplyingTransform:from]; }

Page 134: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Invoking MirrorX Kernel

- (CIImage *) outputImage { if ( CGRectIsInfinite ( inputImage.extent ) ) return nil; !

CGPoint o = inputImage.extent.origin; CGFloat inputWidth = inputImage.extent.size.width;

CGAffineTransform to = CGAffineTransformMakeTranslation ( -o.x, -o.y ); !

CIImage *result = [inputImage imageByApplyingTransform:to]; !

result = [[self myKernel] applyWithExtent: … ]; // same as before CGAffineTransform from = CGAffineTransformMakeTranslation ( o.x, o.y );

return [result imageByApplyingTransform:from]; }

Page 135: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Invoking MirrorX Kernel

- (CIImage *) outputImage { if ( CGRectIsInfinite ( inputImage.extent ) ) return nil; !

CGPoint o = inputImage.extent.origin; CGFloat inputWidth = inputImage.extent.size.width;

CGAffineTransform to = CGAffineTransformMakeTranslation ( -o.x, -o.y ); !

CIImage *result = [inputImage imageByApplyingTransform:to]; !

result = [[self myKernel] applyWithExtent: … ]; // same as before CGAffineTransform from = CGAffineTransformMakeTranslation ( o.x, o.y );

return [result imageByApplyingTransform:from]; }

Page 136: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Invoking MirrorX Kernel

- (CIImage *) outputImage { if ( CGRectIsInfinite ( inputImage.extent ) ) return nil; !

CGPoint o = inputImage.extent.origin; CGFloat inputWidth = inputImage.extent.size.width;

CGAffineTransform to = CGAffineTransformMakeTranslation ( -o.x, -o.y ); !

CIImage *result = [inputImage imageByApplyingTransform:to]; !

result = [[self myKernel] applyWithExtent: … ]; // same as before CGAffineTransform from = CGAffineTransformMakeTranslation ( o.x, o.y );

return [result imageByApplyingTransform:from]; }

Page 137: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Invoking MirrorX Kernel

- (CIImage *) outputImage { if ( CGRectIsInfinite ( inputImage.extent ) ) return nil; !

CGPoint o = inputImage.extent.origin; CGFloat inputWidth = inputImage.extent.size.width;

CGAffineTransform to = CGAffineTransformMakeTranslation ( -o.x, -o.y ); !

CIImage *result = [inputImage imageByApplyingTransform:to]; !

result = [[self myKernel] applyWithExtent: … ]; // same as before CGAffineTransform from = CGAffineTransformMakeTranslation ( o.x, o.y );

return [result imageByApplyingTransform:from]; }

Page 138: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Invoking MirrorX Kernel

- (CIImage *) outputImage { if ( CGRectIsInfinite ( inputImage.extent ) ) return nil; !

CGPoint o = inputImage.extent.origin; CGFloat inputWidth = inputImage.extent.size.width;

CGAffineTransform to = CGAffineTransformMakeTranslation ( -o.x, -o.y ); !

CIImage *result = [inputImage imageByApplyingTransform:to]; !

result = [[self myKernel] applyWithExtent: … ]; // same as before CGAffineTransform from = CGAffineTransformMakeTranslation ( o.x, o.y );

return [result imageByApplyingTransform:from]; }

Page 139: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Invoking MirrorX Kernel

- (CIImage *) outputImage { if ( CGRectIsInfinite ( inputImage.extent ) ) return nil; !

CGPoint o = inputImage.extent.origin; CGFloat inputWidth = inputImage.extent.size.width;

CGAffineTransform to = CGAffineTransformMakeTranslation ( -o.x, -o.y ); !

CIImage *result = [inputImage imageByApplyingTransform:to]; !

result = [[self myKernel] applyWithExtent: … ]; // same as before CGAffineTransform from = CGAffineTransformMakeTranslation ( o.x, o.y );

return [result imageByApplyingTransform:from]; }

Page 140: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

More Complex Warp KernelAnamorphic stretch

Page 141: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

More Complex Warp KernelAnamorphic stretch

1024

Page 142: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

More Complex Warp KernelAnamorphic stretch

1024

768

Page 143: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

More Complex Warp KernelAnamorphic stretch

1024

768

1280

Page 144: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

More Complex Warp KernelAnamorphic stretch

1024

768

1280

Page 145: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

More Complex Warp KernelAnamorphic stretch

1024

768

1280

Page 146: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

sourceToDest() and destToSource()Invertible functions

Page 147: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

sourceToDest() and destToSource()Invertible functions

x

f(x)

Page 148: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

sourceToDest() and destToSource()Invertible functions

x

f(x)

width/2- width/2

Page 149: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

sourceToDest() and destToSource()Invertible functions

x

f(x)

width/2- width/2

scale = 1

Page 150: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

sourceToDest() and destToSource()Invertible functions

xi

f(xi)==xi

x

f(x)

width/2- width/2

scale = 1

Page 151: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

sourceToDest() and destToSource()Invertible functions

xi

f(xi)==xi

x

f(x)

width/2- width/2

scale = 1

Page 152: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

sourceToDest() and destToSource()Invertible functions

xi

f(xi)==xi

x

f(x)

width/2- width/2

scale = 1

Page 153: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

sourceToDest() and destToSource()Invertible functions

x

f(x)

width/2- width/2

scale = 1

DOD

Page 154: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

dest x

sourceToDest() and destToSource()Invertible functions

x

f(x)

width/2- width/2

scale = 1

DOD

src x

Page 155: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

dest x

sourceToDest() and destToSource()Invertible functions

src x

x

f(x)

dest x

width/2- width/2

scale = 1

DOD

Kernel and ROI

src x

Page 156: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

scale = desiredWidth/inputWidthk = inputWidth/(1.0 - (1.0/scale))

sourceToDest() and destToSource()Invertible functions

Page 157: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

scale = desiredWidth/inputWidthk = inputWidth/(1.0 - (1.0/scale))sourceToDest (1024) == 1280destToSource (1280) == 1024

sourceToDest() and destToSource()Invertible functions

Page 158: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec2 strech (float center, float k) { vec2 p = destCoord(); !

!

!

!

return p; }

Kernel

Page 159: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec2 strech (float center, float k) { vec2 p = destCoord(); !

!

!

!

return p; }

Kernel

Page 160: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec2 strech (float center, float k) { vec2 p = destCoord(); !

!

!

!

return p; }

Kernel

p.x -= center;

Page 161: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec2 strech (float center, float k) { vec2 p = destCoord(); !

!

!

!

return p; }

Kernel

p.x -= center;p.x = p.x / (1.0 + abs(p.x / k));p.x += center;

Page 162: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

r

ROI Pseudocode

Page 163: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

r

ROI Pseudocode

r’

Page 164: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

r

ROI Pseudocode

r’

leftP = r.origin.x

Page 165: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

r

ROI Pseudocode

r’

leftP = r.origin.x

Page 166: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

r

ROI Pseudocode

r’

leftP = r.origin.xleftP’ = destToSource ( leftP )

Page 167: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

r

ROI Pseudocode

r’

leftP = r.origin.x rightP = r.origin.x + r.size.widthleftP’ = destToSource ( leftP )

Page 168: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

r

ROI Pseudocode

r’

leftP = r.origin.x rightP = r.origin.x + r.size.widthleftP’ = destToSource ( leftP )

Page 169: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

r

ROI Pseudocode

r’

leftP = r.origin.x rightP = r.origin.x + r.size.widthleftP’ = destToSource ( leftP ) rightP’ = destToSource ( rightP )

Page 170: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

r

ROI Pseudocode

r’

leftP = r.origin.x rightP = r.origin.x + r.size.widthleftP’ = destToSource ( leftP ) rightP’ = destToSource ( rightP )

newWidth = rightP’ - leftP’ r’ = CGRectMake ( leftP’, r.origin.y, newWidth, r.size.height )

Page 171: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

double destToSource(double x, double center, double k) {

return x; } !

ROI—Region of InterestRe-use kernel equation

Page 172: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

double destToSource(double x, double center, double k) {

return x; } !

ROI—Region of InterestRe-use kernel equation

Page 173: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

double destToSource(double x, double center, double k) {

return x; } !

ROI—Region of Interest

x -= center; x = x / (1.0 + fabs(x / k)); x += center;

Re-use kernel equation

Page 174: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

double destToSource(double x, double center, double k) {

return x; } !

ROI—Region of Interest

x -= center; x = x / (1.0 + fabs(x / k)); x += center;

CGRect regionOf (CGRect r, float center, float k) { double leftP = destToSource (r.origin.x, center, k); double rightP = destToSource (r.origin.x + r.size.width, center, k); return CGRectMake (leftP, r.origin.y, rightP-leftP, r.size.height); }

Re-use kernel equation

Page 175: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

double sourceToDest (double x, double center, double k) {

return x; } !

DOD—Domain of Definition

x -= center; x = x / (1.0 - fabs(x / k)); x += center;

Page 176: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

double sourceToDest (double x, double center, double k) {

return x; } !

DOD—Domain of Definition

x -= center; x = x / (1.0 - fabs(x / k)); x += center;

CGRect dodForInputRect (CGRect r, double center, double k) { double leftP = sourceToDest (r.origin.x, center, k); double rightP = sourceToDest (r.origin.x + r.size.width, center, k); return CGRectMake (leftP, r.origin.y, rightP-leftP, r.size.height); }

Page 177: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

outputImage Method

- (CIImage *) outputImage { double inputWidth = inputImage.extent.size.width; !

double k = inputWidth / ( 1.0 - 1.0 / [inputScale floatValue] ); double center = inputImage.extent.origin.x + inputWidth / 2.0; CGRect dod = dodForInputRect (inputImage.extent, center, k); CIImage * result = [[self myKernel] applyWithExtent: dod roiCallback: ^(int index, CGRect rect) { return regionOf(rect, center, k); } inputImage: inputImage arguments: @[@(center), @(k)]]; return result; }

Page 178: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

outputImage Method

- (CIImage *) outputImage { double inputWidth = inputImage.extent.size.width; !

double k = inputWidth / ( 1.0 - 1.0 / [inputScale floatValue] ); double center = inputImage.extent.origin.x + inputWidth / 2.0; CGRect dod = dodForInputRect (inputImage.extent, center, k); CIImage * result = [[self myKernel] applyWithExtent: dod roiCallback: ^(int index, CGRect rect) { return regionOf(rect, center, k); } inputImage: inputImage arguments: @[@(center), @(k)]]; return result; }

Page 179: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

outputImage Method

- (CIImage *) outputImage { double inputWidth = inputImage.extent.size.width; !

double k = inputWidth / ( 1.0 - 1.0 / [inputScale floatValue] ); double center = inputImage.extent.origin.x + inputWidth / 2.0; CGRect dod = dodForInputRect (inputImage.extent, center, k); CIImage * result = [[self myKernel] applyWithExtent: dod roiCallback: ^(int index, CGRect rect) { return regionOf(rect, center, k); } inputImage: inputImage arguments: @[@(center), @(k)]]; return result; }

Page 180: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

outputImage Method

- (CIImage *) outputImage { double inputWidth = inputImage.extent.size.width; !

double k = inputWidth / ( 1.0 - 1.0 / [inputScale floatValue] ); double center = inputImage.extent.origin.x + inputWidth / 2.0; CGRect dod = dodForInputRect (inputImage.extent, center, k); CIImage * result = [[self myKernel] applyWithExtent: dod roiCallback: ^(int index, CGRect rect) { return regionOf(rect, center, k); } inputImage: inputImage arguments: @[@(center), @(k)]]; return result; }

Page 181: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

outputImage Method

- (CIImage *) outputImage { double inputWidth = inputImage.extent.size.width; !

double k = inputWidth / ( 1.0 - 1.0 / [inputScale floatValue] ); double center = inputImage.extent.origin.x + inputWidth / 2.0; CGRect dod = dodForInputRect (inputImage.extent, center, k); CIImage * result = [[self myKernel] applyWithExtent: dod roiCallback: ^(int index, CGRect rect) { return regionOf(rect, center, k); } inputImage: inputImage arguments: @[@(center), @(k)]]; return result; }

Page 182: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

customAttributes Method

+ (NSDictionary *)customAttributes { return @{ kCIAttributeFilterDisplayName : @“Anamorphic Stretch", kCIAttributeFilterCategories : @[kCICategoryDistortionEffect, kCICategoryVideo, kCICategoryInterlaced, kCICategoryNonSquarePixels, kCICategoryStillImage], @"inputScale" : @{ kCIAttributeSliderMin : @1.0, kCIAttributeSliderMax : @2.0, kCIAttributeDefault : @1.0, kCIAttributeIdentity : @1.0, kCIAttributeType : kCIAttributeTypeScalar } }; }

Page 183: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

customAttributes Method

+ (NSDictionary *)customAttributes { return @{ kCIAttributeFilterDisplayName : @“Anamorphic Stretch", kCIAttributeFilterCategories : @[kCICategoryDistortionEffect, kCICategoryVideo, kCICategoryInterlaced, kCICategoryNonSquarePixels, kCICategoryStillImage], @"inputScale" : @{ kCIAttributeSliderMin : @1.0, kCIAttributeSliderMax : @2.0, kCIAttributeDefault : @1.0, kCIAttributeIdentity : @1.0, kCIAttributeType : kCIAttributeTypeScalar } }; }

Page 184: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

customAttributes Method

+ (NSDictionary *)customAttributes { return @{ kCIAttributeFilterDisplayName : @“Anamorphic Stretch", kCIAttributeFilterCategories : @[kCICategoryDistortionEffect, kCICategoryVideo, kCICategoryInterlaced, kCICategoryNonSquarePixels, kCICategoryStillImage], @"inputScale" : @{ kCIAttributeSliderMin : @1.0, kCIAttributeSliderMax : @2.0, kCIAttributeDefault : @1.0, kCIAttributeIdentity : @1.0, kCIAttributeType : kCIAttributeTypeScalar } }; }

Page 185: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

customAttributes Method

+ (NSDictionary *)customAttributes { return @{ kCIAttributeFilterDisplayName : @“Anamorphic Stretch", kCIAttributeFilterCategories : @[kCICategoryDistortionEffect, kCICategoryVideo, kCICategoryInterlaced, kCICategoryNonSquarePixels, kCICategoryStillImage], @"inputScale" : @{ kCIAttributeSliderMin : @1.0, kCIAttributeSliderMax : @2.0, kCIAttributeDefault : @1.0, kCIAttributeIdentity : @1.0, kCIAttributeType : kCIAttributeTypeScalar } }; }

Page 186: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 187: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 188: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 189: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 190: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 191: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 192: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 193: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 194: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 195: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 196: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 197: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 198: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 199: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel Wrap-Up

# Input Images Input Type Access Output

Image DOD ROI

ClColorKernel 0 .. n __sample vec4 vec4 YES NO

ClWarpKernel 1 destCoord() vec2 vec2 YES YES

ClKernel 0 .. n sampler sample(…) vec4 YES YES

Page 200: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

General KernelsCIKernel

Tony Chu

Page 201: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Different Types of Kernels

Color Kernels (CIColorKernel)

Warp Kernels (CIWarpKernel)

General Kernels (CIKernel)

Page 202: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

MotivationCIKernel

When would you need to write a general kernel?

Page 203: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

MotivationCIKernel

When would you need to write a general kernel?• Kernel needs multiple samples of an image

Page 204: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

MotivationCIKernel

When would you need to write a general kernel?• Kernel needs multiple samples of an image

- e.g., any kind of blur or convolution filter

Page 205: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

MotivationCIKernel

When would you need to write a general kernel?• Kernel needs multiple samples of an image

- e.g., any kind of blur or convolution filter

• Kernel contains a dependent texture read

Page 206: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

MotivationCIKernel

When would you need to write a general kernel?• Kernel needs multiple samples of an image

- e.g., any kind of blur or convolution filter

• Kernel contains a dependent texture read

- e.g., sample from image A used to determine where to sample from image B

Page 207: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of General KernelsCIKernel

Input Image(s)Input Image(s)Input Image(s) Output Image

Sampler CIKernel CIImage

Page 208: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of General KernelsCIKernel

Input Image(s)Input Image(s)Input Image(s) Output Image

Sampler CIKernel CIImage

Page 209: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of General Kernels

kernel vec4 do_nothing (sampler image) { vec2 dc = destCoord(); return sample (image, samplerTransform (image, dc)); }

!

!

Page 210: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of General Kernels

kernel vec4 do_nothing (sampler image) { vec2 dc = destCoord(); return sample (image, samplerTransform (image, dc)); }

!

!

kernel vec4 do_nothing (sampler image) { return sample (image, samplerCoord (image)); }

Page 211: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of General Kernels

kernel vec4 do_nothing (sampler image) { vec2 dc = destCoord(); return sample (image, samplerTransform (image, dc)); }

!

!

=kernel vec4 do_nothing (sampler image) { return sample (image, samplerCoord (image)); }

Page 212: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Basic Principles of General Kernels

kernel vec4 do_nothing (sampler image) { vec2 dc = destCoord(); return sample (image, samplerTransform (image, dc)); }

!

!

=

Why use samplerTransform?

kernel vec4 do_nothing (sampler image) { return sample (image, samplerCoord (image)); }

Page 213: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 do_something (sampler image) { vec2 sc = samplerCoord (image); vec2 offset = vec2(0.0, 2.0); return sample (image, sc + offset); }

Basic Principles of General KernelsDestination space vs. Sampler space

Page 214: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 do_something (sampler image) { vec2 sc = samplerCoord (image); vec2 offset = vec2(0.0, 2.0); return sample (image, sc + offset); }

Basic Principles of General KernelsDestination space vs. Sampler space

x

y

400

06000

Destination space

Page 215: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 do_something (sampler image) { vec2 sc = samplerCoord (image); vec2 offset = vec2(0.0, 2.0); return sample (image, sc + offset); }

x

y

0 1

Sampler space

1

0

Basic Principles of General KernelsDestination space vs. Sampler space

x

y

400

06000

Destination space

Page 216: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 do_something (sampler image) { vec2 sc = samplerCoord (image); vec2 offset = vec2(0.0, 2.0); return sample (image, sc + offset); }

x

y

0 1

Sampler space

1

0

Basic Principles of General KernelsDestination space vs. Sampler space

x

y

400

06000

Destination space

(300, 200)

Page 217: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 do_something (sampler image) { vec2 sc = samplerCoord (image); vec2 offset = vec2(0.0, 2.0); return sample (image, sc + offset); }

x

y

0 1

Sampler space

1

0

Basic Principles of General KernelsDestination space vs. Sampler space

x

y

400

06000

Destination space

(300, 200) (0.5, 0.5)

Page 218: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 do_something (sampler image) { vec2 sc = samplerCoord (image); vec2 offset = vec2(0.0, 2.0); return sample (image, sc + offset); }

x

y

0 1

Sampler space

1

0

Basic Principles of General KernelsDestination space vs. Sampler space

(0.5, 2.5)

x

y

400

06000

Destination space

(300, 200) (0.5, 0.5)

Page 219: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 do_something (sampler image) { vec2 sc = samplerCoord (image); vec2 offset = vec2(0.0, 2.0); return sample (image, sc + offset); }

x

y

0 1

Sampler space

1

0

Basic Principles of General KernelsDestination space vs. Sampler space

(0.5, 2.5)

x

y

400

06000

Destination space

(300, 200) (0.5, 0.5)

Page 220: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

x

y

400

06000

Destination space

kernel vec4 do_something (sampler image) { vec2 dc = destCoord(); vec2 offset = vec2(0.0, 2.0); return sample (image, samplerTransform (image, dc + offset)); }

x

y

0 1

Sampler space

1

0

Basic Principles of General KernelsDestination space vs. Sampler space

Page 221: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

x

y

400

06000

Destination space

kernel vec4 do_something (sampler image) { vec2 dc = destCoord(); vec2 offset = vec2(0.0, 2.0); return sample (image, samplerTransform (image, dc + offset)); }

x

y

0 1

Sampler space

1

0

Basic Principles of General KernelsDestination space vs. Sampler space

(300, 200)

Page 222: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

x

y

400

06000

Destination space

kernel vec4 do_something (sampler image) { vec2 dc = destCoord(); vec2 offset = vec2(0.0, 2.0); return sample (image, samplerTransform (image, dc + offset)); }

x

y

0 1

Sampler space

1

0

Basic Principles of General KernelsDestination space vs. Sampler space

(300, 200)

(300, 202)

Page 223: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

x

y

400

06000

Destination space

kernel vec4 do_something (sampler image) { vec2 dc = destCoord(); vec2 offset = vec2(0.0, 2.0); return sample (image, samplerTransform (image, dc + offset)); }

x

y

0 1

Sampler space

1

0

Basic Principles of General KernelsDestination space vs. Sampler space

(0.5, 0.505)(300, 200)

(300, 202)

Page 224: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

x

y

400

06000

Destination space

kernel vec4 do_something (sampler image) { vec2 dc = destCoord(); vec2 offset = vec2(0.0, 2.0); return sample (image, samplerTransform (image, dc + offset)); }

x

y

0 1

Sampler space

1

0

Basic Principles of General KernelsDestination space vs. Sampler space

(0.5, 0.505)(300, 200)

(300, 202)

Page 225: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

ExamplesCIKernel

Page 226: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurKernel requires multiple samples

Page 227: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurKernel requires multiple samples

Compute the average of N samples along a bi-directional vector

Page 228: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurKernel requires multiple samples

Compute the average of N samples along a bi-directional vector

Page 229: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurKernel requires multiple samples

Compute the average of N samples along a bi-directional vector

Page 230: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 motionBlur (sampler image, vec2 velocity) { const int NUM_SAMPLES = 10; // per direction !

vec4 s = vec4(0.0); vec2 dc = destCoord(), offset = -velocity; !

for (int i=0; i < (NUM_SAMPLES * 2 + 1); i++) { s += sample (image, samplerTransform (image, dc + offset)); offset += velocity / float(NUM_SAMPLES); } !

return s / float((NUM_SAMPLES * 2 + 1)); }

Motion BlurCIKernel

Page 231: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 motionBlur (sampler image, vec2 velocity) { const int NUM_SAMPLES = 10; // per direction !

vec4 s = vec4(0.0); vec2 dc = destCoord(), offset = -velocity; !

for (int i=0; i < (NUM_SAMPLES * 2 + 1); i++) { s += sample (image, samplerTransform (image, dc + offset)); offset += velocity / float(NUM_SAMPLES); } !

return s / float((NUM_SAMPLES * 2 + 1)); }

Motion BlurCIKernel

Page 232: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 motionBlur (sampler image, vec2 velocity) { const int NUM_SAMPLES = 10; // per direction !

vec4 s = vec4(0.0); vec2 dc = destCoord(), offset = -velocity; !

for (int i=0; i < (NUM_SAMPLES * 2 + 1); i++) { s += sample (image, samplerTransform (image, dc + offset)); offset += velocity / float(NUM_SAMPLES); } !

return s / float((NUM_SAMPLES * 2 + 1)); }

Motion BlurCIKernel

Page 233: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 motionBlur (sampler image, vec2 velocity) { const int NUM_SAMPLES = 10; // per direction !

vec4 s = vec4(0.0); vec2 dc = destCoord(), offset = -velocity; !

for (int i=0; i < (NUM_SAMPLES * 2 + 1); i++) { s += sample (image, samplerTransform (image, dc + offset)); offset += velocity / float(NUM_SAMPLES); } !

return s / float((NUM_SAMPLES * 2 + 1)); }

Motion BlurCIKernel

Page 234: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 motionBlur (sampler image, vec2 velocity) { const int NUM_SAMPLES = 10; // per direction !

vec4 s = vec4(0.0); vec2 dc = destCoord(), offset = -velocity; !

for (int i=0; i < (NUM_SAMPLES * 2 + 1); i++) { s += sample (image, samplerTransform (image, dc + offset)); offset += velocity / float(NUM_SAMPLES); } !

return s / float((NUM_SAMPLES * 2 + 1)); }

Motion BlurCIKernel

Page 235: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

kernel vec4 motionBlur (sampler image, vec2 velocity) { const int NUM_SAMPLES = 10; // per direction !

vec4 s = vec4(0.0); vec2 dc = destCoord(), offset = -velocity; !

for (int i=0; i < (NUM_SAMPLES * 2 + 1); i++) { s += sample (image, samplerTransform (image, dc + offset)); offset += velocity / float(NUM_SAMPLES); } !

return s / float((NUM_SAMPLES * 2 + 1)); }

Motion BlurCIKernel

Page 236: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurCIFilter subclass

- (CIKernel *)myKernel { static CIKernel *kernel = [CIKernel kernelWithString:source]; return kernel; } !

- (CIImage *)outputImage { float r = inputRadius.floatValue, a = inputAngle.floatValue; CIVector *velocity = [CIVector vectorWithX:r*cos(a) Y:r*sin(a)]; !

return [[self myKernel] applyWithExtent:DOD roiCallback:^(int index, CGRect rect) { return regionOf(rect,velocity); } arguments: @[inputImage, velocity] ]; }

Page 237: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurCIFilter subclass

- (CIKernel *)myKernel { static CIKernel *kernel = [CIKernel kernelWithString:source]; return kernel; } !

- (CIImage *)outputImage { float r = inputRadius.floatValue, a = inputAngle.floatValue; CIVector *velocity = [CIVector vectorWithX:r*cos(a) Y:r*sin(a)]; !

return [[self myKernel] applyWithExtent:DOD roiCallback:^(int index, CGRect rect) { return regionOf(rect,velocity); } arguments: @[inputImage, velocity] ]; }

Page 238: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurCIFilter subclass

- (CIKernel *)myKernel { static CIKernel *kernel = [CIKernel kernelWithString:source]; return kernel; } !

- (CIImage *)outputImage { float r = inputRadius.floatValue, a = inputAngle.floatValue; CIVector *velocity = [CIVector vectorWithX:r*cos(a) Y:r*sin(a)]; !

return [[self myKernel] applyWithExtent:DOD roiCallback:^(int index, CGRect rect) { return regionOf(rect,velocity); } arguments: @[inputImage, velocity] ]; }

kernel vec4 motionBlur (sampler image, vec2 velocity) { const int NUM_SAMPLES = 10; // per direction vec4 s = vec4(0.0); vec2 dc = destCoord(), offset = -velocity; for (int i=0; i < (NUM_SAMPLES * 2 + 1); i++) { s += sample (image, samplerTransform (image, dc + offset)); offset += velocity / float(NUM_SAMPLES); } return s / float((NUM_SAMPLES * 2 + 1)); }

Page 239: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurCIFilter subclass

- (CIKernel *)myKernel { static CIKernel *kernel = [CIKernel kernelWithString:source]; return kernel; } !

- (CIImage *)outputImage { float r = inputRadius.floatValue, a = inputAngle.floatValue; CIVector *velocity = [CIVector vectorWithX:r*cos(a) Y:r*sin(a)]; !

return [[self myKernel] applyWithExtent:DOD roiCallback:^(int index, CGRect rect) { return regionOf(rect,velocity); } arguments: @[inputImage, velocity] ]; }

Page 240: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurCIFilter subclass

- (CIKernel *)myKernel { static CIKernel *kernel = [CIKernel kernelWithString:source]; return kernel; } !

- (CIImage *)outputImage { float r = inputRadius.floatValue, a = inputAngle.floatValue; CIVector *velocity = [CIVector vectorWithX:r*cos(a) Y:r*sin(a)]; !

return [[self myKernel] applyWithExtent:DOD roiCallback:^(int index, CGRect rect) { return regionOf(rect,velocity); } arguments: @[inputImage, velocity] ]; }

Page 241: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurCIFilter subclass

- (CIKernel *)myKernel { static CIKernel *kernel = [CIKernel kernelWithString:source]; return kernel; } !

- (CIImage *)outputImage { float r = inputRadius.floatValue, a = inputAngle.floatValue; CIVector *velocity = [CIVector vectorWithX:r*cos(a) Y:r*sin(a)]; !

return [[self myKernel] applyWithExtent:DOD roiCallback:^(int index, CGRect rect) { return regionOf(rect,velocity); } arguments: @[inputImage, velocity] ]; }

Page 242: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurDOD

extent.size.width

ext

ent.

size

.hei

ght

extent.origin

Page 243: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurDOD

extent.size.width

ext

ent.

size

.hei

ght

extent.origin

Page 244: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurDOD

extent.size.width

ext

ent.

size

.hei

ght

extent.origin

Page 245: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurDOD

extent.size.width

ext

ent.

size

.hei

ght

extent.origin

Page 246: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurDOD

extent.size.width

ext

ent.

size

.hei

ght

extent.origin |velocity.X|

Page 247: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurDOD

extent.size.width

DOD = CGRectInset (inputImage.extent, -abs(velocity.X), -abs(velocity.Y));

ext

ent.

size

.hei

ght

extent.origin |velocity.X|

Page 248: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurROI

Page 249: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurROI

Page 250: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurROI

Page 251: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurROI

Page 252: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurROI

Page 253: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurROI

Page 254: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurROI

Page 255: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurROI

Page 256: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion BlurROI

CGRect regionOf (CGRect rect, CIVector *velocity) { return CGRectInset (rect, -abs(velocity.X), -abs(velocity.Y)); }

Page 257: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur 2.0

Page 258: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur 2.0

Page 259: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur 2.0

Page 260: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldKernel contains dependent texture read

Page 261: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldKernel contains dependent texture read

Page 262: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldKernel contains dependent texture read

Page 263: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldKernel contains dependent texture read

CIKernel

Page 264: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldKernel contains dependent texture read

CIKernel

Page 265: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldKernel contains dependent texture read

CIKernel

Page 266: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldKernel contains dependent texture read

CIKernel

Page 267: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldCIKernel

Page 268: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldCIKernel

Page 269: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldCIKernel

!

!

!

!

kernel vec4 motionBlurWithMask (sampler image, sampler mask, float radius) { // read per-pixel directional vector from mask image first vec2 dir = sample (mask, samplerCoord(mask)).rg; dir = dir * 2.0 - 1.0; // de-normalize vector from [0,1] to [-1,+1] !

vec2 velocity = dir * radius; !

return _motionBlur (image, velocity); }

Page 270: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldCIKernel

!

!

!

!

kernel vec4 motionBlurWithMask (sampler image, sampler mask, float radius) { // read per-pixel directional vector from mask image first vec2 dir = sample (mask, samplerCoord(mask)).rg; dir = dir * 2.0 - 1.0; // de-normalize vector from [0,1] to [-1,+1] !

vec2 velocity = dir * radius; !

return _motionBlur (image, velocity); }

vec4 _motionBlur (sampler image, vec2 velocity) { // apply regular motion blur effect }

Page 271: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldCIKernel

!

!

!

!

kernel vec4 motionBlurWithMask (sampler image, sampler mask, float radius) { // read per-pixel directional vector from mask image first vec2 dir = sample (mask, samplerCoord(mask)).rg; dir = dir * 2.0 - 1.0; // de-normalize vector from [0,1] to [-1,+1] !

vec2 velocity = dir * radius; !

return _motionBlur (image, velocity); }

vec4 _motionBlur (sampler image, vec2 velocity) { // apply regular motion blur effect }

Page 272: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldCIKernel

!

!

!

!

kernel vec4 motionBlurWithMask (sampler image, sampler mask, float radius) { // read per-pixel directional vector from mask image first vec2 dir = sample (mask, samplerCoord(mask)).rg; dir = dir * 2.0 - 1.0; // de-normalize vector from [0,1] to [-1,+1] !

vec2 velocity = dir * radius; !

return _motionBlur (image, velocity); }

vec4 _motionBlur (sampler image, vec2 velocity) { // apply regular motion blur effect }

Page 273: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Motion Blur with Masked Vector FieldCIKernel

!

!

!

!

kernel vec4 motionBlurWithMask (sampler image, sampler mask, float radius) { // read per-pixel directional vector from mask image first vec2 dir = sample (mask, samplerCoord(mask)).rg; dir = dir * 2.0 - 1.0; // de-normalize vector from [0,1] to [-1,+1] !

vec2 velocity = dir * radius; !

return _motionBlur (image, velocity); }

vec4 _motionBlur (sampler image, vec2 velocity) { // apply regular motion blur effect }

Page 274: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

- (CIImage *)outputImage { float r = inputRadius.floatValue; CGRect DOD = CGRectInset (inputImage.extent, -r, -r); !

return [[self myKernel] applyWithExtent:DOD roiCallback:^(int index, CGRect rect) { return regionOf (index, rect, r); } arguments: @[inputImage, maskImage, inputRadius] ]; }

Motion Blur with Masked Vector FieldCIFilter subclass

Page 275: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

- (CIImage *)outputImage { float r = inputRadius.floatValue; CGRect DOD = CGRectInset (inputImage.extent, -r, -r); !

return [[self myKernel] applyWithExtent:DOD roiCallback:^(int index, CGRect rect) { return regionOf (index, rect, r); } arguments: @[inputImage, maskImage, inputRadius] ]; }

Motion Blur with Masked Vector FieldCIFilter subclass

Page 276: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

- (CIImage *)outputImage { float r = inputRadius.floatValue; CGRect DOD = CGRectInset (inputImage.extent, -r, -r); !

return [[self myKernel] applyWithExtent:DOD roiCallback:^(int index, CGRect rect) { return regionOf (index, rect, r); } arguments: @[inputImage, maskImage, inputRadius] ]; }

Motion Blur with Masked Vector FieldCIFilter subclass

Page 277: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CGRect regionOf (int index, CGRect rect, float radius) { if (index == 0) { return CGRectInset (rect, -radius, -radius); // ROI for input image } else if (index == 1) { return rect; // ROI for mask image } !

return CGRectNull; // should not reach here }

Motion Blur with Masked Vector FieldROI for multiple images

Page 278: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CGRect regionOf (int index, CGRect rect, float radius) { if (index == 0) { return CGRectInset (rect, -radius, -radius); // ROI for input image } else if (index == 1) { return rect; // ROI for mask image } !

return CGRectNull; // should not reach here }

Motion Blur with Masked Vector FieldROI for multiple images

Page 279: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CGRect regionOf (int index, CGRect rect, float radius) { if (index == 0) { return CGRectInset (rect, -radius, -radius); // ROI for input image } else if (index == 1) { return rect; // ROI for mask image } !

return CGRectNull; // should not reach here }

Motion Blur with Masked Vector FieldROI for multiple images

Page 280: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Portability of General KernelsOS X and iOS

Desktop-class kernel type with the same language syntax and semantics as OS X

Page 281: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Portability of General KernelsOS X and iOS

Desktop-class kernel type with the same language syntax and semantics as OS X

New built-in filters on iOS ported from OS X using general kernels

Page 282: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Portability of General KernelsOS X and iOS

Desktop-class kernel type with the same language syntax and semantics as OS X

New built-in filters on iOS ported from OS X using general kernels

Glass Distortion

Page 283: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Portability of General KernelsOS X and iOS

Desktop-class kernel type with the same language syntax and semantics as OS X

New built-in filters on iOS ported from OS X using general kernels

Histogram DisplayGlass Distortion

Page 284: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Performance ConsiderationsMultiple render passes

Input Image(s)Input Image(s)Input Image(s) Output Image

Sampler CIKernel CIImage

Page 285: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Performance ConsiderationsMultiple render passes

Input Image(s)Input Image(s)Input Image(s) Output Image

Sampler CIKernel CIImage

Page 286: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

!

!

!

!

!

!

Each input image to a CIKernel adds an extra render pass

Performance ConsiderationsMultiple render passes

Input Image(s)Input Image(s)Input Image(s) Output Image

Sampler CIKernel CIImage

Page 287: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

8-bit kCIFormatRGBA8

16-bit kCIFormatRGBAh

Null Working Space(Color Management Off )

Default Working Space (Linear Rec. 709) Needs Linear to sRGB Needs 2X Memory

Intermediate BufferskCIContextWorkingFormat

Page 288: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

8-bit kCIFormatRGBA8

16-bit kCIFormatRGBAh

Null Working Space(Color Management Off )

Default Working Space (Linear Rec. 709) Needs Linear to sRGB Needs 2X Memory

Intermediate BufferskCIContextWorkingFormat

Page 289: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

8-bit kCIFormatRGBA8

16-bit kCIFormatRGBAh

Null Working Space(Color Management Off )

Default Working Space (Linear Rec. 709) Needs Linear to sRGB Needs 2X Memory

Intermediate BufferskCIContextWorkingFormat

Page 290: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

8-bit kCIFormatRGBA8

16-bit kCIFormatRGBAh

Null Working Space(Color Management Off )

Default Working Space (Linear Rec. 709) Needs Linear to sRGB Needs 2X Memory

Intermediate BufferskCIContextWorkingFormat

Page 291: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel?Square Kaleidoscope

Page 292: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel?Square Kaleidoscope

Page 293: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel?Square Kaleidoscope

!CIFilter

CIKernel?=

Page 294: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

CIKernel?Square Kaleidoscope

!CIFilter

CIKernel?=

Page 295: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

!CIFilter

Better solutionSquare Kaleidoscope

?=

Page 296: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

!CIFilter

Better solutionSquare Kaleidoscope

?=

Page 297: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

!CIFilter

Better solutionSquare Kaleidoscope

CIWarpKernel

?=

Page 298: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

!CIFilter

Better solutionSquare Kaleidoscope

CIWarpKernel

?=

Page 299: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

!CIFilter

Better solutionSquare Kaleidoscope

CIWarpKernel

+

CIColorKernel

?=

Page 300: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

!CIFilter

Better solutionSquare Kaleidoscope

CIWarpKernel

+

CIColorKernel

?=

Page 301: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Square KaleidoscopeCIWarpKernel

kernel vec2 squareKaleidoscopeWarp (vec2 center, float size) { // offset by center and transform to unit square vec2 p = (destCoord() - center) / size; !

// calculate number of mirror reflections to get to this point float z = abs(floor(p.x)) + abs(floor(p.y)); !

// reflect this point into unit square space p = 1.0 - abs(mod(p, 2.0) - 1.0); !

// transform back to destination space return (p * size) + center; }

Page 302: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Square KaleidoscopeCIColorKernel

kernel vec4 squareKaleidoscopeColor (__sample s, vec2 center, float size) { // offset by center and transform to unit square vec2 p = (destCoord() - center) / size; !

// calculate number of mirror reflections to get to this point float z = abs(floor(p.x)) + abs(floor(p.y)); !

// exponential decay float k = pow(0.8, z); !

// multiply color sample with decay return vec4(s.rgb * k, s.a); }

Page 303: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

!

!

!

!

!

!

!

!

!

CIImage *warpedImage = [warpKernel applyWithExtent:CGRectInfinite roiCallback:^(int index, CGRect rect) { return coreRect; } inputImage:inputImage arguments: @[center, size] ];

Square KaleidoscopeCIWarpKernel and CIColorKernel

Page 304: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

!

!

!

!

!

!

!

!

!

CIImage *warpedImage = [warpKernel applyWithExtent:CGRectInfinite roiCallback:^(int index, CGRect rect) { return coreRect; } inputImage:inputImage arguments: @[center, size] ];

Square KaleidoscopeCIWarpKernel and CIColorKernel

CIWarpKernel

Page 305: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

!

!

!

!

!

!

!

!

!

CIImage *warpedImage = [warpKernel applyWithExtent:CGRectInfinite roiCallback:^(int index, CGRect rect) { return coreRect; } inputImage:inputImage arguments: @[center, size] ];

Square KaleidoscopeCIWarpKernel and CIColorKernel

CIWarpKernel

Page 306: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

!

!

!

!

!

!

!

!

!

CIImage *warpedImage = [warpKernel applyWithExtent:CGRectInfinite roiCallback:^(int index, CGRect rect) { return coreRect; } inputImage:inputImage arguments: @[center, size] ];

Square KaleidoscopeCIWarpKernel and CIColorKernel

CIWarpKernel

coreRect;

Page 307: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

!

!

!

!

!

!

!

!

!

CIImage *warpedImage = [warpKernel applyWithExtent:CGRectInfinite roiCallback:^(int index, CGRect rect) { return coreRect; } inputImage:inputImage arguments: @[center, size] ];

Square KaleidoscopeCIWarpKernel and CIColorKernel

CIWarpKernel

Page 308: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Square KaleidoscopeCIWarpKernel and CIColorKernel

!

!

!

!

!

!

!

!

!

CIImage *warpedImage = [warpKernel applyWithExtent:CGRectInfinite roiCallback:^(int index, CGRect rect) { return coreRect; } inputImage:inputImage arguments: @[center, size] ]; !

CIImage *outputImage = [colorKernel applyWithExtent:warpedImage.extent arguments: @[warpedImage, center, size] ];

CIWarpKernel

Page 309: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Square KaleidoscopeCIWarpKernel and CIColorKernel

!

!

!

!

!

!

!

!

!

CIImage *warpedImage = [warpKernel applyWithExtent:CGRectInfinite roiCallback:^(int index, CGRect rect) { return coreRect; } inputImage:inputImage arguments: @[center, size] ]; !

CIImage *outputImage = [colorKernel applyWithExtent:warpedImage.extent arguments: @[warpedImage, center, size] ];

CIWarpKernel CIColorKernel

Page 310: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Square KaleidoscopeCIWarpKernel and CIColorKernel

!

!

!

!

!

!

!

!

!

CIImage *warpedImage = [warpKernel applyWithExtent:CGRectInfinite roiCallback:^(int index, CGRect rect) { return coreRect; } inputImage:inputImage arguments: @[center, size] ]; !

CIImage *outputImage = [colorKernel applyWithExtent:warpedImage.extent arguments: @[warpedImage, center, size] ];

CIWarpKernel CIColorKernel

Page 311: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Recommendations

Page 312: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Recommendations

Write a general kernel only when needed

Page 313: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Recommendations

Write a general kernel only when needed

Write a general kernel initially for rapid prototyping, then try replacing with some combination of warp and color kernels

Page 314: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Platform Differences

Page 315: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Platform Differences

iOS OS X

Renderers GPU CPU and GPU

Control flow in language Yes No

Kernel classesCIKernelCIColorKernelCIWarpKernel

CIKernel

CISampler No Yes

DOD CGRect CIFilterShape

ROI Block Pointer Selector

[CIFilter setDefaults] Automatic Explicit

[CIFilter customAttributes] Class Method Instance Method

Page 316: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

What You’ve Learned Today

Page 317: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

What You’ve Learned Today

How to write Color, Warp, and general kernels

Page 318: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

What You’ve Learned Today

How to write Color, Warp, and general kernels

DOD and ROI

Page 319: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

What You’ve Learned Today

How to write Color, Warp, and general kernels

DOD and ROI• ROI function is critical for large image support to work correctly and optimally

Page 320: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

What You’ve Learned Today

How to write Color, Warp, and general kernels

DOD and ROI• ROI function is critical for large image support to work correctly and optimally

Platform differences

Page 321: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

More Information

Allan Schaffer Graphics and Game Technologies Evangelist [email protected]

Developer Technical Support http://developer.apple.com/contact

Apple Developer Forums http://devforums.apple.com

Page 322: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Related Sessions

• Introducing the Photos Frameworks Nob Hill Thursday 10:15AM

• Advances in Core Image Pacific Heights Thursday 2:00PM

Page 323: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist

Labs

• Core Image Lab Media Lab B Thursday 4:30PM

Page 324: 515 Developing Core Image Filters for iOS DF · 2016. 7. 8. · Developing Core Image Filters for iOS Media Session 515 Alexandre Naaman Lead Customizer! Tony Chu General Specialist