[gdal-dev] Issue with GDAL - JP2KAK driver

Boris Forzun BORISF at rnd-hub.com
Sun Jun 28 01:50:24 PDT 2020


Hi,

I've encountered a problem using the JP2KAK driver for reading JP2 images.
I use the following python code to read a specific overview from an image:

--------------------------------------------------------------------------------------------------------------------------

raster = gdal.Open(path, gdal.GA_ReadOnly)
overview = raster.GetRasterBand(band_num).GetOverview(overview_num)

# Read a 512X512 buffer at offset (0,0) from the given overview.
buffer = overview.ReadAsArray(0,0,512,512,512,512)

--------------------------------------------------------------------------------------------------------------------------

I would expect the driver to read exactly the 512X512 buffer I ask for, from the relevant overview.
In reality, I see the following log:

--------------------------------------------------------------------------------------------------------------------------

[2020-06-25T13:04:23.159Z] [DEBUG] [image_reader_logger] [1.1.0] Requested buffer for image: /vsis3/***.JP2 : Reads region (0, 0, 512, 512) into 512 X 512. Overview: 3 : Overview dimensions: (802X723)
[2020-06-25T13:04:23.177Z] [DEBUG] [image_reader_logger] [1.1.0] Reads band: 1 of overview: 3
JP2KAK: DirectRasterIO() for 0,0,8192,8192 -> 512x512 (no intermediate)

--------------------------------------------------------------------------------------------------------------------------

Also, I see VSICURL logs that the driver downloads 26 MB of data.
I've tested the behavior with a pyramidal tiff image, it works as expected.
I've also written a small C program doing the same. with the same results:

--------------------------------------------------------------------------------------------------------------------------

#include "gdal.h"
#include "cpl_conv.h"

int main()
{
    CPLSetConfigOption("AWS_VIRTUAL_HOSTING", "NO");
    CPLSetConfigOption("AWS_HTTPS", "NO");
    CPLSetConfigOption("AWS_SECRET_ACCESS_KEY", "***");
    CPLSetConfigOption("AWS_ACCESS_KEY_ID", "***");
    CPLSetConfigOption("AWS_S3_ENDPOINT", "localhost:9000");
    CPLSetConfigOption("AWS_SSL_ENABLED", "NO");
    CPLSetConfigOption("CPL_DEBUG", "ON");
    CPLSetConfigOption("CPL_CURL_VERBOSE", "NO");
    CPLSetConfigOption("CPL_VSIL_CURL_CHUNK_SIZE", "1000000");


    GDALDatasetH hDataset;
    GDALAllRegister();
    hDataset = GDALOpen("/vsis3/***.JP2", GA_ReadOnly);

    GDALRasterBandH hBand;

    hBand = GDALGetRasterBand(hDataset, 1);

    hBand = GDALGetOverview(hBand, 3);

    u_int16_t *pafScanline;
    pafScanline = (u_int16_t *)CPLMalloc(sizeof(u_int16_t) * 512 * 512);
    CPLErr err = GDALRasterIO(hBand, GF_Read, 0, 0, 512, 512,
                            pafScanline, 512, 512, GDT_UInt16,
                            0, 0);

    GDALClose(hDataset);
}

--------------------------------------------------------------------------------------------------------------------------

The higher the overview, the bigger the request from S3, as if GDAL reads the best resolution and resamples the results...


  *   The input image is a 12 bit, 4 bands, pyramidal (5 internal pyramids) J2K image (image size: 12826X11565).
  *   I've built GDAL 3.1.0 with kakadu vs8.0.4 (Also tried with 2.3.1 and kakadu vs7.7).

Am I missing something?


Thanks in advance,
Boris.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20200628/f0969c6f/attachment-0001.html>


More information about the gdal-dev mailing list