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.

Interesting PDF bugs – ICC Colorspace alt setting

1 min read

The PDF file I have been looking at today has an issue which is more of a Java ‘feature‘ than a PDF bug but it does cover some PDF features so it is worth covering.

When you define an ICCColorspace, you can define an alternate Colorspace which can be used to display the data (generally DeviceRGB for 3 colors and DeviceCMYK for 4). This can be used instead of the ICCprofile and gives good enough results for most cases. As an ICCProfile is relatively slow in Java, we use it in preference for image conversion. And if the Data is compressed with DCTDecode we can use ImageIO to extract the data. So far so good.

However, we have found a file which does not work with ImageIO. It gives an exception inside Java itself
java.awt.color.CMMException: Invalid image format
at sun.awt.color.CMM.checkStatus(CMM.java:131)
at sun.awt.color.ICC_Transform.(ICC_Transform.java:89)
at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:516)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(JPEGImageReader.java:1169)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1137)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:948)
at javax.imageio.ImageIO.read(ImageIO.java:1422)

The JPG does work,however, if you decode it as an ICC JPeg by extraction the Raster and then converting manually. So we have adopted the pragmatic solution. We will still try to decode it with the Alternate colorspace, so we get all the benefits. But we will check to see if it fails, and treat it as an ICCColorspace. It seems a reasonable workaround to allow for an issue in the JVM.

I have come across quite a few issues with ICCColorspaces in Java5 and there are still some in Java6 so I hope Java7/8 will improve on ICC support. Do you have any favorite workarounds for ICCcolorspace limitations in Java?

This post is part of our “Understanding the PDF File Format” series. In each article, we discuss a PDF feature, bug, gotcha or tip. 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!

Did you know...

IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?

It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page

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 WMF files to SVG in java…

This article will show you how to convert WMF files into SVG files using our JDeli Java Image library. What is WMF? WMF is...
Amy Pearson
1 min read

How to write WebP images in Java

In this article, I will walk you through how to write out images as WebP images in Java. ImageIO does not support WebP images...
Mark Stephens
1 min read

How to convert EMF files to SVG in Java…

This article shows you how to convert EMF files into SVG files using our JDeli Java Image library. What is EMF? EMF is a...
Mark Stephens
1 min read

Leave a Reply

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

IDRsolutions Ltd 2020. All rights reserved.