From 462b81efca8cfe27dd6045fbb8a9fa612d70f9ce Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Wed, 4 Dec 2024 08:39:58 +0100 Subject: [PATCH] Fix: Border bicubic interpolation is wrong around edges The BLI bicubic interpolation function with border boundary is wrong around edges. It returns zero, where interpolated values should exist. This is due to a wrong early exit condition, where only a 2x2 window is assumed instead of the 4x4 window considered by bicubic interpolation. To fix this, assume a 2 pixel region in the early exit condition for both directions. Pull Request: https://projects.blender.org/blender/blender/pulls/131320 --- source/blender/blenlib/intern/math_interp.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/blenlib/intern/math_interp.cc b/source/blender/blenlib/intern/math_interp.cc index 447906d9210..1a59b6f0d31 100644 --- a/source/blender/blenlib/intern/math_interp.cc +++ b/source/blender/blenlib/intern/math_interp.cc @@ -174,11 +174,11 @@ BLI_INLINE void bicubic_interpolation(const T *src_buffer, int iv = int(floor(v)); /* Sample area entirely outside image in border mode? */ - if (wrap_u == InterpWrapMode::Border && (iu + 1 < 0 || iu > width - 1)) { + if (wrap_u == InterpWrapMode::Border && (iu + 2 < 0 || iu > width)) { memset(output, 0, size_t(components) * sizeof(T)); return; } - if (wrap_v == InterpWrapMode::Border && (iv + 1 < 0 || iv > height - 1)) { + if (wrap_v == InterpWrapMode::Border && (iv + 2 < 0 || iv > height)) { memset(output, 0, size_t(components) * sizeof(T)); return; }