[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [52178] trunk/blender/source/blender/ blenkernel/intern/colortools.c: Bugfix #33159

Ton Roosendaal ton at blender.org
Tue Nov 13 13:55:09 CET 2012


Revision: 52178
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=52178
Author:   ton
Date:     2012-11-13 12:55:09 +0000 (Tue, 13 Nov 2012)
Log Message:
-----------
Bugfix #33159

Histogram in Blender was nearly useless - it just didnt work, showed
confusing blank results.

Two reasons for it:
- It was including Alpha in the weighted total value
  (RGB images have alpha 255 for all pixels)
- It was counting the a total weight value max(R, G, B, A), instead of
  using max(R) and max(G) etc.

Now it all draws much nicer - similar to Da Gimp! :)

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/colortools.c

Modified: trunk/blender/source/blender/blenkernel/intern/colortools.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/colortools.c	2012-11-13 12:07:15 UTC (rev 52177)
+++ trunk/blender/source/blender/blenkernel/intern/colortools.c	2012-11-13 12:55:09 UTC (rev 52178)
@@ -1008,8 +1008,8 @@
                    const ColorManagedDisplaySettings *display_settings)
 {
 	int x, y, c;
-	unsigned int n, nl;
-	double div, divl;
+	unsigned int nl, na, nr, ng, nb;
+	double divl, diva, divr, divg, divb;
 	float *rf = NULL;
 	unsigned char *rc = NULL;
 	unsigned int *bin_lum, *bin_r, *bin_g, *bin_b, *bin_a;
@@ -1149,24 +1149,36 @@
 			savedlines += 1;
 	}
 
+	/* test for nicer distribution even - non standard, leave it out for a while
+	for (x = 0; x < 256; x++) {
+		bin_lum[x] = sqrt (bin_lum[x]);
+		bin_r[x] = sqrt(bin_r[x]);
+		bin_g[x] = sqrt(bin_g[x]);
+		bin_b[x] = sqrt(bin_b[x]);
+		bin_a[x] = sqrt(bin_a[x]);
+	}
+	*/
+	
 	/* convert hist data to float (proportional to max count) */
-	n = 0;
-	nl = 0;
+	nl = na = nr = nb = ng = 0;
 	for (x = 0; x < 256; 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];
+		if (bin_r[x]   > nr) nr = bin_r[x];
+		if (bin_g[x]   > ng) ng = bin_g[x];
+		if (bin_b[x]   > nb) nb = bin_b[x];
+		if (bin_a[x]   > na) na = bin_a[x];
 	}
-	div = 1.0 / (double)n;
 	divl = 1.0 / (double)nl;
+	diva = 1.0 / (double)na;
+	divr = 1.0 / (double)nr;
+	divg = 1.0 / (double)ng;
+	divb = 1.0 / (double)nb;
 	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_a[x] = bin_a[x] * div;
+		scopes->hist.data_r[x] = bin_r[x] * divr;
+		scopes->hist.data_g[x] = bin_g[x] * divg;
+		scopes->hist.data_b[x] = bin_b[x] * divb;
+		scopes->hist.data_a[x] = bin_a[x] * diva;
 	}
 	MEM_freeN(bin_lum);
 	MEM_freeN(bin_r);




More information about the Bf-blender-cvs mailing list