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.
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.
Are you a Java Developer working with Image files?
// Read an image
BufferedImage bufferedImage = JDeli.read(dicomImageFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(heicImageFile);
// Write an image
JDeli.write(bufferedImage, "heic", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(jpegImageFile);
// Write an image
JDeli.write(bufferedImage, "jpeg", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(jpeg2000ImageFile);
// Write an image
JDeli.write(bufferedImage, "jpx", outputStreamOrFile);
// Write an image
JDeli.write(bufferedImage, "pdf", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(pngImageFile);
// Write an image
JDeli.write(bufferedImage, "png", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(tiffImageFile);
// Write an image
JDeli.write(bufferedImage, "tiff", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(webpImageFile);
// Write an image
JDeli.write(bufferedImage, "webp", outputStreamOrFile);
Why do developers choose JDeli over free alternatives?
- Works with newer image formats such as AVIF, HEIC, JPEG XL, WEBP
- Better support than alternatives for JPEG, PNG, TIFF.
- Prevent JVM crashes caused by native code in other image libraries
- Better performance than other popular Java image libraries