Simplify usage of set_page_num and get_page_total
[geeqie.git] / src / color-man.cc
index 16005ff..f73080c 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "color-man.h"
 
-#include "image.h"
-#include "ui-fileops.h"
+#include <config.h>
 
+#if HAVE_LCMS
+/*** color support enabled ***/
+
+#include <cstdint>
+#include <cstring>
 #include <vector>
 
-#ifdef HAVE_LCMS
-/*** color support enabled ***/
+#include <glib-object.h>
 
-#ifdef HAVE_LCMS2
-#include <lcms2.h>
+#if HAVE_LCMS2
+#  include <lcms2.h>
 #else
-#include <lcms.h>
+#  include <lcms.h>
 #endif
 
+#include "debug.h"
+#include "filedata.h"
+#include "image.h"
+#include "intl.h"
+#include "options.h"
+#include "ui-fileops.h"
 
 struct ColorManCache {
        cmsHPROFILE   profile_in;
@@ -64,7 +72,7 @@ static void color_man_lib_init()
        if (init_done) return;
        init_done = TRUE;
 
-#ifndef HAVE_LCMS2
+#if !HAVE_LCMS2
        cmsErrorAction(LCMS_ERROR_IGNORE);
 #endif
 }
@@ -72,7 +80,7 @@ static void color_man_lib_init()
 static cmsHPROFILE color_man_create_adobe_comp()
 {
        /* ClayRGB1998 is AdobeRGB compatible */
-#include "ClayRGB1998_icc.h"
+#include "ClayRGB1998_icc.h" // IWYU pragma: keep
        return cmsOpenProfileFromMem(ClayRGB1998_icc, ClayRGB1998_icc_len);
 }
 
@@ -308,7 +316,8 @@ void color_man_correct_region(ColorMan *cm, GdkPixbuf *pixbuf, gint x, gint y, g
        guchar *pix;
        gint rs;
        gint i;
-       gint pixbuf_width, pixbuf_height;
+       gint pixbuf_width;
+       gint pixbuf_height;
 
 
        pixbuf_width = gdk_pixbuf_get_width(pixbuf);
@@ -342,8 +351,9 @@ void color_man_correct_region(ColorMan *cm, GdkPixbuf *pixbuf, gint x, gint y, g
 #pragma GCC diagnostic ignored "-Wunused-function"
 static gboolean color_man_idle_cb_unused(gpointer data)
 {
-       ColorMan *cm = static_cast<ColorMan *>(data);
-       gint width, height;
+       auto *cm = static_cast<ColorMan *>(data);
+       gint width;
+       gint height;
        gint rh;
 
        if (!cm->pixbuf) return FALSE;
@@ -421,7 +431,7 @@ ColorMan *color_man_new(ImageWindow *imd, GdkPixbuf *pixbuf,
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wunused-function"
-void color_man_start_bg_unused(ColorMan *cm, ColorManDoneFunc done_func, gpointer done_data)
+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;
@@ -452,7 +462,7 @@ static gchar *color_man_get_profile_name(ColorManProfileType type, cmsHPROFILE p
                case COLOR_PROFILE_FILE:
                        if (profile)
                                {
-#ifdef HAVE_LCMS2
+#if HAVE_LCMS2
                                char buffer[20];
                                buffer[0] = '\0';
                                cmsGetProfileInfoASCII(profile, cmsInfoDescription, "en", "US", buffer, 20);
@@ -499,7 +509,7 @@ void color_man_update()
        color_man_cache_reset();
 }
 
-#ifdef HAVE_HEIF
+#if HAVE_HEIF
 #include <cmath>
 #include <libheif/heif.h>
 
@@ -510,7 +520,7 @@ static cmsToneCurve* colorspaces_create_transfer(int32_t size, double (*fct)(dou
        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);
+               const double y = MIN(fct(x), 1.0F);
                values.push_back(static_cast<float>(y));
                }
 
@@ -604,19 +614,19 @@ static guchar *nclx_to_lcms_profile(const struct heif_color_profile_nclx *nclx,
 
        whitepoint.x = nclx->color_primary_white_x;
        whitepoint.y = nclx->color_primary_white_y;
-       whitepoint.Y = 1.0f;
+       whitepoint.Y = 1.0F;
 
        primaries.Red.x = nclx->color_primary_red_x;
        primaries.Red.y = nclx->color_primary_red_y;
-       primaries.Red.Y = 1.0f;
+       primaries.Red.Y = 1.0F;
 
        primaries.Green.x = nclx->color_primary_green_x;
        primaries.Green.y = nclx->color_primary_green_y;
-       primaries.Green.Y = 1.0f;
+       primaries.Green.Y = 1.0F;
 
        primaries.Blue.x = nclx->color_primary_blue_x;
        primaries.Blue.y = nclx->color_primary_blue_y;
-       primaries.Blue.Y = 1.0f;
+       primaries.Blue.Y = 1.0F;
 
        switch (nclx->color_primaries)
                {
@@ -670,19 +680,19 @@ static guchar *nclx_to_lcms_profile(const struct heif_color_profile_nclx *nclx,
                        trc_name = "Rec709 RGB";
                        break;
                case heif_transfer_characteristic_ITU_R_BT_470_6_System_M:
-                       curve[0] = curve[1] = curve[2] = cmsBuildGamma (nullptr, 2.2f);
+                       curve[0] = curve[1] = curve[2] = cmsBuildGamma (nullptr, 2.2F);
                        profile = static_cast<cmsHPROFILE *>(cmsCreateRGBProfile(&whitepoint, &primaries, curve));
                        cmsFreeToneCurve(curve[0]);
                        trc_name = "Gamma2.2 RGB";
                        break;
                case heif_transfer_characteristic_ITU_R_BT_470_6_System_B_G:
-                       curve[0] = curve[1] = curve[2] = cmsBuildGamma (nullptr, 2.8f);
+                       curve[0] = curve[1] = curve[2] = cmsBuildGamma (nullptr, 2.8F);
                        profile = static_cast<cmsHPROFILE *>(cmsCreateRGBProfile(&whitepoint, &primaries, curve));
                        cmsFreeToneCurve(curve[0]);
                        trc_name = "Gamma2.8 RGB";
                        break;
                case heif_transfer_characteristic_linear:
-                       curve[0] = curve[1] = curve[2] = cmsBuildGamma (nullptr, 1.0f);
+                       curve[0] = curve[1] = curve[2] = cmsBuildGamma (nullptr, 1.0F);
                        profile = static_cast<cmsHPROFILE *>(cmsCreateRGBProfile(&whitepoint, &primaries, curve));
                        cmsFreeToneCurve(curve[0]);
                        trc_name = "linear RGB";
@@ -723,16 +733,12 @@ static guchar *nclx_to_lcms_profile(const struct heif_color_profile_nclx *nclx,
                        cmsCloseProfile(profile);
                        return static_cast<guchar *>(data);
                        }
-               else
-                       {
-                       cmsCloseProfile(profile);
-                       return nullptr;
-                       }
-               }
-       else
-               {
+
+               cmsCloseProfile(profile);
                return nullptr;
                }
+
+       return nullptr;
 }
 
 guchar *heif_color_profile(FileData *fd, guint *profile_len)
@@ -787,20 +793,18 @@ guchar *heif_color_profile(FileData *fd, guint *profile_len)
 
                return static_cast<guchar *>(data);
                }
-       else
-               {
-               error_code = heif_image_handle_get_nclx_color_profile(handle, &nclxcp);
-               if (error_code.code)
-                       {
-                       log_printf("warning: heif reader error: %s\n", error_code.message);
-                       heif_context_free(ctx);
-                       heif_nclx_color_profile_free(nclxcp);
-                       return nullptr;
-                       }
 
-               profile = nclx_to_lcms_profile(nclxcp, profile_len);
+       error_code = heif_image_handle_get_nclx_color_profile(handle, &nclxcp);
+       if (error_code.code)
+               {
+               log_printf("warning: heif reader error: %s\n", error_code.message);
+               heif_context_free(ctx);
+               heif_nclx_color_profile_free(nclxcp);
+               return nullptr;
                }
 
+       profile = nclx_to_lcms_profile(nclxcp, profile_len);
+
        heif_context_free(ctx);
        heif_nclx_color_profile_free(nclxcp);