Fix interpolation functions ignoring number of components when doing early output
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 23 Feb 2015 19:36:33 +0000 (00:36 +0500)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 23 Feb 2015 19:36:33 +0000 (00:36 +0500)
source/blender/blenlib/BLI_math_vector.h
source/blender/blenlib/intern/math_interp.c
source/blender/blenlib/intern/math_vector.c

index 0f437b7fc38aed2b048ba6dd1ba939a98f37b063..33319f3650765d33e0575f8513ffbf1c9cff27f8 100644 (file)
@@ -321,6 +321,7 @@ void interp_vn_vn(float *array_tar, const float *array_src, const float t, const
 void fill_vn_i(int *array_tar, const int size, const int val);
 void fill_vn_short(short *array_tar, const int size, const short val);
 void fill_vn_ushort(unsigned short *array_tar, const int size, const unsigned short val);
+void fill_vn_uchar(unsigned char *array_tar, const int size, const unsigned char val);
 void fill_vn_fl(float *array_tar, const int size, const float val);
 
 /**************************** Inline Definitions ******************************/
index a0c47be8d483797dcdddf031b17e160e6a9a0e6c..67850463fe212874b5350b488c2c8954b10dc779 100644 (file)
@@ -111,10 +111,12 @@ 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;
+               if (float_output) {
+                       fill_vn_fl(float_output, components, 0.0f);
+               }
+               if (byte_output) {
+                       fill_vn_uchar(byte_output, components, 0);
+               }
                return;
        }
 
@@ -279,7 +281,7 @@ BLI_INLINE void bilinear_interpolation(const unsigned char *byte_buffer, const f
 
                /* 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;
+                       fill_vn_fl(float_output, components, 0.0f);
                        return;
                }
 
@@ -321,7 +323,7 @@ BLI_INLINE void bilinear_interpolation(const unsigned char *byte_buffer, const f
 
                /* 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;
+                       fill_vn_uchar(byte_output, components, 0);
                        return;
                }
 
index d065fa7e5a7602ed7d362e89c51482f52558c1ca..1658c4ffc392a73b8eb42fd09ce6a40ffa34fbf9 100644 (file)
@@ -1040,6 +1040,15 @@ void fill_vn_ushort(unsigned short *array_tar, const int size, const unsigned sh
        }
 }
 
+void fill_vn_uchar(unsigned char *array_tar, const int size, const unsigned char val)
+{
+       unsigned char *tar = array_tar + (size - 1);
+       int i = size;
+       while (i--) {
+               *(tar--) = val;
+       }
+}
+
 void fill_vn_fl(float *array_tar, const int size, const float val)
 {
        float *tar = array_tar + (size - 1);