Fix clang-tidy: readability-non-const-parameter (3)
[geeqie.git] / src / pixbuf-util.cc
index e17c45d..c2780e2 100644 (file)
 
 #include "main.h"
 #include "pixbuf-util.h"
+
 #include "exif.h"
+#include "filedata.h"
 #include "ui-fileops.h"
 
-#include "icons/icons_inline.h"
-
-#include <math.h>
+#include <cmath>
 
 
 /*
@@ -37,7 +37,7 @@
 
 gboolean pixbuf_to_file_as_png(GdkPixbuf *pixbuf, const gchar *filename)
 {
-       GError *error = NULL;
+       GError *error = nullptr;
        gboolean ret;
 
        if (!pixbuf || !filename) return FALSE;
@@ -60,33 +60,36 @@ gboolean pixbuf_to_file_as_png(GdkPixbuf *pixbuf, const gchar *filename)
  *-----------------------------------------------------------------------------
  */
 
-//gboolean pixbuf_to_file_as_jpg(GdkPixbuf *pixbuf, const gchar *filename, gint quality)
-//{
-       //GError *error = NULL;
-       //gchar *qbuf;
-       //gboolean ret;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+gboolean pixbuf_to_file_as_jpg_unused(GdkPixbuf *pixbuf, const gchar *filename, gint quality)
+{
+       GError *error = nullptr;
+       gchar *qbuf;
+       gboolean ret;
 
-       //if (!pixbuf || !filename) return FALSE;
+       if (!pixbuf || !filename) return FALSE;
 
-       //if (quality == -1) quality = 75;
-       //if (quality < 1 || quality > 100)
-               //{
-               //log_printf("Jpeg not saved, invalid quality %d\n", quality);
-               //return FALSE;
-               //}
+       if (quality == -1) quality = 75;
+       if (quality < 1 || quality > 100)
+               {
+               log_printf("Jpeg not saved, invalid quality %d\n", quality);
+               return FALSE;
+               }
 
-       //qbuf = g_strdup_printf("%d", quality);
-       //ret = gdk_pixbuf_save(pixbuf, filename, "jpeg", &error, "quality", qbuf, NULL);
-       //g_free(qbuf);
+       qbuf = g_strdup_printf("%d", quality);
+       ret = gdk_pixbuf_save(pixbuf, filename, "jpeg", &error, "quality", qbuf, NULL);
+       g_free(qbuf);
 
-       //if (error)
-               //{
-               //log_printf("Error saving jpeg to %s\n%s\n", filename, error->message);
-               //g_error_free(error);
-               //}
+       if (error)
+               {
+               log_printf("Error saving jpeg to %s\n%s\n", filename, error->message);
+               g_error_free(error);
+               }
 
-       //return ret;
-//}
+       return ret;
+}
+#pragma GCC diagnostic pop
 
 /*
  *-----------------------------------------------------------------------------
@@ -94,89 +97,129 @@ gboolean pixbuf_to_file_as_png(GdkPixbuf *pixbuf, const gchar *filename)
  *-----------------------------------------------------------------------------
  */
 
-typedef struct _PixbufInline PixbufInline;
-struct _PixbufInline
+struct PixbufInline
 {
        const gchar *key;
-       const guint8 *data;
+       const gchar *data;
 };
 
 static PixbufInline inline_pixbuf_data[] = {
-       { PIXBUF_INLINE_FOLDER_CLOSED,  folder_closed },
-       { PIXBUF_INLINE_FOLDER_LOCKED,  folder_locked },
-       { PIXBUF_INLINE_FOLDER_OPEN,    folder_open },
-       { PIXBUF_INLINE_FOLDER_UP,      folder_up },
-       { PIXBUF_INLINE_SCROLLER,       icon_scroller },
-       { PIXBUF_INLINE_BROKEN,         icon_broken },
-       { PIXBUF_INLINE_METADATA,       icon_metadata },
-       { PIXBUF_INLINE_UNKNOWN,        icon_unknown },
-       { PIXBUF_INLINE_VIDEO,          icon_video },
-       { PIXBUF_INLINE_COLLECTION,     icon_collection },
-       { PIXBUF_INLINE_ICON,           gqview_icon },
-       { PIXBUF_INLINE_LOGO,           geeqie_logo },
-       { PIXBUF_INLINE_ARCHIVE,        icon_archive },
-       { PIXBUF_INLINE_ICON_FLOAT,     icon_float },
-       { PIXBUF_INLINE_ICON_THUMB,     icon_thumb },
-       { PIXBUF_INLINE_ICON_BOOK,      icon_book },
-       { PIXBUF_INLINE_ICON_CONFIG,    icon_config },
-       { PIXBUF_INLINE_ICON_TOOLS,     icon_tools },
-       { PIXBUF_INLINE_ICON_VIEW,      icon_view },
-       { PIXBUF_INLINE_ICON_PANORAMA,  icon_panorama },
-       { PIXBUF_INLINE_ICON_MAINTENANCE,       icon_maintenance },
-       { PIXBUF_INLINE_ICON_ZOOMFILLHOR,       icon_zoomfillhor },
-       { PIXBUF_INLINE_ICON_ZOOMFILLVERT,      icon_zoomfillvert },
-       { PIXBUF_INLINE_ICON_HIDETOOLS, icon_hidetools },
-       { PIXBUF_INLINE_ICON_EXIF,      icon_exif },
-       { PIXBUF_INLINE_ICON_MARKS,     icon_marks },
-       { PIXBUF_INLINE_ICON_INFO,      icon_info },
-       { PIXBUF_INLINE_ICON_SORT,      icon_sort },
-       { PIXBUF_INLINE_ICON_PDF,       icon_pdf },
-       { PIXBUF_INLINE_ICON_DRAW_RECTANGLE,    icon_draw_rectangle },
-       { PIXBUF_INLINE_ICON_MOVE,      icon_move },
-       { PIXBUF_INLINE_ICON_RENAME,    icon_rename },
-       { PIXBUF_INLINE_ICON_SELECT_ALL,        icon_select_all },
-       { PIXBUF_INLINE_ICON_SELECT_NONE,       icon_select_none },
-       { PIXBUF_INLINE_ICON_SELECT_INVERT,     icon_select_invert },
-       { PIXBUF_INLINE_ICON_SELECT_RECTANGLE,  icon_select_rectangle },
-       { PIXBUF_INLINE_ICON_FILE_FILTER,       icon_file_filter },
-       { PIXBUF_INLINE_ICON_CW,        icon_rotate_clockwise },
-       { PIXBUF_INLINE_ICON_CCW,       icon_rotate_counter_clockwise },
-       { PIXBUF_INLINE_ICON_180,       icon_rotate_180 },
-       { PIXBUF_INLINE_ICON_MIRROR,    icon_mirror },
-       { PIXBUF_INLINE_ICON_FLIP,      icon_flip },
-       { PIXBUF_INLINE_ICON_ORIGINAL,  icon_original },
-       { PIXBUF_INLINE_ICON_TRASH,     icon_trash },
-       { PIXBUF_INLINE_ICON_HEIF,      icon_heic },
-       { PIXBUF_INLINE_ICON_GRAYSCALE, icon_grayscale },
-       { PIXBUF_INLINE_ICON_EXPOSURE,  icon_exposure },
-       { PIXBUF_INLINE_SPLIT_PANE_SYNC, icon_split_pane_sync },
-       { NULL, NULL }
+       {  PIXBUF_INLINE_ARCHIVE,                "gq-icon-archive-file" },
+       {  PIXBUF_INLINE_BROKEN,                 "gq-icon-broken" },
+       {  PIXBUF_INLINE_COLLECTION,             "gq-icon-collection" },
+       {  PIXBUF_INLINE_ICON_180,               "gq-icon-rotate-180" },
+       {  PIXBUF_INLINE_ICON_BOOK,              "gq-icon-book" },
+       {  PIXBUF_INLINE_ICON_CONFIG,            "gq-icon-config" },
+       {  PIXBUF_INLINE_ICON_DRAW_RECTANGLE,    "gq-icon-draw-rectangle" },
+       {  PIXBUF_INLINE_ICON_EXIF,              "gq-icon-exif" },
+       {  PIXBUF_INLINE_ICON_EXPOSURE,          "gq-icon-exposure" },
+       {  PIXBUF_INLINE_ICON_FLOAT,             "gq-icon-float" },
+       {  PIXBUF_INLINE_ICON,                   "gqview-icon" },
+       {  PIXBUF_INLINE_ICON_GRAYSCALE,         "gq-icon-grayscale" },
+       {  PIXBUF_INLINE_ICON_HEIF,              "gq-icon-heic" },
+       {  PIXBUF_INLINE_ICON_HIDETOOLS,         "gq-icon-hidetools" },
+       {  PIXBUF_INLINE_ICON_MAINTENANCE,       "gq-icon-maintenance" },
+       {  PIXBUF_INLINE_ICON_MARKS,             "gq-icon-marks" },
+       {  PIXBUF_INLINE_ICON_MOVE,              "gq-icon-move" },
+       {  PIXBUF_INLINE_ICON_ORIGINAL,          "gq-icon-original" },
+       {  PIXBUF_INLINE_ICON_PANORAMA,          "gq-icon-panorama" },
+       {  PIXBUF_INLINE_ICON_PDF,               "gq-icon-pdf" },
+       {  PIXBUF_INLINE_ICON_PROPERTIES,        "gq-icon-properties" },
+       {  PIXBUF_INLINE_ICON_RENAME,            "gq-icon-rename" },
+       {  PIXBUF_INLINE_ICON_SELECT_ALL,        "gq-icon-select-all" },
+       {  PIXBUF_INLINE_ICON_SELECT_INVERT,     "gq-icon-select-invert" },
+       {  PIXBUF_INLINE_ICON_SELECT_NONE,       "gq-icon-select-none" },
+       {  PIXBUF_INLINE_ICON_SELECT_RECTANGLE,  "gq-icon-select-rectangle" },
+       {  PIXBUF_INLINE_ICON_SORT,              "gq-icon-sort" },
+       {  PIXBUF_INLINE_ICON_THUMB,             "gq-icon-thumb" },
+       {  PIXBUF_INLINE_ICON_TOOLS,             "gq-icon-tools" },
+       {  PIXBUF_INLINE_ICON_VIEW,              "gq-icon-view" },
+       {  PIXBUF_INLINE_ICON_ZOOMFILLHOR,       "gq-icon-zoomfillhor" },
+       {  PIXBUF_INLINE_ICON_ZOOMFILLVERT,      "gq-icon-zoomfillvert" },
+       {  PIXBUF_INLINE_LOGO,                   "geeqie-logo" },
+       {  PIXBUF_INLINE_METADATA,               "gq-icon-metadata" },
+       {  PIXBUF_INLINE_SCROLLER,               "gq-scroller" },
+       {  PIXBUF_INLINE_SPLIT_PANE_SYNC,        "gq-icon-split-pane-sync" },
+       {  PIXBUF_INLINE_UNKNOWN,                "gq-icon-unknown" },
+       {  PIXBUF_INLINE_VIDEO,                  "gq-icon-video" },
+       {  nullptr,                              nullptr }
 };
 
 GdkPixbuf *pixbuf_inline(const gchar *key)
 {
+       gboolean dark = FALSE;
+       gchar *file_name = nullptr;
+       gchar *path;
+       gchar *theme_name;
+       GdkPixbuf *icon_pixbuf;
+       GError *error = nullptr;
+       GInputStream *in_stream;
        gint i;
+       GtkSettings *settings;
+
+       if (!key) return nullptr;
 
-       if (!key) return NULL;
+       settings = gtk_settings_get_default();
+       g_object_get(settings, "gtk-theme-name", &theme_name, nullptr);
+       dark = g_str_has_suffix(theme_name, "dark");
+       g_free(theme_name);
 
        i = 0;
        while (inline_pixbuf_data[i].key)
                {
                if (strcmp(inline_pixbuf_data[i].key, key) == 0)
                        {
-                       return gdk_pixbuf_new_from_inline(-1, inline_pixbuf_data[i].data, FALSE, NULL);
+                       file_name = g_strconcat(inline_pixbuf_data[i].data, dark ? "-dark" : "", ".png", nullptr);
+                       path = g_build_filename(GQ_RESOURCE_PATH_ICONS, file_name, nullptr);
+                       g_free(file_name);
+
+                       in_stream = g_resources_open_stream(path, G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
+                       g_free(path);
+
+                       if (error)
+                               {
+                               g_error_free(error);
+                               error = nullptr;
+
+                               file_name = g_strconcat(inline_pixbuf_data[i].data, ".png", nullptr);
+                               path = g_build_filename(GQ_RESOURCE_PATH_ICONS, file_name, nullptr);
+                               g_free(file_name);
+
+                               in_stream = g_resources_open_stream(path, G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
+                               g_free(path);
+                               }
+
+                       if (error)
+                               {
+                               log_printf("warning: inline pixbuf error: %s", error->message);
+                               g_error_free(error);
+                               g_object_unref(in_stream);
+                               return nullptr;
+                               }
+
+                       icon_pixbuf = gdk_pixbuf_new_from_stream(in_stream, nullptr, &error);
+                       g_object_unref(in_stream);
+
+                       if (error)
+                               {
+                               log_printf("warning: inline pixbuf error: %s", error->message);
+                               g_error_free(error);
+                               return nullptr;
+                               }
+
+                       return icon_pixbuf;
                        }
                i++;
                }
 
        log_printf("warning: inline pixbuf key \"%s\" not found.\n", key);
 
-       return NULL;
+       return nullptr;
 }
 
 static void register_stock_icon(const gchar *key, GdkPixbuf *pixbuf)
 {
-       static GtkIconFactory *icon_factory = NULL;
+       static GtkIconFactory *icon_factory = nullptr;
        GtkIconSet *icon_set;
 
        if (!icon_factory)
@@ -190,7 +233,7 @@ static void register_stock_icon(const gchar *key, GdkPixbuf *pixbuf)
 }
 
 
-void pixbuf_inline_register_stock_icons(void)
+void pixbuf_inline_register_stock_icons()
 {
        gint i;
 
@@ -206,7 +249,7 @@ gboolean register_theme_icon_as_stock(const gchar *key, const gchar *icon)
 {
        GtkIconTheme *icon_theme;
        GdkPixbuf *pixbuf;
-       GError *error = NULL;
+       GError *error = nullptr;
 
        icon_theme = gtk_icon_theme_get_default();
 
@@ -215,7 +258,7 @@ gboolean register_theme_icon_as_stock(const gchar *key, const gchar *icon)
        pixbuf = gtk_icon_theme_load_icon(icon_theme,
                            icon, /* icon name */
                            64, /* size */
-                           0,  /* flags */
+                           static_cast<GtkIconLookupFlags>(0),  /* flags */
                            &error);
        if (!pixbuf)
                {
@@ -223,7 +266,7 @@ gboolean register_theme_icon_as_stock(const gchar *key, const gchar *icon)
                        {
                        DEBUG_1("Couldn't load icon %s: %s", icon, error->message);
                        g_error_free(error);
-                       error = NULL;
+                       error = nullptr;
                        }
 
                if (strchr(icon, '.'))
@@ -233,13 +276,13 @@ gboolean register_theme_icon_as_stock(const gchar *key, const gchar *icon)
                        pixbuf = gtk_icon_theme_load_icon(icon_theme,
                                           icon2, /* icon name */
                                           64, /* size */
-                                          0,  /* flags */
+                                          static_cast<GtkIconLookupFlags>(0),  /* flags */
                                           &error);
                        if (error)
                                {
                                DEBUG_1("Couldn't load icon %s: %s", icon2, error->message);
                                g_error_free(error);
-                               error = NULL;
+                               error = nullptr;
 
                                /* try as an absolute path */
                                pixbuf = gdk_pixbuf_new_from_file(icon, &error);
@@ -263,16 +306,16 @@ gboolean pixbuf_scale_aspect(gint req_w, gint req_h,
                             gint old_w, gint old_h,
                             gint *new_w, gint *new_h)
 {
-       if (((gdouble)req_w / old_w) < ((gdouble)req_h / old_h))
+       if ((static_cast<gdouble>(req_w) / old_w) < (static_cast<gdouble>(req_h) / old_h))
                {
                *new_w = req_w;
-               *new_h = (gdouble)*new_w / old_w * old_h;
+               *new_h = static_cast<gdouble>(*new_w) / old_w * old_h;
                if (*new_h < 1) *new_h = 1;
                }
        else
                {
                *new_h = req_h;
-               *new_w = (gdouble)*new_h / old_h * old_w;
+               *new_w = static_cast<gdouble>(*new_h) / old_h * old_w;
                if (*new_w < 1) *new_w = 1;
                }
 
@@ -431,7 +474,7 @@ GdkPixbuf *pixbuf_copy_rotate_90(GdkPixbuf *src, gboolean counter_clockwise)
        gint brs;
        gint w, h;
 
-       if (!src) return NULL;
+       if (!src) return nullptr;
 
        sw = gdk_pixbuf_get_width(src);
        sh = gdk_pixbuf_get_height(src);
@@ -527,7 +570,7 @@ GdkPixbuf *pixbuf_copy_mirror(GdkPixbuf *src, gboolean mirror, gboolean flip)
        gint i, j;
        gint a;
 
-       if (!src) return NULL;
+       if (!src) return nullptr;
 
        w = gdk_pixbuf_get_width(src);
        h = gdk_pixbuf_get_height(src);
@@ -582,7 +625,7 @@ GdkPixbuf *pixbuf_copy_mirror(GdkPixbuf *src, gboolean mirror, gboolean flip)
 GdkPixbuf *pixbuf_apply_orientation(GdkPixbuf *pixbuf, gint orientation)
 {
        GdkPixbuf *dest;
-       GdkPixbuf *tmp = NULL;
+       GdkPixbuf *tmp = nullptr;
 
        switch (orientation)
                {
@@ -676,20 +719,23 @@ void pixbuf_draw_rect_fill(GdkPixbuf *pb,
                }
 }
 
-//void pixbuf_draw_rect(GdkPixbuf *pb,
-                     //gint x, gint y, gint w, gint h,
-                     //gint r, gint g, gint b, gint a,
-                     //gint left, gint right, gint top, gint bottom)
-//{
-       //pixbuf_draw_rect_fill(pb, x + left, y, w - left - right, top,
-                             //r, g, b ,a);
-       //pixbuf_draw_rect_fill(pb, x + w - right, y, right, h,
-                             //r, g, b ,a);
-       //pixbuf_draw_rect_fill(pb, x + left, y + h - bottom, w - left - right, bottom,
-                             //r, g, b ,a);
-       //pixbuf_draw_rect_fill(pb, x, y, left, h,
-                             //r, g, b ,a);
-//}
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+void pixbuf_draw_rect_unused(GdkPixbuf *pb,
+                     gint x, gint y, gint w, gint h,
+                     gint r, gint g, gint b, gint a,
+                     gint left, gint right, gint top, gint bottom)
+{
+       pixbuf_draw_rect_fill(pb, x + left, y, w - left - right, top,
+                             r, g, b ,a);
+       pixbuf_draw_rect_fill(pb, x + w - right, y, right, h,
+                             r, g, b ,a);
+       pixbuf_draw_rect_fill(pb, x + left, y + h - bottom, w - left - right, bottom,
+                             r, g, b ,a);
+       pixbuf_draw_rect_fill(pb, x, y, left, h,
+                             r, g, b ,a);
+}
+#pragma GCC diagnostic pop
 
 void pixbuf_set_rect_fill(GdkPixbuf *pb,
                          gint x, gint y, gint w, gint h,
@@ -847,7 +893,7 @@ static void pixbuf_copy_font(GdkPixbuf *src, gint sx, gint sy,
                }
 }
 
-void pixbuf_draw_layout(GdkPixbuf *pixbuf, PangoLayout *layout, GtkWidget *UNUSED(widget),
+void pixbuf_draw_layout(GdkPixbuf *pixbuf, PangoLayout *layout, GtkWidget *,
                        gint x, gint y,
                        guint8 r, guint8 g, guint8 b, guint8 a)
 {
@@ -878,8 +924,8 @@ void pixbuf_draw_layout(GdkPixbuf *pixbuf, PangoLayout *layout, GtkWidget *UNUSE
                                           cairo_image_surface_get_width (source),
                                           cairo_image_surface_get_height (source),
                                           cairo_image_surface_get_stride (source),
-                                          NULL,
-                                          NULL);
+                                          nullptr,
+                                          nullptr);
 
        sx = 0;
        sy = 0;
@@ -998,12 +1044,12 @@ void pixbuf_draw_triangle(GdkPixbuf *pb,
                t = y1; y1 = y2; y2 = t;
                }
 
-       slope1 = (gdouble)(y2 - y1);
-       if (slope1) slope1 = (gdouble)(x2 - x1) / slope1;
+       slope1 = static_cast<gdouble>(y2 - y1);
+       if (slope1) slope1 = static_cast<gdouble>(x2 - x1) / slope1;
        slope1_x = x1;
        slope1_y = y1;
-       slope2 = (gdouble)(y3 - y1);
-       if (slope2) slope2 = (gdouble)(x3 - x1) / slope2;
+       slope2 = static_cast<gdouble>(y3 - y1);
+       if (slope2) slope2 = static_cast<gdouble>(x3 - x1) / slope2;
 
        for (y = fy1; y < fy2; y++)
                {
@@ -1011,16 +1057,16 @@ void pixbuf_draw_triangle(GdkPixbuf *pb,
 
                if (!middle && y > y2)
                        {
-                       slope1 = (gdouble)(y3 - y2);
-                       if (slope1) slope1 = (gdouble)(x3 - x2) / slope1;
+                       slope1 = static_cast<gdouble>(y3 - y2);
+                       if (slope1) slope1 = static_cast<gdouble>(x3 - x2) / slope1;
                        slope1_x = x2;
                        slope1_y = y2;
 
                        middle = TRUE;
                        }
 
-               xa = slope1_x + ((gdouble)slope1 * (y - slope1_y) + 0.5);
-               xb = x1 + ((gdouble)slope2 * (y - y1) + 0.5);
+               xa = slope1_x + (slope1 * (y - slope1_y) + 0.5);
+               xb = x1 + (slope2 * (y - y1) + 0.5);
 
                if (xa > xb)
                        {
@@ -1174,8 +1220,8 @@ void pixbuf_draw_line(GdkPixbuf *pb,
        if (!util_clip_region(0, 0, pw, ph,
                              clip_x, clip_y, clip_w, clip_h,
                              &rx, &ry, &rw, &rh)) return;
-       if (!util_clip_line((gdouble)rx, (gdouble)ry, (gdouble)rw, (gdouble)rh,
-                           (gdouble)x1, (gdouble)y1, (gdouble)x2, (gdouble)y2,
+       if (!util_clip_line(static_cast<gdouble>(rx), static_cast<gdouble>(ry), static_cast<gdouble>(rw), static_cast<gdouble>(rh),
+                           static_cast<gdouble>(x1), static_cast<gdouble>(y1), static_cast<gdouble>(x2), static_cast<gdouble>(y2),
                            &rx1, &ry1, &rx2, &ry2)) return;
 
        cx1 = rx;
@@ -1202,8 +1248,8 @@ void pixbuf_draw_line(GdkPixbuf *pb,
                if (slope != 0.0) slope = (ry2 - ry1) / slope;
                for (x = rx1; x < rx2; x += 1.0)
                        {
-                       px = (gint)(x + 0.5);
-                       py = (gint)(ry1 + (x - rx1) * slope + 0.5);
+                       px = static_cast<gint>(x + 0.5);
+                       py = static_cast<gint>(ry1 + (x - rx1) * slope + 0.5);
 
                        if (px >=  cx1 && px < cx2 && py >= cy1 && py < cy2)
                                {
@@ -1229,8 +1275,8 @@ void pixbuf_draw_line(GdkPixbuf *pb,
                if (slope != 0.0) slope = (rx2 - rx1) / slope;
                for (y = ry1; y < ry2; y += 1.0)
                        {
-                       px = (gint)(rx1 + (y - ry1) * slope + 0.5);
-                       py = (gint)(y + 0.5);
+                       px = static_cast<gint>(rx1 + (y - ry1) * slope + 0.5);
+                       py = static_cast<gint>(y + 0.5);
 
                        if (px >=  cx1 && px < cx2 && py >= cy1 && py < cy2)
                                {
@@ -1283,7 +1329,7 @@ static void pixbuf_draw_fade_linear(guchar *p_pix, gint prs, gboolean has_alpha,
 static void pixbuf_draw_fade_radius(guchar *p_pix, gint prs, gboolean has_alpha,
                                    gint sx, gint sy, gint border,
                                    gint x1, gint y1, gint x2, gint y2,
-                                   guint8 UNUSED(r), guint8 g, guint8 b, guint8 a)
+                                   guint8, guint8 g, guint8 b, guint8 a)
 {
        guchar *pp;
        gint p_step;
@@ -1298,7 +1344,7 @@ static void pixbuf_draw_fade_radius(guchar *p_pix, gint prs, gboolean has_alpha,
                        guint8 n;
                        gint r;
 
-                       r = MIN(border, (gint)sqrt((i-sx)*(i-sx) + (j-sy)*(j-sy)));
+                       r = MIN(border, (gint)hypot(i - sx, j - sy));
                        n = a - a * r / border;
                        *pp = (r * n + *pp * (256-n)) >> 8;
                        pp++;