diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-07-07 19:14:54 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-07-07 19:14:54 +0300 |
commit | f36741c2eb2a0dc8fe12d71691fee91adefcf9d5 (patch) | |
tree | a2a19e7204f973b50813843d5f3c042bb74bff26 /source/blender/blenlib/intern/math_interp.c | |
parent | 1bb145e023ac579ab5cd19c2daa49de917d7a7ac (diff) |
Fix T48793: Bilinear filter clamps at edge pixels
Diffstat (limited to 'source/blender/blenlib/intern/math_interp.c')
-rw-r--r-- | source/blender/blenlib/intern/math_interp.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/source/blender/blenlib/intern/math_interp.c b/source/blender/blenlib/intern/math_interp.c index 069d23e7147..8c361673715 100644 --- a/source/blender/blenlib/intern/math_interp.c +++ b/source/blender/blenlib/intern/math_interp.c @@ -284,16 +284,19 @@ BLI_INLINE void bilinear_interpolation(const unsigned char *byte_buffer, const f if (x1 < 0) x1 = width - 1; if (x2 >= width) x2 = 0; } + else if (x2 < 0 || x1 >= width) { + copy_vn_fl(float_output, components, 0.0f); + return; + } + if (wrap_y) { if (y1 < 0) y1 = height - 1; if (y2 >= height) y2 = 0; } - - CLAMP(x1, 0, width - 1); - CLAMP(x2, 0, width - 1); - - CLAMP(y1, 0, height - 1); - CLAMP(y2, 0, height - 1); + else if (y2 < 0 || y1 >= height) { + copy_vn_fl(float_output, components, 0.0f); + return; + } /* sample including outside of edges of image */ if (x1 < 0 || y1 < 0) row1 = empty; @@ -331,8 +334,21 @@ BLI_INLINE void bilinear_interpolation(const unsigned char *byte_buffer, const f const unsigned char *row1, *row2, *row3, *row4; unsigned char empty[4] = {0, 0, 0, 0}; - /* sample area entirely outside image? */ - if (x2 < 0 || x1 > width - 1 || y2 < 0 || y1 > height - 1) { + /* pixel value must be already wrapped, however values at boundaries may flip */ + if (wrap_x) { + if (x1 < 0) x1 = width - 1; + if (x2 >= width) x2 = 0; + } + else if (x2 < 0 || x1 >= width) { + copy_vn_uchar(byte_output, components, 0); + return; + } + + if (wrap_y) { + if (y1 < 0) y1 = height - 1; + if (y2 >= height) y2 = 0; + } + else if (y2 < 0 || y1 >= height) { copy_vn_uchar(byte_output, components, 0); return; } |