Skip to main content

Re: RE: [JAI-IMAGEIO] TIFF

1 reply [Last post]
Anonymous

Great, thanks Brian, I surely will test it but it will only after
Chirstmas hols. I'll report here once I'm done.

br Kusti

>>> jai-imageio@javadesktop.org 19.12.2007 22:36:12 >>>
I think this is the same as jai-imageio-core issue 104. I've just
committed a change for this issue. Please try the daily build of
2007-12-20 and let us know whether it is fixed.

Brian

> No problem,
>
> I've tried different compression methods, but looking
> at the source
> code it seems that
> this was done (the exception) very deliberaty,
> probably for some
> internal implementation issues sowhere else in the
> code.
>
> But seeing (or actually not seeing!) that there is
> nothing in the TIFF
> spec
> that says that images cannot be larger than size of
> int,
> I'm inclined to think this is a bug. Should I file
> it?
>
> TIFF spec says, as I'm sure you know, that the total
> file size is
> restricted to 4 GB (limiting to size of int limits
> this to 2GB) but,
> but if the image is packed there is nothign in the
> spec that forbids
> larger than 4GB images. Heck, if CITT bilevel is
> considered the
> images could be humongous!
>
> br Kusti
>
>
> >>> mike.nidel@lmco.com 13.12.2007 20:46:49 >>>
> Sorry, I didn't scroll past the stack trace. My
> apologies.
>
> Well I don't have any new theories. Maybe it has
> something
> to do with the PackBits compression?
>
> > -----Original Message-----
> > From: Kustaa Nyholm
> [mailto:Kustaa.Nyholm@planmeca.com]
> > Sent: Thursday, December 13, 2007 1:20 PM
> > To: interest@jai-imageio.dev.java.net
> > Subject: RE: [JAI-IMAGEIO] TIFF reader exception:
> > width*height > Integer.MAX_VALUE, bug or feature?
> >
> > >>> mike.nidel@lmco.com 13.12.2007 17:59 >>>
> > >>a few more questions:
> >
> > >>what are you setting in your ImageReadParam when
> reading the TIFF?
> > >>What are you setting in your ImageWriteParam?
> >
> > ImageReadParam readParam =
> reader.getDefaultReadParam();
> >
> > TIFFImageWriteParam writeParam =
> (TIFFImageWriteParam)
> > writer.getDefaultWriteParam();
> >
> writeParam.setCompressionMode(ImageWriteParam.MODE_EXP
> LICIT);
> > writeParam.setCompressionType("PackBits");
> >
> writeParam.setTilingMode(ImageWriteParam.MODE_EXPLICIT
> );
> > writeParam.setTiling(256, 256, 0, 0);
> >
> >
> > >>Are you using subsampling?
> >
> > Yes, the complete test case was included with the
> previous
> > mail and seems have propagated to this reply also.
> >
> > br Kusti
> >
> >
> >
> >
> > > -----Original Message-----
> > > From: Kustaa Nyholm
> [mailto:Kustaa.Nyholm@planmeca.com]
> > > Sent: Wednesday, December 12, 2007 11:53 PM
> > > To: interest@jai-imageio.dev.java.net
> > > Subject: RE: [JAI-IMAGEIO] TIFF reader exception:
>
> > > width*height > Integer.MAX_VALUE, bug or feature?
> > >
> > >
> > >
> > > >>> mike.nidel@lmco.com 12.12.2007 22:34:18 >>>
> You must have
> > > missed my
> > > >>>reply last week.
> > > If you mean your answer (and thank you or
> answering) about
> > the image
> > > not being tiled, no, I did not miss it. And I
> acted on it.
> > As far as
> > > I can tell everything is tiled. I checked this by
> printing out the
>
> > > tile width / height at every node in the chain.
> Also, the
> > code works
> > > for an other image that is 10921
> > x
> > > 9533 ie
> > > about 400 MB which is way more than what the
> default JVM 64 MB can
>
> > > handle if not tiled. So I guess it is tiled.
> > >
> > > >I think I have a way for you to
> > > >debug this. You need to get a hold of the LAST
> image in your
> chain
> > > >>before writing to disk. Check if this image is
> tiled -- do a
> > > getTileWidth() and
> > > >getTileHeight() and see if they match your
> expectations.
> > >
> > > Thats what I did.
> > >
> > > >My strong suspicion is that your operation chain
> is constructed
> in
> > > such
> > > >a way that you are untiling the image. If you
> want to be very
> > > thorough,
> > > >print the tile sizes for every
> RenderedImage/RenderedOp in the
> > chain.
> > > >If the tile size jumps up at some point, you
> should set the
> desired
> > > tile
> > > >size in that op by passing in an ImageLayout on
> the
> RenderingHints
> > > under
> > > >JAI.KEY_IMAGE_LAYOUT.
> > > Just rechecked this, the tile size is 256 x 256
> after each
> > op in the
> > > chain.
> > >
> > > So, still confused, bug or feature?
> > >
> > > br Kusti
> > >
> > > > -----Original Message-----
> > > > From: Kustaa Nyholm
> [mailto:Kustaa.Nyholm@planmeca.com]
> > > > Sent: Wednesday, December 12, 2007 3:08 PM
> > > > To: interest@jai-imageio.dev.java.net
> > > > Subject: RE: [JAI-IMAGEIO] TIFF reader
> exception:
> > > > width*height > Integer.MAX_VALUE, bug or
> feature?
> > > >
> > > >
> > > >
> > > > >>> mike.nidel@lmco.com 12.12.2007 21:15:12 >>>
> ok, refresh
> > > my memory
> > >
> > > > >>>again: what's the exact spot where you get
> > > > the
> > > > >>>exception from? it's not after
> readAsRenderedImage() right?
> > > >
> > > > The exception happens when the code tries to
> write out the
> > > subsampled
> > > > image.
> > > >
> > > > The complete test case and exception trace
> follows, plus
> > > I've include
> > > > the 'tiffinfo' dump for the test file I'm
> using.
> > > >
> > > > Note that the test code reads in the image with
>
> > > > reader.readAsRenderedImage(7, readParam);
> because the large
> > > image is
> > > > the last image on that particular tiff. Of
> course '7' would
> > > not work
> > > > for the subsequent calls to 'subit' but the
> code never gets
> > > that far
> > > > with this image.
> > > >
> > > > br Kusti
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > java.lang.IllegalArgumentException:
> width*height >
> > > Integer.MAX_VALUE!
> > > > at
> > > >
> javax.imageio.ImageReader.getDestination(ImageReader.j
> ava:2823)
> > > > at
> > > >
> com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader
> .read(TI
> > > > FFImageReader.java:1170)
> > > > at
> > > >
> com.sun.media.imageioimpl.plugins.tiff.TIFFRenderedIma
> ge.read(
> > > > TIFFRenderedImage.java:259)
> > > > at
> > > >
> com.sun.media.imageioimpl.plugins.tiff.TIFFRenderedIma
> ge.copyD
> > > > ata(TIFFRenderedImage.java:274)
> > > > at
> > > >
> javax.media.jai.RenderedImageAdapter.copyData(Rendered
> ImageAda
> > > > pter.java:171)
> > > > at
> > > >
> >
> javax.media.jai.PlanarImage.copyExtendedData(PlanarIma
> ge.java:2411)
> > > > at
> > > >
> com.sun.media.jai.opimage.BorderOpImage.computeTile(Bo
> rderOpIm
> > > > age.java:220)
> > > > at
> > > >
> com.sun.media.jai.util.SunTileScheduler.scheduleTile(S
> unTileSc
> > > > heduler.java:912)
> > > > at
> javax.media.jai.OpImage.getTile(OpImage.java:1139)
> > > > at
> > > >
> javax.media.jai.PlanarImage.cobbleByte(PlanarImage.jav
> a:2863)
> > > > at
> javax.media.jai.PlanarImage.getData(PlanarImage.java:2
> 182)
> > > > at
> > > >
> javax.media.jai.GeometricOpImage.computeTile(Geometric
> OpImage.
> > > > java:676)
> > > > at
> > > >
> com.sun.media.jai.util.SunTileScheduler.scheduleTile(S
> unTileSc
> > > > heduler.java:912)
> > > > at
> javax.media.jai.OpImage.getTile(OpImage.java:1139)
> > > > at
> > > >
> javax.media.jai.PlanarImage.cobbleByte(PlanarImage.jav
> a:2863)
> > > > at
> javax.media.jai.PlanarImage.getData(PlanarImage.java:2
> 182)
> > > > at
> javax.media.jai.RenderedOp.getData(RenderedOp.java:228
> 7)
> > > > at
> > > >
> com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter
> .writeTi
> > > > le(TIFFImageWriter.java:1754)
> > > > at
> > > >
> com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter
> .write(T
> > > > IFFImageWriter.java:2686)
> > > > at
> > > >
> com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriter
> .write(T
> > > > IFFImageWriter.java:2417)
> > > > at
> renderer.SubSampleTest2.subit(SubSampleTest2.java:94)
> > > > at
> renderer.SubSampleTest2.main(SubSampleTest2.java:21)
> > > >
> > > >
> > > > package renderer;
> > > >
> > > > import java.io.*;
> > > > i> > > > import javax.imageio.stream.*;
> > > > import javax.media.jai.*;
> > > > import javax.imageio.metadata.*;
> > > >
> > > > import com.sun.media.imageio.plugins.tiff.*;
> > > > import com.sun.media.jai.codec.*;
> > > > import java.util.*;
> > > > import java.awt.*;
> > > > import java.awt.image.*;
> > > > import java.awt.image.renderable.*;
> > > >
> > > > import javax.imageio.metadata.*;
> > > >
> > > > public class SubSampleTest2 {
> > > > public static void main(String args[]) {
> > > > try {
> > > > subit(new File("./images/world.tif"),
> > > new File("r0.tif"));
> > > > subit(new File("r0.tif"), new
> File("r1.tif"));
> > > > subit(new File("r1.tif"), new
> File("r2.tif"));
> > > > subit(new File("r2.tif"), new
> File("r3.tif"));
> > > > subit(new File("r3.tif"), new
> > > > File("test-out.tif"));
> > > > } catch (Throwable e) {
> > > > e.printStackTrace();
> > > > }
> > > > }
> > > >
> > > > public static void subit(File sourceFile, File
> > > > destFile) throws IOException {
> > > > long t0 = System.nanoTime();
> > > >
> > > > FileImageOutputStream outputStream = new
> > > > FileImageOutputStream(destFile);
> > > > ImageWriter writer =
> > > >
> ImageIO.getImageWritersByFormatName("tiff").next();
> > > >
> > > > FileImageInputStream inputStream = new
> > > > FileImageInputStream(sourceFile);
> > > > ImageReader reader =
> ImageIO.getImageReader(writer);
> > > > reader.setInput(inputStream);
> > > >
> > > > IIOMetadata metadata =
> reader.getImageMetadata(0);
> > > >
> > > > ImageReadParam readParam =
> > > > reader.getDefaultReadParam();
> > > > RenderedImage inputImg =
> > > > reader.readAsRenderedImage(7, readParam);
> > > >
> > > > ParameterBlock pb;
> > > >
> > > > ImageLayout tileLayout = new
> ImageLayout(inputImg);
> > > > tileLayout.setTileWidth(256);
> > > > tileLayout.setTileHeight(256);
> > > > RenderingHints tileHints = new
> > > > RenderingHints(JAI.KEY_IMAGE_LAYOUT,
> tileLayout);
> > > >
> > > > pb = new ParameterBlock();
> > > > pb.addSource(inputImg);
> > > > inputImg = JAI.create("format", pb,
> tileHints);
> > > >
> > > > pb.addSource(inputImg);
> > > > pb.add(1);
> > > > pb.add(1);
> > > > pb.add(1);
> > > > pb.add(1);
> > > >
> > > >
> pb.add(BorderExtender.createInstance(BorderExtender.BO
> RDER_COPY));
> > > > pb.add(0);
> > > > inputImg= JAI.create("border", pb);
> > > >
> > > > pb = new ParameterBlock();
> > > > pb.addSource(inputImg);
> > > > pb.add(2).add(2);
> > > > pb.add(new float[] { 0.5F, 1.0F / 3.0F, 0.0F,
> > > -1.0F / 12.0F ,2});
> > > >
> > > >
> pb.add(Interpolation.getInstance(Interpolation.INTERP_
> BICUBIC_2));
> > > > inputImg = JAI.create("filteredsubsample",
> pb);
> > > >
> > > > writer.setOutput(outputStream);
> > > >
> > > > TIFFImageWriteParam writeParam =
> > > > (TIFFImageWriteParam)
> writer.getDefaultWriteParam();
> > > >
> > > >
> writeParam.setCompressionMode(ImageWriteParam.MODE_EXP
> LICIT);
> > > > writeParam.setCompressionType("PackBits");
> > > >
> > >
> >
> wri> > > > }
> > > >
> > > >
> > > > TIFF Directory at offset 0x1759a
> > > > Subfile Type: reduced-resolution image (1 =
> 0x1)
> > > > Image Width: 675 Image Length: 337
> > > > Tile Width: 256 Tile Length: 256
> > > > Bits/Sample: 8
> > > > Compression Scheme: JPEG
> > > > Photometric Interpretation: RGB color
> > > > YCbCr Subsampling: 2, 2
> > > > Copyright: "Frederic Delhoume"
> > > > Image Description: ""
> > > > Orientation: row 0 top, col 0 lhs
> > > > Samples/Pixel: 3
> > > > Planar Configuration: single image plane
> > > > Software: Very Large Image Viewer
> > > > JPEG Tables: (289 bytes)
> > > > TIFF Directory at offset 0x4d9e4
> > > > Subfile Type: reduced-resolution image (1 =
> 0x1)
> > > > Image Width: 1350 Image Length: 675
> > > > Tile Width: 256 Tile Length: 256
> > > > Bits/Sample: 8
> > > > Compression Scheme: JPEG
> > > > Photometric Interpretation: RGB color
> > > > YCbCr Subsampling: 2, 2
> > > > Orientation: row 0 top, col 0 lhs
> > > > Samples/Pixel: 3
> > > > Planar Configuration: single image plane
> > > > JPEG Tables: (289 bytes)
> > > > TIFF Directory at offset 0xf2cb2
> > > > Subfile Type: reduced-resolution image (1 =
> 0x1)
> > > > Image Width: 2700 Image Length: 1350
> > > > Tile Width: 256 Tile Length: 256
> > > > Bits/Sample: 8
> > > > Compression Scheme: JPEG
> > > > Photometric Interpretation: RGB color
> > > > YCbCr Subsampling: 2, 2
> > > > Orientation: row 0 top, col 0 lhs
> > > > Samples/Pixel: 3
> > > > Planar Configuration: single image plane
> > > > JPEG Tables: (289 bytes)
> > > > TIFF Directory at offset 0x2f50ee
> > > > Subfile Type: reduced-resolution image (1 =
> 0x1)
> > > > Image Width: 5400 Image Length: 2700
> > > > Tile Width: 256 Tile Length: 256
> > > > Bits/Sample: 8
> > > > Compression Scheme: JPEG
> > > > Photometric Interpretation: RGB color
> > > > YCbCr Subsampling: 2, 2
> > > > Orientation: row 0 top, col 0 lhs
> > > > Samples/Pixel: 3
> > > > Planar Configuration: single image plane
> > > > JPEG Tables: (289 bytes)
> > > > TIFF Directory at offset 0x9d4a56
> > > > Subfile Type: reduced-resolution image (1 =
> 0x1)
> > > > Image Width: 10800 Image Length: 5400
> > > > Tile Width: 256 Tile Length: 256
> > > > Bits/Sample: 8
> > > > Compression Scheme: JPEG
> > > > Photometric Interpretation: RGB color
> > > > YCbCr Subsampling: 2, 2
> > > > Orientation: row 0 top, col 0 lhs
> > > > Samples/Pixel: 3
> > > > Planar Configuration: single image plane
> > > > JPEG Tables: (289 bytes)
> > > > TIFF Directory at offset 0x214a4ee
> > > > Subfile Type: reduced-resolution image (1 =
> 0x1)
> > > > Image Width: 21600 Image Length: 10800
> > > > Tile Width: 256 Tile Length: 256
> > > > Bits/Sample: 8
> > > > Compression Scheme: JPEG
> > > > Photometric Interpretation: RGB color
> > > > YCbCr Subsampling: 2, 2
> > > > Orientation: row 0 top, col 0 lhs
> > > > Samples/Pixel: 3
> > > > Planar Configuration: single image plane
> > > > JPEG Tables: (289 bytes)
> > > > TIFF Directory at offset 0x7351000
> > > > Subfile Type: reduced-resolution image (1 =
> 0x1)
> > > > Image Width: 43200 Image Length: 21600
> > > > Tile Width: 256 Tile Length: 256
> > > > Bits/Sample: 8
> > > > Compression Scheme: JPEG
> > > > Photometric Interpretation: RGB color
> > > > YCbCr Subsampling: 2, 2
> > > > Orientation: row 0 top, col 0 lhs
> > > > Samples/Pixel: 3
> > > > Planar Configuration: single image plane
> > > > JPEG Tables: (289 bytes)
> > > > TIFF Directory at offset 0x197568b8
> > > > Image Width: 86400 Image Length: 43200
> > > > Tile Width: 256 Tile Length: 256
> > > > Bits/Sample: 8
> > > > Compression Scheme: JPEG
> > > > Photometric Interpretation: RGB color
> > > > YCbCr Subsampling: 2, 2
> > > > Orientation: row 0 top, col 0 lhs
> > > > Samples/Pixel: 3
> > > > Planar Configuration: single image plane
> > > > JPEG Tables: (289 bytes)
> > > >
> > > >
> > >
> >
> ------------------------------------------------------
> ---------------
> > > > To unsubscribe, e-mail:
> > > interest-unsubscribe@jai-imageio.dev.java.net
> > >
> > > > For additional commands, e-mail:
> > > > interest-help@jai-imageio.dev.java.net
> > > >
> > > >
> > >
> > >
> >
> ------------------------------------------------------
> ---------------
> > > To unsubscribe, e-mail:
> > interest-unsubscribe@jai-imageio.dev.java.net
> >
> > > For additional commands, e-mail:
> > > interest-help@jai-imageio.dev.java.net
> > >
> > >
> > >
> >
> ------------------------------------------------------
> ---------------
> > > To unsubscribe, e-mail:
> > interest-unsubscribe@jai-imageio.dev.java.net
> >
> > > For additional commands, e-mail:
> > > interest-help@jai-imageio.dev.java.net
> > >
> > >
> >
> >
> ------------------------------------------------------
> ---------------
> > To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
>
> > For additional commands, e-mail:
> > interest-help@jai-imageio.dev.java.net
> >
> >
> >
> ------------------------------------------------------
> ---------------
> > To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
>
> > For additional commands, e-mail:
> > interest-help@jai-imageio.dev.java.net
> >
> >
>
> ------------------------------------------------------
> ---------------
> To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
>
>
> ------------------------------------------------------
> ---------------
> To unsubscribe, e-mail:
> interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail:
> interest-help@jai-imageio.dev.java.net
[Message sent by forum member 'bpb' (bpb)]

http://forums.java.net/jive/thread.jspa?messageID=250843

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

---------------------------------------------------------------------
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.
bpb
Offline
Joined: 2004-06-23

No hurry: Sun is closed for the holidays from 21 Dec through 1 Jan, inclusive, and I am out until Jan. 7.

Happy Holidays!

Brian

> Great, thanks Brian, I surely will test it but it
> will only after
> Chirstmas hols. I'll report here once I'm done.
>
> br Kusti
>
>
> >>> jai-imageio@javadesktop.org 19.12.2007 22:36:12
> >>>
> I think this is the same as jai-imageio-core issue
> 104. I've just
> committed a change for this issue. Please try the
> daily build of
> 2007-12-20 and let us know whether it is fixed.
>
> Brian