diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2013-12-04 14:56:36 +0400 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2013-12-04 15:09:13 +0400 |
commit | 45fc80153a40fb01db6b1e25b4ab575a06a331b8 (patch) | |
tree | 898972a78c5074ef1fc3f4f90c9f9791225c538f /source/blender/blenlib/intern/math_interp.c | |
parent | a698709d956f01ff4a2a1c0d27450c6880dd2ad5 (diff) |
Fix for interpolation errors on lower-left borders in compositor image
inputs.
http://wiki.blender.org/uploads/4/4c/Compo_image_interpolation_borders.png
Problem is that all image buffer reader nodes (RenderLayer, Image,
MovieClip) were clipping pixel coordinates to 0..N range (N being width
or height respectively). Bilinear interpolation works ok then on the
upper-right borders (x, N) and (N, y), since the last (N-1) pixel fades
out to N (background). But the lower-left (x, 0) and (0, y) borders are
not correctly interpolated because the nodes cut off the negative pixels
before the interpolation function can calculate their value.
To fix this, the interpolation functions are now entirely responsible
for handling "out of range" cases, i.e. setting (0,0,0,0) results for
invalid pixels, while also handling interpolation for borders.
Callers should not do pixel range checks themselves, which also makes
the code simpler. Should not have any real performance penalty,
the interpolation functions do this check anyway, so is probably even
slightly faster.
Diffstat (limited to 'source/blender/blenlib/intern/math_interp.c')
-rw-r--r-- | source/blender/blenlib/intern/math_interp.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/source/blender/blenlib/intern/math_interp.c b/source/blender/blenlib/intern/math_interp.c index d1acd45e40e..35a763c5173 100644 --- a/source/blender/blenlib/intern/math_interp.c +++ b/source/blender/blenlib/intern/math_interp.c @@ -105,6 +105,10 @@ BLI_INLINE void bicubic_interpolation(const unsigned char *byte_buffer, const fl /* sample area entirely outside image? */ if (ceil(u) < 0 || floor(u) > width - 1 || ceil(v) < 0 || floor(v) > height - 1) { + if (float_output) + float_output[0] = float_output[1] = float_output[2] = float_output[3] = 0.0f; + if (byte_output) + byte_output[0] = byte_output[1] = byte_output[2] = byte_output[3] = 0; return; } @@ -263,15 +267,16 @@ BLI_INLINE void bilinear_interpolation(const unsigned char *byte_buffer, const f y1 = (int)floor(v); y2 = (int)ceil(v); - /* sample area entirely outside image? */ - if (x2 < 0 || x1 > width - 1 || y2 < 0 || y1 > height - 1) { - return; - } - if (float_output) { const float *row1, *row2, *row3, *row4; float empty[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + /* sample area entirely outside image? */ + if (x2 < 0 || x1 > width - 1 || y2 < 0 || y1 > height - 1) { + float_output[0] = float_output[1] = float_output[2] = float_output[3] = 0.0f; + return; + } + /* sample including outside of edges of image */ if (x1 < 0 || y1 < 0) row1 = empty; else row1 = float_buffer + width * y1 * components + components * x1; @@ -308,6 +313,12 @@ 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) { + byte_output[0] = byte_output[1] = byte_output[2] = byte_output[3] = 0; + return; + } + /* sample including outside of edges of image */ if (x1 < 0 || y1 < 0) row1 = empty; else row1 = byte_buffer + width * y1 * components + components * x1; |