Author: post
Date: 2010-11-07 19:09:48 +0100 (Sun, 07 Nov 2010)
New Revision: 3603

Modified:
   trunk/librawstudio/rs-curve.c
Log:
Use the third largest histogram value to scale the histogram, and calculate 
height correctly.

Modified: trunk/librawstudio/rs-curve.c
===================================================================
--- trunk/librawstudio/rs-curve.c       2010-11-07 17:01:32 UTC (rev 3602)
+++ trunk/librawstudio/rs-curve.c       2010-11-07 18:09:48 UTC (rev 3603)
@@ -558,8 +558,11 @@
 static void
 rs_curve_draw_background(GtkWidget *widget)
 {
-       gint i, max = 0, x, y;
+       gint i, j, x, y;
+       gint max[3];
 
+       memset(max, 0, 3*sizeof(gint));
+
        /* Width */
        gint width;
 
@@ -596,14 +599,19 @@
                /* Prepare histogram */
                if (curve->histogram_data)
                {
-                       /* find the max value */
-                       /* Except 0 and 255! */
-                       for (i = 1; i < 255; i++)
-                               if (curve->histogram_data[i] > max)
-                                       max = curve->histogram_data[i];
+                       /* find the third largest value */
+                       for (i = 0; i < 256; i++)
+                               for (j = 0; j < 3; j++)
+                                       if (curve->histogram_data[i] > max[j])
+                                       {
+                                               for (x = 2; x >= j; x--)
+                                                       max[x+1] = max[x];
+                                               max[j] = 
curve->histogram_data[i];
+                                               j = 3;
+                                       }
 
                        /* Find height scale factor */
-                       gfloat factor = (gfloat)(max+height)/(gfloat)height;
+                       gfloat factor = (gfloat)height * (1.0f 
/(gfloat)(max[2]));
 
                        /* Find width scale factor */
                        gfloat source, scale = 253.0/width;
@@ -617,8 +625,8 @@
                                weight1 = 1.0 - (source-source1);
                                weight2 = 1.0 - weight1;
 
-                               hist[i] = (curve->histogram_data[1+source1] * 
weight1
-                                       + curve->histogram_data[1+source2] * 
weight2)/factor;
+                               hist[i] = MIN(height-1, 
(curve->histogram_data[1+source1] * weight1
+                                       + curve->histogram_data[1+source2] * 
weight2) * factor);
                        }
 
                        for (x = 0; x < width; x++)


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to