Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

How to convert YCCK color to RGB color

1 min read

There are some ‘odd’ images in PDF files. They pretend to be CMYK but in fact they are not… Here is a description of what they really are and how to handle them.

PDF files can contain image data which is DCT encoded (ie it is a JPEG image). These JPEGs can be any colorspace (sRGB, CMYK, etc). However, not all CMYK images are actually CMYK. If you were to view them (even in a package which can handle CMYK JPEGs), they would look horrible.

ycck image

These images are actually encoded as YCCK. You need to look at the image header to discover this.

Like CMYK, YCCK is made up of 4 channels but they are not the same.

CMYK consists of a mix of Cyan, Magenta, Yellow and Key (black). YCCK encodes the data so that information less sensitive to the huge eye is discarded (YCbCr), allowing it to keep more of the detail which our eye would notice. This is the YCC bit (K is the same).

So for each pixel value we need to translate the YCC parts into CMY values. Luckily there is a standard formula for doing this, defined in the original Postscript format (the Red Book). Here it is

R = clip(Y + 1.402 * Cr - 179.456);
G=  clip(Y - 0.34414 * Cb - 0.71414 * Cr + 135.45984);
B = clip(Y + 1.772 * Cb - 226.816);

This gives us a value for RGB, which is not the RGB values for the pixel (we have not included the K value). But we can translate it into CMY using another formula or an ICC profile.

C = 255 - (int)R;
M = 255 - (int)G;
Y = 255 - (int)B;

This gives us the CMY pixels values which with the unaltered K value gives us CMYK. We can translate this into sRGB using profiles or several formulae. Dealing with colors is a very colorful experience!



Download your JDeli guide:

How to read, write and process common image file Formats in Java with JDeli

Start reading and writing images with one line of code

Read: BufferedImage image = JDeli.read(streamOrFile);

Write: JDeli.write(myBufferedImage, OutputFormat.HEIC, outputStreamOrFile)

Learn more >>

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

What is JPEG2000?

Alicia
54 sec read

What is PSD?

chika
52 sec read

What is PNG?

Mark Stephens
36 sec read

2 Replies to “How to convert YCCK color to RGB color”

  1. ycck jpegs gave me a bit of a headache about a week ago. With a non-aware decoder they can end up looking a bit like negatives, at least it did in my case, and reversing the colors can almost made it look good. Had me chasing down the wrong path.

    I eventually discovered that those jpeg files have a non-standard App14 marker, and then I found the formula for YCCK conversion on Intel’s homepage of all places. Looking in the PostScript specs never crossed my mind.

    Windows fails to properly render those jpegs too, but libjpeg handles them just fine.

    <i<Do you have any tips for color conversion?

    Not really, but for CMYK->RGB conversion my testing shows that using a 48 entry sample table, and plain interpolation, gives fairly close results to a proper algorithm. Good enough for me anyway, and if more accuracy is needed I only have to add more samples later.

  2. libjpeg looks like an interesting tool so I will definitely investigate (I was disappointed with the Info Photoshop gave on YCCK jpegs). Thanks for the tip on CMYK to RGB.

Comments are closed.