clang-tidy: modernize-use-nullptr
[geeqie.git] / src / color-man.cc
index 01e822f..5efea3d 100644 (file)
 #include "main.h"
 #include "color-man.h"
 
+#include "filedata.h"
 #include "image.h"
 #include "ui-fileops.h"
 
+#include <vector>
 
 #ifdef HAVE_LCMS
 /*** color support enabled ***/
@@ -290,13 +292,16 @@ static ColorManCache *color_man_cache_get(ColorManProfileType in_type, const gch
  *-------------------------------------------------------------------
  */
 
-//static void color_man_done(ColorMan *cm, ColorManReturnType type)
-//{
-       //if (cm->func_done)
-               //{
-               //cm->func_done(cm, type, cm->func_done_data);
-               //}
-//}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+static void color_man_done_unused(ColorMan *cm, ColorManReturnType type)
+{
+       if (cm->func_done)
+               {
+               cm->func_done(cm, type, cm->func_done_data);
+               }
+}
+#pragma GCC diagnostic pop
 
 void color_man_correct_region(ColorMan *cm, GdkPixbuf *pixbuf, gint x, gint y, gint w, gint h)
 {
@@ -334,44 +339,47 @@ void color_man_correct_region(ColorMan *cm, GdkPixbuf *pixbuf, gint x, gint y, g
 
 }
 
-//static gboolean color_man_idle_cb(gpointer data)
-//{
-       //ColorMan *cm = static_cast<ColorMan *>(data);
-       //gint width, height;
-       //gint rh;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+static gboolean color_man_idle_cb_unused(gpointer data)
+{
+       ColorMan *cm = static_cast<ColorMan *>(data);
+       gint width, height;
+       gint rh;
 
-       //if (!cm->pixbuf) return FALSE;
+       if (!cm->pixbuf) return FALSE;
 
-       //if (cm->imd &&
-           //cm->pixbuf != image_get_pixbuf(cm->imd))
-               //{
-               //cm->idle_id = 0;
-               //color_man_done(cm, COLOR_RETURN_IMAGE_CHANGED);
-               //return FALSE;
-               //}
+       if (cm->imd &&
+           cm->pixbuf != image_get_pixbuf(cm->imd))
+               {
+               cm->idle_id = 0;
+               color_man_done_unused(cm, COLOR_RETURN_IMAGE_CHANGED);
+               return FALSE;
+               }
 
-       //width = gdk_pixbuf_get_width(cm->pixbuf);
-       //height = gdk_pixbuf_get_height(cm->pixbuf);
+       width = gdk_pixbuf_get_width(cm->pixbuf);
+       height = gdk_pixbuf_get_height(cm->pixbuf);
 
-       //if (cm->row > height)
-               //{
-               //if (!cm->incremental_sync && cm->imd)
-                       //{
-                       //image_area_changed(cm->imd, 0, 0, width, height);
-                       //}
+       if (cm->row > height)
+               {
+               if (!cm->incremental_sync && cm->imd)
+                       {
+                       image_area_changed(cm->imd, 0, 0, width, height);
+                       }
 
-               //cm->idle_id = 0;
-               //color_man_done(cm, COLOR_RETURN_SUCCESS);
-               //return FALSE;
-               //}
+               cm->idle_id = 0;
+               color_man_done_unused(cm, COLOR_RETURN_SUCCESS);
+               return FALSE;
+               }
 
-       //rh = COLOR_MAN_CHUNK_SIZE / width + 1;
-       //color_man_correct_region(cm, cm->pixbuf, 0, cm->row, width, rh);
-       //if (cm->incremental_sync && cm->imd) image_area_changed(cm->imd, 0, cm->row, width, rh);
-       //cm->row += rh;
+       rh = COLOR_MAN_CHUNK_SIZE / width + 1;
+       color_man_correct_region(cm, cm->pixbuf, 0, cm->row, width, rh);
+       if (cm->incremental_sync && cm->imd) image_area_changed(cm->imd, 0, cm->row, width, rh);
+       cm->row += rh;
 
-       //return TRUE;
-//}
+       return TRUE;
+}
+#pragma GCC diagnostic pop
 
 static ColorMan *color_man_new_real(ImageWindow *imd, GdkPixbuf *pixbuf,
                                    ColorManProfileType input_type, const gchar *input_file,
@@ -412,12 +420,15 @@ ColorMan *color_man_new(ImageWindow *imd, GdkPixbuf *pixbuf,
                                  screen_type, screen_file, screen_data, screen_data_len);
 }
 
-//void color_man_start_bg(ColorMan *cm, ColorManDoneFunc done_func, gpointer done_data)
-//{
-       //cm->func_done = done_func;
-       //cm->func_done_data = done_data;
-       //cm->idle_id = g_idle_add(color_man_idle_cb, cm);
-//}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+void color_man_start_bg_unused(ColorMan *cm, ColorMan::DoneFunc done_func, gpointer done_data)
+{
+       cm->func_done = done_func;
+       cm->func_done_data = done_data;
+       cm->idle_id = g_idle_add(color_man_idle_cb_unused, cm);
+}
+#pragma GCC diagnostic pop
 
 ColorMan *color_man_new_embedded(ImageWindow *imd, GdkPixbuf *pixbuf,
                                 guchar *input_data, guint input_data_len,
@@ -490,23 +501,21 @@ void color_man_update()
 }
 
 #ifdef HAVE_HEIF
+#include <cmath>
 #include <libheif/heif.h>
-#include <math.h>
 
 static cmsToneCurve* colorspaces_create_transfer(int32_t size, double (*fct)(double))
 {
-       auto values = static_cast<float *>(g_malloc(sizeof(float) * size));
-
+       std::vector<float> values;
+       values.reserve(size);
        for(int32_t i = 0; i < size; ++i)
                {
                const double x = static_cast<float>(i) / (size - 1);
                const double y = MIN(fct(x), 1.0f);
-               values[i] = static_cast<float>(y);
+               values.push_back(static_cast<float>(y));
                }
 
-       cmsToneCurve* result = cmsBuildTabulatedToneCurveFloat(nullptr, size, values);
-       g_free(values);
-       return result;
+       return cmsBuildTabulatedToneCurveFloat(nullptr, size, values.data());
 }
 
 // https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.2100-2-201807-I!!PDF-F.pdf
@@ -799,7 +808,7 @@ guchar *heif_color_profile(FileData *fd, guint *profile_len)
        return profile;
 }
 #else
-guchar *heif_color_profile(FileData *UNUSED(fd), guint *UNUSED(profile_len))
+guchar *heif_color_profile(FileData *, guint *)
 {
        return NULL;
 }
@@ -809,25 +818,25 @@ guchar *heif_color_profile(FileData *UNUSED(fd), guint *UNUSED(profile_len))
 /*** color support not enabled ***/
 
 
-ColorMan *color_man_new(ImageWindow *UNUSED(imd), GdkPixbuf *UNUSED(pixbuf),
-                       ColorManProfileType UNUSED(input_type), const gchar *UNUSED(input_file),
-                       ColorManProfileType UNUSED(screen_type), const gchar *UNUSED(screen_file),
-                       guchar *UNUSED(screen_data), guint UNUSED(screen_data_len))
+ColorMan *color_man_new(ImageWindow *, GdkPixbuf *,
+                       ColorManProfileType, const gchar *,
+                       ColorManProfileType, const gchar *,
+                       guchar *, guint)
 {
        /* no op */
        return nullptr;
 }
 
-ColorMan *color_man_new_embedded(ImageWindow *UNUSED(imd), GdkPixbuf *UNUSED(pixbuf),
-                                guchar *UNUSED(input_data), guint UNUSED(input_data_len),
-                                ColorManProfileType UNUSED(screen_type), const gchar *UNUSED(screen_file),
-                                guchar *UNUSED(screen_data), guint UNUSED(screen_data_len))
+ColorMan *color_man_new_embedded(ImageWindow *, GdkPixbuf *,
+                                guchar *, guint,
+                                ColorManProfileType, const gchar *,
+                                guchar *, guint)
 {
        /* no op */
        return nullptr;
 }
 
-void color_man_free(ColorMan *UNUSED(cm))
+void color_man_free(ColorMan *)
 {
        /* no op */
 }
@@ -837,17 +846,17 @@ void color_man_update()
        /* no op */
 }
 
-void color_man_correct_region(ColorMan *UNUSED(cm), GdkPixbuf *UNUSED(pixbuf), gint UNUSED(x), gint UNUSED(y), gint UNUSED(w), gint UNUSED(h))
+void color_man_correct_region(ColorMan *, GdkPixbuf *, gint, gint, gint, gint)
 {
        /* no op */
 }
 
-gboolean color_man_get_status(ColorMan *UNUSED(cm), gchar **UNUSED(image_profile), gchar **UNUSED(screen_profile))
+gboolean color_man_get_status(ColorMan *, gchar **, gchar **)
 {
        return FALSE;
 }
 
-guchar *heif_color_profile(FileData *UNUSED(fd), guint *UNUSED(profile_len))
+guchar *heif_color_profile(FileData *, guint *)
 {
        return nullptr;
 }