Clean up histogram stuff: options saving/restoring, osd histogram separation, tidy up.
authorLaurent Monin <geeqie@norz.org>
Thu, 26 Feb 2009 20:50:36 +0000 (20:50 +0000)
committerLaurent Monin <geeqie@norz.org>
Thu, 26 Feb 2009 20:50:36 +0000 (20:50 +0000)
src/bar_histogram.c
src/histogram.c
src/image-overlay.c
src/options.c
src/options.h
src/rcfile.c
src/typedefs.h

index 39e75ac..fa91fd2 100644 (file)
@@ -40,8 +40,6 @@ struct _PaneHistogramData
        Histogram *histogram;
        gint histogram_width;
        gint histogram_height;
-       gint histogram_channel;
-       gint histogram_logmode;
        GdkPixbuf *pixbuf;
        FileData *fd;
 };
@@ -91,8 +89,8 @@ static void bar_pane_histogram_write_config(GtkWidget *pane, GString *outstr, gi
        indent++;
        WRITE_CHAR(*phd, pane.title);
        WRITE_BOOL(*phd, pane.expanded);
-       WRITE_INT(*phd, histogram_channel);
-       WRITE_INT(*phd, histogram_logmode);
+       WRITE_INT(*phd->histogram, histogram_channel);
+       WRITE_INT(*phd->histogram, histogram_mode);
        indent--;
        WRITE_STRING("/>\n");
 }
@@ -167,7 +165,6 @@ static void bar_pane_histogram_popup_channels_cb(GtkWidget *widget, gpointer dat
        if (channel == histogram_get_channel(phd->histogram)) return;
 
        histogram_set_channel(phd->histogram, channel);
-       phd->histogram_channel = channel;
        bar_pane_histogram_update(phd);
 }
 
@@ -186,7 +183,6 @@ static void bar_pane_histogram_popup_logmode_cb(GtkWidget *widget, gpointer data
        if (logmode == histogram_get_mode(phd->histogram)) return;
 
        histogram_set_mode(phd->histogram, logmode);
-       phd->histogram_logmode = logmode;
        bar_pane_histogram_update(phd);
 }
 
@@ -294,7 +290,7 @@ static gboolean bar_pane_histogram_press_cb(GtkWidget *widget, GdkEventButton *b
 }
 
 
-GtkWidget *bar_pane_histogram_new(const gchar *title, gint height, gint expanded, gint histogram_channel, gint histogram_logmode)
+GtkWidget *bar_pane_histogram_new(const gchar *title, gint height, gint expanded, gint histogram_channel, gint histogram_mode)
 {
        PaneHistogramData *phd;
 
@@ -308,7 +304,7 @@ GtkWidget *bar_pane_histogram_new(const gchar *title, gint height, gint expanded
        phd->histogram = histogram_new();
 
        histogram_set_channel(phd->histogram, histogram_channel);
-       histogram_set_mode(phd->histogram, histogram_logmode);
+       histogram_set_mode(phd->histogram, histogram_mode);
 
        phd->widget = gtk_vbox_new(FALSE, PREF_PAD_GAP);
 
@@ -345,7 +341,7 @@ GtkWidget *bar_pane_histogram_new_from_config(const gchar **attribute_names, con
        gboolean expanded = TRUE;
        gint height = 80;
        gint histogram_channel = HCHAN_RGB;
-       gint histogram_logmode = 0;
+       gint histogram_mode = 0;
 
        while (*attribute_names)
                {
@@ -355,13 +351,13 @@ GtkWidget *bar_pane_histogram_new_from_config(const gchar **attribute_names, con
                if (READ_CHAR_FULL("pane.title", title)) continue;
                if (READ_BOOL_FULL("pane.expanded", expanded)) continue;
                if (READ_INT_FULL("histogram_channel", histogram_channel)) continue;
-               if (READ_INT_FULL("histogram_logmode", histogram_logmode)) continue;
+               if (READ_INT_FULL("histogram_mode", histogram_mode)) continue;
 
                
                DEBUG_1("unknown attribute %s = %s", option, value);
                }
        
-       return bar_pane_histogram_new(title, height, expanded, histogram_channel, histogram_logmode);
+       return bar_pane_histogram_new(title, height, expanded, histogram_channel, histogram_mode);
 }
 
 
index cc19d37..e48e31e 100644 (file)
@@ -32,27 +32,14 @@ struct _HistMap {
        gulong max[HISTMAP_SIZE];
 };
 
-struct _Histogram {
-       gint channel_mode; /* drawing mode for histogram */
-       gint log_mode;     /* logarithmical or not */
-       guint vgrid; /* number of vertical divisions, 0 for none */
-       guint hgrid; /* number of horizontal divisions, 0 for none */
-       struct {
-               int R; /* red */
-               int G; /* green */
-               int B; /* blue */
-               int A; /* alpha */
-       } grid_color;  /* grid color */
-
-};
 
 Histogram *histogram_new(void)
 {
        Histogram *histogram;
 
        histogram = g_new0(Histogram, 1);
-       histogram->channel_mode = options->histogram.last_channel_mode;
-       histogram->log_mode = options->histogram.last_log_mode;
+       histogram->histogram_channel = HCHAN_RGB;
+       histogram->histogram_mode = 0;
 
        /* grid */
        histogram->vgrid = 5;
@@ -74,27 +61,27 @@ void histogram_free(Histogram *histogram)
 gint histogram_set_channel(Histogram *histogram, gint chan)
 {
        if (!histogram) return 0;
-       options->histogram.last_channel_mode = histogram->channel_mode = chan;
+       histogram->histogram_channel = chan;
        return chan;
 }
 
 gint histogram_get_channel(Histogram *histogram)
 {
        if (!histogram) return 0;
-       return histogram->channel_mode;
+       return histogram->histogram_channel;
 }
 
 gint histogram_set_mode(Histogram *histogram, gint mode)
 {
        if (!histogram) return 0;
-       options->histogram.last_log_mode = histogram->log_mode = mode;
+       histogram->histogram_mode = mode;
        return mode;
 }
 
 gint histogram_get_mode(Histogram *histogram)
 {
        if (!histogram) return 0;
-       return histogram->log_mode;
+       return histogram->histogram_mode;
 }
 
 gint histogram_toggle_channel(Histogram *histogram)
@@ -115,8 +102,8 @@ const gchar *histogram_label(Histogram *histogram)
        
        if (!histogram) return NULL;
 
-       if (histogram->log_mode)
-               switch (histogram->channel_mode)
+       if (histogram->histogram_mode)
+               switch (histogram->histogram_channel)
                        {
                        case HCHAN_R:   t1 = _("logarithmical histogram on red"); break;
                        case HCHAN_G:   t1 = _("logarithmical histogram on green"); break;
@@ -125,7 +112,7 @@ const gchar *histogram_label(Histogram *histogram)
                        case HCHAN_MAX: t1 = _("logarithmical histogram on max value"); break;
                        }
        else
-               switch (histogram->channel_mode)
+               switch (histogram->histogram_channel)
                        {
                        case HCHAN_R:   t1 = _("linear histogram on red"); break;
                        case HCHAN_G:   t1 = _("linear histogram on green"); break;
@@ -277,15 +264,13 @@ gint histogram_draw(Histogram *histogram, const HistMap *histmap, GdkPixbuf *pix
                
                for (j = 0; j < 4; j++)
                        {
-                       gint k;
-                       gint chanmax = 0;
+                       gint chanmax = HCHAN_R;
                
-                       for (k = 1; k < 3; k++)
-                               if (v[k] > v[chanmax])
-                                       chanmax = k;
+                       if (v[HCHAN_G] > v[HCHAN_R]) chanmax = HCHAN_G;
+                       if (v[HCHAN_B] > v[HCHAN_G]) chanmax = HCHAN_B;
                                
-                       if (histogram->channel_mode >= HCHAN_RGB
-                           || chanmax == histogram->channel_mode)
+                       if (histogram->histogram_channel >= HCHAN_RGB
+                           || chanmax == histogram->histogram_channel)
                                {
                                gulong pt;
                                gint r = rplus;
@@ -294,28 +279,28 @@ gint histogram_draw(Histogram *histogram, const HistMap *histmap, GdkPixbuf *pix
 
                                switch (chanmax)
                                        {
-                                       case 0: rplus = r = 255; break;
-                                       case 1: gplus = g = 255; break;
-                                       case 2: bplus = b = 255; break;
+                                       case HCHAN_R: rplus = r = 255; break;
+                                       case HCHAN_G: gplus = g = 255; break;
+                                       case HCHAN_B: bplus = b = 255; break;
                                        }
 
-                               switch (histogram->channel_mode)
+                               switch (histogram->histogram_channel)
                                        {
                                        case HCHAN_RGB:
                                                if (r == 255 && g == 255 && b == 255)
                                                        {
-                                                       r = 0; b = 0; g = 0;
+                                                       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;
+                                       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)
                                        pt = 0;
-                               else if (histogram->log_mode)
+                               else if (histogram->histogram_mode)
                                        pt = ((gdouble)log(v[chanmax])) / logmax * (height - 1);
                                else
                                        pt = ((gdouble)v[chanmax]) / max * (height - 1);
index b404fa6..f2cd3c5 100644 (file)
@@ -131,6 +131,7 @@ void image_osd_histogram_chan_toggle(ImageWindow *imd)
        if (!osd || !osd->histogram) return;
 
        histogram_toggle_channel(osd->histogram);
+       options->image_overlay.common.histogram_channel = histogram_get_channel(osd->histogram);
        image_osd_update(imd);
 }
 
@@ -141,6 +142,7 @@ void image_osd_histogram_log_toggle(ImageWindow *imd)
        if (!osd || !osd->histogram) return;
 
        histogram_toggle_mode(osd->histogram);
+       options->image_overlay.common.histogram_mode = histogram_get_mode(osd->histogram);
        image_osd_update(imd);
 }
 
@@ -1020,7 +1022,11 @@ static void image_osd_enable(ImageWindow *imd, OsdShowFlags show)
                }
 
        if (show & OSD_SHOW_HISTOGRAM)
+               {
                osd->histogram = histogram_new();
+               histogram_set_channel(osd->histogram, options->image_overlay.common.histogram_channel);
+               histogram_set_mode(osd->histogram, options->image_overlay.common.histogram_mode);
+               }
        else if (osd->histogram)
                {
                histogram_free(osd->histogram);
index c442a61..bf29c91 100644 (file)
@@ -59,8 +59,8 @@ ConfOptions *init_options(ConfOptions *options)
        options->fullscreen.disable_saver = TRUE;
        options->fullscreen.screen = -1;
 
-       options->histogram.last_channel_mode = HCHAN_RGB;
-       options->histogram.last_log_mode = 1;
+       options->image_overlay.common.histogram_channel = HCHAN_RGB;
+       options->image_overlay.common.histogram_mode = 1;
        
        memset(&options->image.border_color, 0, sizeof(options->image.border_color));
        options->image.dither_quality = GDK_RGB_DITHER_NORMAL;
index 4ac6572..6db0921 100644 (file)
@@ -138,12 +138,6 @@ struct _ConfOptions
                gboolean above;
        } fullscreen;
 
-       /* histogram */
-       struct {
-               guint last_channel_mode;
-               guint last_log_mode;
-       } histogram;
-       
        /* image overlay */
        struct {
                struct {
@@ -152,6 +146,8 @@ struct _ConfOptions
                        gchar *template_string;
                        gint x;
                        gint y;
+                       gint histogram_channel;
+                       gint histogram_mode;
                } common;
        } image_overlay;
 
index 0310d5b..a8d368a 100644 (file)
@@ -371,15 +371,12 @@ static void write_global_attributes(GString *outstr, gint indent)
        WRITE_BOOL(*options, fullscreen.above);
 
 
-//     WRITE_SUBTITLE("Histogram Options");
-       WRITE_UINT(*options, histogram.last_channel_mode);
-       WRITE_UINT(*options, histogram.last_log_mode);
-
-
 //     WRITE_SUBTITLE("Image Overlay Options");
        WRITE_UINT(*options, image_overlay.common.state);
        WRITE_BOOL(*options, image_overlay.common.show_at_startup);
        WRITE_CHAR(*options, image_overlay.common.template_string);
+       WRITE_INT(*options, image_overlay.common.histogram_channel);
+       WRITE_INT(*options, image_overlay.common.histogram_mode);
        WRITE_SEPARATOR();
 
 //     g_string_append_printf(outstr, "# these are relative positions:\n");
@@ -674,14 +671,12 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
                if (READ_BOOL(*options, fullscreen.disable_saver)) continue;
                if (READ_BOOL(*options, fullscreen.above)) continue;
 
-               /* histogram */
-               if (READ_UINT(*options, histogram.last_channel_mode)) continue;
-               if (READ_UINT(*options, histogram.last_log_mode)) continue;
-
                /* image overlay */
                if (READ_UINT(*options, image_overlay.common.state)) continue;
                if (READ_BOOL(*options, image_overlay.common.show_at_startup)) continue;
                if (READ_CHAR(*options, image_overlay.common.template_string)) continue;
+               if (READ_INT(*options, image_overlay.common.histogram_channel)) continue;
+               if (READ_INT(*options, image_overlay.common.histogram_mode)) continue;
 
                if (READ_INT(*options, image_overlay.common.x)) continue;
                if (READ_INT(*options, image_overlay.common.y)) continue;
index 27d1933..80f4366 100644 (file)
@@ -211,6 +211,21 @@ typedef struct _EditorDescription EditorDescription;
 
 typedef struct _CommandLine CommandLine;
 
+struct _Histogram {
+       gint histogram_channel; /* drawing mode for histogram */
+       gint histogram_mode;     /* logarithmical or not */
+       guint vgrid; /* number of vertical divisions, 0 for none */
+       guint hgrid; /* number of horizontal divisions, 0 for none */
+       struct {
+               int R; /* red */
+               int G; /* green */
+               int B; /* blue */
+               int A; /* alpha */
+       } grid_color;  /* grid color */
+
+};
+
+
 struct _EditorDescription {
        gchar *key;             /* desktop file name, not including path, including extension */
        gchar *name;            /* Name, localized name presented to user */