[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47674] trunk/blender/source/blender: mango request - add alpha to histogram & sample line.

Campbell Barton ideasman42 at gmail.com
Sun Jun 10 14:33:28 CEST 2012


Revision: 47674
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47674
Author:   campbellbarton
Date:     2012-06-10 12:33:27 +0000 (Sun, 10 Jun 2012)
Log Message:
-----------
mango request - add alpha to histogram & sample line.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/colortools.c
    trunk/blender/source/blender/editors/interface/interface_draw.c
    trunk/blender/source/blender/editors/space_image/image_ops.c
    trunk/blender/source/blender/makesdna/DNA_color_types.h
    trunk/blender/source/blender/makesrna/intern/rna_color.c

Modified: trunk/blender/source/blender/blenkernel/intern/colortools.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/colortools.c	2012-06-10 12:31:07 UTC (rev 47673)
+++ trunk/blender/source/blender/blenkernel/intern/colortools.c	2012-06-10 12:33:27 UTC (rev 47674)
@@ -910,7 +910,7 @@
 	return bin;
 }
 
-DO_INLINE void save_sample_line(Scopes *scopes, const int idx, const float fx, const float rgb[3], const float ycc[3])
+static void save_sample_line(Scopes *scopes, const int idx, const float fx, const float rgb[3], const float ycc[3])
 {
 	float yuv[3];
 
@@ -953,9 +953,9 @@
 	double div, divl;
 	float *rf = NULL;
 	unsigned char *rc = NULL;
-	unsigned int *bin_r, *bin_g, *bin_b, *bin_lum;
+	unsigned int *bin_lum, *bin_r, *bin_g, *bin_b, *bin_a;
 	int savedlines, saveline;
-	float rgb[3], ycc[3], luma;
+	float rgba[4], ycc[3], luma;
 	int ycc_mode = -1;
 	const short is_float = (ibuf->rect_float != NULL);
 
@@ -987,11 +987,12 @@
 			break;
 	}
 
-	/* temp table to count pix value for histo */
-	bin_r = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
-	bin_g = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
-	bin_b = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
-	bin_lum = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
+	/* temp table to count pix value for histogram */
+	bin_r     = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
+	bin_g     = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
+	bin_b     = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
+	bin_a = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
+	bin_lum   = MEM_callocN(256 * sizeof(unsigned int), "temp historgram bins");
 
 	/* convert to number of lines with logarithmic scale */
 	scopes->sample_lines = (scopes->accuracy * 0.01f) * (scopes->accuracy * 0.01f) * ibuf->y;
@@ -1038,27 +1039,28 @@
 
 			if (is_float) {
 				if (use_color_management)
-					linearrgb_to_srgb_v3_v3(rgb, rf);
+					linearrgb_to_srgb_v3_v3(rgba, rf);
 				else
-					copy_v3_v3(rgb, rf);
+					copy_v3_v3(rgba, rf);
+				rgba[3] = rf[3];
 			}
 			else {
-				for (c = 0; c < 3; c++)
-					rgb[c] = rc[c] * INV_255;
+				for (c = 0; c < 4; c++)
+					rgba[c] = rc[c] * INV_255;
 			}
 
 			/* we still need luma for histogram */
-			luma = rgb_to_luma(rgb);
+			luma = rgb_to_luma(rgba);
 
 			/* check for min max */
 			if (ycc_mode == -1) {
 				for (c = 0; c < 3; c++) {
-					if (rgb[c] < scopes->minmax[c][0]) scopes->minmax[c][0] = rgb[c];
-					if (rgb[c] > scopes->minmax[c][1]) scopes->minmax[c][1] = rgb[c];
+					if (rgba[c] < scopes->minmax[c][0]) scopes->minmax[c][0] = rgba[c];
+					if (rgba[c] > scopes->minmax[c][1]) scopes->minmax[c][1] = rgba[c];
 				}
 			}
 			else {
-				rgb_to_ycc(rgb[0], rgb[1], rgb[2], &ycc[0], &ycc[1], &ycc[2], ycc_mode);
+				rgb_to_ycc(rgba[0], rgba[1], rgba[2], &ycc[0], &ycc[1], &ycc[2], ycc_mode);
 				for (c = 0; c < 3; c++) {
 					ycc[c] *= INV_255;
 					if (ycc[c] < scopes->minmax[c][0]) scopes->minmax[c][0] = ycc[c];
@@ -1066,16 +1068,17 @@
 				}
 			}
 			/* increment count for histo*/
-			bin_r[get_bin_float(rgb[0])] += 1;
-			bin_g[get_bin_float(rgb[1])] += 1;
-			bin_b[get_bin_float(rgb[2])] += 1;
 			bin_lum[get_bin_float(luma)] += 1;
+			bin_r[get_bin_float(rgba[0])] += 1;
+			bin_g[get_bin_float(rgba[1])] += 1;
+			bin_b[get_bin_float(rgba[2])] += 1;
+			bin_a[get_bin_float(rgba[3])] += 1;
 
 			/* save sample if needed */
 			if (saveline) {
 				const float fx = (float)x / (float)ibuf->x;
 				const int idx = 2 * (ibuf->x * savedlines + x);
-				save_sample_line(scopes, idx, fx, rgb, ycc);
+				save_sample_line(scopes, idx, fx, rgba, ycc);
 			}
 
 			rf += ibuf->channels;
@@ -1089,27 +1092,26 @@
 	n = 0;
 	nl = 0;
 	for (x = 0; x < 256; x++) {
-		if (bin_r[x] > n)
-			n = bin_r[x];
-		if (bin_g[x] > n)
-			n = bin_g[x];
-		if (bin_b[x] > n)
-			n = bin_b[x];
-		if (bin_lum[x] > nl)
-			nl = bin_lum[x];
+		if (bin_lum[x] > nl) nl = bin_lum[x];
+		if (bin_r[x]   > n) n = bin_r[x];
+		if (bin_g[x]   > n) n = bin_g[x];
+		if (bin_b[x]   > n) n = bin_b[x];
+		if (bin_a[x]   > n) n = bin_a[x];
 	}
 	div = 1.0 / (double)n;
 	divl = 1.0 / (double)nl;
 	for (x = 0; x < 256; x++) {
+		scopes->hist.data_luma[x] = bin_lum[x] * divl;
 		scopes->hist.data_r[x] = bin_r[x] * div;
 		scopes->hist.data_g[x] = bin_g[x] * div;
 		scopes->hist.data_b[x] = bin_b[x] * div;
-		scopes->hist.data_luma[x] = bin_lum[x] * divl;
+		scopes->hist.data_a[x] = bin_a[x] * div;
 	}
+	MEM_freeN(bin_lum);
 	MEM_freeN(bin_r);
 	MEM_freeN(bin_g);
 	MEM_freeN(bin_b);
-	MEM_freeN(bin_lum);
+	MEM_freeN(bin_a);
 
 	scopes->ok = 1;
 }

Modified: trunk/blender/source/blender/editors/interface/interface_draw.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_draw.c	2012-06-10 12:31:07 UTC (rev 47673)
+++ trunk/blender/source/blender/editors/interface/interface_draw.c	2012-06-10 12:33:27 UTC (rev 47674)
@@ -753,8 +753,12 @@
 		fdrawline(rect.xmin + (i / 4.f) * w, rect.ymin, rect.xmin + (i / 4.f) * w, rect.ymax);
 	}
 	
-	if (hist->mode == HISTO_MODE_LUMA)
+	if (hist->mode == HISTO_MODE_LUMA) {
 		histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res, is_line);
+	}
+	else if (hist->mode == HISTO_MODE_ALPHA) {
+		histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_a, res, is_line);
+	}
 	else {
 		if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_R)
 			histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res, is_line);

Modified: trunk/blender/source/blender/editors/space_image/image_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/image_ops.c	2012-06-10 12:31:07 UTC (rev 47673)
+++ trunk/blender/source/blender/editors/space_image/image_ops.c	2012-06-10 12:33:27 UTC (rev 47674)
@@ -2150,7 +2150,7 @@
 		y = (int)(0.5f + y1 + (float)i * (y2 - y1) / 255.0f);
 		
 		if (x < 0 || y < 0 || x >= ibuf->x || y >= ibuf->y) {
-			hist->data_luma[i] = hist->data_r[i] = hist->data_g[i] = hist->data_b[i] = 0.0f;
+			hist->data_luma[i] = hist->data_r[i] = hist->data_g[i] = hist->data_b[i] = hist->data_a[i] = 0.0f;
 		}
 		else {
 			if (ibuf->rect_float) {
@@ -2161,17 +2161,19 @@
 				else
 					copy_v3_v3(rgb, fp);
 
-				hist->data_r[i] = rgb[0];
-				hist->data_g[i] = rgb[1];
-				hist->data_b[i] = rgb[2];
-				hist->data_luma[i] = rgb_to_luma(rgb);
+				hist->data_luma[i]  = rgb_to_luma(rgb);
+				hist->data_r[i]     = rgb[0];
+				hist->data_g[i]     = rgb[1];
+				hist->data_b[i]     = rgb[2];
+				hist->data_a[i]     = fp[3];
 			}
 			else if (ibuf->rect) {
 				cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
-				hist->data_r[i] = (float)cp[0] / 255.0f;
-				hist->data_g[i] = (float)cp[1] / 255.0f;
-				hist->data_b[i] = (float)cp[2] / 255.0f;
-				hist->data_luma[i] = (float)rgb_to_luma_byte(cp) / 255.0f;
+				hist->data_luma[i]  = (float)rgb_to_luma_byte(cp) / 255.0f;
+				hist->data_r[i]     = (float)cp[0] / 255.0f;
+				hist->data_g[i]     = (float)cp[1] / 255.0f;
+				hist->data_b[i]     = (float)cp[2] / 255.0f;
+				hist->data_a[i]     = (float)cp[3] / 255.0f;
 			}
 		}
 	}

Modified: trunk/blender/source/blender/makesdna/DNA_color_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_color_types.h	2012-06-10 12:31:07 UTC (rev 47673)
+++ trunk/blender/source/blender/makesdna/DNA_color_types.h	2012-06-10 12:33:27 UTC (rev 47674)
@@ -96,11 +96,14 @@
 } CurveMappingPreset;
 
 /* histogram->mode */
-#define HISTO_MODE_LUMA	0
-#define HISTO_MODE_RGB	1
-#define HISTO_MODE_R	2
-#define HISTO_MODE_G	3
-#define HISTO_MODE_B	4
+enum {
+	HISTO_MODE_LUMA   = 0,
+	HISTO_MODE_RGB    = 1,
+	HISTO_MODE_R      = 2,
+	HISTO_MODE_G      = 3,
+	HISTO_MODE_B      = 4,
+	HISTO_MODE_ALPHA  = 5
+};
 
 enum {
 	HISTO_FLAG_LINE        = (1 << 0),
@@ -110,17 +113,18 @@
 typedef struct Histogram {
 	int channels;
 	int x_resolution;
+	float data_luma[256];
 	float data_r[256];
 	float data_g[256];
 	float data_b[256];
-	float data_luma[256];
+	float data_a[256];
 	float xmax, ymax;
 	short mode;
 	short flag;
 	int height;
 
 	/* sample line only */
-	/* image coords src -> est */
+	/* image coords src -> dst */
 	float co[2][2];
 } Histogram;
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_color.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_color.c	2012-06-10 12:31:07 UTC (rev 47673)
+++ trunk/blender/source/blender/makesrna/intern/rna_color.c	2012-06-10 12:33:27 UTC (rev 47674)
@@ -575,9 +575,10 @@
 		{HISTO_MODE_R, "R", 0, "R", "Red"},
 		{HISTO_MODE_G, "G", 0, "G", "Green"},
 		{HISTO_MODE_B, "B", 0, "B", "Blue"},
+		{HISTO_MODE_ALPHA, "A", 0, "A", "Alpha"},
 		{0, NULL, 0, NULL, NULL}
 	};
-		
+
 	srna = RNA_def_struct(brna, "Histogram", NULL);
 	RNA_def_struct_ui_text(srna, "Histogram", "Statistical view of the levels of color in an image");
 	




More information about the Bf-blender-cvs mailing list