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

ColorModel and SampleModel gotten from the same ImageTypeSpecifier instance can be not compatible

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b136
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      See the code below:

      import java.awt.color.ColorSpace;
      import java.awt.image.ColorModel;
      import java.awt.image.DataBuffer;
      import java.awt.image.SampleModel;
      import java.io.PrintWriter;
      import javax.imageio.ImageTypeSpecifier;

      public class createPackedTest {


          public static void main(String[] args) throws Exception {
              createPackedTest tst = new createPackedTest();
              tst.createPacked();
          }

          public void createPacked() {
              ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
              int i = Integer.MIN_VALUE;
      19: ImageTypeSpecifier itspecifier = ImageTypeSpecifier.createPacked(cs, i, i, i, i, 0, false);

              ColorModel cm = itspecifier.getColorModel();
              SampleModel sm = itspecifier.getSampleModel();
              java.awt.image.DirectColorModel dcm = (java.awt.image.DirectColorModel)cm;

              if (dcm.isCompatibleSampleModel(sm)){
                  System.out.println("createPacked test passed.");
              }else{
                  System.out.println("DirectColorModel is not compatible with SampleModel.");
              }
          }
      }

      The output will be:
          for JDK 7 b125: "createPacked test passed."
          for JDK 7 b126: "DirectColorModel is not compatible with SampleModel."

      The reason is the DataBuffer.TYPE_BYTE was used as a transferType during creating of the packed image in the line 19. If TYPE_INT is used the test will pass.
      Looks like the bit mask exceeding data type capacity is truncated when a SampleModel was creating. DataBuffer.TYPE_BYTE is 8 bit in this case. It can't reflect Integer.MIN_VALUE.

      See CR 7014316, 6782574. JDK spec for the SinglePixelPackedSampleModel constructor has the note: "Bit masks exceeding data type capacity are truncated". So, situation is expected.

      From other side a user will expect that the ColorModel and SampleModel gotten from the same ImageTypeSpecifier instance are compatible. And situation like above will confuse.

      Need to notice in the JDK specification for ImageTypeSpecifier.createPacked() method the situations when the ColorModel and SampleModel gotten from the same ImageTypeSpecifier instance can not be compatible. Or need to prevent such situation.

      The following JCK test case failed during JCK-runtime 7 testing for the JDK 7 b126 by the reason:
      api/javax_imageio/ImageTypeSpecifier/index.html#createPacked[createPacked001]
      api/javax_imageio/ImageTypeSpecifier/index.html#createPacked[createPacked005]
      api/javax_imageio/ImageTypeSpecifier/index.html#createPacked[createPacked006]

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bae Andrew Brygin
                Reporter:
                afomin Alexander Fomin (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: