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

RasterFormatException: Incorrect scanline stride

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • tbd
    • 7u51, 8
    • client-libs
    • 2d
    • x86_64
    • linux

      FULL PRODUCT VERSION :
      java version "1.7.0_51"
      Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux astana 3.11.0-15-generic #25-Ubuntu SMP Thu Jan 30 17:22:01 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux (Ubuntu 13.04)

      A DESCRIPTION OF THE PROBLEM :
      Creating a Raster containing a subset of another Raster sometimes results in a error regarding the scanline stride (RasterFormatException: Incorrect scanline stride).

      As you can see the from the executable test case the problem occurs when creating a 1-band and 1-row subset Raster from a 3-band raster Raster with a PixelInterleavedSampleModel.

      I believe this bug is related to https://bugs.openjdk.java.net/browse/JDK-6604105.

      Working around this bug is technically possible by either creating the DataBuffer manually or implementing custom ColorModel/SampleModel's. However in practice making these modifications is difficult since the bug also affects third-party libraries (for example JAI).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test case below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The test case succeeds.
      ACTUAL -
      The test case fails with a RasterFormatException.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.awt.image.RasterFormatException: Incorrect scanline stride: 300
      at sun.awt.image.ShortComponentRaster.verify(ShortComponentRaster.java:828)
      at sun.awt.image.ShortComponentRaster.<init>(ShortComponentRaster.java:201)
      at sun.awt.image.ShortInterleavedRaster.<init>(ShortInterleavedRaster.java:131)
      at sun.awt.image.ShortInterleavedRaster.<init>(ShortInterleavedRaster.java:97)
      at java.awt.image.Raster.createWritableRaster(Raster.java:983)
      at java.awt.image.Raster.createWritableRaster(Raster.java:941)
      at com.luciad.java.awt.image.ImageTest.createSubBandImage(ImageTest.java:32)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
        @Test
        public void createSubBandImage() throws Exception {
          // Create a raster
          SampleModel sm1 = new PixelInterleavedSampleModel(DataBuffer.TYPE_USHORT, 100, 100, 3, 300, new int[]{0, 1, 2});
          WritableRaster raster1 = WritableRaster.createWritableRaster(
              sm1, new Point(0, 0)
          );

          // Reduce to 1 band
          SampleModel sm2 = sm1.createSubsetSampleModel(new int[]{0});
          WritableRaster raster2 = WritableRaster.createWritableRaster(
              sm2, new Point(0, 0)
          );

          // Further reduce to 1 row
          SampleModel sm3 = sm2.createCompatibleSampleModel(100, 1);
          // The line belows throws a RasterFormatException
          WritableRaster raster3 = WritableRaster.createWritableRaster(
              sm3, new Point(0, 0)
          );
        }
      ---------- END SOURCE ----------

            serb Sergey Bylokhov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: