[gdal-dev] Best way to read jpeg interleaved

Even Rouault even.rouault at spatialys.com
Thu Dec 17 10:47:24 PST 2020


Javier,

> I want to read quickly a jpeg file, and store it in memory interleaved
> (RGBRGBRGB).
> Is this the fastest way to read it?

Yes. There is even an optimized code path in the JPEG driver for that 
situation that short circuits completely the GDAL block cache.

> Regarding the parameter "nLineSpace", documentation says
> nLineSpace The byte offset from the start of one scanline in pData to the
> start of the next. If defaulted (0) the size of the datatype eBufType *
> nBufXSize is used.
> In the code above, if I set nLineSpace to 0, it works fine. However, if I
> write what documentation says ( 1 * width ), it does not work. Is this a
> bug in the documentation, or am I understanding it wrongly?

The relevant code is:

/* -------------------------------------------------------------------- */
/*      If pixel and line spacing are defaulted assign reasonable      */
/*      value assuming a packed buffer.                                 */
/* -------------------------------------------------------------------- */
    if( nPixelSpace == 0 )
        nPixelSpace = GDALGetDataTypeSizeBytes(eBufType);

    if( nLineSpace == 0 )
    {
        nLineSpace = nPixelSpace * nBufXSize;
    }

    if( nBandSpace == 0 && nBandCount > 1 )
    {
        nBandSpace = nLineSpace * nBufYSize;
    }

The doc is correct if all spacing parameters are set to 0, but indeed not if 
you put some to 0 and others not. PR to make it more accurate welcome.

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list