Skip to content

Commit

Permalink
Merge pull request #6437 from rouault/bilinear_fix_src_bounds_checks
Browse files Browse the repository at this point in the history
Bilinear resampling: fix bound checks to avoid extending source raster by 0.5 target pixel
  • Loading branch information
jmckenna committed Nov 19, 2021
2 parents 2441354 + 17d4e14 commit 6fee2b2
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 33 deletions.
12 changes: 7 additions & 5 deletions mapresample.c
Expand Up @@ -342,6 +342,13 @@ msBilinearRasterResampler( imageObj *psSrcImage, rasterBufferObj *src_rb,
continue;
}

/* If we are right off the source, skip this pixel */
nSrcX = (int) floor(x[nDstX]);
nSrcY = (int) floor(y[nDstX]);
if( nSrcX < 0 || (!bWrapAtLeftRight && nSrcX >= nSrcXSize)
|| nSrcY < 0 || nSrcY >= nSrcYSize )
continue;

/*
** Offset to treat TL pixel corners as pixel location instead
** of the center.
Expand All @@ -358,11 +365,6 @@ msBilinearRasterResampler( imageObj *psSrcImage, rasterBufferObj *src_rb,
dfRatioX2 = x[nDstX] - nSrcX;
dfRatioY2 = y[nDstX] - nSrcY;

/* If we are right off the source, skip this pixel */
if( nSrcX2 < 0 || (!bWrapAtLeftRight && nSrcX >= nSrcXSize)
|| nSrcY2 < 0 || nSrcY >= nSrcYSize )
continue;

/* Trim in stuff one pixel off the edge */
nSrcX = MS_MAX(nSrcX,0);
nSrcY = MS_MAX(nSrcY,0);
Expand Down
37 changes: 37 additions & 0 deletions msautotest/gdal/bilinear_left_right.map
@@ -0,0 +1,37 @@
# Test assembling two rasters and bilinear resampling
MAP

NAME TEST
PROJECTION
"init=epsg:4326"
END

EXTENT -3.515625 -35.15625 3.515625 35.15625
SIZE 32 320
IMAGETYPE png

LAYER
NAME "east-bilinear"
TYPE RASTER
STATUS default

PROJECTION
"init=epsg:4326"
END
PROCESSING "RESAMPLE=BILINEAR"
DATA "data/east.tif"
END

LAYER
NAME "west-bilinear"
TYPE RASTER
STATUS default

PROJECTION
"init=epsg:4326"
END
PROCESSING "RESAMPLE=BILINEAR"
DATA "data/west.tif"
END

END
2 changes: 1 addition & 1 deletion msautotest/gdal/bilinear_src_transp.map
Expand Up @@ -6,7 +6,7 @@ MAP
NAME TEST
STATUS ON
SIZE 400 40
EXTENT 0.5 0.5 39.5 1.5
EXTENT 0.5 1.5 39.5 2.5
IMAGECOLOR 0 0 0

OUTPUTFORMAT
Expand Down
Binary file added msautotest/gdal/data/east.tif
Binary file not shown.
Binary file added msautotest/gdal/data/west.tif
Binary file not shown.
Binary file added msautotest/gdal/expected/bilinear_left_right.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified msautotest/gdal/expected/bilinear_src_transp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified msautotest/gdal/expected/bilinear_src_transp2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 27 additions & 27 deletions msautotest/gdal/expected/rawmode_nodata_resample.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6fee2b2

Please sign in to comment.