[Bf-blender-cvs] [ff1174e52c9] master: Cleanup: improve readability for color assignment

Campbell Barton noreply at git.blender.org
Fri May 1 09:57:56 CEST 2020


Commit: ff1174e52c92ba5580a309ff9f6636fe179c4051
Author: Campbell Barton
Date:   Fri May 1 14:58:58 2020 +1000
Branches: master
https://developer.blender.org/rBff1174e52c92ba5580a309ff9f6636fe179c4051

Cleanup: improve readability for color assignment

===================================================================

M	source/blender/blenkernel/intern/brush.c
M	source/blender/blenlib/BLI_math_vector.h
M	source/blender/blenlib/intern/math_vector_inline.c

===================================================================

diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index c734205e84c..052f16b36a3 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -2055,7 +2055,7 @@ unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side, bool use_sec
   unsigned int *texcache = NULL;
   MTex *mtex = (use_secondary) ? &br->mask_mtex : &br->mtex;
   float intensity;
-  float rgba[4];
+  float rgba_dummy[4];
   int ix, iy;
   int side = half_side * 2;
 
@@ -2073,11 +2073,8 @@ unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side, bool use_sec
 
         /* This is copied from displace modifier code */
         /* TODO(sergey): brush are always caching with CM enabled for now. */
-        RE_texture_evaluate(mtex, co, 0, NULL, false, false, &intensity, rgba);
-
-        ((char *)texcache)[(iy * side + ix) * 4] = ((char *)texcache)[(iy * side + ix) * 4 + 1] =
-            ((char *)texcache)[(iy * side + ix) * 4 + 2] = ((
-                char *)texcache)[(iy * side + ix) * 4 + 3] = (char)(intensity * 255.0f);
+        RE_texture_evaluate(mtex, co, 0, NULL, false, false, &intensity, rgba_dummy);
+        copy_v4_uchar((uchar *)&texcache[iy * side + ix], (char)(intensity * 255.0f));
       }
     }
   }
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 6cfa2d2ced6..d6e156a56cb 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -62,6 +62,11 @@ MINLINE void swap_v4_v4(float a[4], float b[4]);
 MINLINE void copy_v2_v2_uchar(unsigned char r[2], const unsigned char a[2]);
 MINLINE void copy_v3_v3_uchar(unsigned char r[3], const unsigned char a[3]);
 MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4]);
+
+MINLINE void copy_v2_uchar(unsigned char r[2], unsigned char a);
+MINLINE void copy_v3_uchar(unsigned char r[3], unsigned char a);
+MINLINE void copy_v4_uchar(unsigned char r[4], unsigned char a);
+
 /* char */
 MINLINE void copy_v2_v2_char(char r[2], const char a[2]);
 MINLINE void copy_v3_v3_char(char r[3], const char a[3]);
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index d2c55233653..ca405907bdd 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -123,6 +123,27 @@ MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
   r[3] = a[3];
 }
 
+MINLINE void copy_v2_uchar(unsigned char r[2], const unsigned char a)
+{
+  r[0] = a;
+  r[1] = a;
+}
+
+MINLINE void copy_v3_uchar(unsigned char r[3], const unsigned char a)
+{
+  r[0] = a;
+  r[1] = a;
+  r[2] = a;
+}
+
+MINLINE void copy_v4_uchar(unsigned char r[4], const unsigned char a)
+{
+  r[0] = a;
+  r[1] = a;
+  r[2] = a;
+  r[3] = a;
+}
+
 /* char */
 MINLINE void copy_v2_v2_char(char r[2], const char a[2])
 {



More information about the Bf-blender-cvs mailing list