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 – Indexed Colorspaces

1 min read

Indexed colorspaces are a very useful way of reducing the amount of memory and space needed when you only need a certain number of colours. It is best explained by an example.

Let’s image you have a image in CMYK colour. That means you need 4 bytes to describe the colour of a pixel. If the image had 4,000 pixels, that would be 16,000 bytes.

Now, lets imagine that the image only used 255 colors. Instead of storing each pixel value, we could have a table with 256 entries (that is 1,024 bytes storing the 4 bytes for each CMYK color used) and then just store 1 byte per pixel to say which entry in the table to use. That would be a total of 4,000 bytes (for the colours) and 1,024 bytes for the look-up table. That is 5,024 bytes (quite a reduction from the 16,000 bytes.

And if we do not need 256 colours, we could do even better by squashing the bits together. If we only had 2 colours, we would still need 8 bytes for the look-up table but only a bit (one eighth of a byte) for each pixel to say which colour to use – a total of 508 bytes for everything!

This is what an indexed colorspace does. It allows us to store a table of colours in a look-up table and store the index, not the color. This reduces substantially the size of data needed. It works best with fewer colours so images with a huge number of colours do not gain as well and could actually take up more memory. But for appropriate images, 16,000 bytes to 508 bytes is a substantial size reduction.

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.