@@ -395,16 +395,16 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
395
395
396
396
int dataSize = dataTypeSize ( theBandNo );
397
397
398
- if ( !mExtent .contains ( theExtent ) )
398
+ if ( !mExtent .contains ( theExtent ) )
399
399
{
400
400
// fill with null values
401
401
QByteArray ba = QgsRasterBlock::valueBytes ( dataType ( theBandNo ), noDataValue ( theBandNo ) );
402
402
char *nodata = ba.data ();
403
403
char *block = ( char * ) theBlock;
404
404
for ( int i = 0 ; i < thePixelWidth * thePixelHeight; i++ )
405
405
{
406
- memcpy ( block, nodata, dataSize );
407
- block += dataSize;
406
+ memcpy ( block, nodata, dataSize );
407
+ block += dataSize;
408
408
}
409
409
}
410
410
@@ -564,23 +564,28 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
564
564
double tmpXRes = srcWidth * srcXRes / tmpWidth;
565
565
double tmpYRes = srcHeight * srcYRes / tmpHeight; // negative
566
566
567
+ double y = myRasterExtent.yMaximum () - 0.5 * yRes;
567
568
for ( int row = 0 ; row < height; row++ )
568
569
{
569
- double y = myRasterExtent.yMaximum () - ( row + 0.5 ) * yRes;
570
570
int tmpRow = static_cast <int >( floor ( -1 . * ( tmpYMax - y ) / tmpYRes ) );
571
571
572
572
char *srcRowBlock = tmpBlock + dataSize * tmpRow * tmpWidth;
573
573
char *dstRowBlock = ( char * )theBlock + dataSize * ( top + row ) * thePixelWidth;
574
- for ( int col = 0 ; col < width; col++ )
574
+
575
+ double x = myRasterExtent.xMinimum () + 0.5 * xRes; // cell center
576
+ char * dst = dstRowBlock + dataSize * left;
577
+ char * src = 0 ;
578
+ int tmpCol = 0 ;
579
+ for ( int col = 0 ; col < width; ++col )
575
580
{
576
- // cell center
577
- double x = myRasterExtent.xMinimum () + ( col + 0.5 ) * xRes;
578
581
// floor() is quite slow! Use just cast to int.
579
- int tmpCol = static_cast <int >(( x - tmpXMin ) / tmpXRes ) ;
580
- char *src = srcRowBlock + dataSize * tmpCol;
581
- char *dst = dstRowBlock + dataSize * ( left + col );
582
+ tmpCol = static_cast <int >(( x - tmpXMin ) / tmpXRes ) ;
583
+ src = srcRowBlock + dataSize * tmpCol;
582
584
memcpy ( dst, src, dataSize );
585
+ dst += dataSize;
586
+ x += xRes;
583
587
}
588
+ y -= yRes;
584
589
}
585
590
586
591
QgsFree ( tmpBlock );
0 commit comments