Quartz Composer – How to specify destination size for a Core Image filter?

380 Views Asked by At

I have a Quartz Composer composition using a Core Image filter that I want to produce an output image of a different size than the input. As a silly example, suppose I want to squish the image vertically by a factor of 2 using a filter like:

kernel vec4 coreImageKernel(sampler image ) {
    vec4 color = sample(image, samplerCoord(image) * vec2(1.0, 2.0));
    color.a = 1.0;
    return color;
}

I have unchecked "Define Output Image Domain of Definition as Union of Input Sampler DoD's" in the settings for the Core Image filter patch. But I'm unclear on what the alternative is. The help text for the Core Image patch suggests using an Image Crop patch, so I did. In my example, I crop to a height half the size of the input image, and a width that's the same as the input image.

snapshot of composition

The size and content of the resulting image is what expect, except that about the top quarter of it is solid black.

1

There are 1 best solutions below

0
Andy Jazz On

In Quartz Composer patches are divided into three main groups that designate their execution mode (patch execution follows a lazy evaluation approach) – consumer, processor and then provider. A consumer patches (like Cube, Billboard, or Gradient) render a result to a destination. Core Image patch here is a processor, so it can't change the final size of the frame.

The best way to specify a destination size in Quartz Composer is to use a Sprite patch.

For squeezing 900x900 image vertically in Quartz Composer you do not need to use an Core Image Filter and Image Crop in your composition. All you need is a Sprite patch, not a Billboard. The normalised 0....1 Height parameter in Sprite patch must be set to 0.5 (or must be set to 1.0 in 0....2 normalised scale).

Sprite patch renders a single quad with optionally antialiased borders. The image on the quad is multiplied by the colour set on the "Color" input and can be combined with a mask using the optional "Mask Image" input. The mask will be resized to match the image's size.

So, as you can see in the following picture the destination format is 900x450:

enter image description here

Although Billboard patch has only Width value by default for proportional scale, you can enable Custom Size in Settings Panel for activating its Height value. But setting Height to 0.5 in Billboard brings you an improper result like this:

enter image description here

Also, Image Crop patch doesn't crop boundaries of the frame, it just crops image inside the frame's destination size.