[gdal-dev] GDAL and JPEG2000 (Kakadu specially), manually reading image data

Frank Warmerdam warmerdam at pobox.com
Tue Apr 6 20:01:25 EDT 2010

Zermeno, Robert J CIV NAVAIR, 472100D wrote:
> Can anyone let me know how to properly read a 24bpp JPEG2000 image data?
> This image has 1 Band overview.  I am using the C API.
> I have a few questions.  Please respond even if you know something about any
> of the questions I have.
> 1.  Can someone reference me to where I can acquire what Band overviews are
> in respect to JPEG2000?


I don't understand this question.

> 2. What does GDALGetOverview() really return when referring to image data?
> I understand it returns a GDALRasterBandH in which I can call
> GDALReadBlock(), but it does not successfully (I believe its because my
> image array is not big enough).

GDALGetOverview() returns a GDALRasterBandH which can be used to access
the reduced resolution overview of the main full res image.  In the
case of JPEG2000 the overview does not exist on disk as a distinct object,
but rather is mixed into the compressed data stream for the image is a
whole.  But the overview band objects fairly efficiently extract the
image overview data.

I do not understand your point about GDALReadBlock not working.  I will
note that it is often better to use the RasterIO() interface as the band
or dataset level rather than fetching by blocks with JPEG2000.

> 3. In GDALReadBlock(), what does it mean when this method returns a
> "natural" block from the raster band?  So, since my image is say 24bpp 900 x
> 900, will return a line of 900 x 3 (for RGB per pixel)?

Many file formats have a "natural block size".  For scanline oriented
formats the block size is one full scanline.  For tiled images, it is one
tile.  JPEG2000 does not really have a natural block size, so we arbitrarily
establish a block size (usually 2048x128 for the JP2KAK JPEG2000 driver)
that provides for reasonably efficient access.

> 4.  When using GDALReadBlock() when the image has an overview, I still
> retrieve image data before even calling GDALGetOverview().  What data am I
> actually getting?

You are presumably getting blocks of imagery from the full resolution image.

> My main issue is understanding how the image data in JPEG2000 is retrieved
> by GDAL and what GDALGetOverview() and GDALReadBlock() really returns to the
> programmer when your image contains an Overview?

Well, the overview data is extracted from the JPEG2000 datastream by setting
a window and resolution level with the lower level library (usually
Kakadu) and then reading the imagery back.  The lower level library takes
care of the complex logic.

Best regards,
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

More information about the gdal-dev mailing list