Skip to content

Commit e9b8cc0

Browse files
committedDec 19, 2011
No access to invalid image pixels
1 parent 52b559e commit e9b8cc0

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed
 

‎src/core/raster/qgsbilinearrasterresampler.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,39 @@ void QgsBilinearRasterResampler::resample( const QImage& srcImage, QImage& dstIm
3131
double nSrcPerDstX = ( double ) srcImage.width() / ( double ) dstImage.width();
3232
double nSrcPerDstY = ( double ) srcImage.height() / ( double ) dstImage.height();
3333

34-
double currentSrcRow = nSrcPerDstX / 2.0;
34+
double currentSrcRow = nSrcPerDstX / 2.0 - 0.5;
3535
double currentSrcCol;
3636

3737
QRgb px1, px2, px3, px4;
3838

3939
for ( int i = 0; i < dstImage.height(); ++i )
4040
{
41-
currentSrcCol = nSrcPerDstY / 2.0;
41+
//avoid access to invalid rows
42+
if ( currentSrcRow < 0 )
43+
{
44+
currentSrcRow += nSrcPerDstY;
45+
}
46+
else if ( currentSrcRow > srcImage.height() - 2 )
47+
{
48+
//todo: resample in one direction only
49+
break;
50+
}
51+
52+
currentSrcCol = nSrcPerDstY / 2.0 - 0.5;
4253
for ( int j = 0; j < dstImage.width(); ++j )
4354
{
55+
if ( currentSrcCol > srcImage.width() - 2 )
56+
{
57+
//todo: resample in one direction only
58+
currentSrcCol += nSrcPerDstX;
59+
continue;
60+
}
4461
px1 = srcImage.pixel( currentSrcCol, currentSrcRow );
4562
px2 = srcImage.pixel( currentSrcCol + 1, currentSrcRow );
4663
px3 = srcImage.pixel( currentSrcCol + 1, currentSrcRow + 1 );
4764
px4 = srcImage.pixel( currentSrcCol, currentSrcRow + 1 );
48-
double u = currentSrcCol - ( int ) currentSrcCol;
49-
double v = currentSrcRow - ( int ) currentSrcRow;
65+
double u = currentSrcCol - ( int )currentSrcCol;
66+
double v = currentSrcRow - ( int )currentSrcRow;
5067
dstImage.setPixel( j, i, resampleColorValue( u, v, px1, px2, px3, px4 ) );
5168
currentSrcCol += nSrcPerDstX;
5269
}

0 commit comments

Comments
 (0)
Please sign in to comment.