Skip to content

Commit

Permalink
Move overlay histogram stuff from ImageWindow to OverlayStateData.
Browse files Browse the repository at this point in the history
It simplifies things a lot and make more sense.

Note: overlay icons display is broken since a long time it seems.
  • Loading branch information
Laurent Monin committed May 9, 2008
1 parent 46a015d commit c93ee03
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 46 deletions.
85 changes: 48 additions & 37 deletions src/image-overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "image-overlay.h"

#include "collect.h"
#include "debug.h"
#include "exif.h"
#include "filedata.h"
#include "image.h"
Expand All @@ -36,6 +37,8 @@ struct _OverlayStateData {
ImageWindow *imd;
ImageState changed_states;

Histogram *histogram;

OsdShowFlags show;

gint ovl_info;
Expand Down Expand Up @@ -112,57 +115,50 @@ static void image_set_osd_data(ImageWindow *imd, OverlayStateData *osd)
*/


static void image_osd_histogram_onoff_toggle(ImageWindow *imd, gint x)
{
imd->histogram_enabled = !!(x);
if (imd->histogram_enabled && !imd->histogram)
imd->histogram = histogram_new();
}

static gint image_osd_histogram_onoff_status(ImageWindow *imd)
{
return imd->histogram_enabled;
}

void image_osd_histogram_chan_toggle(ImageWindow *imd)
{
if (!imd->histogram) return;
OverlayStateData *osd = image_get_osd_data(imd);

if (!osd || !osd->histogram) return;

histogram_set_channel(imd->histogram, (histogram_get_channel(imd->histogram) +1)%HCHAN_COUNT);
histogram_set_channel(osd->histogram, (histogram_get_channel(osd->histogram) +1)%HCHAN_COUNT);
image_osd_update(imd);
}

void image_osd_histogram_log_toggle(ImageWindow *imd)
{
if (!imd->histogram) return;
OverlayStateData *osd = image_get_osd_data(imd);

if (!osd || !osd->histogram) return;

histogram_set_mode(imd->histogram, !histogram_get_mode(imd->histogram));
histogram_set_mode(osd->histogram, !histogram_get_mode(osd->histogram));
image_osd_update(imd);
}

void image_osd_toggle(ImageWindow *imd)
{
OsdShowFlags show;
OverlayStateData *osd;

if (image_osd_get(imd, &show) && (show & OSD_SHOW_INFO))
if (!imd) return;

osd = image_get_osd_data(imd);
if (!osd)
{
if (image_osd_histogram_onoff_status(imd))
image_osd_set(imd, OSD_SHOW_INFO | OSD_SHOW_STATUS);
return;
}

if (osd->show != OSD_SHOW_NOTHING)
{
if (osd->show & OSD_SHOW_HISTOGRAM)
{
image_osd_histogram_onoff_toggle(imd, 0);
image_osd_update(imd);
image_osd_set(imd, OSD_SHOW_NOTHING);
}
else
{
image_osd_set(imd, OSD_SHOW_NOTHING);
image_osd_set(imd, osd->show | OSD_SHOW_HISTOGRAM);
}
}
else
{
image_osd_set(imd, OSD_SHOW_INFO | OSD_SHOW_STATUS);
image_osd_icon(imd, IMAGE_OSD_ICON, -1);
image_osd_histogram_onoff_toggle(imd, 1);
image_osd_update(imd);
}
}

static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *vars)
Expand Down Expand Up @@ -268,7 +264,7 @@ static gchar *image_osd_mkinfo(const gchar *str, ImageWindow *imd, GHashTable *v
return ret;
}

static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
{
GdkPixbuf *pixbuf = NULL;
gint width, height;
Expand All @@ -286,6 +282,7 @@ static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
gchar *ct;
gint w, h;
GHashTable *vars;
ImageWindow *imd = osd->imd;

vars = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);

Expand Down Expand Up @@ -360,7 +357,7 @@ static GdkPixbuf *image_osd_info_render(ImageWindow *imd)
imgpixbuf = (PIXBUF_RENDERER(imd->pr))->pixbuf;
}

if (imgpixbuf && imd->histogram_enabled && imd->histogram
if (imgpixbuf && (osd->show & OSD_SHOW_HISTOGRAM) && osd->histogram
&& (!imd->il || imd->il->done))
with_hist=1;

Expand Down Expand Up @@ -425,7 +422,7 @@ static GdkPixbuf *image_osd_info_render(ImageWindow *imd)

if (with_hist)
{
gchar *escaped_histogram_label = g_markup_escape_text(histogram_label(imd->histogram), -1);
gchar *escaped_histogram_label = g_markup_escape_text(histogram_label(osd->histogram), -1);
if (*text)
text2 = g_strdup_printf("%s\n%s", text, escaped_histogram_label);
else
Expand All @@ -452,7 +449,7 @@ static GdkPixbuf *image_osd_info_render(ImageWindow *imd)

if (with_hist)
{
histogram_read(imd->histogram, imgpixbuf);
histogram_read(osd->histogram, imgpixbuf);
if (width < 266) width = 266;
height += HISTOGRAM_HEIGHT + 5;
}
Expand All @@ -471,7 +468,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(imd->histogram, pixbuf, 5, height - HISTOGRAM_HEIGHT - 5 , width - 10, HISTOGRAM_HEIGHT);
histogram_draw(osd->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 Expand Up @@ -577,7 +574,7 @@ static gint image_osd_update_cb(gpointer data)
{
GdkPixbuf *pixbuf;

pixbuf = image_osd_info_render(osd->imd);
pixbuf = image_osd_info_render(osd);
if (pixbuf)
{
if (osd->ovl_info == 0)
Expand Down Expand Up @@ -760,15 +757,16 @@ static void image_osd_free(OverlayStateData *osd)
}
}

if (osd->histogram) histogram_free(osd->histogram);

g_free(osd);
}

static void image_osd_remove(ImageWindow *imd)
{
OverlayStateData *osd = image_get_osd_data(imd);

g_assert(osd);
image_osd_free(osd);
if (osd) image_osd_free(osd);
}

static void image_osd_destroy_cb(GtkWidget *widget, gpointer data)
Expand All @@ -789,6 +787,8 @@ static void image_osd_enable(ImageWindow *imd, OsdShowFlags show)
osd->imd = imd;
osd->idle_id = -1;
osd->timer_id = -1;
osd->show = OSD_SHOW_NOTHING;
osd->histogram = NULL;

osd->destroy_id = g_signal_connect(G_OBJECT(imd->pr), "destroy",
G_CALLBACK(image_osd_destroy_cb), osd);
Expand All @@ -797,6 +797,17 @@ static void image_osd_enable(ImageWindow *imd, OsdShowFlags show)
image_set_state_func(osd->imd, image_osd_state_cb, osd);
}

if (show & OSD_SHOW_HISTOGRAM)
osd->histogram = histogram_new();
else if (osd->histogram)
{
histogram_free(osd->histogram);
osd->histogram = NULL;
}

if (show & OSD_SHOW_STATUS)
image_osd_icon(imd, IMAGE_OSD_ICON, -1);

if (show != osd->show)
image_osd_update_schedule(osd, TRUE);

Expand Down
5 changes: 0 additions & 5 deletions src/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -1940,9 +1940,6 @@ static void image_free(ImageWindow *imd)
file_data_unref(imd->image_fd);
g_free(imd->title);
g_free(imd->title_right);

if (imd->histogram) histogram_free(imd->histogram);

g_free(imd);
}

Expand Down Expand Up @@ -2064,8 +2061,6 @@ 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/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,6 @@ 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

0 comments on commit c93ee03

Please sign in to comment.