JAI, Image I/O, TIFF Images, and ImageReadParam

C

Chuck Taylor

I'm trying to use JAI and JAI ImageIO to convert a huge TIFF file
(21600x21600) into a series of tiles. To accomplish that, I want to
read just a portion of the image, which I'm trying to do by setting
the sourceRegion property of the reader's defaultReadParam.

My setups:
Windows 2000, Red Hat Linux 8.0
Java 2 SDK 1.4.2
Java Advanced Imaging 1.1.2
JAI Image I/O Tools 1.0, installed per instructions


On both platforms, when I run the sample code below, I get one of two
possible exceptions, depending on the TIFF file supplied as a
command-line argument. The code works fine with JPEG and PNG images,
and it works with smaller TIFF images when I use the read() call
without the readParam argument.

Has anyone been able to load portions of TIFF images in a manner
similar to this using JAI?


--- Begin sample code ---

import java.awt.image.BufferedImage;
import java.awt.Rectangle;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.ImageReadParam;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import javax.swing.JLabel;



public class ImageTester
{


public static void main (String arg[])
{
JFrame fr;
File f = null;
BufferedImage bi = null;
ImageReadParam readParam = null;
ImageReader rdr = null;
Iterator itr = null;
String defaultFilename = new String ("test.tif");

if (arg.length > 0)
f = new File (arg[0]);
else
f = new File (defaultFilename);
try {
itr = ImageIO.getImageReaders
(ImageIO.createImageInputStream (f));
if (!itr.hasNext ()) {
return;
}

rdr = (ImageReader) itr.next ();
rdr.setInput (ImageIO.createImageInputStream (f));
readParam = rdr.getDefaultReadParam ();
readParam.setSourceRegion (new Rectangle (0, 0, 50, 50));
if (true)
bi = rdr.read (rdr.getMinIndex (), readParam);
else
bi = rdr.read (rdr.getMinIndex ());

}
catch (IOException excp) {
System.err.println (excp);
return;
}

fr = new JFrame ("JAI Image");
fr.getContentPane ().add (new JLabel (new ImageIcon (bi)));
fr.pack ();
fr.show ();
}

}

--- End sample code ---



--- Begin exception 1 ---

Exception in thread "main" java.lang.IndexOutOfBoundsException: off <
0 || len < 0 || off + len > b.length!
at
javax.imageio.stream.ImageInputStreamImpl.readFully(ImageInputStreamImpl.java:323)
at
com.sun.media.imageioimpl.plugins.tiff.TIFFLSBDecompressor.decodeRaw(TIFFLSBDecompressor.java:49)
at
com.sun.media.imageio.plugins.tiff.TIFFDecompressor.decode(TIFFDecompressor.java:2010)
at
com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageReader.java:836)
at
com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1081)
at ImageTester.main(ImageTester.java:53)

--- End exception 1 ---



--- Begin exception 2 ---

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at
com.sun.media.imageioimpl.plugins.tiff.TIFFLZWDecompressor.decodeRaw(TIFFLZWDecompressor.java:114)
at
com.sun.media.imageio.plugins.tiff.TIFFDecompressor.decode(TIFFDecompressor.java:2010)
at
com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageReader.java:836)
at
com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1081)
at ImageTester.main(ImageTester.java:53)

--- End exception 2 ---
 
C

Chuck Taylor

If you don't get a solution here: for all questions on JAI,
<http://java.sun.com/products/java-media/jai/forDevelopers/interest_group.html>
is a good place to ask. Quick answers by the people who wrote it. Try
to search the archives
<http://archives.java.sun.com/archives/jai-interest.html> first,
though.



Thanks. I'll try that group soon. Since posting my earlier message,
however, I've found other behaviors that can only be bugs in the IIO
library, so I may have to choose a different strategy anyway (such as
perhaps the "real" JAI 1.1.2 I/O classes).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top