Revision: 1406
          http://geeqie.svn.sourceforge.net/geeqie/?rev=1406&view=rev
Author:   zas_
Date:     2009-02-22 17:40:32 +0000 (Sun, 22 Feb 2009)

Log Message:
-----------
Fix and simplify histogram code, drop histogram based on mean value.

Modified Paths:
--------------
    trunk/src/histogram.c
    trunk/src/histogram.h

Modified: trunk/src/histogram.c
===================================================================
--- trunk/src/histogram.c       2009-02-22 15:35:37 UTC (rev 1405)
+++ trunk/src/histogram.c       2009-02-22 17:40:32 UTC (rev 1406)
@@ -29,7 +29,6 @@
        gulong r[HISTMAP_SIZE];
        gulong g[HISTMAP_SIZE];
        gulong b[HISTMAP_SIZE];
-       gulong avg[HISTMAP_SIZE];
        gulong max[HISTMAP_SIZE];
 };
 
@@ -110,7 +109,6 @@
                        case HCHAN_R:   t1 = _("logarithmical histogram on 
red"); break;
                        case HCHAN_G:   t1 = _("logarithmical histogram on 
green"); break;
                        case HCHAN_B:   t1 = _("logarithmical histogram on 
blue"); break;
-                       case HCHAN_VAL: t1 = _("logarithmical histogram on 
value"); break;
                        case HCHAN_RGB: t1 = _("logarithmical histogram on 
RGB"); break;
                        case HCHAN_MAX: t1 = _("logarithmical histogram on max 
value"); break;
                        }
@@ -120,7 +118,6 @@
                        case HCHAN_R:   t1 = _("linear histogram on red"); 
break;
                        case HCHAN_G:   t1 = _("linear histogram on green"); 
break;
                        case HCHAN_B:   t1 = _("linear histogram on blue"); 
break;
-                       case HCHAN_VAL: t1 = _("linear histogram on value"); 
break;
                        case HCHAN_RGB: t1 = _("linear histogram on RGB"); 
break;
                        case HCHAN_MAX: t1 = _("linear histogram on max 
value"); break;
                        }
@@ -131,7 +128,6 @@
 {
        gint w, h, i, j, srs, has_alpha, step;
        guchar *s_pix;
-
        HistMap *histmap;
        
        w = gdk_pixbuf_get_width(imgpixbuf);
@@ -148,17 +144,15 @@
                guchar *sp = s_pix + (i * srs); /* 8bit */
                for (j = 0; j < w; j++)
                        {
-                       guint avg = (sp[0] + sp[1] + sp[2]) / 3;
                        guint max = sp[0];
                        if (sp[1] > max) max = sp[1];
                        if (sp[2] > max) max = sp[2];
-       
+               
                        histmap->r[sp[0]]++;
                        histmap->g[sp[1]]++;
                        histmap->b[sp[2]]++;
-                       histmap->avg[avg]++;
                        histmap->max[max]++;
-                       
+
                        sp += step;
                        }
                }
@@ -170,7 +164,7 @@
 {
        if (fd->histmap) return fd->histmap;
        
-       if (fd->pixbuf) 
+       if (fd->pixbuf)
                {
                fd->histmap = histmap_read(fd->pixbuf);
                return fd->histmap;
@@ -228,31 +222,25 @@
        gdouble logmax;
        gint combine = (HISTMAP_SIZE - 1) / width + 1;
        gint ypos = y + height;
-
+       
        if (!histogram || !histmap) return 0;
        
        /* Draw the grid */
        histogram_vgrid(histogram, pixbuf, x, y, width, height);
        histogram_hgrid(histogram, pixbuf, x, y, width, height);
 
-       switch (histogram->channel_mode)
+       for (i = 0; i < HISTMAP_SIZE; i++)
                {
-               case HCHAN_VAL:
-               case HCHAN_MAX:
-               case HCHAN_RGB:
-                       for (i = 0; i < HISTMAP_SIZE; 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];
-                               }
-                       break;
-               case HCHAN_R: for (i = 0; i < HISTMAP_SIZE; i++) if 
(histmap->r[i] > max) max = histmap->r[i]; break;
-               case HCHAN_G: for (i = 0; i < HISTMAP_SIZE; i++) if 
(histmap->g[i] > max) max = histmap->g[i]; break;
-               case HCHAN_B: for (i = 0; i < HISTMAP_SIZE; i++) if 
(histmap->b[i] > max) max = histmap->b[i]; break;
+               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];
                }
 
-       logmax = log(max);
+       if (max > 0)
+               logmax = log(max);
+       else
+               logmax = 1.0;
+
        for (i = 0; i < width; i++)
                {
                gint j;
@@ -269,23 +257,20 @@
                        v[0] += histmap->r[p];
                        v[1] += histmap->g[p];
                        v[2] += histmap->b[p];
-                       if (histogram->channel_mode == HCHAN_VAL)
-                               {
-                               v[3] += histmap->avg[p];
-                               }
-                       else
-                               {
-                               v[3] += histmap->max[p];
-                               }
+                       v[3] += histmap->max[p];
                        }
-
+       
+               for (j = 0; combine > 1 && j < 4; j++)
+                       v[j] /= combine;
+               
                for (j = 0; j < 4; j++)
                        {
                        gint k;
                        gint chanmax = 0;
                
-                       for (k = 1; k < 4; k++)
-                               if (v[k] > v[chanmax]) chanmax = k;
+                       for (k = 1; k < 3; k++)
+                               if (v[k] > v[chanmax])
+                                       chanmax = k;
                                
                        if (histogram->channel_mode >= HCHAN_RGB
                            || chanmax == histogram->channel_mode)
@@ -310,11 +295,10 @@
                                                        r = 0; b = 0; g = 0;
                                                        }
                                                break;
-                                       case HCHAN_R:          b = 0; g = 0; 
break;
-                                       case HCHAN_G:   r = 0; b = 0;        
break;
-                                       case HCHAN_B:   r = 0;        g = 0; 
break;
-                                       case HCHAN_MAX:
-                                       case HCHAN_VAL: r = 0; b = 0; g = 0; 
break;
+                                       case HCHAN_R:     b = 0; g = 0; break;
+                                       case HCHAN_G:   r = 0; b = 0;   break;
+                                       case HCHAN_B:   r = 0;  g = 0; break;
+                                       case HCHAN_MAX: r = 0; b = 0; g = 0; 
break;
                                        }
                                
                                if (v[chanmax] == 0)

Modified: trunk/src/histogram.h
===================================================================
--- trunk/src/histogram.h       2009-02-22 15:35:37 UTC (rev 1405)
+++ trunk/src/histogram.h       2009-02-22 17:40:32 UTC (rev 1406)
@@ -18,8 +18,7 @@
 #define HCHAN_G 1
 #define HCHAN_B 2
 #define HCHAN_RGB 3
-#define HCHAN_VAL 4
-#define HCHAN_MAX 5
+#define HCHAN_MAX 4
 #define HCHAN_COUNT (HCHAN_MAX+1)
 
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Geeqie-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geeqie-svn

Reply via email to