* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "main.h"
#include "histogram.h"
-#include "pixbuf-util.h"
-#include "filedata.h"
+#include <cmath>
-#include <math.h>
+#include <glib-object.h>
+
+#include "debug.h"
+#include "filedata.h"
+#include "intl.h"
+#include "pixbuf-util.h"
/*
*----------------------------------------------------------------------------
*----------------------------------------------------------------------------
*/
-#define HISTMAP_SIZE 256
+enum {
+ HISTMAP_SIZE = 256
+};
-struct _HistMap {
+struct HistMap {
gulong r[HISTMAP_SIZE];
gulong g[HISTMAP_SIZE];
gulong b[HISTMAP_SIZE];
};
-Histogram *histogram_new(void)
+Histogram *histogram_new()
{
Histogram *histogram;
{
const gchar *t1 = "";
- if (!histogram) return NULL;
+ if (!histogram) return nullptr;
if (histogram->histogram_mode)
switch (histogram->histogram_channel)
return t1;
}
-static HistMap *histmap_new(void)
+static HistMap *histmap_new()
{
- HistMap *histmap = g_new0(HistMap, 1);
+ auto histmap = g_new0(HistMap, 1);
return histmap;
}
static gboolean histmap_read(HistMap *histmap, gboolean whole)
{
- gint w, h, i, j, srs, has_alpha, step, end_line;
+ gint w;
+ gint h;
+ gint i;
+ gint j;
+ gint srs;
+ gint has_alpha;
+ gint step;
+ gint end_line;
guchar *s_pix;
GdkPixbuf *imgpixbuf = histmap->pixbuf;
{
if (fd->histmap && !fd->histmap->idle_id) return fd->histmap; /* histmap exists and is finished */
- return NULL;
+ return nullptr;
}
static gboolean histmap_idle_cb(gpointer data)
{
- FileData *fd = (FileData *)data;
+ auto fd = static_cast<FileData *>(data);
if (histmap_read(fd->histmap, FALSE))
{
/* finished */
g_object_unref(fd->histmap->pixbuf); /*pixbuf is no longer needed */
- fd->histmap->pixbuf = NULL;
+ fd->histmap->pixbuf = nullptr;
fd->histmap->idle_id = 0;
file_data_send_notification(fd, NOTIFY_HISTMAP);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
- return TRUE;
+ return G_SOURCE_CONTINUE;
}
gboolean histmap_start_idle(FileData *fd)
fd->histmap->pixbuf = fd->pixbuf;
g_object_ref(fd->histmap->pixbuf);
- fd->histmap->idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, histmap_idle_cb, fd, NULL);
+ fd->histmap->idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, histmap_idle_cb, fd, nullptr);
return TRUE;
}
if (histogram->vgrid == 0) return;
- add = width / (float)histogram->vgrid;
+ add = width / static_cast<float>(histogram->vgrid);
for (i = 1; i < histogram->vgrid; i++)
{
- gint xpos = x + (int)(i * add + 0.5);
+ gint xpos = x + static_cast<int>(i * add + 0.5);
pixbuf_draw_line(pixbuf, x, y, width, height, xpos, y, xpos, y + height,
histogram->grid_color.R,
if (histogram->hgrid == 0) return;
- add = height / (float)histogram->hgrid;
+ add = height / static_cast<float>(histogram->hgrid);
for (i = 1; i < histogram->hgrid; i++)
{
- gint ypos = y + (int)(i * add + 0.5);
+ gint ypos = y + static_cast<int>(i * add + 0.5);
pixbuf_draw_line(pixbuf, x, y, width, height, x, ypos, x + width, ypos,
histogram->grid_color.R,
if (v[chanmax] == 0)
pt = 0;
else if (histogram->histogram_mode)
- pt = ((gdouble)log(v[chanmax])) / logmax * (height - 1);
+ pt = (static_cast<gdouble>(log(v[chanmax]))) / logmax * (height - 1);
else
- pt = ((gdouble)v[chanmax]) / max * (height - 1);
+ pt = (static_cast<gdouble>(v[chanmax])) / max * (height - 1);
pixbuf_draw_line(pixbuf,
x, y, width, height,
return TRUE;
}
-void histogram_notify_cb(FileData *fd, NotifyType type, gpointer UNUSED(data))
+void histogram_notify_cb(FileData *fd, NotifyType type, gpointer)
{
if ((type & NOTIFY_REREAD) && fd->histmap)
{
DEBUG_1("Notify histogram: %s %04x", fd->path, type);
histmap_free(fd->histmap);
- fd->histmap = NULL;
+ fd->histmap = nullptr;
}
}