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

SampleModel should support very large images (width*height > Integer.MAX_VALUE)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4
    • None
    • 1.4.2
    • client-libs
    • None
    • 2d
    • Fix Understood
    • generic
    • generic

    Description

      Since the SampleModel class does not support very large images (those whose width * height > Integer.MAX_VALUE), Image I/O cannot be used to read in these very large images. Customer Michael Owen <###@###.###> has run into this problem:

      FULL PRODUCT VERSION :
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      The JPEG2000 codec is unable to decode huge JP2 files. This appears to affect both the java and native decoder.

      This occurs with the image-io tools for JAI v1.0 and v1.0_01 releases.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the suppliedsample program with a very large .jp2 file. The dimensions of the JP2 image need to be over 65,536 pixels. A 1.5kb JP2 file for an image that is 100,000 x 100,000 pixels is attached.
      The actual images used for the real application are photo mosaics of many images, which have been compressed as JPEG2000 images externally to this application. These are almost always larger than 65,536 x 65,536 pixels.


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Trying reader jpeg 2000
      java.lang.IllegalArgumentException: Dimensions (width=100000 height=100000) are too large
              at java.awt.image.SampleModel.<init>(SampleModel.java:112)
              at java.awt.image.ComponentSampleModel.<init>(ComponentSampleModel.java:128)
              at java.awt.image.PixelInterleavedSampleModel.<init>(PixelInterleavedSampleModel.java:69)
              at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.createSampleModel(J2KRenderedImageCodecLib.java:591)
              at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.createOriginalSampleModel(J2KRenderedImageCodecLib.java:579)
              at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.<init>(J2KRenderedImageCodecLib.java:191)

              at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLib.readHeader(J2KImageReaderCodecLib.java:334)

              at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLib.getWidth(J2KImageReaderCodecLib.java:145)
              at JP2Test.main(JP2Test.java:28)
      java.lang.IllegalArgumentException: The destination or source region is empty.
              at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.computeRegionsWrapper(J2KImageReader.java:180)
              at com.sun.media.imageioimpl.plugins.jpeg2000.J2KRenderedImageCodecLib.<init>(J2KRenderedImageCodecLib.java:167)

              at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLib.read(J2KImageReaderCodecLib.java:281)
              at JP2Test.main(JP2Test.java:43)
      Trying reader jpeg 2000
      Image size = 100000,100000
      java.lang.IllegalArgumentException: Dimensions (width=100000 height=100000) are too large
              at java.awt.image.SampleModel.<init>(SampleModel.java:112)
              at java.awt.image.ComponentSampleModel.<init>(ComponentSampleModel.java:128)
              at java.awt.image.PixelInterleavedSampleModel.<init>(PixelInterleavedSampleModel.java:69)
              at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.getSampleModel(J2KReadState.java:787)
              at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.getColorModel(J2KReadState.java:827)
              at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.readBufferedImage(J2KReadState.java:302)
              at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.read(J2KImageReader.java:356)
              at JP2Test.main(JP2Test.java:43)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.image.*;
      import java.io.*;
      import java.util.*;
      import javax.swing.*;
      import javax.imageio.*;
      import javax.imageio.stream.*;
      import javax.imageio.metadata.*;
      import com.sun.media.imageio.plugins.jpeg2000.*;


      public class JP2Test {
          public static void main(String[] args) {
              File jp2File = new File(args[0]);

              // Demonstrate the problem using ImageIO
              Iterator iterator = ImageIO.getImageReadersByFormatName("jpeg2000");
              while (iterator.hasNext()) {
                  try {
                      ImageInputStream iis = ImageIO.createImageInputStream(jp2File);
                      ImageReader reader = (ImageReader) iterator.next();
                      reader.setInput(iis);

                      // First bug - line below fails on huge images
                      // The Java decoder throws an OutOfMemoryError, the native decoder throws an IllegalArgumenmtException
                      try {
                          int width = reader.getWidth(0);
                          int height = reader.getHeight(0);
                          System.out.println("Image size = " + width + "," + height);
                      } catch(IllegalArgumentException ex) {
                          ex.printStackTrace();
                      } catch(OutOfMemoryError e) {
                          e.printStackTrace();
                      }
                  }
                  catch (Throwable t) {
                      t.printStackTrace();
                  }
              }
          }
      }


      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: