Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6357444

JPEG: setDestinationType() causes IOException in case of embedded ICC profile.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • client-libs
    • None

      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 ============================

            bae Andrew Brygin
            bae Andrew Brygin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: