From 6ba4b3bfdb1799d2426225192d11040032dc8619 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 17 Dec 2018 20:29:31 +0000 Subject: [PATCH] fix clipping with new mapim cods we had the clip in the wrong place see https://github.com/libvips/libvips/issues/1180 --- libvips/resample/mapim.c | 14 ++++++++------ test/test-suite/test_resample.py | 6 ++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libvips/resample/mapim.c b/libvips/resample/mapim.c index b82960fa..b582b8ad 100644 --- a/libvips/resample/mapim.c +++ b/libvips/resample/mapim.c @@ -231,8 +231,8 @@ vips_mapim_region_minmax( VipsRegion *region, VipsRect *r, VipsRect *bounds ) TYPE * restrict p1 = (TYPE *) p; \ \ for( x = 0; x < r->width; x++ ) { \ - TYPE px = p1[0] + window_offset; \ - TYPE py = p1[1] + window_offset; \ + TYPE px = p1[0]; \ + TYPE py = p1[1]; \ \ if( px >= clip_width || \ py >= clip_height ) { \ @@ -240,7 +240,8 @@ vips_mapim_region_minmax( VipsRegion *region, VipsRect *r, VipsRect *bounds ) q[z] = 0; \ } \ else \ - interpolate( mapim->interpolate, q, ir[0], px, py ); \ + interpolate( mapim->interpolate, q, ir[0], \ + px + window_offset, py + window_offset ); \ \ p1 += 2; \ q += ps; \ @@ -251,8 +252,8 @@ vips_mapim_region_minmax( VipsRegion *region, VipsRect *r, VipsRect *bounds ) TYPE * restrict p1 = (TYPE *) p; \ \ for( x = 0; x < r->width; x++ ) { \ - TYPE px = p1[0] + window_offset; \ - TYPE py = p1[1] + window_offset; \ + TYPE px = p1[0]; \ + TYPE py = p1[1]; \ \ if( px < 0 || \ px >= clip_width || \ @@ -262,7 +263,8 @@ vips_mapim_region_minmax( VipsRegion *region, VipsRect *r, VipsRect *bounds ) q[z] = 0; \ } \ else \ - interpolate( mapim->interpolate, q, ir[0], px, py ); \ + interpolate( mapim->interpolate, q, ir[0], \ + px + window_offset, py + window_offset ); \ \ p1 += 2; \ q += ps; \ diff --git a/test/test-suite/test_resample.py b/test/test-suite/test_resample.py index 1375718b..791a30c7 100644 --- a/test/test-suite/test_resample.py +++ b/test/test-suite/test_resample.py @@ -200,11 +200,9 @@ class TestResample: # this was a bug at one point, strangely, if executed with debug # enabled - mp = pyvips.Image.xyz(100, 100) + mp = pyvips.Image.xyz(im.width, im.height) interp = pyvips.Interpolate.new('bicubic') - assert im.mapim(mp, interpolate=interp).avg() == \ - im.crop(0, 0, 100, 100).avg() - + assert im.mapim(mp, interpolate=interp).avg() == im.avg() if __name__ == '__main__':