[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31942] trunk/blender/source/blender: Apply patch [#23755] Sequencer: small code cleanup using existing color math functions

Nathan Letwory nathan at letworyinteractive.com
Wed Sep 15 13:58:20 CEST 2010


Revision: 31942
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31942
Author:   jesterking
Date:     2010-09-15 13:58:19 +0200 (Wed, 15 Sep 2010)

Log Message:
-----------
Apply patch [#23755] Sequencer: small code cleanup using existing color math functions
By Luca Bonavita (mindrones)

>From detailed description: This patch doesnt change functionality, but uses the existing color math functions from math_color.c into
sequencer_draw.c.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_color.h
    trunk/blender/source/blender/blenlib/intern/math_color.c
    trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_color.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_color.h	2010-09-15 11:48:59 UTC (rev 31941)
+++ trunk/blender/source/blender/blenlib/BLI_math_color.h	2010-09-15 11:58:19 UTC (rev 31942)
@@ -86,7 +86,10 @@
 
 int constrain_rgb(float *r, float *g, float *b);
 void minmax_rgb(short c[3]);
-	
+
+void rgb_float_set_hue_float_offset(float * rgb, float hue_offset);
+void rgb_byte_set_hue_float_offset(char * rgb, float hue_offset);
+
 /***************** 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);

Modified: trunk/blender/source/blender/blenlib/intern/math_color.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_color.c	2010-09-15 11:48:59 UTC (rev 31941)
+++ trunk/blender/source/blender/blenlib/intern/math_color.c	2010-09-15 11:58:19 UTC (rev 31942)
@@ -464,3 +464,28 @@
 	}
 }
 
+/* ******************************************** other ************************************************* */
+
+/* Applies an hue offset to a float rgb color */
+void rgb_float_set_hue_float_offset(float rgb[3], float hue_offset)
+{
+	float hsv[3];
+	
+	rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
+	
+	hsv[0]+= hue_offset;
+	if(hsv[0]>1.0)		hsv[0]-=1.0;
+	else if(hsv[0]<0.0)	hsv[0]+= 1.0;
+	
+	hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
+}
+
+/* Applies an hue offset to a byte rgb color */
+void rgb_byte_set_hue_float_offset(char rgb[3], float hue_offset)
+{
+	float rgb_float[3];
+	
+	rgb_byte_to_float(rgb, rgb_float);
+	rgb_float_set_hue_float_offset(rgb_float, hue_offset);
+	rgb_float_to_byte(rgb_float, rgb);
+}

Modified: trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c	2010-09-15 11:48:59 UTC (rev 31941)
+++ trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c	2010-09-15 11:58:19 UTC (rev 31942)
@@ -75,19 +75,21 @@
 static void get_seq_color3ubv(Scene *curscene, Sequence *seq, char *col)
 {
 	char blendcol[3];
-	float hsv[3], rgb[3];
 	SolidColorVars *colvars = (SolidColorVars *)seq->effectdata;
 
 	switch(seq->type) {
 	case SEQ_IMAGE:
 		UI_GetThemeColor3ubv(TH_SEQ_IMAGE, col);
 		break;
+		
 	case SEQ_META:
 		UI_GetThemeColor3ubv(TH_SEQ_META, col);
 		break;
+		
 	case SEQ_MOVIE:
 		UI_GetThemeColor3ubv(TH_SEQ_MOVIE, col);
 		break;
+		
 	case SEQ_SCENE:
 		UI_GetThemeColor3ubv(TH_SEQ_SCENE, col);
 		
@@ -95,24 +97,17 @@
 			UI_GetColorPtrBlendShade3ubv(col, col, col, 1.0, 20);
 		}
 		break;
-
+		
 	/* transitions */
 	case SEQ_CROSS:
 	case SEQ_GAMCROSS:
 	case SEQ_WIPE:
-		/* slightly offset hue to distinguish different effects */
 		UI_GetThemeColor3ubv(TH_SEQ_TRANSITION, col);
-		
-		rgb[0] = col[0]/255.0; rgb[1] = col[1]/255.0; rgb[2] = col[2]/255.0; 
-		rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
-		
-		if (seq->type == SEQ_CROSS)		hsv[0]+= 0.04;
-		if (seq->type == SEQ_GAMCROSS)	hsv[0]+= 0.08;
-		if (seq->type == SEQ_WIPE)		hsv[0]+= 0.12;
-		
-		if(hsv[0]>1.0) hsv[0]-=1.0; else if(hsv[0]<0.0) hsv[0]+= 1.0;
-		hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
-		col[0] = (char)(rgb[0]*255); col[1] = (char)(rgb[1]*255); col[2] = (char)(rgb[2]*255); 
+
+		/* slightly offset hue to distinguish different effects */
+		if (seq->type == SEQ_CROSS)			rgb_byte_set_hue_float_offset(col,0.04);
+		if (seq->type == SEQ_GAMCROSS)		rgb_byte_set_hue_float_offset(col,0.08);
+		if (seq->type == SEQ_WIPE)			rgb_byte_set_hue_float_offset(col,0.12);
 		break;
 		
 	/* effects */
@@ -126,42 +121,37 @@
 	case SEQ_OVERDROP:
 	case SEQ_GLOW:
 	case SEQ_MULTICAM:
-		/* slightly offset hue to distinguish different effects */
 		UI_GetThemeColor3ubv(TH_SEQ_EFFECT, col);
 		
-		rgb[0] = col[0]/255.0; rgb[1] = col[1]/255.0; rgb[2] = col[2]/255.0; 
-		rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2);
-		
-		if (seq->type == SEQ_ADD)		hsv[0]+= 0.04;
-		if (seq->type == SEQ_SUB)		hsv[0]+= 0.08;
-		if (seq->type == SEQ_MUL)		hsv[0]+= 0.12;
-		if (seq->type == SEQ_ALPHAOVER)	hsv[0]+= 0.16;
-		if (seq->type == SEQ_ALPHAUNDER)	hsv[0]+= 0.20;
-		if (seq->type == SEQ_OVERDROP)	hsv[0]+= 0.24;
-		if (seq->type == SEQ_GLOW)		hsv[0]+= 0.28;
-		if (seq->type == SEQ_TRANSFORM)		hsv[0]+= 0.36;
-
-		if(hsv[0]>1.0) hsv[0]-=1.0; else if(hsv[0]<0.0) hsv[0]+= 1.0;
-		hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2);
-		col[0] = (char)(rgb[0]*255); col[1] = (char)(rgb[1]*255); col[2] = (char)(rgb[2]*255); 
+		/* slightly offset hue to distinguish different effects */
+		if (seq->type == SEQ_ADD)			rgb_byte_set_hue_float_offset(col,0.04);
+		if (seq->type == SEQ_SUB)			rgb_byte_set_hue_float_offset(col,0.08);
+		if (seq->type == SEQ_MUL)			rgb_byte_set_hue_float_offset(col,0.12);
+		if (seq->type == SEQ_ALPHAOVER)		rgb_byte_set_hue_float_offset(col,0.16);
+		if (seq->type == SEQ_ALPHAUNDER)	rgb_byte_set_hue_float_offset(col,0.20);
+		if (seq->type == SEQ_OVERDROP)		rgb_byte_set_hue_float_offset(col,0.24);
+		if (seq->type == SEQ_GLOW)			rgb_byte_set_hue_float_offset(col,0.28);
+		if (seq->type == SEQ_TRANSFORM)		rgb_byte_set_hue_float_offset(col,0.36);
 		break;
+		
 	case SEQ_COLOR:
 		if (colvars->col) {
-			col[0]= (char)(colvars->col[0]*255);
-			col[1]= (char)(colvars->col[1]*255);
-			col[2]= (char)(colvars->col[2]*255);
+			rgb_float_to_byte(colvars->col, col);
 		} else {
 			col[0] = col[1] = col[2] = 128;
 		}
 		break;
+		
 	case SEQ_PLUGIN:
 		UI_GetThemeColor3ubv(TH_SEQ_PLUGIN, col);
 		break;
+		
 	case SEQ_SOUND:
 		UI_GetThemeColor3ubv(TH_SEQ_AUDIO, col);
 		blendcol[0] = blendcol[1] = blendcol[2] = 128;
 		if(seq->flag & SEQ_MUTE) UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.5, 20);
 		break;
+		
 	default:
 		col[0] = 10; col[1] = 255; col[2] = 40;
 	}





More information about the Bf-blender-cvs mailing list