Skip to main content

Multiple images in JP2 stream

3 replies [Last post]
scyudits
Offline
Joined: 2005-07-15

Hi,

I am getting the following exception when I do ImageReader.getMetadata(1) for a JP2 image.

java.lang.IndexOutOfBoundsException: Only support to decode the first image in JP2 stream.
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.checkIndex(J2KImageReader.java:278)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.getImageMetadata(J2KImageReader.java:318)

Is this happening because this particular image has only one image in its codestream, or does the J2KImageReader not support multiple images at all?

Thanks,

Sophia

Reply viewing options

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

This is the code for checkIndex():

private void checkIndex(int imageIndex) {
if (imageIndex != 0) {
throw new IndexOutOfBoundsException(I18N.getString("J2KImageReader4"));
}
}

It only supports one image. If you have more than one image in the stream you
should be just to invoke setInput() on the reader assuming that the SOC marker
of the next image immediately follows the EOC marker of the image just read.

BTW, from the stack trace it looks as if you are not using the most recent
version of JAI Image I/O Tools.

Brian

On Wed, 31 Jan 2007, jai-imageio@javadesktop.org wrote:

> Hi,
>
> I am getting the following exception when I do ImageReader.getMetadata(1) for a JP2 image.
>
> java.lang.IndexOutOfBoundsException: Only support to decode the first image in JP2 stream.
> at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.checkIndex(J2KImageReader.java:278)
> at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.getImageMetadata(J2KImageReader.java:318)
>
> Is this happening because this particular image has only one image in its codestream, or does the J2KImageReader not support multiple images at all?
>
> Thanks,
>
> Sophia
> [Message sent by forum member 'scyudits' (scyudits)]
>
> http://forums.java.net/jive/thread.jspa?messageID=200392
>
> ---------------------------------------------------------------------
> 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

scyudits
Offline
Joined: 2005-07-15

Thanks. What parameters should I be using in setInput() in this case? Do I call it just once or before every new ImageRead? Would I be using index 0 then for each image?

Yes, I am currently testing with an old version of jai_imageio.jar. :)

> This is the code for checkIndex():
>
> private void checkIndex(int imageIndex) {
> if (imageIndex != 0) {
> throw new
> throw new
> new
> IndexOutOfBoundsException(I18N.getString("J2KImageRead
> er4"));
> }
> }
>
> It only supports one image. If you have more than one
> image in the stream you
> should be just to invoke setInput() on the reader
> assuming that the SOC marker
> of the next image immediately follows the EOC marker
> of the image just read.
>
> BTW, from the stack trace it looks as if you are not
> using the most recent
> version of JAI Image I/O Tools.
>
> Brian
>
> On Wed, 31 Jan 2007, jai-imageio@javadesktop.org
> wrote:
>
> > Hi,
> >
> > I am getting the following exception when I do
> ImageReader.getMetadata(1) for a JP2 image.
> >
> > java.lang.IndexOutOfBoundsException: Only support
> to decode the first image in JP2 stream.
> > at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageRea
> der.checkIndex(J2KImageReader.java:278)
> > at
> com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageRea
> der.getImageMetadata(J2KImageReader.java:318)
> >
> > Is this happening because this particular image has
> only one image in its codestream, or does the
> J2KImageReader not support multiple images at all?
> >
> > Thanks,
> >
> > Sophia
> > [Message sent by forum member 'scyudits'
> (scyudits)]
> >
> >
> http://forums.java.net/jive/thread.jspa?messageID=2003
> 92
> >
> >
> ------------------------------------------------------
> ---------------
> > 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

Brian Burkhalter

It would be like this for example:

ImageInputStream input;
reader.setInput(input); // stream at SOC of first image
BufferedImage image1 = reader.read(0); // stream left at first byte after EOC
reader.setInput(input); // stream at SOC of second image
BufferedImage image2 = reader.read(0);

You have to use "0" in reader.read() or you will get an exception.

Brian

On Wed, 31 Jan 2007, jai-imageio@javadesktop.org wrote:

> Thanks. What parameters should I be using in setInput() in this case? Do I call it just once or before every new ImageRead? Would I be using index 0 then for each image?
>
> Yes, I am currently testing with an old version of jai_imageio.jar. :)
>
>> This is the code for checkIndex():
>>
>> private void checkIndex(int imageIndex) {
>> if (imageIndex != 0) {
>> throw new
>> throw new
>> new
>> IndexOutOfBoundsException(I18N.getString("J2KImageRead
>> er4"));
>> }
>> }
>>
>> It only supports one image. If you have more than one
>> image in the stream you
>> should be just to invoke setInput() on the reader
>> assuming that the SOC marker
>> of the next image immediately follows the EOC marker
>> of the image just read.
>>
>> BTW, from the stack trace it looks as if you are not
>> using the most recent
>> version of JAI Image I/O Tools.
>>
>> Brian
>>
>> On Wed, 31 Jan 2007, jai-imageio@javadesktop.org
>> wrote:
>>
>>> Hi,
>>>
>>> I am getting the following exception when I do
>> ImageReader.getMetadata(1) for a JP2 image.
>>>
>>> java.lang.IndexOutOfBoundsException: Only support
>> to decode the first image in JP2 stream.
>>> at
>> com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageRea
>> der.checkIndex(J2KImageReader.java:278)
>>> at
>> com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageRea
>> der.getImageMetadata(J2KImageReader.java:318)
>>>
>>> Is this happening because this particular image has
>> only one image in its codestream, or does the
>> J2KImageReader not support multiple images at all?
>>>
>>> Thanks,
>>>
>>> Sophia
>>> [Message sent by forum member 'scyudits'
>> (scyudits)]
>>>
>>>
>> http://forums.java.net/jive/thread.jspa?messageID=2003
>> 92
>>>
>>>
>> ------------------------------------------------------
>> ---------------
>>> 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
> [Message sent by forum member 'scyudits' (scyudits)]
>
> http://forums.java.net/jive/thread.jspa?messageID=200432
>
> ---------------------------------------------------------------------
> 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