Skip to main content

JP2 Header File.

4 replies [Last post]
tyler_c
Offline
Joined: 2006-09-28

I am trying to parse the header file of a JP2 image, but I am having problems once I get to the SIZ Marker.

Here is an example of what I am doing, I can get the SOC fine but it doesnt like the SIZ.

stream.mark();
int marker = (stream.read() << 8) | stream.read();

//Checks to make sure there is a SOC
if (marker == 0xFF4F)
{
stream.reset();

marker = stream.readShort();
if(marker == 0xff51)
{

int length = stream.readUnsignedShort();
byte [] buf = new byte[length];
buf[0]= (byte)((length>>8) & 0xFF);
buf[1]= (byte)(length & 0xFF);
stream.readFully(buf,2,length-2);

ByteArrayInputStream bais = new ByteArrayInputStream(buf);
DataInputStream dis = new DataInputStream(bais);

int len2 = dis.readUnsignedShort();

// Read the capability of the codestream (Rsiz)
int cap = dis.readUnsignedShort();

Swidth = dis.readInt();
Sheight = dis.readInt();

}
}

I am not sure what my problem is. For stream right now I am using InputImageStream...should I be using some sort of RandomAcessIO?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
castalia
Offline
Joined: 2005-12-06

If you would like a set of Java classes that can read and report on all the
JP2 boxes, and the codestream segments, let me know and I will send you
a binary jar or the source code.

I use this utility routinely to examine JP2 fles.

Bradford Castalia
Sr. Systems Analyst
HiRISE Operations Center
University of Arizona

Jie Zhang

There is a big issue in TIFF reader of jai-imagio. It seems it needs
to read whole file even for getting image height or width. I got a lot
of out of memory errors even when I want to get metadata of a non-tiled
10000x10000 TIFF image. Does anyone know how to get metadata of large
image without OOM error.

Thanks,

---------------------------------------------------------------------
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

I don't believe that this is the case. No image data are read just to get
metadata. Depending on the structure of the TIFF source however the whole file
might need to be passed over. For example if the IFD occurs after the data
instead of before it, i.e., the order is

File Header -> Image Data -> Image File Directory

instead of

File Header -> Image File Directory -> Image Data

In the first case it will have to seek past the data to get the IFD.

Brian

On Wed, 4 Oct 2006, Jie Zhang wrote:

> There is a big issue in TIFF reader of jai-imagio. It seems it needs to read
> whole file even for getting image height or width. I got a lot of out of
> memory errors even when I want to get metadata of a non-tiled 10000x10000
> TIFF image. Does anyone know how to get metadata of large image without OOM
> error.
>
> Thanks,
>
>
>
> ---------------------------------------------------------------------
> 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

On Mon, 2 Oct 2006, jai-imageio@javadesktop.org wrote:

> I am trying to parse the header file of a JP2 image, but I am having problems once I get to the SIZ Marker.
>
> Here is an example of what I am doing, I can get the SOC fine but it doesnt like the SIZ.
>
> stream.mark();
> int marker = (stream.read() << 8) | stream.read();
>
> //Checks to make sure there is a SOC
> if (marker == 0xFF4F)
> {

After you reset() here the stream will be positioned ince again at the SOC
marker so the next short you read will be 0xFF4F, the SOC code, so you will
never enter the if(marker == 0xff51) block where 0xff51 is the SIZ code.

Brian

> stream.reset();
>
>
> marker = stream.readShort();
> if(marker == 0xff51)
> {
>
> int length = stream.readUnsignedShort();
> byte [] buf = new byte[length];
> buf[0]= (byte)((length>>8) & 0xFF);
> buf[1]= (byte)(length & 0xFF);
> stream.readFully(buf,2,length-2);
>
>
> ByteArrayInputStream bais = new ByteArrayInputStream(buf);
> DataInputStream dis = new DataInputStream(bais);
>
> int len2 = dis.readUnsignedShort();
>
> // Read the capability of the codestream (Rsiz)
> int cap = dis.readUnsignedShort();
>
> Swidth = dis.readInt();
> Sheight = dis.readInt();
>
> }
> }
>
> I am not sure what my problem is. For stream right now I am using InputImageStream...should I be using some sort of RandomAcessIO?
> [Message sent by forum member 'tyler_c' (tyler_c)]
>
> http://forums.java.net/jive/thread.jspa?messageID=158933
>
> ---------------------------------------------------------------------
> 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