|
|
Quartz Composer Patch : Color Distortion Maps, YUV
/* 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: QameraYUVMunge.qtzThis kernel distorts the color in the image using two source image "maps". Each image map is evaluated as a greyscale value. This results in an average brightness from 0.0 ... 1.0. Using 0.5 as the center, the source pixel is adjusted in the U and V color axes by the displacements from the maps. The effect is blended back into the source pixel according to amount_normal. kernel vec4 msBlackColorDisplaceYUV(sampler image, sampler distort_u_map, sampler distort_v_map, float amount_normal) { float input_amount = clamp(amount_normal,0.0,1.0); float inverse_amount = 1.0-input_amount; 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);
vec4 pixel = sample(image, samplerCoord(image)); vec3 pel = pixel; vec3 distort_u = sample(distort_u_map, samplerCoord(distort_u_map)); vec3 distort_v = sample(distort_v_map, samplerCoord(distort_v_map));
float delta_u = clamp((distort_u.x+distort_u.y+distort_u.z)/3.0,0.0,1.0)-0.5; float delta_v = clamp((distort_v.x+distort_v.y+distort_v.z)/3.0,0.0,1.0)-0.5; vec3 pixel_yuv; pixel_yuv.x = dot(pel,rgb_y); pixel_yuv.y = dot(pel,rgb_u); pixel_yuv.z = dot(pel,rgb_v); pixel_yuv.y = clamp(pixel_yuv.y + delta_u,0.0,1.0); pixel_yuv.z = clamp(pixel_yuv.z + delta_v,0.0,1.0); pel.r = dot(pixel_yuv,yuv_r); pel.g = dot(pixel_yuv,yuv_g); pel.b = dot(pixel_yuv,yuv_b);
vec3 result = (input_amount*pel) + inverse_amount*vec3(pixel); return vec4(result.r, result.g, result.b,pixel.a); } Labels: chroma
By : Ms. Black Color Distortion Maps, YUV
|
|
|
|
|
|
|
|