...
 
Commits (2)
......@@ -222,31 +222,37 @@ Similar to A1, this appendix shows how a warp kernel can be used for a distortio
### Appendix 4 – `CIColorKernel`
The `CIColorKernel` is another kernel subtype that constraints to only work on changing the color of a single pixel, purely based on the pixel color values in the source image.
The code in this appendix is set up to produce a grey scale image using the average of the red, green, and blue values.
The code in this appendix is set up to produce a greyscale image using the average of the red, green, and blue values.
The `CIBlendKernel` introduced in task 4 is actually a subtype of `CIColorKernel` specifically.
### Appendix 5 – `CIKernel`
This appendix shows how to use the source position of a pixel to alter the output image. It fades the source image out to a grey scale image when going from left to right in the photo. It reads the position using the automatically provided `destination` parameter and its `coord()` method.
This appendix shows how to use the source position of a pixel to alter the output image. It fades the source image out to a greyscale image when going from left to right in the photo. It reads the position using the automatically provided `destination` parameter and its `coord()` method.
### Appendix 6 – `CIColorKernel`
A `CIColorKernel` can also accept multiple input sources like a `CIKernel`, so in this example a depth map is provided along with the color source image. The output calculations are similar to those in A5, but instead of using the position to decide the amount of grey scale, it uses the depth value at a given position.
A `CIColorKernel` can also accept multiple input sources like a `CIKernel`, so in this example a depth map is provided along with the color source image. The output calculations are similar to those in A5, but instead of using the position to decide the amount of greyscale, it uses the depth value at a given position.
### Appendix 7 – `CIKernel`
This appendix shows how to create an effects that uses both the position (like A5) and the values from a depth map (like A6) to alter the color source image.
## Appendix 8 – `CIImageProcessorKernel`
## Appendices 8-9 – `CIImageProcessorKernel`
When `CIImage`’s built-in tools for image processing aren’t enough, the `CIImageProcessorKernel` class is provided as an “escape hatch” allowing you to hook into the Core Image processing graph with any processing frameworks or method that you wish.
### The effect
To use the `CIImageProcessorKernel` class, you subclass it and override a few methods, out of which the `process()` method is the most interesting. It receives 3 arguments: An array of inputs, a dictionary of arguments, and an output.
The example in this appendix performs CPU-based rendering of a simple distortion effect.
The inputs and outputs are of type `CIImageProcessorInput` and `CIImageProcessorOutput`, respectively, and they contain meta data about the input and output images along with different methods of accessing and manipulating the image data (Metal textures, Core Video pixel buffers, IOSurface objects). For this appendix, we’re interested in pointers to the “raw” memory address of the input data (for reading from) as well as the memory address for the output (for writing to).
For each row of pixels in the image, go through the pixels from left to right and set each pixel to the average color of the pixel encountered so far.
These pointers are of type `UnsafeRawPointer` and `UnsafeMutableRawPointer` which we bind to `UnsafePointer<Float32>` and `UnsafeMutablePointer<Float32>` to make them easier to read from and write to.
### Appendix 8 – CPU-Based Rendering
The example in this appendix performs CPU-based rendering of a distortion effect that isn’t possible to achieve using `CIKernel`s.
For each row of pixels in the image, it goes through the pixels from left to right and set each pixel to the average color of the pixel encountered so far.
In other words, for each row:
- Pixel #1 will have its original color
......@@ -254,16 +260,9 @@ In other words, for each row:
- Pixel #3 will be the average color of pixels #1, #2 and #3
- ...and so on
### `CIImageProcessorKernel`
To use the `CIImageProcessorKernel` class, you subclass it and override a few methods, out of which the `process()` method is the most interesting. It receives 3 arguments: an array of inputs, a dictionary of arguments and an output.
The inputs and outputs are of type `CIImageProcessorInput` and `CIImageProcessorOutput`, respectively, and they contain meta data about the input and output images along with different methods of accessing and manipulating the image data (Metal textures, CoreVideo pixel buffers, IOSurface objects). For this appendix, we’re interested in pointers to the “raw” memory address of the input data (for reading from) as well as the memory address for the output (for writing to).
These pointers are of type `UnsafeRawPointer` and `UnsafeMutableRawPointer` which we bind to `UnsafePointer<Float32>` and `UnsafeMutablePointer<Float32>` to make them easier to read from and write to.
### Appendix 9 – CPU-Based Rendering
## Appendix 9
This is a more advanced example of what could be done using a `CIImageProcessorKernel`. It implements an old school stereogram effect, or more specifically a random-dot stereogram. It’s a seemingly noisy picture that, when looking at it “correctly” with both eyes produces a 3D effect. It is produced using depth information. Therefor we can use our depth maps for the calculations.
# References
......