@@ -31,22 +31,39 @@ void QgsBilinearRasterResampler::resample( const QImage& srcImage, QImage& dstIm
31
31
double nSrcPerDstX = ( double ) srcImage.width () / ( double ) dstImage.width ();
32
32
double nSrcPerDstY = ( double ) srcImage.height () / ( double ) dstImage.height ();
33
33
34
- double currentSrcRow = nSrcPerDstX / 2.0 ;
34
+ double currentSrcRow = nSrcPerDstX / 2.0 - 0.5 ;
35
35
double currentSrcCol;
36
36
37
37
QRgb px1, px2, px3, px4;
38
38
39
39
for ( int i = 0 ; i < dstImage.height (); ++i )
40
40
{
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 ;
42
53
for ( int j = 0 ; j < dstImage.width (); ++j )
43
54
{
55
+ if ( currentSrcCol > srcImage.width () - 2 )
56
+ {
57
+ // todo: resample in one direction only
58
+ currentSrcCol += nSrcPerDstX;
59
+ continue ;
60
+ }
44
61
px1 = srcImage.pixel ( currentSrcCol, currentSrcRow );
45
62
px2 = srcImage.pixel ( currentSrcCol + 1 , currentSrcRow );
46
63
px3 = srcImage.pixel ( currentSrcCol + 1 , currentSrcRow + 1 );
47
64
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;
50
67
dstImage.setPixel ( j, i, resampleColorValue ( u, v, px1, px2, px3, px4 ) );
51
68
currentSrcCol += nSrcPerDstX;
52
69
}
0 commit comments