fixed histogram drawing
authorVladimir Nadvornik <nadvornik@suse.cz>
Thu, 26 Mar 2009 07:56:01 +0000 (07:56 +0000)
committerVladimir Nadvornik <nadvornik@suse.cz>
Thu, 26 Mar 2009 07:56:01 +0000 (07:56 +0000)
src/histogram.c
src/histogram.h

index 8f65376..a8d3449 100644 (file)
@@ -280,11 +280,13 @@ gboolean histogram_draw(Histogram *histogram, const HistMap *histmap, GdkPixbuf
        histogram_vgrid(histogram, pixbuf, x, y, width, height);
        histogram_hgrid(histogram, pixbuf, x, y, width, height);
 
-       for (i = 0; i < HISTMAP_SIZE; i++)
+       /* exclude overexposed and underexposed */
+       for (i = 1; i < HISTMAP_SIZE - 1; i++)
                {
                if (histmap->r[i] > max) max = histmap->r[i];
                if (histmap->g[i] > max) max = histmap->g[i];
                if (histmap->b[i] > max) max = histmap->b[i];
+               if (histmap->max[i] > max) max = histmap->max[i];
                }
 
        if (max > 0)
@@ -301,6 +303,7 @@ gboolean histogram_draw(Histogram *histogram, const HistMap *histmap, GdkPixbuf
                gint bplus = 0;
                gint ii = i * HISTMAP_SIZE / width;
                gint xpos = x + i;
+               gint num_chan;
 
                for (j = 0; j < combine; j++)
                        {
@@ -314,15 +317,21 @@ gboolean histogram_draw(Histogram *histogram, const HistMap *histmap, GdkPixbuf
                for (j = 0; combine > 1 && j < 4; j++)
                        v[j] /= combine;
                
-               for (j = 0; j < 4; j++)
+               num_chan = (histogram->histogram_channel == HCHAN_RGB) ? 3 : 1;
+               for (j = 0; j < num_chan; j++)
                        {
-                       gint chanmax = HCHAN_R;
-               
-                       if (v[HCHAN_G] > v[HCHAN_R]) chanmax = HCHAN_G;
-                       if (v[HCHAN_B] > v[HCHAN_G]) chanmax = HCHAN_B;
-                               
-                       if (histogram->histogram_channel >= HCHAN_RGB
-                           || chanmax == histogram->histogram_channel)
+                       gint chanmax;
+                       if (histogram->histogram_channel == HCHAN_RGB) 
+                               {
+                               chanmax = HCHAN_R;
+                               if (v[HCHAN_G] > v[HCHAN_R]) chanmax = HCHAN_G;
+                               if (v[HCHAN_B] > v[chanmax]) chanmax = HCHAN_B;
+                               }
+                       else
+                               {
+                               chanmax = histogram->histogram_channel;
+                               }
+                       
                                {
                                gulong pt;
                                gint r = rplus;
index 991367b..2d89028 100644 (file)
@@ -17,9 +17,9 @@
 #define HCHAN_R 0
 #define HCHAN_G 1
 #define HCHAN_B 2
-#define HCHAN_RGB 3
-#define HCHAN_MAX 4
-#define HCHAN_COUNT (HCHAN_MAX+1)
+#define HCHAN_MAX 3
+#define HCHAN_RGB 4
+#define HCHAN_COUNT 5
 
 
 Histogram *histogram_new(void);