[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47043] trunk/blender: add vector versions of hsv_to_rgb, rgb_to_hsv & rgb_to_hsv_compat

Campbell Barton ideasman42 at gmail.com
Sat May 26 13:01:02 CEST 2012


Revision: 47043
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47043
Author:   campbellbarton
Date:     2012-05-26 11:01:01 +0000 (Sat, 26 May 2012)
Log Message:
-----------
add vector versions of hsv_to_rgb, rgb_to_hsv & rgb_to_hsv_compat

Modified Paths:
--------------
    trunk/blender/release/plugins/sequence/color-correction-hsv.c
    trunk/blender/source/blender/blenkernel/intern/image_gen.c
    trunk/blender/source/blender/blenlib/BLI_math_color.h
    trunk/blender/source/blender/blenlib/intern/math_color.c
    trunk/blender/source/blender/editors/animation/anim_ipo_utils.c
    trunk/blender/source/blender/editors/include/ED_anim_api.h
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_regions.c
    trunk/blender/source/blender/editors/interface/interface_widgets.c
    trunk/blender/source/blender/imbuf/intern/divers.c
    trunk/blender/source/blender/modifiers/intern/MOD_weightvg_util.c
    trunk/blender/source/blender/python/mathutils/mathutils_Color.c

Modified: trunk/blender/release/plugins/sequence/color-correction-hsv.c
===================================================================
--- trunk/blender/release/plugins/sequence/color-correction-hsv.c	2012-05-26 10:05:22 UTC (rev 47042)
+++ trunk/blender/release/plugins/sequence/color-correction-hsv.c	2012-05-26 11:01:01 UTC (rev 47043)
@@ -19,24 +19,24 @@
 #include "plugin.h"
 #include <stdio.h>
 
-char name[]= "Color Correction";
+char name[] = "Color Correction";
 
-VarStruct varstr[]= {
-	{ NUMSLI|FLO, "St Y:", 0.0,	-1.0,	1.0, "Setup Y"}, 
-	{ NUMSLI|FLO, "Gn Y:",  1.0,	0.0,	10.0,"Gain Y"},
-	{ NUMSLI|FLO, "Ga Y:", 1.0,	0.0,	10.0, "Gamma Y"},
+VarStruct varstr[] = {
+	{ NUMSLI | FLO, "St Y:", 0.0, -1.0,   1.0, "Setup Y"},
+	{ NUMSLI | FLO, "Gn Y:",  1.0,    0.0,    10.0, "Gain Y"},
+	{ NUMSLI | FLO, "Ga Y:", 1.0, 0.0,    10.0, "Gamma Y"},
 
-	{ NUMSLI|FLO, "Lo S:",  1.0,	0.0,	10.0,"Saturation Shadows"},
-	{ NUMSLI|FLO, "Md S:",  1.0,	0.0,	10.0,"Saturation Midtones"},
-	{ NUMSLI|FLO, "Hi S:",  1.0,	0.0,	10.0,"Saturation Highlights"},
+	{ NUMSLI | FLO, "Lo S:",  1.0,    0.0,    10.0, "Saturation Shadows"},
+	{ NUMSLI | FLO, "Md S:",  1.0,    0.0,    10.0, "Saturation Midtones"},
+	{ NUMSLI | FLO, "Hi S:",  1.0,    0.0,    10.0, "Saturation Highlights"},
 
-	{ NUMSLI|FLO, "MA S:",  1.0,	0.0,	10.0,"Master Saturation"}, 
+	{ NUMSLI | FLO, "MA S:",  1.0,    0.0,    10.0, "Master Saturation"},
 
-	{ NUMSLI|FLO, "Lo T:",  0.25, 0.0, 1.0,
+	{ NUMSLI | FLO, "Lo T:",  0.25, 0.0, 1.0,
 	  "Saturation Shadow Thres"}, 
-	{ NUMSLI|FLO, "Hi T:",  0.75, 0.0, 1.0,
+	{ NUMSLI | FLO, "Hi T:",  0.75, 0.0, 1.0,
 	  "Saturation Highlights Thres"}, 
-	{ TOG|INT,	"Debug", 0.0,	0.0,	1.0,   
+	{ TOG | INT,  "Debug", 0.0,   0.0,    1.0,
 	  "Show curves as overlay"}, 
 };
 
@@ -58,25 +58,28 @@
 
 void plugin_seq_doit(Cast *, float, float, int, int, ImBuf *, ImBuf *, ImBuf *, ImBuf *);
 
-int plugin_seq_getversion(void) { return B_PLUGIN_VERSION;}
+int plugin_seq_getversion(void)
+{
+	return B_PLUGIN_VERSION;
+}
 void plugin_but_changed(int but) {}
 void plugin_init() {}
 
 void plugin_getinfo(PluginInfo *info)
 {
-	info->name= name;
-	info->nvars= sizeof(varstr)/sizeof(VarStruct);
-	info->cfra= &cfra;
+	info->name = name;
+	info->nvars = sizeof(varstr) / sizeof(VarStruct);
+	info->cfra = &cfra;
 
-	info->varstr= varstr;
+	info->varstr = varstr;
 
-	info->init= plugin_init;
-	info->seq_doit= (SeqDoit) plugin_seq_doit;
-	info->callback= plugin_but_changed;
+	info->init = plugin_init;
+	info->seq_doit = (SeqDoit) plugin_seq_doit;
+	info->callback = plugin_but_changed;
 }
 
-static void hsv_to_rgb (double  h, double  s, double  v,
-			double *r, double *g, double *b)
+static void hsv_to_rgb(double h, double s, double v,
+                       double *r, double *g, double *b)
 {
 	int i;
 	double f, w, q, t;
@@ -90,8 +93,7 @@
 		*g = v;
 		*b = v;
 	}
-	else
-	{
+	else {
 		if (h == 360.0)
 			h = 0.0;
 		h = h / 60.0;
@@ -103,42 +105,42 @@
 		
 		switch (i)
 		{
-		case 0:
-			*r = v;
-			*g = t;
-			*b = w;
-			break;
-		case 1:
-			*r = q;
-			*g = v;
-			*b = w;
-			break;
-		case 2:
-			*r = w;
-			*g = v;
-			*b = t;
-			break;
-		case 3:
-			*r = w;
-			*g = q;
-			*b = v;
-			break;
-		case 4:
-			*r = t;
-			*g = w;
-			*b = v;
-			break;
-		case 5:
-			*r = v;
-			*g = w;
-			*b = q;
-			break;
+			case 0:
+				*r = v;
+				*g = t;
+				*b = w;
+				break;
+			case 1:
+				*r = q;
+				*g = v;
+				*b = w;
+				break;
+			case 2:
+				*r = w;
+				*g = v;
+				*b = t;
+				break;
+			case 3:
+				*r = w;
+				*g = q;
+				*b = v;
+				break;
+			case 4:
+				*r = t;
+				*g = w;
+				*b = v;
+				break;
+			case 5:
+				*r = v;
+				*g = w;
+				*b = q;
+				break;
 		}
 	}
 }
 
-static void rgb_to_hsv (double  r, double  g, double  b,
-			double *h, double *s, double *v)
+static void rgb_to_hsv(double r, double g, double b,
+                       double *h, double *s, double *v)
 {
 	double max, min, delta;
 
@@ -163,8 +165,7 @@
 	
 	if (*s == 0.0)
 		*h = -1.0;
-	else
-	{
+	else {
 		delta = max - min;
 		
 		if (r == max)
@@ -182,7 +183,8 @@
 }
 
 void plugin_seq_doit(Cast *cast, float facf0, float facf1, int width, 
-	int height, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *out, ImBuf *use) {
+                     int height, ImBuf *ibuf1, ImBuf *ibuf2, ImBuf *out, ImBuf *use)
+{
 	char *dest, *src1;
 	int x, y, c;
 	double gamma_table[256];
@@ -192,18 +194,19 @@
 	
 	if (!ibuf1) return;
 
-	dest= (char *) out->rect;
-	src1= (char *) ibuf1->rect;
-	src1f= ibuf1->rect_float;
+	dest = (char *) out->rect;
+	src1 = (char *) ibuf1->rect;
+	src1f = ibuf1->rect_float;
 
 	for (y = 0; y < 256; y++) {
 		float v = 1.0 * y / 255;
 		v += cast->setup_y;
 		v *= cast->gain_y;
 		v = pow(v, cast->gamma_y);
-		if ( v > 1.0) {
+		if (v > 1.0) {
 			v = 1.0;
-		} else if (v < 0.0) {
+		}
+		else if (v < 0.0) {
 			v = 0.0;
 		}
 		gamma_table[y] = v * 255;
@@ -214,9 +217,11 @@
 		v *= cast->master_sat;
 		if (y < cast->lo_thres * 255) {
 			v *= cast->sat_shadows;
-		} else if (y > cast->hi_thres * 255) {
+		}
+		else if (y > cast->hi_thres * 255) {
 			v *= cast->sat_highlights;
-		} else {
+		}
+		else {
 			v *= cast->sat_midtones;
 		}
 		uv_table[y] = v;
@@ -225,15 +230,15 @@
 
 	for (y = 0; y < height; y++) {
 		for (x = 0; x < width; x++) {
-			double h,s,v,r,g,b;
+			double h, s, v, r, g, b;
 			double fac;
 
 			if (ibuf1->rect_float) rgb_to_hsv(src1f[0], src1f[1],
-				src1f[2],&h,&s,&v);
-			else rgb_to_hsv((double) src1[0]/255.0,
-				   (double) src1[1]/255.0,
-				   (double) src1[2]/255.0,
-				   &h, &s, &v);
+				                              src1f[2], &h, &s, &v);
+			else rgb_to_hsv((double) src1[0] / 255.0,
+				            (double) src1[1] / 255.0,
+				            (double) src1[2] / 255.0,
+				            &h, &s, &v);
 			v = gamma_table[(int) (v * 255.0)] / 255.0;
 
 			fac = uv_table[(int) (255.0 * v)];
@@ -242,18 +247,19 @@
 			if (s >= 1.0) {
 				s = 1.0;
 			}
-			hsv_to_rgb(h,s,v, &r, &g, &b);
+			hsv_to_rgb(h, s, v, &r, &g, &b);
 			
 			if (out->rect_float) {
 				destf[0] = r;
 				destf[1] = g;
 				destf[2] = b;
 				destf = destf + 4;
-				src1f +=4;
-			} else {
-				dest[0] = r*255.0;
-				dest[1] = g*255.0;
-				dest[2] = b*255.0;
+				src1f += 4;
+			}
+			else {
+				dest[0] = r * 255.0;
+				dest[1] = g * 255.0;
+				dest[2] = b * 255.0;
 				dest += 4;
 			}
 
@@ -262,7 +268,7 @@
 	}
 
 	if (cast->debug) {
-		dest= (char *) out->rect;
+		dest = (char *) out->rect;
 		for (c = 0; c < 10; c++) {
 			x = 0;
 			for (y = 0; y < 256; y++) {
@@ -279,7 +285,7 @@
 		for (c = 0; c < 10; c++) {
 			x = 0;
 			for (y = 0; y < 256; y++) {
-				char val = uv_table[y] * 255.0/10.0;
+				char val = uv_table[y] * 255.0 / 10.0;
 				while (x < y * width / 255) {
 					*dest++ = val;
 					*dest++ = val;

Modified: trunk/blender/source/blender/blenkernel/intern/image_gen.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image_gen.c	2012-05-26 10:05:22 UTC (rev 47042)
+++ trunk/blender/source/blender/blenkernel/intern/image_gen.c	2012-05-26 11:01:01 UTC (rev 47043)
@@ -78,7 +78,9 @@
 	float *rect_float_orig = rect_float;
 
 	
-	float h = 0.0, hoffs = 0.0, hue = 0.0, s = 0.9, v = 0.9, r, g, b;
+	float h = 0.0, hoffs = 0.0;
+	float hsv[3] = {0.0f, 0.9f, 0.9f};
+	float rgb[3];
 
 	/* checkers */
 	for (y = 0; y < height; y++) {
@@ -128,20 +130,20 @@
 				if ((fabs((x % checkerwidth) - (checkerwidth / 2)) < 1) ||
 				    (fabs((y % checkerwidth) - (checkerwidth / 2)) < 1))
 				{
-					hue = fmodf(fabs(h - hoffs), 1.0f);
-					hsv_to_rgb(hue, s, v, &r, &g, &b);
+					hsv[0] = fmodf(fabs(h - hoffs), 1.0f);
+					hsv_to_rgb_v(hsv, rgb);
 					
 					if (rect) {
-						rect[0] = (char)(r * 255.0f);
-						rect[1] = (char)(g * 255.0f);
-						rect[2] = (char)(b * 255.0f);
+						rect[0] = (char)(rgb[0] * 255.0f);
+						rect[1] = (char)(rgb[1] * 255.0f);
+						rect[2] = (char)(rgb[2] * 255.0f);
 						rect[3] = 255;
 					}
 					
 					if (rect_float) {
-						rect_float[0] = r;
-						rect_float[1] = g;
-						rect_float[2] = b;
+						rect_float[0] = rgb[0];
+						rect_float[1] = rgb[1];
+						rect_float[2] = rgb[2];
 						rect_float[3] = 1.0f;
 					}
 				}
@@ -162,33 +164,33 @@
 static void checker_board_color_fill(unsigned char *rect, float *rect_float, int width, int height)
 {
 	int hue_step, y, x;
-	float hue, val, sat, r, g, b;
+	float hsv[3], rgb[3];
 
-	sat = 1.0;
+	hsv[1] = 1.0;
 
 	hue_step = power_of_2_max_i(width / 8);
 	if (hue_step < 8) hue_step = 8;
 
 	for (y = 0; y < height; y++) {
 
-		val = 0.1 + (y * (0.4 / height)); /* use a number lower then 1.0 else its too bright */
+		hsv[2] = 0.1 + (y * (0.4 / height)); /* use a number lower then 1.0 else its too bright */
 		for (x = 0; x < width; x++) {
-			hue = (float)((double)(x / hue_step) * 1.0 / width * hue_step);
-			hsv_to_rgb(hue, sat, val, &r, &g, &b);
+			hsv[0] = (float)((double)(x / hue_step) * 1.0 / width * hue_step);
+			hsv_to_rgb_v(hsv, rgb);
 
 			if (rect) {
-				rect[0] = (char)(r * 255.0f);
-				rect[1] = (char)(g * 255.0f);
-				rect[2] = (char)(b * 255.0f);
+				rect[0] = (char)(rgb[0] * 255.0f);
+				rect[1] = (char)(rgb[1] * 255.0f);
+				rect[2] = (char)(rgb[2] * 255.0f);
 				rect[3] = 255;
 				
 				rect += 4;
 			}
 
 			if (rect_float) {
-				rect_float[0] = r;
-				rect_float[1] = g;
-				rect_float[2] = b;
+				rect_float[0] = rgb[0];
+				rect_float[1] = rgb[1];
+				rect_float[2] = rgb[2];
 				rect_float[3] = 1.0f;
 				
 				rect_float += 4;

Modified: trunk/blender/source/blender/blenlib/BLI_math_color.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_color.h	2012-05-26 10:05:22 UTC (rev 47042)
+++ trunk/blender/source/blender/blenlib/BLI_math_color.h	2012-05-26 11:01:01 UTC (rev 47043)
@@ -54,6 +54,7 @@
 /******************* Conversion to RGB ********************/
 
 void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b);
+void hsv_to_rgb_v(const float hsv[3], float r_rgb[3]);
 void hex_to_rgb(char *hexcol, float *r, float *g, float *b);
 void yuv_to_rgb(float y, float u, float v, float *lr, float *lg, float *lb);
 void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb, int colorspace);
@@ -65,7 +66,9 @@
 void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv);
 void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, int colorspace);
 void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list