[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43524] trunk/blender/source/blender: use color conversions functions in more places.

Campbell Barton ideasman42 at gmail.com
Thu Jan 19 11:04:53 CET 2012


Revision: 43524
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43524
Author:   campbellbarton
Date:     2012-01-19 10:04:51 +0000 (Thu, 19 Jan 2012)
Log Message:
-----------
use color conversions functions in more places.
also add rgba_float_to_uchar, rgba_uchar_to_float

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_image.h
    trunk/blender/source/blender/blenkernel/intern/brush.c
    trunk/blender/source/blender/blenkernel/intern/image_gen.c
    trunk/blender/source/blender/blenkernel/intern/node.c
    trunk/blender/source/blender/blenlib/BLI_math_color.h
    trunk/blender/source/blender/blenlib/intern/math_color.c
    trunk/blender/source/blender/editors/interface/interface_intern.h
    trunk/blender/source/blender/editors/interface/interface_templates.c
    trunk/blender/source/blender/editors/interface/interface_widgets.c
    trunk/blender/source/blender/editors/object/object_bake.c
    trunk/blender/source/blender/editors/space_view3d/drawmesh.c
    trunk/blender/source/blender/imbuf/intern/divers.c
    trunk/blender/source/blender/render/intern/source/rendercore.c

Modified: trunk/blender/source/blender/blenkernel/BKE_image.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_image.h	2012-01-19 09:58:25 UTC (rev 43523)
+++ trunk/blender/source/blender/blenkernel/BKE_image.h	2012-01-19 10:04:51 UTC (rev 43524)
@@ -186,7 +186,7 @@
 int BKE_image_has_alpha(struct Image *image);
 
 /* image_gen.c */
-void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, float color[4]);
+void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, const float color[4]);
 void BKE_image_buf_fill_checker(unsigned char *rect, float *rect_float, int height, int width);
 void BKE_image_buf_fill_checker_color(unsigned char *rect, float *rect_float, int height, int width);
 

Modified: trunk/blender/source/blender/blenkernel/intern/brush.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/brush.c	2012-01-19 09:58:25 UTC (rev 43523)
+++ trunk/blender/source/blender/blenkernel/intern/brush.c	2012-01-19 10:04:51 UTC (rev 43524)
@@ -527,7 +527,7 @@
 	float xy[2], rgba[4], *dstf;
 	int x, y, rowbytes, xoff, yoff, imbflag;
 	const int radius= brush_size(scene, brush);
-	char *dst, crgb[3];
+	unsigned char *dst, crgb[3];
 	const float alpha= brush_alpha(scene, brush);
 	float brush_rgb[3];
     
@@ -571,10 +571,10 @@
 	}
 	else {
 		float alpha_f; /* final float alpha to convert to char */
-		F3TOCHAR3(brush->rgb, crgb);
+		rgb_float_to_uchar(crgb, brush->rgb);
 
 		for (y=0; y < ibuf->y; y++) {
-			dst = (char*)ibuf->rect + y*rowbytes;
+			dst = (unsigned char *)ibuf->rect + y*rowbytes;
 
 			for (x=0; x < ibuf->x; x++, dst+=4) {
 				xy[0] = x + xoff;
@@ -590,19 +590,15 @@
 				}
 				else if (texfall == 1) {
 					brush_sample_tex(scene, brush, xy, rgba, 0);
-					dst[0] = FTOCHAR(rgba[0]);
-					dst[1] = FTOCHAR(rgba[1]);
-					dst[2] = FTOCHAR(rgba[2]);
-					dst[3] = FTOCHAR(rgba[3]);
+					rgba_float_to_uchar(dst, rgba);
 				}
 				else if (texfall == 2) {
 					brush_sample_tex(scene, brush, xy, rgba, 0);
 					mul_v3_v3(rgba, brush->rgb);
 					alpha_f = rgba[3] * alpha * brush_curve_strength_clamp(brush, len_v2(xy), radius);
 
-					dst[0] = FTOCHAR(rgba[0]);
-					dst[1] = FTOCHAR(rgba[1]);
-					dst[2] = FTOCHAR(rgba[2]);
+					rgb_float_to_uchar(dst, rgba);
+
 					dst[3] = FTOCHAR(alpha_f);
 				}
 				else {
@@ -843,7 +839,7 @@
 	Brush *brush= painter->brush;
 	ImBuf *ibuf, *maskibuf, *texibuf;
 	float *bf, *mf, *tf, *otf=NULL, xoff, yoff, xy[2], rgba[4];
-	char *b, *m, *t, *ot= NULL;
+	unsigned char *b, *m, *t, *ot= NULL;
 	int dotexold, origx= x, origy= y;
 	const int radius= brush_size(painter->scene, brush);
 
@@ -895,12 +891,12 @@
 	}
 	else {
 		for (; y < h; y++) {
-			b = (char*)ibuf->rect + (y*ibuf->x + origx)*4;
-			t = (char*)texibuf->rect + (y*texibuf->x + origx)*4;
-			m = (char*)maskibuf->rect + (y*maskibuf->x + origx)*4;
+			b = (unsigned char *)ibuf->rect + (y*ibuf->x + origx)*4;
+			t = (unsigned char *)texibuf->rect + (y*texibuf->x + origx)*4;
+			m = (unsigned char *)maskibuf->rect + (y*maskibuf->x + origx)*4;
 
 			if (dotexold)
-				ot = (char*)oldtexibuf->rect + ((y - origy + yt)*oldtexibuf->x + xt)*4;
+				ot = (unsigned char *)oldtexibuf->rect + ((y - origy + yt)*oldtexibuf->x + xt)*4;
 
 			for (x=origx; x < w; x++, b+=4, m+=4, t+=4) {
 				if (dotexold) {
@@ -915,10 +911,7 @@
 					xy[1] = y + yoff;
 
 					brush_sample_tex(scene, brush, xy, rgba, 0);
-					t[0]= FTOCHAR(rgba[0]);
-					t[1]= FTOCHAR(rgba[1]);
-					t[2]= FTOCHAR(rgba[2]);
-					t[3]= FTOCHAR(rgba[3]);
+					rgba_float_to_uchar(t, rgba);
 				}
 
 				b[0] = t[0]*m[0]/255;

Modified: trunk/blender/source/blender/blenkernel/intern/image_gen.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/image_gen.c	2012-01-19 09:58:25 UTC (rev 43523)
+++ trunk/blender/source/blender/blenkernel/intern/image_gen.c	2012-01-19 10:04:51 UTC (rev 43524)
@@ -33,7 +33,7 @@
 #include "BLI_math_base.h"
 #include "BLF_api.h"
 
-void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, float color[4])
+void BKE_image_buf_fill_color(unsigned char *rect, float *rect_float, int width, int height, const float color[4])
 {
 	int x, y;
 
@@ -41,22 +41,17 @@
 	if(rect_float) {
 		for(y= 0; y<height; y++) {
 			for(x= 0; x<width; x++) {
-				rect_float[0]= color[0];
-				rect_float[1]= color[1];
-				rect_float[2]= color[2];
-				rect_float[3]= color[3];
+				copy_v4_v4(rect_float, color);
 				rect_float+= 4;
 			}
 		}
 	}
 	
 	if(rect) {
-		char ccol[4];
+		unsigned char ccol[4];
 
-		ccol[0]= (char)(color[0]*255.0f);
-		ccol[1]= (char)(color[1]*255.0f);
-		ccol[2]= (char)(color[2]*255.0f);
-		ccol[3]= (char)(color[3]*255.0f);
+		rgba_float_to_uchar(ccol, color);
+
 		for(y= 0; y<height; y++) {
 			for(x= 0; x<width; x++) {
 				

Modified: trunk/blender/source/blender/blenkernel/intern/node.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/node.c	2012-01-19 09:58:25 UTC (rev 43523)
+++ trunk/blender/source/blender/blenkernel/intern/node.c	2012-01-19 10:04:51 UTC (rev 43524)
@@ -793,10 +793,7 @@
 					linearrgb_to_srgb_uchar4(tar, col);
 				}
 				else {
-					tar[0]= FTOCHAR(col[0]);
-					tar[1]= FTOCHAR(col[1]);
-					tar[2]= FTOCHAR(col[2]);
-					tar[3]= FTOCHAR(col[3]);
+					rgba_float_to_uchar(tar, col);
 				}
 			}
 			//else printf("prv out bound x y %d %d\n", x, y);

Modified: trunk/blender/source/blender/blenlib/BLI_math_color.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_color.h	2012-01-19 09:58:25 UTC (rev 43523)
+++ trunk/blender/source/blender/blenlib/BLI_math_color.h	2012-01-19 10:04:51 UTC (rev 43524)
@@ -102,7 +102,9 @@
 void rgb_byte_set_hue_float_offset(unsigned char * rgb, float hue_offset);
 
 void rgb_uchar_to_float(float col_r[3], const unsigned char col_ub[3]);
+void rgba_uchar_to_float(float col_r[4], const unsigned char col_ub[4]);
 void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3]);
+void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4]);
 
 /***************** lift/gamma/gain / ASC-CDL conversion *****************/
 

Modified: trunk/blender/source/blender/blenlib/intern/math_color.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_color.c	2012-01-19 09:58:25 UTC (rev 43523)
+++ trunk/blender/source/blender/blenlib/intern/math_color.c	2012-01-19 10:04:51 UTC (rev 43524)
@@ -344,6 +344,14 @@
 	col_r[2]= ((float)col_ub[2]) / 255.0f;
 }
 
+void rgba_uchar_to_float(float col_r[4], const unsigned char col_ub[4])
+{
+	col_r[0]= ((float)col_ub[0]) / 255.0f;
+	col_r[1]= ((float)col_ub[1]) / 255.0f;
+	col_r[2]= ((float)col_ub[2]) / 255.0f;
+	col_r[3]= ((float)col_ub[3]) / 255.0f;
+}
+
 void rgb_float_to_uchar(unsigned char col_r[3], const float col_f[3])
 {
 	int r, g, b;
@@ -357,6 +365,21 @@
 	col_r[2]= (char)((b <= 0)? 0 : (b >= 255)? 255 : b);
 }
 
+void rgba_float_to_uchar(unsigned char col_r[4], const float col_f[4])
+{
+	int r, g, b, a;
+
+	r= (int)(col_f[0] * 255.0f);
+	g= (int)(col_f[1] * 255.0f);
+	b= (int)(col_f[2] * 255.0f);
+	a= (int)(col_f[3] * 255.0f);
+
+	col_r[0]= (char)((r <= 0)? 0 : (r >= 255)? 255 : r);
+	col_r[1]= (char)((g <= 0)? 0 : (g >= 255)? 255 : g);
+	col_r[2]= (char)((b <= 0)? 0 : (b >= 255)? 255 : b);
+	col_r[3]= (char)((a <= 0)? 0 : (a >= 255)? 255 : a);
+}
+
 /* ********************************* color transforms ********************************* */
 
 

Modified: trunk/blender/source/blender/editors/interface/interface_intern.h
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_intern.h	2012-01-19 09:58:25 UTC (rev 43523)
+++ trunk/blender/source/blender/editors/interface/interface_intern.h	2012-01-19 10:04:51 UTC (rev 43524)
@@ -163,7 +163,7 @@
 	float hardmin, hardmax, softmin, softmax;
 	float a1, a2;
 	float aspect;
-	char col[4];
+	unsigned char col[4];
 
 	uiButHandleFunc func;
 	void *func_arg1;

Modified: trunk/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_templates.c	2012-01-19 09:58:25 UTC (rev 43523)
+++ trunk/blender/source/blender/editors/interface/interface_templates.c	2012-01-19 10:04:51 UTC (rev 43524)
@@ -2626,9 +2626,7 @@
 	uiBlockBeginAlign(block);
 	but= uiDefBut(block, ROUNDBOX, 0, "", 0, 0, UI_UNIT_X+10, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");
 	/* set the report's bg color in but->col - ROUNDBOX feature */
-	but->col[0]= FTOCHAR(rti->col[0]);
-	but->col[1]= FTOCHAR(rti->col[1]);
-	but->col[2]= FTOCHAR(rti->col[2]);
+	rgb_float_to_uchar(but->col, rti->col);
 	but->col[3]= 255; 
 
 	but= uiDefBut(block, ROUNDBOX, 0, "", UI_UNIT_X+10, 0, UI_UNIT_X+width, UI_UNIT_Y, NULL, 0.0f, 0.0f, 0, 0, "");

Modified: trunk/blender/source/blender/editors/interface/interface_widgets.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_widgets.c	2012-01-19 09:58:25 UTC (rev 43523)
+++ trunk/blender/source/blender/editors/interface/interface_widgets.c	2012-01-19 10:04:51 UTC (rev 43524)
@@ -2501,7 +2501,7 @@
 	if (color_profile)
 		linearrgb_to_srgb_v3_v3(col, col);
 	
-	F4TOCHAR4(col, wcol->inner);
+	rgba_float_to_uchar((unsigned char *)wcol->inner, col);
 
 	wcol->shaded = 0;
 	wcol->alpha_check = (wcol->inner[3] < 255);

Modified: trunk/blender/source/blender/editors/object/object_bake.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_bake.c	2012-01-19 09:58:25 UTC (rev 43523)
+++ trunk/blender/source/blender/editors/object/object_bake.c	2012-01-19 10:04:51 UTC (rev 43524)
@@ -807,10 +807,8 @@
 
 		ibuf->userflags= IB_RECT_INVALID;
 	} else {
-		char *rrgb= (char*)ibuf->rect + pixel*4;
-		rrgb[0]= FTOCHAR(vec[0]);
-		rrgb[1]= FTOCHAR(vec[1]);
-		rrgb[2]= FTOCHAR(vec[2]);
+		unsigned char *rrgb= (unsigned char *)ibuf->rect + pixel*4;
+		rgb_float_to_uchar(rrgb, vec);
 		rrgb[3]= 255;
 	}
 }


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list