Converts RGB data to YUV (YCrCb) data, or the other way around.
When converting to YUV, the resulting data is stored like this:
pixel.r = v (cr); pixel.g = y; pixel.b = u (cb);
When converting to RGB, the input data is asumed to be placed in
the pixels as above.
 |
 |
 |
original |
->yuv_to_rgb(); |
->rgb_to_yuv(); |
 |
 |
 |
tuned box (below) |
the rainbow (below) |
same, but rgb_to_yuv() |
RGB to YUB calculation (this follows CCIR.601):
in = input pixel
out = destination pixel
Ey = 0.299*in.r+0.587*in.g+0.114*in.b
Ecr = 0.713*(in.r - Ey) = 0.500*in.r-0.419*in.g-0.081*in.b
Ecb = 0.564*(in.b - Ey) = -0.169*in.r-0.331*in.g+0.500*in.b
out.r=0.875*Ecr+128
out.g=0.86*Ey+16
out.b=0.875*Ecb+128
Example: Nice rainbow.
object i = Image.Image(200,200);
i = i->tuned_box(0,0, 200,200,
({ ({ 255,255,128 }), ({ 0,255,128 }),
({ 255,255,255 }), ({ 0,255,255 })}))
->yuv_to_rgb();