Skip to content

Commit

Permalink
No access to invalid image pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Dec 19, 2011
1 parent 52b559e commit e9b8cc0
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/core/raster/qgsbilinearrasterresampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,39 @@ void QgsBilinearRasterResampler::resample( const QImage& srcImage, QImage& dstIm
double nSrcPerDstX = ( double ) srcImage.width() / ( double ) dstImage.width();
double nSrcPerDstY = ( double ) srcImage.height() / ( double ) dstImage.height();

double currentSrcRow = nSrcPerDstX / 2.0;
double currentSrcRow = nSrcPerDstX / 2.0 - 0.5;
double currentSrcCol;

QRgb px1, px2, px3, px4;

for ( int i = 0; i < dstImage.height(); ++i )
{
currentSrcCol = nSrcPerDstY / 2.0;
//avoid access to invalid rows
if ( currentSrcRow < 0 )
{
currentSrcRow += nSrcPerDstY;
}
else if ( currentSrcRow > srcImage.height() - 2 )
{
//todo: resample in one direction only
break;
}

currentSrcCol = nSrcPerDstY / 2.0 - 0.5;
for ( int j = 0; j < dstImage.width(); ++j )
{
if ( currentSrcCol > srcImage.width() - 2 )
{
//todo: resample in one direction only
currentSrcCol += nSrcPerDstX;
continue;
}
px1 = srcImage.pixel( currentSrcCol, currentSrcRow );
px2 = srcImage.pixel( currentSrcCol + 1, currentSrcRow );
px3 = srcImage.pixel( currentSrcCol + 1, currentSrcRow + 1 );
px4 = srcImage.pixel( currentSrcCol, currentSrcRow + 1 );
double u = currentSrcCol - ( int ) currentSrcCol;
double v = currentSrcRow - ( int ) currentSrcRow;
double u = currentSrcCol - ( int )currentSrcCol;
double v = currentSrcRow - ( int )currentSrcRow;
dstImage.setPixel( j, i, resampleColorValue( u, v, px1, px2, px3, px4 ) );
currentSrcCol += nSrcPerDstX;
}
Expand Down

0 comments on commit e9b8cc0

Please sign in to comment.