Quartz Composer Patch : Image Registration: YUV, Rectangular (dx,dy)
/* Published by b-l-a-c-k-o-p.com
Copyright (c) 2007-2012
http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
*/
SAMPLE: QameraBetterPopArt5.qtzThis is similar to the ARGB registration kernels, but it works in YUV color space, where the brightness is already separated from the chromaticity. Thus, when you de-register, the deregistered color is more closely related to the center.
kernel vec4 msBlackRectRegistrationYUV(sampler input_image, vec2 u_delta, vec2 v_delta)
{
const vec3 rgb_y = vec3(0.257, 0.504, 0.098);
const vec3 rgb_u = vec3(-0.148, -0.291, 0.439);
const vec3 rgb_v = vec3(0.439, -0.368, -0.071);
const vec3 yuv_r = vec3(1.0000, 0.0000, 1.4022 );
const vec3 yuv_g = vec3( 1.0000, -0.3457, -0.7145);
const vec3 yuv_b = vec3(1.0000, 1.7710, 0.0000);
vec2 center = samplerCoord(input_image);
vec4 pixel = sample(input_image, center);
vec3 pel = pixel;
vec3 u_pixel = sample(input_image, center + u_delta);
vec3 v_pixel = sample(input_image, center + v_delta);
vec3 pixel_yuv;
pixel_yuv.x = dot(pel,rgb_y);
pixel_yuv.y = dot(u_pixel,rgb_u);
pixel_yuv.z = dot(v_pixel,rgb_v);
pixel.r = dot(pixel_yuv,yuv_r);
pixel.g = dot(pixel_yuv,yuv_g);
pixel.b = dot(pixel_yuv,yuv_b);
return pixel;
}