Simplify usage of set_page_num and get_page_total
[geeqie.git] / src / histogram.cc
index 395527d..e8aa293 100644 (file)
  * 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];
@@ -46,7 +51,7 @@ struct _HistMap {
 };
 
 
-Histogram *histogram_new(void)
+Histogram *histogram_new()
 {
        Histogram *histogram;
 
@@ -113,7 +118,7 @@ const gchar *histogram_label(Histogram *histogram)
 {
        const gchar *t1 = "";
 
-       if (!histogram) return NULL;
+       if (!histogram) return nullptr;
 
        if (histogram->histogram_mode)
                switch (histogram->histogram_channel)
@@ -136,9 +141,9 @@ const gchar *histogram_label(Histogram *histogram)
        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;
 }
 
@@ -152,7 +157,14 @@ void histmap_free(HistMap *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;
 
@@ -199,22 +211,22 @@ const HistMap *histmap_get(FileData *fd)
 {
        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)
@@ -225,7 +237,7 @@ 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;
 }
 
@@ -237,11 +249,11 @@ static void histogram_vgrid(Histogram *histogram, GdkPixbuf *pixbuf, gint x, gin
 
        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,
@@ -258,11 +270,11 @@ static void histogram_hgrid(Histogram *histogram, GdkPixbuf *pixbuf, gint x, gin
 
        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,
@@ -369,9 +381,9 @@ gboolean histogram_draw(Histogram *histogram, const HistMap *histmap, GdkPixbuf
                                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,
@@ -386,13 +398,13 @@ gboolean histogram_draw(Histogram *histogram, const HistMap *histmap, GdkPixbuf
        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;
                }
 }