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.

Are you a Java Developer working with Image files?

Read and write images in Java with JDeli

What are Indexed Colorspaces?

52 sec read

What are indexed Colorspaces?

What are Indexed Colorspaces?

Indexed Colorspaces store a list of the colors used and reference that list to get the color of each pixel, rather than directly referencing each color value for a pixel in an image.

What are indexed Colorspaces?

Why are Indexed Colorspaces useful?

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. They are also less beneficial if the image contains lots of colors.

Some examples of how IndexedColorpaces are used

In Java there is an IndexedImage type or you can use the lookup table to build the original image data. This is also optimised for speed so it is faster and more memory-efficient.

The PDF file format uses IndexedColorspaces to reduce the size of PDF files.

GIF image files use a lookup table to reduce the size of the files created.



Find out how to read and write images files in Java with JDeli:

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.