Make histogram depends on image window not layout window.
authorLaurent Monin <geeqie@norz.org>
Tue, 22 Apr 2008 08:34:30 +0000 (08:34 +0000)
committerLaurent Monin <geeqie@norz.org>
Tue, 22 Apr 2008 08:34:30 +0000 (08:34 +0000)
It simplifies the code, and make more sense.

src/image-overlay.c
src/image.c
src/layout.c
src/typedefs.h

index 51b5e39..d76a43c 100644 (file)
@@ -90,40 +90,28 @@ void set_default_image_overlay_template_string(ConfOptions *options)
  */
 
 
-#define HIST_PREPARE(imd, lw)                          \
-       LayoutWindow *lw = NULL;                        \
-       if (imd)                                        \
-              lw = layout_find_by_image(imd);
-
 void image_osd_histogram_onoff_toggle(ImageWindow *imd, gint x)
 {
-       HIST_PREPARE(imd, lw)
-       if (lw)
-               {
-               lw->histogram_enabled = !!(x);
-               if (lw->histogram_enabled && !lw->histogram)
-                       lw->histogram = histogram_new();
-               }
+       imd->histogram_enabled = !!(x);
+       if (imd->histogram_enabled && !imd->histogram)
+               imd->histogram = histogram_new();
 }
 
 gint image_osd_histogram_onoff_status(ImageWindow *imd)
 {
-       HIST_PREPARE(imd, lw)
-       return lw ?  lw->histogram_enabled : FALSE;
+      return imd->histogram_enabled;
 }
 
 void image_osd_histogram_chan_toggle(ImageWindow *imd)
 {
-       HIST_PREPARE(imd, lw)
-       if (lw && lw->histogram)
-              histogram_set_channel(lw->histogram, (histogram_get_channel(lw->histogram) +1)%HCHAN_COUNT);
+       if (imd->histogram)
+               histogram_set_channel(imd->histogram, (histogram_get_channel(imd->histogram) +1)%HCHAN_COUNT);
 }
 
 void image_osd_histogram_log_toggle(ImageWindow *imd)
 {
-       HIST_PREPARE(imd,lw)
-       if (lw && lw->histogram)
-              histogram_set_mode(lw->histogram, !histogram_get_mode(lw->histogram));
+       if (imd->histogram)
+               histogram_set_mode(imd->histogram, !histogram_get_mode(imd->histogram));
 }
 
 
@@ -317,10 +305,8 @@ static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
                        pixbuf_renderer_get_image_size(PIXBUF_RENDERER(imd->pr), &w, &h);
                        imgpixbuf = (PIXBUF_RENDERER(imd->pr))->pixbuf;
                        }
-               if (!lw)
-                       lw = layout_find_by_image(imd);
-
-               if (imgpixbuf && lw && lw->histogram && lw->histogram_enabled
+       
+               if (imgpixbuf && imd->histogram_enabled && imd->histogram
                              && (!imd->il || imd->il->done))
                        with_hist=1;
 
@@ -387,9 +373,9 @@ static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
                if (with_hist)
                        {
                        if (*text)
-                               text2 = g_strdup_printf("%s\n%s", text, histogram_label(lw->histogram));
+                               text2 = g_strdup_printf("%s\n%s", text, histogram_label(imd->histogram));
                        else
-                               text2 = g_strdup(histogram_label(lw->histogram));
+                               text2 = g_strdup(histogram_label(imd->histogram));
                        g_free(text);
                        text = text2;
                        }
@@ -411,7 +397,7 @@ static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
 
        if (with_hist)
                {
-               histogram_read(lw->histogram, imgpixbuf);
+               histogram_read(imd->histogram, imgpixbuf);
                if (width < 266) width = 266;
                height += HISTOGRAM_HEIGHT + 5;
                }
@@ -430,7 +416,7 @@ static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
                pixbuf_pixel_set(pixbuf, width - 1, height - 1, 0, 0, 0, 0);
 
                if (with_hist)
-                       histogram_draw(lw->histogram, pixbuf, 5, height - HISTOGRAM_HEIGHT - 5 , width - 10, HISTOGRAM_HEIGHT);
+                       histogram_draw(imd->histogram, pixbuf, 5, height - HISTOGRAM_HEIGHT - 5 , width - 10, HISTOGRAM_HEIGHT);
 
                pixbuf_draw_layout(pixbuf, layout, imd->pr, 5, 5, 0, 0, 0, 255);
        }
index da3eb52..1df0f9e 100644 (file)
@@ -19,6 +19,7 @@
 #include "collect.h"
 #include "color-man.h"
 #include "exif.h"
+#include "histogram.h"
 #include "image-overlay.h"
 #include "layout.h"
 #include "layout_image.h"
@@ -1934,6 +1935,8 @@ static void image_free(ImageWindow *imd)
        g_free(imd->title);
        g_free(imd->title_right);
 
+       if (imd->histogram) histogram_free(imd->histogram);
+
        g_free(imd);
 }
 
@@ -2055,6 +2058,8 @@ ImageWindow *image_new(gint frame)
 
        imd->orientation = 1;
 
+       imd->histogram_enabled = FALSE; /* TODO: option */
+
        imd->pr = GTK_WIDGET(pixbuf_renderer_new());
 
        image_options_set(imd);
index f2c0abf..3d1b0d3 100644 (file)
@@ -1859,8 +1859,6 @@ void layout_free(LayoutWindow *lw)
 
        gtk_widget_destroy(lw->window);
 
-       histogram_free(lw->histogram);
-
        g_free(lw->path);
 
        g_free(lw);
@@ -1906,8 +1904,6 @@ LayoutWindow *layout_new_with_geometry(const gchar *path, gint popped, gint hidd
        lw->bar_exif_size = -1;
        lw->bar_exif_advanced = FALSE;
 
-       lw->histogram_enabled = FALSE;
-
        /* default layout */
 
        layout_config_parse(options->layout.style, options->layout.order,
index 77939b4..2e7ff11 100644 (file)
@@ -377,6 +377,10 @@ struct _ImageWindow
        gint color_profile_from_image;
        gpointer cm;
 
+       /* histogram */
+       gint histogram_enabled;
+       Histogram *histogram;
+
        AlterType delay_alter_type;
 
        ImageLoader *read_ahead_il;
@@ -533,9 +537,6 @@ struct _LayoutWindow
        GtkWidget *bar_exif;
        GtkWidget *bar_info;
 
-       gint histogram_enabled;
-       Histogram *histogram;
-
        gint bar_sort_enabled;
        gint bar_exif_enabled;
        gint bar_info_enabled;