Skip to content

Commit

Permalink
Make histogram depends on image window not layout window.
Browse files Browse the repository at this point in the history
It simplifies the code, and make more sense.
  • Loading branch information
Laurent Monin committed Apr 22, 2008
1 parent 360f7fc commit 5a18e80
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 35 deletions.
42 changes: 14 additions & 28 deletions src/image-overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}


Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions src/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5a18e80

Please sign in to comment.