JDK-6357444 : JPEG: setDestinationType() causes IOException in case of embedded ICC profile.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2005-12-01
  • Updated: 2011-01-19
  • Resolved: 2006-04-03
Related Reports
Duplicate :  
Description
If source image contains embedded ICC profile and corresponding image type is set as
destination type by using ImageReadParam instance, then JPEG image reader throws IOException
like this:
javax.imageio.IIOException: Destination type from ImageReadParam does not match!
        at javax.imageio.ImageReader.getDestination(ImageReader.java:2862)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:892)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:864)
        at DestinationTest.main(DestinationTest.java:47)

This test can be used to reproduce the problem:

================== source code ===================================
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.ImageTypeSpecifier;
import javax.imageio.stream.ImageInputStream;

public class DestinationTest {
    
    /** Creates a new instance of DestinationTest */
    public DestinationTest() {
    }
    
    public static void main(String[] args) throws IOException {
        ImageInputStream iis = 
                ImageIO.createImageInputStream(new FileInputStream(new File(args[0])));
        
        ImageReader reader = ImageIO.getImageReaders(iis).next();
        
        reader.setInput(iis);
        
        Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
        
        ImageTypeSpecifier iccType = null;
        
        while (types.hasNext() && iccType == null) {
            ImageTypeSpecifier t = types.next();
            ColorSpace cs = t.getColorModel().getColorSpace();
            if (cs.getType() == ColorSpace.TYPE_RGB &&
                    !cs.isCS_sRGB()) {
                iccType = t;
            }
        }
         
        if (iccType == null) {
            System.out.println("Image does not contain ICC profile.");
            return;
        }
        ImageReadParam param = reader.getDefaultReadParam();
        param.setDestinationType(iccType); 
        try {
            reader.read(0, param);
        } catch (IOException e) {
            throw new RuntimeException("Test failed.", e);
        }
}
================== end of source code ============================

Comments
EVALUATION This problem was fixed as part of fix for 6395551.
03-04-2006

WORK AROUND setDestination() method can be used insted: param = reader.getDefaultReadParam(); int w = reader.getWidth(0); int h = reader.getHeight(0); param.setDestination(iccType.createBufferedImage(w, h)); BufferedImage dst = reader.read(0, param);
01-12-2005