A couple of posts back, I enthused about the new features of Quartz Composer 3.0s Core Image Filter patch.
It turns out they’re a little more tricky to use than I’d realised, so the wonderful space-saving composition I posted a screenshot of didn’t actually work as I’d intended, sadly.
As Kevin Quennesson from the Apple Quartzcomposer-dev list very patiently explained to me, the reason it didn’t work is to do with ROIs and DODs.
The DOD (Domain Of Definition) defines the dimensions of the image returned by a given Kernel function.
All this isn’t an issue, if you’re creating a simple, single-pass filter, or if the dimensions of the output of the filter are the same as those of the input image. However, I wanted to combine 2 seperate filter functions, and a crop (which resulted in the dimensions of the output image changing, obviously). These are the stages of the multi-pass filter I created:
Filter 2: Pixel-Strip
Creates strip at bottom-left, with each vertical stripe representing one ’tile’ of the input image.
Pixels outside this ‘active area’ receive the colour values of the pixel at 0.0, 0.0, but are cropped-out at the next stage, anyway.
I’ve highlighted the ROI/DOD-related code in purple.
function __image main(__image Image, __number Rows, __number Cols)
// CREATE CONTROL VALUES FROM INPUT SPLITTERS
// Input image dimensions
var Width = Image.extent.width;
var Height = Image.extent.height;
// Dimensions of Pixellation cells
var CellWidth = Width / (Math.ceil(Rows));
var CellHeight = Height / (Math.ceil(Cols));
// Total number of cells
var CellNum = Rows * Cols;
// ROI + DOD FUNCTIONS
// Thanks to Kevin Quennesson for his explanation and sample code
// Region Of Interest (ROI) of input image to be processed
function myROIFunction(samplerIndex, dstRect, info)
// Output image dimensions (DOD rect)
var dodRect = new Vec(0.0, 0.0, Width, Height);
// IMAGE OPERATIONS
// Pixellate image
xy_pixellate.ROIHandler = myROIFunction;
imagePixellated = xy_pixellate.apply(dodRect, dodRect, Image, CellWidth, CellHeight);
// Create strip
makeStrip.ROIHandler = myROIFunction;
imageStrip = makeStrip.apply(dodRect, dodRect, imagePixellated, CellWidth, CellHeight, CellNum, Cols);
imageCropped = Filter.Crop(imageStrip, new Vec(0.0, 0.0, CellNum, 1.0));