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.

Understanding the PDF File Format: Your 5 minute guide to Indexed ColorSpaces

1 min read

Why are Indexed Colorspaces useful?

indexed colour spaces
Understanding the PDF File Format. Indexed Colour spaces

Indexed colorspaces are very useful if you only have a limited number of colors in an image. If you only use 2 colors, you can create a table to store the 24bit color values (6 bytes) and then reference them as a pointer to which value to use (0 or 1) which only needs 1 bits. So each pixel will use a quarter of a byte as opposed to 3 bytes (a file size saving of 24 times which can be a very big number on large images.

If you have less than 16 colors, you need a 4 bit look-up and even if you have 255 colors you will still save 2 bytes for every pixel.

And the disadvantages?

The main disadvantage of indexed colorspaces is that they make reconstructing the image more complicated. Once you have the raw pixel data, you need to convert this back into the actual color.  Tricks like treating DCTDecode or JPXDecode data as JPEGs do not work because the pixel value is not the color but merely a pointer to the color (stored externally in the PDF file). Java’s ImageIO class allows you to extract and read the Raster directly which you can then use to build the real image.

In Java there is an IndexedImage type or you can use the lookup table to build the original image data. This also gets ‘complicated in Java because it only uses sRGB, so the Indexed color values (which can be in any ColorSpace) need conversion. So you could have a single Indexed value which is used to look-up a 4 byte YCCK color which then needs conversion into CMYK and then sRGB so that you can use it!

Power and flexibility can come at a price. As we were saying at the recent PDF Association conference, the PDF file format gives you lots of powerful tools, but it is up to you how you choose to use (or misuse them)….

Want to learn more about PDF files?

This post is part of our “Understanding the PDF File Format” series. In each article, we aim to take a specific PDF feature and explain it in simple terms. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

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.

Enabling SVG Gzip Compression on Apache and NGINX

Gzip compression is a widely supported method of reducing the size of the content sent from a web server in order to improve the...
Leon Atherton
47 sec read

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2019. All rights reserved.