[Bf-blender-cvs] [f36741c] master: Fix T48793: Bilinear filter clamps at edge pixels
Campbell Barton
noreply at git.blender.org
Thu Jul 7 18:18:29 CEST 2016
Commit: f36741c2eb2a0dc8fe12d71691fee91adefcf9d5
Author: Campbell Barton
Date: Fri Jul 8 02:14:54 2016 +1000
Branches: master
https://developer.blender.org/rBf36741c2eb2a0dc8fe12d71691fee91adefcf9d5
Fix T48793: Bilinear filter clamps at edge pixels
===================================================================
M source/blender/blenlib/intern/math_interp.c
===================================================================
diff --git a/source/blender/blenlib/intern/math_interp.c b/source/blender/blenlib/intern/math_interp.c
index 069d23e..8c36167 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;
}
More information about the Bf-blender-cvs
mailing list