Skip to content

Commit

Permalink
JPEG: slightly improve performance of whole RGB image loading with pi…
Browse files Browse the repository at this point in the history
…xel-interleaved buffer
  • Loading branch information
rouault committed Jun 26, 2018
1 parent 3a44b4a commit 8bf714f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
24 changes: 15 additions & 9 deletions gdal/frmts/jpeg/jpgdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ bool JPGDataset::ErrorOutOnNonFatalError()
/* LoadScanline() */
/************************************************************************/

CPLErr JPGDataset::LoadScanline( int iLine )
CPLErr JPGDataset::LoadScanline( int iLine, GByte* outBuffer )

{
if( nLoadedScanline == iLine )
Expand Down Expand Up @@ -1416,7 +1416,7 @@ CPLErr JPGDataset::LoadScanline( int iLine )
bHasDoneJpegStartDecompress = true;
}

if( pabyScanline == nullptr )
if( outBuffer == nullptr && pabyScanline == nullptr )
{
int nJPEGBands = 0;
switch(sDInfo.out_color_space)
Expand Down Expand Up @@ -1449,7 +1449,8 @@ CPLErr JPGDataset::LoadScanline( int iLine )

while( nLoadedScanline < iLine )
{
JSAMPLE *ppSamples = reinterpret_cast<JSAMPLE *>(pabyScanline);
JSAMPLE *ppSamples = reinterpret_cast<JSAMPLE *>(
outBuffer ? outBuffer : pabyScanline);
jpeg_read_scanlines(&sDInfo, &ppSamples, 1);
if( ErrorOutOnNonFatalError() )
return CE_Failure;
Expand Down Expand Up @@ -1826,6 +1827,7 @@ CPLErr JPGDatasetCommon::IRasterIO( GDALRWFlag eRWFlag,
return CE_Failure;
}

#ifndef JPEG_LIB_MK1
if((eRWFlag == GF_Read) &&
(nBandCount == 3) &&
(nBands == 3) &&
Expand All @@ -1846,17 +1848,19 @@ CPLErr JPGDatasetCommon::IRasterIO( GDALRWFlag eRWFlag,
{
for(int y = 0; y < nYSize; ++y)
{
CPLErr tmpError = LoadScanline(y);
if(tmpError != CE_None)
return tmpError;

if( nPixelSpace == 3 )
{
memcpy(&(((GByte *)pData)[(y * nLineSpace)]), pabyScanline,
3 * nXSize);
CPLErr tmpError = LoadScanline(y,
&(((GByte *)pData)[(y * nLineSpace)]));
if(tmpError != CE_None)
return tmpError;
}
else
{
CPLErr tmpError = LoadScanline(y);
if(tmpError != CE_None)
return tmpError;

for(int x = 0; x < nXSize; ++x)
{
memcpy(&(((GByte *)pData)[(y * nLineSpace) +
Expand All @@ -1865,6 +1869,7 @@ CPLErr JPGDatasetCommon::IRasterIO( GDALRWFlag eRWFlag,
}
}
}
nLoadedScanline = -1;
}
else
{
Expand All @@ -1888,6 +1893,7 @@ CPLErr JPGDatasetCommon::IRasterIO( GDALRWFlag eRWFlag,

return CE_None;
}
#endif

return GDALPamDataset::IRasterIO(eRWFlag, nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize, eBufType,
Expand Down
4 changes: 2 additions & 2 deletions gdal/frmts/jpeg/jpgdataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class JPGDatasetCommon : public GDALPamDataset
bool bHasDoneJpegCreateDecompress;
bool bHasDoneJpegStartDecompress;

virtual CPLErr LoadScanline(int) = 0;
virtual CPLErr LoadScanline(int, GByte* outBuffer = nullptr) = 0;
virtual CPLErr Restart() = 0;

virtual int GetDataPrecision() = 0;
Expand Down Expand Up @@ -282,7 +282,7 @@ class JPGDataset final: public JPGDatasetCommon
struct jpeg_error_mgr sJErr;
struct jpeg_progress_mgr sJProgress;

virtual CPLErr LoadScanline(int) override;
virtual CPLErr LoadScanline(int, GByte* outBuffer) override;
virtual CPLErr Restart() override;
virtual int GetDataPrecision() override { return sDInfo.data_precision; }
virtual int GetOutColorSpace() override { return sDInfo.out_color_space; }
Expand Down

0 comments on commit 8bf714f

Please sign in to comment.