Skip to content
Permalink
Browse files

tmp block size calc fix

git-svn-id: http://svn.osgeo.org/qgis/trunk@15534 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek
rblazek committed Mar 19, 2011
1 parent 44cc8a7 commit a9ab1719823e61158c81dfd4eba421773f6cd0d7
Showing with 11 additions and 8 deletions.
  1. +11 −8 src/providers/gdal/qgsgdalprovider.cpp
@@ -698,8 +698,17 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
int tmpWidth = srcWidth;
int tmpHeight = srcHeight;

if ( xRes > srcXRes ) tmpWidth = width;
if ( yRes > srcYRes ) tmpHeight = height;
if ( xRes > srcXRes )
{
tmpWidth = static_cast<int>( qRound( srcWidth * srcXRes / xRes ) ) ;
}
if ( yRes > srcYRes )
{
tmpHeight = static_cast<int>( qRound( -1.*srcHeight * srcYRes / yRes ) ) ;
}
double tmpXMin = mExtent.xMinimum() + srcLeft * srcXRes;
double tmpYMax = mExtent.yMaximum() + srcTop * srcYRes;
QgsDebugMsg( QString( "tmpXMin = %1 tmpYMax = %2 tmpWidth = %3 tmpHeight = %4" ).arg( tmpXMin ).arg( tmpYMax ).arg( tmpWidth ).arg( tmpHeight ) );

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

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

QgsDebugMsg( QString( "tmpXMin = %1 tmpYMax = %2 tmpWidth = %3 tmpHeight = %4" ).arg( tmpXMin ).arg( tmpYMax ).arg( tmpWidth ).arg( tmpHeight ) );

for ( int row = 0; row < height; row++ )
{
double y = myRasterExtent.yMaximum() - ( row + 0.5 ) * yRes;
@@ -744,8 +749,6 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
double x = myRasterExtent.xMinimum() + ( col + 0.5 ) * xRes;
// floor() is quite slow! Use just cast to int.
int tmpCol = static_cast<int>(( x - tmpXMin ) / tmpXRes ) ;
//QgsDebugMsg( QString( "row = %1 col = %2 tmpRow = %3 tmpCol = %4" ).arg(row).arg(col).arg(tmpRow).arg(tmpCol) );

char *src = srcRowBlock + dataSize * tmpCol;
char *dst = dstRowBlock + dataSize * ( left + col );
memcpy( dst, src, dataSize );

0 comments on commit a9ab171

Please sign in to comment.
You can’t perform that action at this time.