Skip to main content

Extracting Multi Pages from TIFF Loading via URL

14 replies [Last post]
stevenbrey
Offline
Joined: 2006-06-09

Hi,

I need to load a tiff from a remote server, I use the following to load:
PlanarImage img = JAI.create("url",new URL);Now I want to extract the Pages from the Tiff doc, however, I see that the only method is to load it (in order to extract the pages) is as a FileSeekableStream, this however requires a filename but my documents are stored remotely and I HAVE to use the URL method to access the tiff image, can anyone help (this is for an applet)??

thanks, regards, steve

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
stevenbrey
Offline
Joined: 2006-06-09

Hi Brian, must be a rogue image, works with all other tiffs so far, thanks again for the assistance, regards, steve

Message was edited by: stevenbrey

James Cheng

Hi Steve,

> C [clib_jiio.dll+0x1dd3]
> j com.sun.medialib.codec.g4fax.Decoder.G4FAXDecode([B[BIII)I+0
> J com.sun.media.imageioimpl.plugins.tiff.TIFFCodecLibFaxDecompressor.decodeRaw([BIII)V

It seems to me that either there is a bug in the g4fax decoder of
clib_jiio.dll or that specific tiff file is not standard compliant
and the decoder can not handle it in a more graceful way.

You seemed to be using an earlier release of jai-imageio-core, as
I don't see clib_jiio_util.dll in your stack trace. If that's the
case, could you please try the latest Daily Build 1.1 available
here?

https://jai-imageio.dev.java.net/binary-builds.html

Then, if you still see the problem, could you please file an issue
against subcomponent codeclib at

https://jai-imageio-core.dev.java.net/servlets/ProjectIssues

and attach the tiff file in question?

If you prefer, you can send that tiff file to me or Brian in a
private email.

Thanks,
-James

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

stevenbrey
Offline
Joined: 2006-06-09

Hi James, I loaded the:
Stable builds 1.1 version
and the reader read the file (but not the pages), good enough for my purposes, thanks to you and Brain for the assistance, I will pm the tiff file to you for your info
best regards, steve

Brian Burkhalter

Steve,

By "Stable builds 1.1 version" do you mean 1.1-beta? If so that contains the
most recent update to the native component of JAI-IMAGEIO.

Brian

On Fri, 25 Aug 2006, jai-imageio@javadesktop.org wrote:

> Hi James, I loaded the:
> Stable builds 1.1 version
> and the reader read the file (but not the pages), good enough for my purposes, thanks to you and Brain for the assistance, I will pm the tiff file to you for your info
> best regards, steve

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

stevenbrey
Offline
Joined: 2006-06-09

Hi Brian,

Yes, it was the 1.1-beta. I have mailed the tiff to James for interest sake (I couldnt find your eMail), if you want a copy mail me direct and I will send.
Thanks again, this kind of support is rare (on other platforms!!) and greatly appreciated, best regards, steve

Brian Burkhalter

> Yes, it was the 1.1-beta.

Good!

> I have mailed the tiff to James for interest sake (I couldnt find your
> eMail), if you want a copy mail me direct and I will send.

No need: James's team handles the native code.

> Thanks again, this kind of support is rare (on other platforms!!) and
> greatly appreciated, best regards, steve

We are happy to have been of assistance.

Thanks,

Brian

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

stevenbrey
Offline
Joined: 2006-06-09

Hi Brian,

image = tiffReader.read(imageIndex, null);

Best regards,steve

Brian Burkhalter

I mean native exception.

Brian

On Wed, 23 Aug 2006, jai-imageio@javadesktop.org wrote:

> Hi Brian,
>
> image = tiffReader.read(imageIndex, null);
>
> Best regards,steve
> [Message sent by forum member 'stevenbrey' (stevenbrey)]
>
> http://forums.java.net/jive/thread.jspa?messageID=146392
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

stevenbrey
Offline
Joined: 2006-06-09

Hi Brian,

Tried your suggestion and it worked fine (and fast) except...

I have a multipage tiff image, when I try to load it I get teh following exception (have I run into an image where the layout is not as it should be??):
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x77fcca36, pid=968, tid=2656
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, sharing)
# Problematic frame:
# C [ntdll.dll+0x4ca36]
#
# An error report file with more information is saved as hs_err_pid968.log
-----------
my revised code is:

ImageInputStream stream;
Iterator readers =
ImageIO.getImageReadersBySuffix("tif");
ImageReader tiffReader = (ImageReader)readers.next();
URL con = new URL(filename);
InputStream is = con.openStream();
System.out.println("Stream Open.....");
stream = ImageIO.createImageInputStream(is);
System.out.println("Stream Allocated.....");
try {
tiffReader.setInput(stream);
System.out.println("Stream Allocated to reader.....");
} catch(IllegalArgumentException e) {
throw new IOException(e.toString());
}
//tiffReader.setInput(stream);
int imageIndex = 0;
ArrayList images = new ArrayList();
System.out.println("Array initialised....");
do {
BufferedImage image = null;
try {
System.out.println("Read image to buffered array....");
image = tiffReader.read(imageIndex, null);
System.out.println("Image Read....");
} catch(IndexOutOfBoundsException e) {
// Happens when imageIndex == number of pages in stream
break;
}
images.add(image);
stream.flush(); // Discard cached data up to current position
imageIndex++; // Go to the next image.
} while(true);
System.out.println("Images Loaded# " +imageIndex);
--------------------------

this works with a single page tif without a problem

Any ideas??
best regards, steve

Brian Burkhalter

No idea why that would happen. Where does the native exception occur?

Brian

On Wed, 23 Aug 2006, jai-imageio@javadesktop.org wrote:

> Hi Brian,
>
> Tried your suggestion and it worked fine (and fast) except...
>
> I have a multipage tiff image, when I try to load it I get teh following exception (have I run into an image where the layout is not as it should be??):
> # An unexpected error has been detected by HotSpot Virtual Machine:
> #
> # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x77fcca36, pid=968, tid=2656
> #
> # Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, sharing)
> # Problematic frame:
> # C [ntdll.dll+0x4ca36]
> #
> # An error report file with more information is saved as hs_err_pid968.log
> -----------
> my revised code is:
>
> ImageInputStream stream;
> Iterator readers =
> ImageIO.getImageReadersBySuffix("tif");
> ImageReader tiffReader = (ImageReader)readers.next();
> URL con = new URL(filename);
> InputStream is = con.openStream();
> System.out.println("Stream Open.....");
> stream = ImageIO.createImageInputStream(is);
> System.out.println("Stream Allocated.....");
> try {
> tiffReader.setInput(stream);
> System.out.println("Stream Allocated to reader.....");
> } catch(IllegalArgumentException e) {
> throw new IOException(e.toString());
> }
> //tiffReader.setInput(stream);
> int imageIndex = 0;
> ArrayList images = new ArrayList();
> System.out.println("Array initialised....");
> do {
> BufferedImage image = null;
> try {
> System.out.println("Read image to buffered array....");
> image = tiffReader.read(imageIndex, null);
> System.out.println("Image Read....");
> } catch(IndexOutOfBoundsException e) {
> // Happens when imageIndex == number of pages in stream
> break;
> }
> images.add(image);
> stream.flush(); // Discard cached data up to current position
> imageIndex++; // Go to the next image.
> } while(true);
> System.out.println("Images Loaded# " +imageIndex);
> --------------------------
>
> this works with a single page tif without a problem
>
> Any ideas??
> best regards, steve
> [Message sent by forum member 'stevenbrey' (stevenbrey)]
>
> http://forums.java.net/jive/thread.jspa?messageID=146350
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

stevenbrey
Offline
Joined: 2006-06-09

Hi Brian,

Thank you for the reply, much appreciated,, yes I am new at this, what I did that seemed to work was the following (loading pages into an array) - if anything really silly done, then please shout :-) :
best regards, steve

//-------------------------------------------------
TIFFDecodeParam param = null;
URL con = new URL(filename);
InputStream is = con.openStream();
int numImages = 0;
int i;

ImageDecoder dec = ImageCodec.createImageDecoder("tiff", is, param);
numImages = dec.getNumPages();
pageList = new RenderedImage[numImages];
System.out.println("Number of images in this TIFF: " +
dec.getNumPages());

for (i=0;i<= numImages-1;i++){

pageList [ i ] = new NullOpImage(dec.decodeAsRenderedImage(i),
null,
OpImage.OP_IO_BOUND,
null);
System.out.println("Loading Image#" +i);
}

Message was edited by: stevenbrey

Brian Burkhalter

Steve,

Retrieving the number of images will require seeking through the linked list
of TIFF IFDs in the stream. This is not so bad if you are using a file as
input but with a URL you might end up buffering a lot of data. I would suggest
using a forward-only stream and just looping until you get an exception. Try
it and see whether the performance improves.

Brian

On Tue, 22 Aug 2006, jai-imageio@javadesktop.org wrote:

> Hi Brian,
>
> Thank you for the reply, much appreciated,, yes I am new at this, what I did that seemed to work was the following (loading pages into an array) - if anything really silly done, then please shout :-) :
> best regards, steve
>
> //-------------------------------------------------
> TIFFDecodeParam param = null;
> URL con = new URL(filename);
> InputStream is = con.openStream();
> int numImages = 0;
> int i;
>
> ImageDecoder dec = ImageCodec.createImageDecoder("tiff", is, param);
> numImages = dec.getNumPages();
> pageList = new RenderedImage[numImages];
> System.out.println("Number of images in this TIFF: " +
> dec.getNumPages());
>
> for (i=0;i<= numImages-1;i++){
>
> pageList[i] = new NullOpImage(dec.decodeAsRenderedImage(i),
> null,
> OpImage.OP_IO_BOUND,
> null);
> System.out.println("Loading Image#" +i);
> }
> [Message sent by forum member 'stevenbrey' (stevenbrey)]
>
> http://forums.java.net/jive/thread.jspa?messageID=145750
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

stevenbrey
Offline
Joined: 2006-06-09

I have found the answer

Message was edited by: stevenbrey

Brian Burkhalter

Firstly if possile I would recommend using the JAI Image I/O TIFF reader
(https://jai-imageio.dev.java.net) if you are just starting development.

With respect to the question, there is no guarantee in a TIFF multi-page
stream that you won't have to download the whole thing anyway. For example,
the IFDs could all be at the begnning with all the strips/tiles at the end;
that is perfectly legal.

It is more likely however that the structure would be like this:

TIFF Header
Image 0 IFD
Image 0 Data
Image 1 IFD
Image 1 Data
...

In the latter case you could almost read the image sequentially.

If you are using the JAI Image I/O plugin I think the best approach would be
to create an InputStream from the URL and then wrap the InputStream in an
ImageInputStream using ImageIO.createImageInputStream(). Then assuming you
want to generate buffered images you could do something like this:

ImageInputStream stream;
ImageReader tiffReader;

tiffReader.setInput(stream);
int imageIndex = 0;
ArrayList images = new ArrayList();

do {
BufferedImage image = null;
try {
image = reader.read(imageIndex, null);
} catch(IndexOutOfBoundsException e) {
// Happens when imageIndex == number of pages in stream
break;
}

images.add(image);
stream.flush(); // Discard cached data up to current position
imageIndex++; // Go to the next image.
} while(true);

In this example flushing the ImageInputStream discards any data cached from an
earlier position in the stream.

Brian

On Sat, 19 Aug 2006, jai-imageio@javadesktop.org wrote:

> Is it possible to extract the Tiff pages from the Planar image in any way?
> or should I download it and store it on the local machine and then read it in from there as a FileSeekable stream??
> any help/advice would really be appreciated
> thanks, regards steve
> [Message sent by forum member 'stevenbrey' (stevenbrey)]
>
> http://forums.java.net/jive/thread.jspa?messageID=144725
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: interest-unsubscribe@jai-imageio.dev.java.net
> For additional commands, e-mail: interest-help@jai-imageio.dev.java.net
>
>

----------------
Brian Burkhalter
Java Media, Imaging, and Graphics
Sun Microsystems, Inc.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email message is for the sole use of the intended recipient(s)
and may contain confidential and privileged information. Any
unauthorized review, use, disclosure or distribution is prohibited.
If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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