[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57135] trunk/blender/source/blender/ blenlib/intern/math_color.c: UI: support 3 digit hex colors like HTML, e.g.

Brecht Van Lommel brechtvanlommel at pandora.be
Thu May 30 11:48:17 CEST 2013


Revision: 57135
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57135
Author:   blendix
Date:     2013-05-30 09:48:17 +0000 (Thu, 30 May 2013)
Log Message:
-----------
UI: support 3 digit hex colors like HTML, e.g. #123 becomes #112233.

Patch #35359 by Forest Ka.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/intern/math_color.c

Modified: trunk/blender/source/blender/blenlib/intern/math_color.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_color.c	2013-05-30 09:39:23 UTC (rev 57134)
+++ trunk/blender/source/blender/blenlib/intern/math_color.c	2013-05-30 09:48:17 UTC (rev 57135)
@@ -197,17 +197,26 @@
 	if (hexcol[0] == '#') hexcol++;
 
 	if (sscanf(hexcol, "%02x%02x%02x", &ri, &gi, &bi) == 3) {
-		*r = ri * (1.0f / 255.0f);
-		*g = gi * (1.0f / 255.0f);
-		*b = bi * (1.0f / 255.0f);
-		CLAMP(*r, 0.0f, 1.0f);
-		CLAMP(*g, 0.0f, 1.0f);
-		CLAMP(*b, 0.0f, 1.0f);
+		/* six digit hex colors */
 	}
+	else if (sscanf(hexcol, "%01x%01x%01x", &ri, &gi, &bi) == 3) {
+		/* three digit hex colors (#123 becomes #112233) */
+		ri += ri << 4;
+		gi += gi << 4;
+		bi += bi << 4;
+	}
 	else {
 		/* avoid using un-initialized vars */
 		*r = *g = *b = 0.0f;
+		return;
 	}
+
+	*r = ri * (1.0f / 255.0f);
+	*g = gi * (1.0f / 255.0f);
+	*b = bi * (1.0f / 255.0f);
+	CLAMP(*r, 0.0f, 1.0f);
+	CLAMP(*g, 0.0f, 1.0f);
+	CLAMP(*b, 0.0f, 1.0f);
 }
 
 void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv)




More information about the Bf-blender-cvs mailing list