Skip to content

Commit

Permalink
tmp block size calc fix
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15534 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Mar 19, 2011
1 parent c96acd1 commit f173a45
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -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 );
Expand All @@ -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;
Expand All @@ -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 );
Expand Down

0 comments on commit f173a45

Please sign in to comment.