[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36239] trunk/blender/source/blender/ editors: Upgrade for pixel color info in image editor and compositor backdrop.

Lukas Toenne lukas.toenne at googlemail.com
Wed Apr 20 11:49:32 CEST 2011


Revision: 36239
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36239
Author:   lukastoenne
Date:     2011-04-20 09:49:32 +0000 (Wed, 20 Apr 2011)
Log Message:
-----------
Upgrade for pixel color info in image editor and compositor backdrop. Next to the RGB color values there is now a small rectangle displaying the actual color under the mouse cursor. In addition to that the HSV and luminance values are also displayed.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_image/image_draw.c
    trunk/blender/source/blender/editors/space_node/drawnode.c

Modified: trunk/blender/source/blender/editors/space_image/image_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_draw.c	2011-04-20 09:46:45 UTC (rev 36238)
+++ trunk/blender/source/blender/editors/space_image/image_draw.c	2011-04-20 09:49:32 UTC (rev 36239)
@@ -45,6 +45,7 @@
 
 #include "PIL_time.h"
 
+#include "BLI_math_color.h"
 #include "BLI_threads.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
@@ -135,27 +136,20 @@
 void draw_image_info(ARegion *ar, int channels, int x, int y, char *cp, float *fp, int *zp, float *zpf)
 {
 	char str[256];
-	int ofs= 0;
+	float dx= 6;
+	/* text colors */
+	/* XXX colored text not allowed in Blender UI */
+	#if 0
+	unsigned char red[3] = {255, 50, 50};
+	unsigned char green[3] = {0, 255, 0};
+	unsigned char blue[3] = {100, 100, 255};
+	#else
+	unsigned char red[3] = {255, 255, 255};
+	unsigned char green[3] = {255, 255, 255};
+	unsigned char blue[3] = {255, 255, 255};
+	#endif
+	float hue=0, sat=0, val=0, lum=0, u=0, v=0;
 
-	ofs += BLI_snprintf(str + ofs, sizeof(str)-ofs, "X: %4d Y: %4d ", x, y);
-	if(cp)
-		ofs+= BLI_snprintf(str + ofs, sizeof(str)-ofs, "| R: %3d G: %3d B: %3d A: %3d ", cp[0], cp[1], cp[2], cp[3]);
-
-	if(fp) {
-		if(channels==4)
-			ofs+= BLI_snprintf(str + ofs, sizeof(str)-ofs, "| R: %.4f G: %.4f B: %.4f A: %.4f ", fp[0], fp[1], fp[2], fp[3]);
-		else if(channels==1)
-			ofs+= BLI_snprintf(str + ofs, sizeof(str)-ofs, "| Val: %.4f ", fp[0]);
-		else if(channels==3)
-			ofs+= BLI_snprintf(str + ofs, sizeof(str)-ofs, "| R: %.4f G: %.4f B: %.4f ", fp[0], fp[1], fp[2]);
-	}
-
-	if(zp)
-		ofs+= BLI_snprintf(str + ofs, sizeof(str)-ofs, "| Z: %.4f ", 0.5f+0.5f*(((float)*zp)/(float)0x7fffffff));
-	if(zpf)
-		ofs+= BLI_snprintf(str + ofs, sizeof(str)-ofs, "| Z: %.3f ", *zpf);
-	(void)ofs; /* quiet clang */
-
 	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
 	glEnable(GL_BLEND);
 
@@ -163,14 +157,164 @@
 	glColor4ub(0, 0, 0, 190);
 	glRecti(0.0, 0.0, ar->winrct.xmax - ar->winrct.xmin + 1, 20);
 	glDisable(GL_BLEND);
-	
+
+	BLF_size(blf_mono_font, 11, 72);
+
 	glColor3ub(255, 255, 255);
-	
+	sprintf(str, "X:%-4d  Y:%-4d |", x, y);
 	// UI_DrawString(6, 6, str); // works ok but fixed width is nicer.
-	BLF_size(blf_mono_font, 11, 72);
-	BLF_position(blf_mono_font, 6, 6, 0);
+	BLF_position(blf_mono_font, dx, 6, 0);
 	BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+	dx += BLF_width(blf_mono_font, str);
+
+	if(zp) {
+		glColor3ub(255, 255, 255);
+		sprintf(str, " Z:%-.4f |", 0.5f+0.5f*(((float)*zp)/(float)0x7fffffff));
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+	}
+	if(zpf) {
+		glColor3ub(255, 255, 255);
+		sprintf(str, " Z:%-.3f |", *zpf);
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+	}
+
+	if(channels >= 3) {
+		glColor3ubv(red);
+		if (fp)
+			sprintf(str, "  R:%-.4f", fp[0]);
+		else if (cp)
+			sprintf(str, "  R:%-3d", cp[0]);
+ 		else
+			sprintf(str, "  R:-");
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+		
+		glColor3ubv(green);
+		if (fp)
+			sprintf(str, "  G:%-.4f", fp[1]);
+		else if (cp)
+			sprintf(str, "  G:%-3d", cp[1]);
+ 		else
+			sprintf(str, "  G:-");
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+		
+		glColor3ubv(blue);
+		if (fp)
+			sprintf(str, "  B:%-.4f", fp[2]);
+		else if (cp)
+			sprintf(str, "  B:%-3d", cp[2]);
+ 		else
+			sprintf(str, "  B:-");
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+		
+		if(channels == 4) {
+			glColor3ub(255, 255, 255);
+			if (fp)
+				sprintf(str, "  A:%-.4f", fp[3]);
+			else if (cp)
+				sprintf(str, "  A:%-3d", cp[3]);
+			else
+				sprintf(str, "- ");
+			BLF_position(blf_mono_font, dx, 6, 0);
+			BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+			dx += BLF_width(blf_mono_font, str);
+		}
+	}
 	
+	glDisable(GL_BLEND);
+	if (channels==1) {
+		if (fp)
+			glColor3f(fp[0], fp[0], fp[0]);
+		else if (cp)
+			glColor3ub(cp[0], cp[0], cp[0]);
+		else
+			glColor3ub(0, 0, 0);
+	}
+	else if (channels==3) {
+		if (fp)
+			glColor3fv(fp);
+		else if (cp)
+			glColor3ub(cp[0], cp[1], cp[2]);
+		else
+			glColor3ub(0, 0, 0);
+	}
+	else if (channels==4) {
+		if (fp)
+			glColor4fv(fp);
+		else if (cp)
+			glColor4ub(cp[0], cp[1], cp[2], cp[3]);
+		else
+			glColor3ub(0, 0, 0);
+	}
+	dx += 5;
+	glBegin(GL_QUADS);
+	glVertex2f(dx, 3);
+	glVertex2f(dx, 17);
+	glVertex2f(dx+30, 17);
+	glVertex2f(dx+30, 3);
+	glEnd();
+	dx += 35;
+
+	glColor3ub(255, 255, 255);
+	if(channels == 1) {
+		if (fp) {
+			rgb_to_hsv(fp[0], fp[0], fp[0], &hue, &sat, &val);
+			rgb_to_yuv(fp[0], fp[0], fp[0], &lum, &u, &v);
+		}
+		else if (cp) {
+			rgb_to_hsv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &hue, &sat, &val);
+			rgb_to_yuv((float)cp[0]/255.0f, (float)cp[0]/255.0f, (float)cp[0]/255.0f, &lum, &u, &v);
+		}
+		
+		sprintf(str, "V:%-.4f", val);
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+
+		sprintf(str, "   L:%-.4f", lum);
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+	}
+	else if(channels >= 3) {
+		if (fp) {
+			rgb_to_hsv(fp[0], fp[1], fp[2], &hue, &sat, &val);
+			rgb_to_yuv(fp[0], fp[1], fp[2], &lum, &u, &v);
+		}
+		else if (cp) {
+			rgb_to_hsv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &hue, &sat, &val);
+			rgb_to_yuv((float)cp[0]/255.0f, (float)cp[1]/255.0f, (float)cp[2]/255.0f, &lum, &u, &v);
+		}
+
+		sprintf(str, "H:%-.4f", hue);
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+
+		sprintf(str, "  S:%-.4f", sat);
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+
+		sprintf(str, "  V:%-.4f", val);
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+
+		sprintf(str, "   L:%-.4f", lum);
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+	}
 }
 
 /* image drawing */

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c	2011-04-20 09:46:45 UTC (rev 36238)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c	2011-04-20 09:49:32 UTC (rev 36239)
@@ -1445,42 +1445,187 @@
 void draw_nodespace_color_info(ARegion *ar, int channels, int x, int y, char *cp, float *fp)
 {
 	char str[256];
-	int ofs;
-	
-	ofs= sprintf(str, "X: %4d Y: %4d ", x, y);
+	float dx= 6;
+	/* text colors */
+	/* XXX colored text not allowed in Blender UI */
+	#if 0
+	unsigned char red[3] = {255, 50, 50};
+	unsigned char green[3] = {0, 255, 0};
+	unsigned char blue[3] = {100, 100, 255};
+	#else
+	unsigned char red[3] = {255, 255, 255};
+	unsigned char green[3] = {255, 255, 255};
+	unsigned char blue[3] = {255, 255, 255};
+	#endif
+	float hue=0, sat=0, val=0, lum=0, u=0, v=0;
 
-	if(channels==4) {
-		if(cp)
-			ofs+= sprintf(str+ofs, "| R: %3d G: %3d B: %3d A: %3d ", cp[0], cp[1], cp[2], cp[3]);
+	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+	glEnable(GL_BLEND);
+
+	/* noisy, high contrast make impossible to read if lower alpha is used. */
+	glColor4ub(0, 0, 0, 190);
+	glRecti(0.0, 0.0, ar->winrct.xmax - ar->winrct.xmin + 1, 20);
+	glDisable(GL_BLEND);
+
+	BLF_size(blf_mono_font, 11, 72);
+
+	glColor3ub(255, 255, 255);
+	sprintf(str, "X:%-4d  Y:%-4d |", x, y);
+	// UI_DrawString(6, 6, str); // works ok but fixed width is nicer.
+	BLF_position(blf_mono_font, dx, 6, 0);
+	BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+	dx += BLF_width(blf_mono_font, str);
+
+	#if 0	/* XXX no Z value in compo backdrop atm */
+	if(zp) {
+		glColor3ub(255, 255, 255);
+		sprintf(str, " Z:%-.4f |", 0.5f+0.5f*(((float)*zp)/(float)0x7fffffff));
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+	}
+	if(zpf) {
+		glColor3ub(255, 255, 255);
+		sprintf(str, " Z:%-.3f |", *zpf);
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+	}
+	#endif
+
+	if(channels >= 3) {
+		glColor3ubv(red);
 		if (fp)
-			ofs+= sprintf(str+ofs, "| R: %.4f G: %.4f B: %.4f A: %.4f ", fp[0], fp[1], fp[2], fp[3]);
+			sprintf(str, "  R:%-.4f", fp[0]);
+		else if (cp)
+			sprintf(str, "  R:%-3d", cp[0]);
+ 		else
+			sprintf(str, "  R:-");
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+		
+		glColor3ubv(green);
+		if (fp)
+			sprintf(str, "  G:%-.4f", fp[1]);
+		else if (cp)
+			sprintf(str, "  G:%-3d", cp[1]);
+ 		else
+			sprintf(str, "  G:-");
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+		
+		glColor3ubv(blue);
+		if (fp)
+			sprintf(str, "  B:%-.4f", fp[2]);
+		else if (cp)
+			sprintf(str, "  B:%-3d", cp[2]);
+ 		else
+			sprintf(str, "  B:-");
+		BLF_position(blf_mono_font, dx, 6, 0);
+		BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+		dx += BLF_width(blf_mono_font, str);
+		
+		if(channels == 4) {
+			glColor3ub(255, 255, 255);
+			if (fp)
+				sprintf(str, "  A:%-.4f", fp[3]);
+			else if (cp)
+				sprintf(str, "  A:%-3d", cp[3]);
+			else
+				sprintf(str, "- ");
+			BLF_position(blf_mono_font, dx, 6, 0);
+			BLF_draw_ascii(blf_mono_font, str, sizeof(str));
+			dx += BLF_width(blf_mono_font, str);
+		}
 	}
-	else if(channels==1) {
-		if(cp)
-			ofs+= sprintf(str+ofs, "| Val: %3d ", cp[0]);
+	
+	glDisable(GL_BLEND);
+	if (channels==1) {
 		if (fp)
-			ofs+= sprintf(str+ofs, "| Val: %.4f ", fp[0]);
+			glColor3f(fp[0], fp[0], fp[0]);
+		else if (cp)
+			glColor3ub(cp[0], cp[0], cp[0]);
+		else
+			glColor3ub(0, 0, 0);
 	}
-	else if(channels==3) {
-		if(cp)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list