2005.09.20 09:15 "[Tiff] Parse image into YCbCr data", by Katrina Maramba

2005.09.21 16:06 "RE: [Tiff] Parse image into YCbCr data", by Philip Watkinson


Is there an algorithm to convert from CMYK to RGB and vice versa?


-----Original Message-----

From: tiff-bounces@lists.maptools.org [mailto:tiff-bounces@lists.maptools.org] On Behalf Of Joris Sent: September 20, 2005 6:00 AM

To: katrina maramba; tiff mail list Subject: Re: [Tiff] Parse image into YCbCr data

What is the simplest way to parse a tiff image into YCbCr data? What is the API to call for this? What I found in the files was an API to convert YCbCr to RGB.

 Is there an API that has the same behavior as

TIFFReadRGBAStrip but instead output YCbCr??

No, there is no such function.

You can, however, easilly convert the RGBA returned from TIFFReadRGBAStrip into YCbCr. The relation between these color spaces is documented in the TIFF spec, and in the LibJpeg jdcolor.c and jccolor.c files. It's the same YCbCr.

        R = Y                + 1.40200 * Cr
        G = Y - 0.34414 * Cb - 0.71414 * Cr
        B = Y + 1.77200 * Cb

       Y  =  0.29900 * R + 0.58700 * G + 0.11400 * B
       Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B  + 128
       Cr =  0.50000 * R - 0.41869 * G - 0.08131 * B  + 128

Note that these are floating point convertions. To optimize to integer arithmatic, multiply all coëfficients with 65536, add 32767 to the complete result, and shift right 16 bits. Or consult jccolor.c.

Also note that these aren't completely round trip. If you need 16bit or floating point precision, and you want a convertion from RGB to YCbCr to RGB to yield the exact values you started with, you'll have to do some matrix convertion of your own with greater precision.