Skip to main content

ArrayIndexOutOfBoundsException in PointOpImage#computeTile

7 replies [Last post]
s_ushakov
Offline
Joined: 2009-07-21
Points: 0

Hi,

I've run into a ArrayIndexOutOfBoundsException issue that seems already discussed here, but I could not find any resolution, sorry.

The exception happens to me when I try to write a modified image to png format. The debugger shows that the cause of the problem seems to root in the javax.media.jai.PointOpImage#computeTile code. Namely, the image dimensions are arbitrary, while computeTile tries to generate uniform 512x512 tiles, and that leads to an exception. This happens despite the fact that source cobbling is enabled (by default).

The top-level program flow is very straightforward:
RenderedImage image = imageReader.read (...);
RenderedOp improvedImage = JAI.create ("rescale", parameterBlockRescale);
IIOImage iIOImage = new IIOImage (improvedImage, null, null);
imageWriter.write (null, iIOImage, null);

The exception stack trace is as follows:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at sun.awt.image.ByteInterleavedRaster.getByteData(ByteInterleavedRaster.java:432)
at sun.awt.image.ByteInterleavedRaster.getDataElements(ByteInterleavedRaster.java:347)
at java.awt.image.BufferedImage.getData(BufferedImage.java:1411)
at javax.media.jai.RenderedImageAdapter.getData(RenderedImageAdapter.java:158)
at javax.media.jai.PointOpImage.computeTile(PointOpImage.java:794)
at com.sun.media.jai.util.SunTileScheduler.scheduleTile(SunTileScheduler.java:904)
at javax.media.jai.OpImage.getTile(OpImage.java:1129)
at javax.media.jai.PlanarImage.cobbleByte(PlanarImage.java:2850)
at javax.media.jai.PlanarImage.getData(PlanarImage.java:2169)
at javax.media.jai.RenderedOp.getData(RenderedOp.java:2276)
at com.sun.imageio.plugins.png.PNGImageWriter.encodePass(PNGImageWriter.java:806)
at com.sun.imageio.plugins.png.PNGImageWriter.write_IDAT(PNGImageWriter.java:930)
at com.sun.imageio.plugins.png.PNGImageWriter.write(PNGImageWriter.java:1146)
at test.EnhanceContrast.writeResultFile(EnhanceContrast.java:133)
at test.EnhanceContrast.main(EnhanceContrast.java:197)

Any ideas/comments would be most appreciated.

Regards,
Sergey

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cafeanimal
Offline
Joined: 2008-04-29
Points: 0

Hi Sergey,

If the change fixes your app that's great, but I'm trying to understand why...

Looking at the code for PointOpImage and OpImage, the original statement:
if ( !cobbleSources )
seems to me to result in what the method docs advertise. What am I missing ?

cheers
Michael

s_ushakov
Offline
Joined: 2009-07-21
Points: 0

An easy-to-fix bug was found in JAI 1.1.3. Solution is provided.

s_ushakov
Offline
Joined: 2009-07-21
Points: 0

A patch was submitted to the Issue Tracker:
https://jai-core.dev.java.net/issues/show_bug.cgi?id=134

power3d
Offline
Joined: 2006-07-17
Points: 0

What's inside the parameterBlockRescale parameter?

s_ushakov
Offline
Joined: 2009-07-21
Points: 0

Yes, sure :) parameterBlockRescale is as follows:

double [] subtract = new double [1];
subtract [0] = 64.;
double [] divide = new double [1];
divide [0] = 2.;
ParameterBlock parameterBlockRescale = new ParameterBlock ();
parameterBlockRescale.add (divide);
parameterBlockRescale.add (subtract);
parameterBlockRescale.addSource (image);

Thanks,
Sergey

s_ushakov
Offline
Joined: 2009-07-21
Points: 0

Hi again,

well, I've got the answer myself :) There is a bug in JAI 1.1.3, as line 727 in javax.media.jai.PointOpImage reads "if (!cobbleSources) {" while it should be "if (cobbleSources) {". With this line fixed no exceptions do happen.

Regards,
Sergey

power3d
Offline
Joined: 2006-07-17
Points: 0

Very well :D