Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 5089981
Votes 3
Synopsis A lower resolution image decoded from a JPEG2000 image has incorrect image dimensions.
Category jai:codec_imageio
Reported Against 1.1.2
Release Fixed 1.1
State 10-Fix Delivered, bug
Priority: 4-Low
Related Bugs 6306685 , 6476371 , 6175702 , 6175765 , 5101502
Submit Date 20-AUG-2004
Description


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 :
 customer  Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
The JPEG2000 codec is unable to decode a low  resolution version of huge JP2 files.   This appears to affect both the java and native decoder.
Low resolution versions of smaller JP2 images are decoded, but the width and height have been set incorrectly (they are set to the original image size, rather than the size of the low-res image).

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.  I can supply a 1.5kb JP2 file for an image that is 100,000 x 100,000 pixels if required.
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.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expected that the image dimensions would be set to the final image size (based on number of wavelet levels requested) which would allow me to generate a thumbnail for a large JP2 image.

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)
Error: One factory fails for the operation "imageread"
Occurs in: javax.media.jai.ThreadSafeOperationRegistry
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
        at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)
        at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)
        at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
        at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)
        at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
        at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
        at javax.media.jai.RenderedOp$1.getPropertyNames(RenderedOp.java:1802)
        at javax.media.jai.PropertyEnvironment.mapDefaults(PropertyEnvironment.java:280)
        at javax.media.jai.PropertyEnvironment.getPropertyNames(PropertyEnvironment.java:135)
        at javax.media.jai.WritablePropertySourceImpl.addProperties(WritablePropertySourceImpl.java:306)
        at javax.media.jai.RenderedOp.createPropertySource(RenderedOp.java:1828)
        at javax.media.jai.RenderedOp.getPropertyNames(RenderedOp.java:1862)
        at JP2Test.displayImageProperties(JP2Test.java:65)
        at JP2Test.main(JP2Test.java:59)
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Dimensions (width=100000 height=100000) are too large
        at com.sun.media.jai.imageioimpl.ImageReadCRIF.create(ImageReadCRIF.java:282)
        ... 19 more
Caused by: 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.getImageTypes(J2KImageReaderCodecLib.java:133)
        at javax.imageio.ImageReader.getRawImageType(ImageReader.java:665)
        at com.sun.media.jai.imageioimpl.ImageReadOpImage.layoutHelper(ImageReadOpImage.java:202)
        at com.sun.media.jai.imageioimpl.ImageReadOpImage.<init>(ImageReadOpImage.java:447)
        at com.sun.media.jai.imageioimpl.ImageReadCRIF.create(ImageReadCRIF.java:274)
        ... 19 more
Exception in thread "main" javax.media.jai.util.ImagingException: All factories fail for the operation "imageread"
        at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1695)
        at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)
        at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
        at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:830)
        at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:878)
        at javax.media.jai.RenderedOp.getRendering(RenderedOp.java:899)
        at javax.media.jai.RenderedOp$1.getPropertyNames(RenderedOp.java:1802)
        at javax.media.jai.PropertyEnvironment.mapDefaults(PropertyEnvironment.java:280)
        at javax.media.jai.PropertyEnvironment.getPropertyNames(PropertyEnvironment.java:135)
        at javax.media.jai.WritablePropertySourceImpl.addProperties(WritablePropertySourceImpl.java:306)
        at javax.media.jai.RenderedOp.createPropertySource(RenderedOp.java:1828)
        at javax.media.jai.RenderedOp.getPropertyNames(RenderedOp.java:1862)
        at JP2Test.displayImageProperties(JP2Test.java:65)
        at JP2Test.main(JP2Test.java:59)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
        at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1682)
        ... 13 more
Caused by: java.lang.RuntimeException: java.lang.IllegalArgumentException: Dimensions (width=100000 height=100000) are too large
        at com.sun.media.jai.imageioimpl.ImageReadCRIF.create(ImageReadCRIF.java:282)
        ... 19 more
Caused by: 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.getImageTypes(J2KImageReaderCodecLib.java:133)
        at javax.imageio.ImageReader.getRawImageType(ImageReader.java:665)
        at com.sun.media.jai.imageioimpl.ImageReadOpImage.layoutHelper(ImageReadOpImage.java:202)
        at com.sun.media.jai.imageioimpl.ImageReadOpImage.<init>(ImageReadOpImage.java:447)
        at com.sun.media.jai.imageioimpl.ImageReadCRIF.create(ImageReadCRIF.java:274)
        ... 19 more


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.media.jai.*;
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();
                }

                // Second bug - cannot obtain a low resolution version of the image properly
                J2KImageReadParam jp2Param = (J2KImageReadParam) reader.getDefaultReadParam();
                jp2Param.setResolution(0);
                displayImage(reader.read(0,jp2Param));
            }
            catch (Throwable t) {
                t.printStackTrace();
            }
        }

        // Demonstrate the problem using JAI
        J2KImageReadParam jp2Param = new J2KImageReadParam();
        jp2Param.setResolution(0);
        ParameterBlockJAI pbj = new ParameterBlockJAI("imageread");
        pbj.setParameter("readparam",jp2Param);
        pbj.setParameter("input",jp2File.getAbsolutePath());
        PlanarImage pi = JAI.create("imageread",pbj);
        displayImageProperties(pi);
        displayImage(pi.getAsBufferedImage());

    }

    private static void displayImageProperties(RenderedImage ri) {
        String []props = ri.getPropertyNames();
        if(props == null)
            System.out.println("[No image properties]");
        else
            for(int i=0; (i < props.length); i++)
                System.out.println((i+1)+". "+props[i]+": "+ri.getProperty(props[i]));
    }

    private static void displayImage(BufferedImage bi) {
        JLabel jl = new JLabel(new ImageIcon(bi));
        JFrame jf = new JFrame();
        jf.getContentPane().add(new JScrollPane(jl));
        jf.setSize(400,400);
        jf.setVisible(true);
    }
}


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

CUSTOMER SUBMITTED WORKAROUND :
no workaround available
(Incident Review ID: 290246) 
======================================================================
Work Around
N/A
Evaluation
There are two different bugs reported here. 

1) The first bug has to do with the inability of Image I/O to read in very large images. This is a deficiency in the java.awt.image.SampleModel class. Accordingly bug 5101502 has been filed against this problem.

2) The second bug has to do with incorrect image dimensions for an lower res image decoded from a JPEG2000 image. This bug report/id will track this second problem.
 
  xxxxx@xxxxx   2004-09-13
Comments
  
  Include a link with my name & email   

Submitted On 09-DEC-2004
ChristianO
I have a problem related. What I want to do is extract a region (x,y,1024x768) of the source image,
Here what I  thought looking at the API :
1- First, it need to support setSourceRenderSize.
2- Second, it have to interpolate from source region to render size, render size being the render size of the source region. else It will never be posible to render a pixels at full resolution  from geospatial raster images.



PLEASE NOTE: JDK6 is formerly known as Project Mustang