[Bf-blender-cvs] [07ceb99] master: Code Cleanup: use strict flags for math lib, add inline declarations

Campbell Barton noreply at git.blender.org
Thu Dec 5 17:59:01 CET 2013


Commit: 07ceb99213166b678f0a0bac9c35e9897f22e827
Author: Campbell Barton
Date:   Fri Dec 6 03:46:27 2013 +1100
http://developer.blender.org/rB07ceb99213166b678f0a0bac9c35e9897f22e827

Code Cleanup: use strict flags for math lib, add inline declarations

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

M	source/blender/blenlib/BLI_math_base.h
M	source/blender/blenlib/BLI_math_color.h
M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/BLI_math_vector.h
M	source/blender/blenlib/intern/math_base.c
M	source/blender/blenlib/intern/math_base_inline.c
M	source/blender/blenlib/intern/math_color.c
M	source/blender/blenlib/intern/math_color_blend_inline.c
M	source/blender/blenlib/intern/math_color_inline.c
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/blenlib/intern/math_geom_inline.c
M	source/blender/blenlib/intern/math_interp.c
M	source/blender/blenlib/intern/math_matrix.c
M	source/blender/blenlib/intern/math_rotation.c
M	source/blender/blenlib/intern/math_vector.c
M	source/blender/blenlib/intern/math_vector_inline.c

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

diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h
index 14c1055..6d37f79 100644
--- a/source/blender/blenlib/BLI_math_base.h
+++ b/source/blender/blenlib/BLI_math_base.h
@@ -139,6 +139,9 @@ static const int NAN_INT = 0x7FC00000;
 #ifndef hypotf
 #define hypotf(a, b) ((float)hypot(a, b))
 #endif
+#ifndef copysignf
+#define copysignf(a, b) ((float)copysign(a, b))
+#endif
 
 #endif  /* C99 or POSIX.1-2001 */
 
@@ -214,9 +217,17 @@ MINLINE float interpf(float a, float b, float t);
 
 MINLINE float min_ff(float a, float b);
 MINLINE float max_ff(float a, float b);
+MINLINE float min_fff(float a, float b, float c);
+MINLINE float max_fff(float a, float b, float c);
+MINLINE float min_ffff(float a, float b, float c, float d);
+MINLINE float max_ffff(float a, float b, float c, float d);
 
 MINLINE int min_ii(int a, int b);
 MINLINE int max_ii(int a, int b);
+MINLINE int min_iii(int a, int b, int c);
+MINLINE int max_iii(int a, int b, int c);
+MINLINE int min_iiii(int a, int b, int c, int d);
+MINLINE int max_iiii(int a, int b, int c, int d);
 
 MINLINE float signf(float f);
 
@@ -230,6 +241,9 @@ MINLINE int power_of_2_min_i(int n);
 MINLINE int divide_round_i(int a, int b);
 MINLINE int mod_i(int i, int n);
 
+MINLINE unsigned int highest_order_bit_i(unsigned int n);
+MINLINE unsigned short highest_order_bit_s(unsigned short n);
+
 MINLINE float shell_angle_to_dist(const float angle);
 
 #if (defined(WIN32) || defined(WIN64)) && !defined(FREE_WINDOWS)
diff --git a/source/blender/blenlib/BLI_math_color.h b/source/blender/blenlib/BLI_math_color.h
index 6f43276..7167aad 100644
--- a/source/blender/blenlib/BLI_math_color.h
+++ b/source/blender/blenlib/BLI_math_color.h
@@ -76,7 +76,12 @@ void rgb_to_xyz(float r, float g, float b, float *x, float *y, float *z);
 unsigned int rgb_to_cpack(float r, float g, float b);
 unsigned int hsv_to_cpack(float h, float s, float v);
 
-/* rgb_to_grayscale & rgb_to_luma functions moved to math_color_inline.c */
+MINLINE float rgb_to_bw(const float rgb[3]);
+MINLINE float rgb_to_grayscale(const float rgb[3]);
+MINLINE unsigned char rgb_to_grayscale_byte(const unsigned char rgb[3]);
+MINLINE float rgb_to_luma(const float rgb[3]);
+MINLINE unsigned char rgb_to_luma_byte(const unsigned char rgb[3]);
+MINLINE float rgb_to_luma_y(const float rgb[3]);
 
 /**************** Profile Transformations *****************/
 
@@ -95,6 +100,11 @@ MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4]);
 MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[4]);
 MINLINE void linearrgb_to_srgb_predivide_v4(float srgb[4], const float linear[4]);
 
+MINLINE unsigned short to_srgb_table_lookup(const float f);
+MINLINE void linearrgb_to_srgb_ushort4(unsigned short srgb[4], const float linear[4]);
+MINLINE void srgb_to_linearrgb_uchar4(float linear[4], const unsigned char srgb[4]);
+MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned char srgb[4]);
+
 MINLINE void linearrgb_to_srgb_uchar3(unsigned char srgb[3], const float linear[3]);
 MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4]);
 
@@ -126,6 +136,13 @@ void xyz_to_lab(float x, float y, float z, float *l, float *a, float *b);
 
 MINLINE int compare_rgb_uchar(const unsigned char a[3], const unsigned char b[3], const int limit);
 
+#define rgba_char_args_set_fl(col, r, g, b, a) \
+	rgba_char_args_set(col, (r) * 255, (g) * 255, (b) * 255, (a) * 255)
+
+MINLINE void rgba_char_args_set(char col[4], const char r, const char g, const char b, const char a);
+MINLINE void rgba_char_args_test_set(char col[4], const char r, const char g, const char b, const char a);
+MINLINE void cpack_cpy_3ub(unsigned char r_col[3], const unsigned int pack);
+
 /********* lift/gamma/gain / ASC-CDL conversion ***********/
 
 void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *offset, float *slope, float *power);
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index ad7dab0..4f41ac8 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -284,6 +284,7 @@ MINLINE void zero_sh(float r[9]);
 MINLINE void copy_sh_sh(float r[9], const float a[9]);
 MINLINE void mul_sh_fl(float r[9], const float f);
 MINLINE void add_sh_shsh(float r[9], const float a[9], const float b[9]);
+MINLINE float dot_shsh(const float a[9], const float b[9]);
 
 MINLINE float eval_shv3(float r[9], const float v[3]);
 MINLINE float diffuse_shv3(float r[9], const float v[3]);
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 21bafef..3c0f215 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -125,6 +125,7 @@ MINLINE float dot_m4_v3_row_x(float M[4][4], const float a[3]) ATTR_WARN_UNUSED_
 MINLINE float dot_m4_v3_row_y(float M[4][4], const float a[3]) ATTR_WARN_UNUSED_RESULT;
 MINLINE float dot_m4_v3_row_z(float M[4][4], const float a[3]) ATTR_WARN_UNUSED_RESULT;
 
+MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f);
 MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f);
 MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3]);
 MINLINE void madd_v2_v2v2fl(float r[2], const float a[2], const float b[2], float f);
@@ -174,6 +175,7 @@ MINLINE float normalize_v2(float r[2]);
 MINLINE float normalize_v2_v2(float r[2], const float a[2]);
 MINLINE float normalize_v3(float r[3]);
 MINLINE float normalize_v3_v3(float r[3], const float a[3]);
+MINLINE double normalize_v3_d(double n[3]);
 
 /******************************* Interpolation *******************************/
 
diff --git a/source/blender/blenlib/intern/math_base.c b/source/blender/blenlib/intern/math_base.c
index 38d303e..3ff1af3 100644
--- a/source/blender/blenlib/intern/math_base.c
+++ b/source/blender/blenlib/intern/math_base.c
@@ -27,10 +27,10 @@
  *  \ingroup bli
  */
 
-
-
 #include "BLI_math.h"
 
+#include "BLI_strict_flags.h"
+
 /* WARNING: MSVC compiling hack for double_round() */
 #if (defined(WIN32) || defined(WIN64)) && !(defined(FREE_WINDOWS))
 
diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c
index c68ca3e..a215d99 100644
--- a/source/blender/blenlib/intern/math_base_inline.c
+++ b/source/blender/blenlib/intern/math_base_inline.c
@@ -182,7 +182,7 @@ MINLINE unsigned short highest_order_bit_s(unsigned short n)
 	n |= (n >>  2);
 	n |= (n >>  4);
 	n |= (n >>  8);
-	return n - (n >> 1);
+	return (unsigned short)(n - (n >> 1));
 }
 
 MINLINE float min_ff(float a, float b)
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index 8cfe470..f57ae96 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -27,7 +27,6 @@
  *  \ingroup bli
  */
 
-
 #include <assert.h>
 
 #include "MEM_guardedalloc.h"
@@ -36,26 +35,26 @@
 #include "BLI_rand.h"
 #include "BLI_utildefines.h"
 
+#include "BLI_strict_flags.h"
+
 void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b)
 {
-	int i;
-	float f, p, q, t;
-
-	if (s == 0.0f) {
+	if (UNLIKELY(s == 0.0f)) {
 		*r = v;
 		*g = v;
 		*b = v;
 	}
 	else {
+		float i, f, p, q, t;
 		h = (h - floorf(h)) * 6.0f;
 
-		i = (int)floorf(h);
+		i = floorf(h);
 		f = h - i;
 		p = v * (1.0f - s);
 		q = v * (1.0f - (s * f));
 		t = v * (1.0f - (s * (1.0f - f)));
 
-		switch (i) {
+		switch ((int)i) {
 			case 0:
 				*r = v;
 				*g = t;
@@ -213,9 +212,9 @@ void hex_to_rgb(char *hexcol, float *r, float *g, float *b)
 		return;
 	}
 
-	*r = ri * (1.0f / 255.0f);
-	*g = gi * (1.0f / 255.0f);
-	*b = bi * (1.0f / 255.0f);
+	*r = (float)ri * (1.0f / 255.0f);
+	*g = (float)gi * (1.0f / 255.0f);
+	*b = (float)bi * (1.0f / 255.0f);
 	CLAMP(*r, 0.0f, 1.0f);
 	CLAMP(*g, 0.0f, 1.0f);
 	CLAMP(*b, 0.0f, 1.0f);
@@ -365,15 +364,15 @@ void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int
 
 unsigned int hsv_to_cpack(float h, float s, float v)
 {
-	short r, g, b;
+	unsigned int r, g, b;
 	float rf, gf, bf;
 	unsigned int col;
 
 	hsv_to_rgb(h, s, v, &rf, &gf, &bf);
 
-	r = (short) (rf * 255.0f);
-	g = (short) (gf * 255.0f);
-	b = (short) (bf * 255.0f);
+	r = (unsigned int) (rf * 255.0f);
+	g = (unsigned int) (gf * 255.0f);
+	b = (unsigned int) (bf * 255.0f);
 
 	col = (r + (g * 256) + (b * 256 * 256));
 	return col;
@@ -381,17 +380,15 @@ unsigned int hsv_to_cpack(float h, float s, float v)
 
 unsigned int rgb_to_cpack(float r, float g, float b)
 {
-	int ir, ig, ib;
+	unsigned int ir, ig, ib;
+
+	ir = (unsigned int)floorf(255.0f * max_ff(r, 0.0f));
+	ig = (unsigned int)floorf(255.0f * max_ff(g, 0.0f));
+	ib = (unsigned int)floorf(255.0f * max_ff(b, 0.0f));
 
-	ir = (int)floor(255.0f * r);
-	if (ir < 0) ir = 0;
-	else if (ir > 255) ir = 255;
-	ig = (int)floor(255.0f * g);
-	if (ig < 0) ig = 0;
-	else if (ig > 255) ig = 255;
-	ib = (int)floor(255.0f * b);
-	if (ib < 0) ib = 0;
-	else if (ib > 255) ib = 255;
+	if (ir > 255) ir = 255;
+	if (ig > 255) ig = 255;
+	if (ib > 255) ib = 255;
 
 	return (ir + (ig * 256) + (ib * 256 * 256));
 }
@@ -601,14 +598,14 @@ static float index_to_float(const unsigned short i)
 void BLI_init_srgb_conversion(void)
 {
 	static int initialized = 0;
-	int i, b;
+	unsigned int i, b;
 
 	if (initialized) return;
 	initialized = 1;
 
 	/* Fill in the lookup table to convert floats to bytes: */
 	for (i = 0; i < 0x10000; i++) {
-		float f = linearrgb_to_srgb(index_to_float(i)) * 255.0f;
+		float f = linearrgb_to_srgb(index_to_float((unsigned short)i)) * 255.0f;
 		if (f <= 0) BLI_color_to_srgb_table[i] = 0;
 		else if (f < 255) BLI_color_to_srgb_table[i] = (unsigned short) (f * 0x100 + 0.5f);
 		else BLI_color_to_srgb_table[i] = 0xff00;
@@ -620,13 +617,13 @@ void BLI_init_srgb_conversion(void)
 		BLI_color_from_srgb_table[b] = f;
 		i = hipart(f);
 		/* replace entries so byte->float->byte does not change the data: */
-		BLI_color_to_srgb_table[i] = b * 0x100;
+		BLI_color_to_srgb_table[i] = (unsigned short)(b * 0x100);
 	}
 }
 static float inverse_srgb_companding(f

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list