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

IllegalArgExptn thrown when reading image using TYPE_BYTE_GRAY after TYPE_CUSTOM

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 1.8, 1.4.0, 11, 12, 16
    • client-libs

      I am trying to read a jpeg image from a file using ImageIO using all the type specifiers returned by reader.getImageTypes(). The JPEG reader returns 3 type specifiers - TYPE_3BYTE_BGR, TYPE_BYTE_GRAY and TYPE_CUSTOM. First I am setting the destination in the image read param to the buffered image created out of TYPE_CUSTOM and reading the image. I am able to read the image successfully. When I set the destination to the buffered image created out of TYPE_BYTE_GRAY right after this and try to read the same image using the same reader I am getting an IllegalArgumentException which is specified at the end of this bug report. But this does not occur when i read the image first using TYPE_BYTE_GRAY. This is reproducible on Solaris as well as Windows right from JDK1.4+.

      I have attached a sample code. Execute it. You would see the list of type specifiers returned by JPEG Reader. You will also see this IllegalArgumentException. When you edit and comment out the portion of the code which sets the destination to TYPE_CUSTOM the gray scale image will be read properly. But I am not quite sure why this is failing especially when doing it after TYPE_CUSTOM.

      Here is the exception:
      java.lang.IllegalArgumentException: Numbers of source Raster bands and source color space components do not match
      at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:437)
      at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(JPEGImageReader.java:1092)
      at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
      at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1053)
      at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:853)
      at SetDestinationTest.<init>(SetDestinationTest.java:47)
      at SetDestinationTest.main(SetDestinationTest.java:99)

            jdv Jayathirth D V
            pmohansunw Praveen Mohan (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: