Skip to content

Commit f173a45

Browse files
author
rblazek
committed
tmp block size calc fix
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15534 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c96acd1 commit f173a45

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/providers/gdal/qgsgdalprovider.cpp

+11-8
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,17 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
698698
int tmpWidth = srcWidth;
699699
int tmpHeight = srcHeight;
700700

701-
if ( xRes > srcXRes ) tmpWidth = width;
702-
if ( yRes > srcYRes ) tmpHeight = height;
701+
if ( xRes > srcXRes )
702+
{
703+
tmpWidth = static_cast<int>( qRound( srcWidth * srcXRes / xRes ) ) ;
704+
}
705+
if ( yRes > srcYRes )
706+
{
707+
tmpHeight = static_cast<int>( qRound( -1.*srcHeight * srcYRes / yRes ) ) ;
708+
}
709+
double tmpXMin = mExtent.xMinimum() + srcLeft * srcXRes;
710+
double tmpYMax = mExtent.yMaximum() + srcTop * srcYRes;
711+
QgsDebugMsg( QString( "tmpXMin = %1 tmpYMax = %2 tmpWidth = %3 tmpHeight = %4" ).arg( tmpXMin ).arg( tmpYMax ).arg( tmpWidth ).arg( tmpHeight ) );
703712

704713
// Allocate temporary block
705714
char *tmpBlock = ( char * )malloc( dataSize * tmpWidth * tmpHeight );
@@ -724,13 +733,9 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
724733
QgsDebugMsg( QString( "GDALRasterIO time (ms): %1" ).arg( time.elapsed() ) );
725734
time.start();
726735

727-
double tmpXMin = mExtent.xMinimum() + srcLeft * srcXRes;
728-
double tmpYMax = mExtent.yMaximum() + srcTop * srcYRes;
729736
double tmpXRes = srcWidth * srcXRes / tmpWidth;
730737
double tmpYRes = srcHeight * srcYRes / tmpHeight; // negative
731738

732-
QgsDebugMsg( QString( "tmpXMin = %1 tmpYMax = %2 tmpWidth = %3 tmpHeight = %4" ).arg( tmpXMin ).arg( tmpYMax ).arg( tmpWidth ).arg( tmpHeight ) );
733-
734739
for ( int row = 0; row < height; row++ )
735740
{
736741
double y = myRasterExtent.yMaximum() - ( row + 0.5 ) * yRes;
@@ -744,8 +749,6 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
744749
double x = myRasterExtent.xMinimum() + ( col + 0.5 ) * xRes;
745750
// floor() is quite slow! Use just cast to int.
746751
int tmpCol = static_cast<int>(( x - tmpXMin ) / tmpXRes ) ;
747-
//QgsDebugMsg( QString( "row = %1 col = %2 tmpRow = %3 tmpCol = %4" ).arg(row).arg(col).arg(tmpRow).arg(tmpCol) );
748-
749752
char *src = srcRowBlock + dataSize * tmpCol;
750753
char *dst = dstRowBlock + dataSize * ( left + col );
751754
memcpy( dst, src, dataSize );

0 commit comments

Comments
 (0)