Skip to main content

[JAI-IMAGEIO] Problem when reading TIFF

1 reply [Last post]
Anonymous

Hi,

I'm planning to switch from JAI Codec to JAI ImageIO for my application. My application converts images from different formats into PNG or JPEG. I studied a bit on the discussion forum and have some idea how I can do so. However, I encountered a problem now. I tested most of the images (TIFF, JPEG, GIF, etc...) and the program runs properly except some TIFF images. For some of the TIFF images, I got the following exception:-

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 126719
at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.nextNBits(TIFFFaxDecompressor.java:1503)
at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decodeNextScanline(TIFFFaxDecompressor.java:707)
at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decode1D(TIFFFaxDecompressor.java:687)
at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decodeRaw(TIFFFaxDecompressor.java:674)
at com.sun.media.imageio.plugins.tiff.TIFFDecompressor.decode(TIFFDecompressor.java:2514)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageReader.java:1132)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1412)
at com.sun.media.imageioimpl.plugins.tiff.TIFFRenderedImage.read(TIFFRenderedImage.java:259)
at com.sun.media.imageioimpl.plugins.tiff.TIFFRenderedImage.getData(TIFFRenderedImage.java:243)
at com.sun.media.imageioimpl.plugins.tiff.TIFFRenderedImage.getTile(TIFFRenderedImage.java:235)
at com.sun.media.imageioimpl.plugins.clib.CLibImageWriter.getContiguousData(CLibImageWriter.java:272)
at com.sun.media.imageioimpl.plugins.clib.CLibImageWriter.getMediaLibImage(CLibImageWriter.java:712)
at com.sun.media.imageioimpl.plugins.png.CLibPNGImageWriter.write(CLibPNGImageWriter.java:162)
at javax.imageio.ImageWriter.write(ImageWriter.java:573)
at MultiPage.savePNG(MultiPage.java:58)
at MultiPage.main(MultiPage.java:38)

I'm attaching my test program and the sample TIFF image for your investigation. I don't think the attached TIFF image corrupted because I used to process the image by JAI Codec without any problem.

I'm running JDK1.4.1_04 on windows with the latest imageio daily build (1_1-pre-dr-b04 on Jun 6, 2006). I tried JDK1.5.0_07 as well and I got the same exception.

I appreciate for any advice. Thank you.

Best Regards,
Kelvin
[att1.html]
[MultiPage.zip]
---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Aaron Bruegl

Hi Kelvin,

I have recently switched from JAI Codec to JAI ImageIO for my
application as well. However the reader is not very robust yet, but
fixing that seems to be in the works by the JAI staff. Read the thread
"How to handle TIFF decoding exceptions (particularly fax images)" to
get some more information on this.

I tested your image and got the exact same error. This is because the
tiff is not formatted correctly, and below are the results of a "tiffcp"
(a common program on Linux).

So what I have done in my code to best try and handle these problems
(until changes are made to the JAI ImageIO reader itself), is catch the
exception from the ImageIO read, and try reading the image with the JAI
Codec. It seems to work ok for me :)

Regards,
-Aaron Bruegl

*tiffcp*

TIFFReadDirectory: Warning, atest.tif: unknown field with tag 292
(0x124) encoun tered.
TIFFReadDirectory: Warning, atest.tif: invalid TIFF directory; tags are
not sort ed in ascending order.
atest.tif: Warning, incorrect count for field "DateTime" (19, expecting
20); tag ignored.
atest.tif: Warning, using top-left orientation.
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1709, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1725, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 2776, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 2579, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1699, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 3042, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 3383, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 3400, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1698, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1703, expected 1696).
Fax3Decode2D: atest.tif: Uncompressed data (not supported) at scanline 0
(x 239) .
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 239,
expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1697, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 2901, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1697, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1809, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1978, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 3355, expected 1696).
Fax3Decode2D: atest.tif: Bad code word at scanline 0 (x 427).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 427,
expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1777, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 2370, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1698, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 2469, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 3164, expected 1696).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 0,
expected 1 696).
TIFFReadDirectory: Warning, atest.tif: unknown field with tag 292
(0x124) encoun tered.
TIFFReadDirectory: Warning, atest.tif: invalid TIFF directory; tags are
not sort ed in ascending order.
atest.tif: Warning, incorrect count for field "DateTime" (19, expecting
20); tag ignored.
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1697, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 3206, expected 1696).
Fax3Decode2D: atest.tif: Bad code word at scanline 0 (x 140).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 140,
expected 1696).
Fax3Decode2D: atest.tif: Uncompressed data (not supported) at scanline 0
(x 87).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 87,
expected 1696).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 0,
expected 1 696).
TIFFReadDirectory: Warning, atest.tif: unknown field with tag 292
(0x124) encoun tered.
TIFFReadDirectory: Warning, atest.tif: invalid TIFF directory; tags are
not sort ed in ascending order.
atest.tif: Warning, incorrect count for field "DateTime" (19, expecting
20); tag ignored.
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 2554, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 2892, expected 1696).
Fax3Decode2D: atest.tif: Uncompressed data (not supported) at scanline 0
(x 22).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 22,
expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1704, expected 1696).
Fax3Decode2D: atest.tif: Uncompressed data (not supported) at scanline 0
(x 1582 ).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 1582,
expecte d 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1724, expected 1696).
Fax3Decode2D: atest.tif: Bad code word at scanline 0 (x 1422).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 1422,
expecte d 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1781, expected 1696).
Fax3Decode2D: atest.tif: Uncompressed data (not supported) at scanline 0
(x 595) .
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 595,
expected 1696).
Fax3Decode2D: atest.tif: Uncompressed data (not supported) at scanline 0
(x 288) .
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 288,
expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1698, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 2013, expected 1696).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 0,
expected 1 696).
TIFFReadDirectory: Warning, atest.tif: unknown field with tag 292
(0x124) encoun tered.
TIFFReadDirectory: Warning, atest.tif: invalid TIFF directory; tags are
not sort ed in ascending order.
atest.tif: Warning, incorrect count for field "DateTime" (19, expecting
20); tag ignored.
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1770, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 2223, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 3068, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1705, expected 1696).
Fax3Decode2D: atest.tif: Bad code word at scanline 0 (x 92).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 92,
expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 3106, expected 1696).
Fax3Decode2D: atest.tif: Bad code word at scanline 0 (x 109).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 109,
expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1697, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1847, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1892, expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1795, expected 1696).
Fax3Decode2D: atest.tif: Bad code word at scanline 0 (x 240).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 240,
expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1697, expected 1696).
Fax3Decode2D: atest.tif: Bad code word at scanline 0 (x 1340).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 1340,
expecte d 1696).
Fax3Decode2D: atest.tif: Bad code word at scanline 0 (x 56).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 56,
expected 1696).
Fax3Decode2D: Warning, atest.tif: Line length mismatch at scanline 0
(got 1697, expected 1696).
Fax3Decode2D: Warning, atest.tif: Premature EOL at scanline 0 (got 0,
expected 1 696).

Kelvin Leung wrote:
> Hi,
> I'm planning to switch from JAI Codec to JAI ImageIO for my
> application. My application converts images from different formats
> into PNG or JPEG. I studied a bit on the discussion forum and have
> some idea how I can do so. However, I encountered a problem now. I
> tested most of the images (TIFF, JPEG, GIF, etc...) and the program
> runs properly except some TIFF images. For some of the TIFF images, I
> got the following exception:-
> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:
> 126719
> at
> com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.nextNBits(TIFFFaxDecompressor.java:1503)
> at
> com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decodeNextScanline(TIFFFaxDecompressor.java:707)
> at
> com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decode1D(TIFFFaxDecompressor.java:687)
> at
> com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decodeRaw(TIFFFaxDecompressor.java:674)
> at
> com.sun.media.imageio.plugins.tiff.TIFFDecompressor.decode(TIFFDecompressor.java:2514)
> at
> com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageReader.java:1132)
> at
> com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1412)
> at
> com.sun.media.imageioimpl.plugins.tiff.TIFFRenderedImage.read(TIFFRenderedImage.java:259)
> at
> com.sun.media.imageioimpl.plugins.tiff.TIFFRenderedImage.getData(TIFFRenderedImage.java:243)
> at
> com.sun.media.imageioimpl.plugins.tiff.TIFFRenderedImage.getTile(TIFFRenderedImage.java:235)
> at
> com.sun.media.imageioimpl.plugins.clib.CLibImageWriter.getContiguousData(CLibImageWriter.java:272)
> at
> com.sun.media.imageioimpl.plugins.clib.CLibImageWriter.getMediaLibImage(CLibImageWriter.java:712)
> at
> com.sun.media.imageioimpl.plugins.png.CLibPNGImageWriter.write(CLibPNGImageWriter.java:162)
> at javax.imageio.ImageWriter.write(ImageWriter.java:573)
> at MultiPage.savePNG(MultiPage.java:58)
> at MultiPage.main(MultiPage.java:38)
> I'm attaching my test program and the sample TIFF image for your
> investigation. I don't think the attached TIFF image corrupted because
> I used to process the image by JAI Codec without any problem.
> I'm running JDK1.4.1_04 on windows with the latest imageio daily build
> (1_1-pre-dr-b04 on Jun 6, 2006). I tried JDK1.5.0_07 as well and I got
> the same exception.
> I appreciate for any advice. Thank you.
> Best Regards,
> Kelvin
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.ne

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
For additional commands, e-mail: interest-help@jai-imageio.dev.java.net