Skip to content

Commit f424e2a

Browse files
committed
Small performance improvement in gdal provider
1 parent a18ae68 commit f424e2a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/providers/gdal/qgsgdalprovider.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,6 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
502502
int srcBottom = ySize() - 1;
503503
int srcRight = xSize() - 1;
504504

505-
QTime time;
506-
time.start();
507505
// Note: original approach for xRes < srcXRes || yRes < qAbs( srcYRes ) was to avoid
508506
// second resampling and read with GDALRasterIO to another temporary data block
509507
// extended to fit src grid. The problem was that with src resolution much bigger
@@ -595,9 +593,6 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
595593
return;
596594
}
597595

598-
QgsDebugMsg( QString( "GDALRasterIO time (ms): %1" ).arg( time.elapsed() ) );
599-
time.start();
600-
601596
double tmpXRes = srcWidth * srcXRes / tmpWidth;
602597
double tmpYRes = srcHeight * srcYRes / tmpHeight; // negative
603598

@@ -609,25 +604,30 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
609604
char *srcRowBlock = tmpBlock + dataSize * tmpRow * tmpWidth;
610605
char *dstRowBlock = ( char * )theBlock + dataSize * ( top + row ) * thePixelWidth;
611606

612-
double x = myRasterExtent.xMinimum() + 0.5 * xRes; // cell center
607+
double x = ( myRasterExtent.xMinimum() + 0.5 * xRes - tmpXMin ) / tmpXRes; // cell center
608+
double increment = xRes / tmpXRes;
609+
613610
char* dst = dstRowBlock + dataSize * left;
614-
char* src = 0;
611+
char* src = srcRowBlock;
615612
int tmpCol = 0;
613+
int lastCol = 0;
616614
for ( int col = 0; col < width; ++col )
617615
{
618616
// floor() is quite slow! Use just cast to int.
619-
tmpCol = static_cast<int>(( x - tmpXMin ) / tmpXRes ) ;
620-
src = srcRowBlock + dataSize * tmpCol;
617+
tmpCol = static_cast<int>( x ) ;
618+
if ( tmpCol > lastCol )
619+
{
620+
src += ( tmpCol - lastCol ) * dataSize;
621+
lastCol = tmpCol;
622+
}
621623
memcpy( dst, src, dataSize );
622624
dst += dataSize;
623-
x += xRes;
625+
x += increment;
624626
}
625627
y -= yRes;
626628
}
627629

628630
qgsFree( tmpBlock );
629-
QgsDebugMsg( QString( "resample time (ms): %1" ).arg( time.elapsed() ) );
630-
631631
return;
632632
}
633633

0 commit comments

Comments
 (0)