Skip to content

Commit

Permalink
Add grid to bar histogram, simplify the code and draw horizontal line…
Browse files Browse the repository at this point in the history
…s too.
  • Loading branch information
Laurent Monin committed Feb 21, 2009
1 parent 6b0883b commit 0f103e1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
48 changes: 47 additions & 1 deletion src/histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ struct _HistMap {
struct _Histogram {
gint histogram_chan;
gint histogram_logmode;
};
guint histogram_vgrid; /* number of vertical divisions, 0 for none */
guint histogram_hgrid; /* number of horizontal divisions, 0 for none */

};

Histogram *histogram_new(void)
{
Expand All @@ -51,6 +53,8 @@ Histogram *histogram_new(void)
histogram = g_new0(Histogram, 1);
histogram->histogram_chan = options->histogram.last_channel_mode;
histogram->histogram_logmode = options->histogram.last_log_mode;
histogram->histogram_vgrid = 5;
histogram->histogram_hgrid = 3;

return histogram;
}
Expand Down Expand Up @@ -166,6 +170,44 @@ const HistMap *histmap_get(FileData *fd)
return NULL;
}

static void histogram_vgrid(Histogram *histogram, GdkPixbuf *pixbuf, gint x, gint y, gint width, gint height)
{
static gint c = 160;
static gint alpha = 250;
guint i;
float add;

if (histogram->histogram_vgrid == 0) return;

add = width / (float)histogram->histogram_vgrid;

for (i = 1; i < histogram->histogram_vgrid; i++)
{
gint xpos = x + (int)(i * add + 0.5);

pixbuf_draw_line(pixbuf, x, y, width, height, xpos, y, xpos, y + height, c, c, c, alpha);
}
}

static void histogram_hgrid(Histogram *histogram, GdkPixbuf *pixbuf, gint x, gint y, gint width, gint height)
{
static gint c = 160;
static gint alpha = 250;
guint i;
float add;

if (histogram->histogram_hgrid == 0) return;

add = height / (float)histogram->histogram_hgrid;

for (i = 1; i < histogram->histogram_hgrid; i++)
{
gint ypos = y + (int)(i * add + 0.5);

pixbuf_draw_line(pixbuf, x, y, width, height, x, ypos, x + width, ypos, c, c, c, alpha);
}
}

gint histogram_draw(Histogram *histogram, const HistMap *histmap, GdkPixbuf *pixbuf, gint x, gint y, gint width, gint height)
{
/* FIXME: use the coordinates correctly */
Expand All @@ -174,6 +216,10 @@ gint histogram_draw(Histogram *histogram, const HistMap *histmap, GdkPixbuf *pix
gdouble logmax;

if (!histogram || !histmap) return 0;

/* Draw the grid */
histogram_vgrid(histogram, pixbuf, x, y, width, height);
histogram_hgrid(histogram, pixbuf, x, y, width, height);

for (i = 0; i < 1024; i++) {
#if 0
Expand Down
15 changes: 1 addition & 14 deletions src/image-overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,21 +640,8 @@ static GdkPixbuf *image_osd_info_render(OverlayStateData *osd)
gint x = 5;
gint y = height - HISTOGRAM_HEIGHT - 5;
gint w = width - 10;
float xoffset = 0;
gint subdiv = 5;
gint c = 160;
gint alpha = 250;
gint i;
float add = w / (float)subdiv;

for (i = 0; i < subdiv; i++)
{
gint d = (i > 0 ? 0 : 1);

pixbuf_set_rect(pixbuf, x + xoffset + 0.5, y, add + d + 0.5, HISTOGRAM_HEIGHT, c, c, c, alpha, d, 1, 1, 1);
xoffset += add+d;
}

pixbuf_set_rect_fill(pixbuf, x, y, w, HISTOGRAM_HEIGHT, 220, 220, 220, 210);
histogram_draw(osd->histogram, histmap, pixbuf, x, y, w, HISTOGRAM_HEIGHT);
}
pixbuf_draw_layout(pixbuf, layout, imd->pr, 5, 5, 0, 0, 0, 255);
Expand Down

0 comments on commit 0f103e1

Please sign in to comment.