Fix representing percent in c-format string
[geeqie.git] / src / pixbuf-util.cc
index bab7ffb..1171568 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include "main.h"
 #include "pixbuf-util.h"
+
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+
+#include <cairo.h>
+#include <gio/gio.h>
+#include <glib-object.h>
+#include <pango/pangocairo.h>
+
+#include <config.h>
+
+#include "debug.h"
 #include "exif.h"
+#include "filedata.h"
+#include "main-defines.h"
+#include "typedefs.h"
 #include "ui-fileops.h"
 
-#include <math.h>
-
 
 /*
  *-----------------------------------------------------------------------------
@@ -58,33 +71,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
 
 /*
  *-----------------------------------------------------------------------------
@@ -92,81 +108,98 @@ gboolean pixbuf_to_file_as_png(GdkPixbuf *pixbuf, const gchar *filename)
  *-----------------------------------------------------------------------------
  */
 
-typedef struct _PixbufInline PixbufInline;
-struct _PixbufInline
+struct PixbufInline
 {
        const gchar *key;
        const gchar *data;
 };
 
 static PixbufInline inline_pixbuf_data[] = {
-       { PIXBUF_INLINE_ARCHIVE,        "gq-archive-file.png" },
-       { PIXBUF_INLINE_BROKEN, "gq-sheet-broken.png" },
-       { PIXBUF_INLINE_COLLECTION,     "gq-collection.png" },
-       { PIXBUF_INLINE_ICON,   "gqview-icon.png" },
-       { PIXBUF_INLINE_ICON_180,       "gq-icon-rotate-180.png" },
-       { PIXBUF_INLINE_ICON_BOOK,      "gq-icon-book.png" },
-       { PIXBUF_INLINE_ICON_CCW,       "gq-icon-rotate-counter-clockwise.png" },
-       { PIXBUF_INLINE_ICON_CONFIG,    "gq-icon-config.png" },
-       { PIXBUF_INLINE_ICON_CW,        "gq-icon-rotate-clockwise.png" },
-       { PIXBUF_INLINE_ICON_DRAW_RECTANGLE,    "gq-icon-draw-rectangle.png" },
-       { PIXBUF_INLINE_ICON_EXIF,      "gq-icon-exif.png" },
-       { PIXBUF_INLINE_ICON_EXPOSURE,  "gq-icon-exposure.png" },
-       { PIXBUF_INLINE_ICON_FILE_FILTER,       "gq-icon-file-filter.png" },
-       { PIXBUF_INLINE_ICON_FLIP,      "gq-icon-flip.png" },
-       { PIXBUF_INLINE_ICON_FLOAT,     "gq-icon-float.png" },
-       { PIXBUF_INLINE_ICON_GRAYSCALE, "gq-icon-grayscale.png" },
-       { PIXBUF_INLINE_ICON_HEIF,      "gq-icon-heic.png" },
-       { PIXBUF_INLINE_ICON_HIDETOOLS,         "gq-icon-hidetools.png" },
-       { PIXBUF_INLINE_ICON_INFO,      "gq-icon-info.png" },
-       { PIXBUF_INLINE_ICON_MAINTENANCE,       "gq-icon-maintenance.png" },
-       { PIXBUF_INLINE_ICON_MARKS,     "gq-icon-marks.png" },
-       { PIXBUF_INLINE_ICON_MIRROR,    "gq-icon-mirror.png" },
-       { PIXBUF_INLINE_ICON_MOVE,      "gq-icon-move.png" },
-       { PIXBUF_INLINE_ICON_ORIGINAL,  "gq-icon-original.png" },
-       { PIXBUF_INLINE_ICON_PANORAMA,  "gq-icon-panorama.png" },
-       { PIXBUF_INLINE_ICON_PDF,       "gq-icon-pdf.png" },
-       { PIXBUF_INLINE_ICON_RENAME,    "gq-icon-rename.png" },
-       { PIXBUF_INLINE_ICON_SELECT_ALL,        "gq-icon-select-all.png" },
-       { PIXBUF_INLINE_ICON_SELECT_INVERT,     "gq-icon-select-invert.png" },
-       { PIXBUF_INLINE_ICON_SELECT_NONE,       "gq-icon-select-none.png" },
-       { PIXBUF_INLINE_ICON_SELECT_RECTANGLE,  "gq-icon-select-rectangle.png" },
-       { PIXBUF_INLINE_ICON_SORT,      "gq-icon-sort.png" },
-       { PIXBUF_INLINE_ICON_THUMB,     "gq-icon-thumb.png" },
-       { PIXBUF_INLINE_ICON_TOOLS,             "gq-icon-tools.png" },
-       { PIXBUF_INLINE_ICON_TRASH,     "gq-icon-trash.png" },
-       { PIXBUF_INLINE_ICON_VIEW,      "gq-icon-view.png" },
-       { PIXBUF_INLINE_ICON_ZOOMFILLHOR,       "gq-icon-zoomfillhor.png" },
-       { PIXBUF_INLINE_ICON_ZOOMFILLVERT,      "gq-icon-zoomfillvert.png" },
-       { PIXBUF_INLINE_LOGO,   "geeqie-logo.png" },
-       { PIXBUF_INLINE_METADATA,       "gq-sheet-metadata.png" },
-       { PIXBUF_INLINE_SCROLLER,       "gq-scroller.png" },
-       { PIXBUF_INLINE_SPLIT_PANE_SYNC, "gq-icon-split-pane-sync.png" },
-       { PIXBUF_INLINE_UNKNOWN,        "gq-sheet-unknown.png" },
-       { PIXBUF_INLINE_VIDEO,  "gq-sheet-video.png" },
-       { nullptr, nullptr }
+       {  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;
-       GdkPixbuf *icon_pixbuf;
-       gchar *path;
        gint i;
+       GtkSettings *settings;
 
        if (!key) return nullptr;
 
+       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)
                        {
-                       path = g_build_filename(GQ_RESOURCE_PATH_ICONS, inline_pixbuf_data[i].data, 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);
@@ -211,7 +244,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;
 
@@ -335,7 +368,8 @@ GdkPixbuf *pixbuf_fallback(FileData *fd, gint requested_width, gint requested_he
 
                if (w > requested_width || h > requested_height)
                        {
-                       gint nw, nh;
+                       gint nw;
+                       gint nh;
 
                        if (pixbuf_scale_aspect(requested_width, requested_height,
                                                          w, h, &nw, &nh))
@@ -389,7 +423,8 @@ static void pixbuf_copy_block_rotate(guchar *src, gint src_row_stride, gint x, g
                                     guchar *dest, gint dest_row_stride, gint w, gint h,
                                     gint bytes_per_pixel, gboolean counter_clockwise)
 {
-       gint i, j;
+       gint i;
+       gint j;
        guchar *sp;
        guchar *dp;
 
@@ -430,8 +465,10 @@ static void pixbuf_copy_block(guchar *src, gint src_row_stride, gint w, gint h,
                }
 }
 
-#define ROTATE_BUFFER_WIDTH 48
-#define ROTATE_BUFFER_HEIGHT 48
+enum {
+       ROTATE_BUFFER_WIDTH = 48,
+       ROTATE_BUFFER_HEIGHT = 48
+};
 
 /*
  * Returns a copy of pixbuf src rotated 90 degrees clockwise or 90 counterclockwise
@@ -441,16 +478,22 @@ GdkPixbuf *pixbuf_copy_rotate_90(GdkPixbuf *src, gboolean counter_clockwise)
 {
        GdkPixbuf *dest;
        gboolean has_alpha;
-       gint sw, sh, srs;
-       gint dw, dh, drs;
+       gint sw;
+       gint sh;
+       gint srs;
+       gint dw;
+       gint dh;
+       gint drs;
        guchar *s_pix;
        guchar *d_pix;
-       gint i, j;
+       gint i;
+       gint j;
        gint a;
        GdkPixbuf *buffer;
        guchar *b_pix;
        gint brs;
-       gint w, h;
+       gint w;
+       gint h;
 
        if (!src) return nullptr;
 
@@ -478,7 +521,8 @@ GdkPixbuf *pixbuf_copy_rotate_90(GdkPixbuf *src, gboolean counter_clockwise)
                w = MIN(ROTATE_BUFFER_WIDTH, (sh - i));
                for (j = 0; j < sw; j += ROTATE_BUFFER_HEIGHT)
                        {
-                       gint x, y;
+                       gint x;
+                       gint y;
 
                        h = MIN(ROTATE_BUFFER_HEIGHT, (sw - j));
                        pixbuf_copy_block_rotate(s_pix, srs, j, i,
@@ -539,13 +583,16 @@ GdkPixbuf *pixbuf_copy_mirror(GdkPixbuf *src, gboolean mirror, gboolean flip)
 {
        GdkPixbuf *dest;
        gboolean has_alpha;
-       gint w, h, srs;
+       gint w;
+       gint h;
+       gint srs;
        gint drs;
        guchar *s_pix;
        guchar *d_pix;
        guchar *sp;
        guchar *dp;
-       gint i, j;
+       gint i;
+       gint j;
        gint a;
 
        if (!src) return nullptr;
@@ -664,10 +711,13 @@ void pixbuf_draw_rect_fill(GdkPixbuf *pb,
                           gint r, gint g, gint b, gint a)
 {
        gboolean has_alpha;
-       gint pw, ph, prs;
+       gint pw;
+       gint ph;
+       gint prs;
        guchar *p_pix;
        guchar *pp;
-       gint i, j;
+       gint i;
+       gint j;
 
        if (!pb) return;
 
@@ -697,30 +747,36 @@ 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,
                          gint r, gint g, gint b, gint a)
 {
        gboolean has_alpha;
-       gint pw, ph, prs;
+       gint pw;
+       gint ph;
+       gint prs;
        guchar *p_pix;
        guchar *pp;
-       gint i, j;
+       gint i;
+       gint j;
 
        if (!pb) return;
 
@@ -795,18 +851,23 @@ static void pixbuf_copy_font(GdkPixbuf *src, gint sx, gint sy,
                             gint w, gint h,
                             guint8 r, guint8 g, guint8 b, guint8 a)
 {
-       gint sw, sh, srs;
+       gint sw;
+       gint sh;
+       gint srs;
        gboolean s_alpha;
        gint s_step;
        guchar *s_pix;
-       gint dw, dh, drs;
+       gint dw;
+       gint dh;
+       gint drs;
        gboolean d_alpha;
        gint d_step;
        guchar *d_pix;
 
        guchar *sp;
        guchar *dp;
-       gint i, j;
+       gint i;
+       gint j;
 
        if (!src || !dest) return;
 
@@ -868,14 +929,17 @@ 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)
 {
        GdkPixbuf *buffer;
-       gint w, h;
-       gint sx, sy;
-       gint dw, dh;
+       gint w;
+       gint h;
+       gint sx;
+       gint sy;
+       gint dw;
+       gint dh;
        cairo_surface_t *source;
        cairo_t *cr;
 
@@ -941,7 +1005,10 @@ void pixbuf_draw_layout(GdkPixbuf *pixbuf, PangoLayout *layout, GtkWidget *UNUSE
 void util_clip_triangle(gint x1, gint y1, gint x2, gint y2, gint x3, gint y3,
                        gint *rx, gint *ry, gint *rw, gint *rh)
 {
-       gint tx, ty, tw, th;
+       gint tx;
+       gint ty;
+       gint tw;
+       gint th;
 
        tx = MIN(x1, x2);
        tx = MIN(tx, x3);
@@ -964,17 +1031,30 @@ void pixbuf_draw_triangle(GdkPixbuf *pb,
                          guint8 r, guint8 g, guint8 b, guint8 a)
 {
        gboolean has_alpha;
-       gint pw, ph, prs;
-       gint rx, ry, rw, rh;
-       gint tx, ty, tw, th;
-       gint fx1, fy1;
-       gint fx2, fy2;
-       gint fw, fh;
+       gint pw;
+       gint ph;
+       gint prs;
+       gint rx;
+       gint ry;
+       gint rw;
+       gint rh;
+       gint tx;
+       gint ty;
+       gint tw;
+       gint th;
+       gint fx1;
+       gint fy1;
+       gint fx2;
+       gint fy2;
+       gint fw;
+       gint fh;
        guchar *p_pix;
        guchar *pp;
        gint p_step;
-       gdouble slope1, slope2;
-       gint slope1_x, slope1_y;
+       gdouble slope1;
+       gdouble slope2;
+       gint slope1_x;
+       gint slope1_y;
        gint y;
        gint t;
        gboolean middle = FALSE;
@@ -1028,7 +1108,8 @@ void pixbuf_draw_triangle(GdkPixbuf *pb,
 
        for (y = fy1; y < fy2; y++)
                {
-               gint xa, xb;
+               gint xa;
+               gint xb;
 
                if (!middle && y > y2)
                        {
@@ -1176,16 +1257,29 @@ void pixbuf_draw_line(GdkPixbuf *pb,
                      guint8 r, guint8 g, guint8 b, guint8 a)
 {
        gboolean has_alpha;
-       gint pw, ph, prs;
-       gint rx, ry, rw, rh;
-       gdouble rx1, ry1, rx2, ry2;
+       gint pw;
+       gint ph;
+       gint prs;
+       gint rx;
+       gint ry;
+       gint rw;
+       gint rh;
+       gdouble rx1;
+       gdouble ry1;
+       gdouble rx2;
+       gdouble ry2;
        guchar *p_pix;
        guchar *pp;
        gint p_step;
        gdouble slope;
-       gdouble x, y;
-       gint px, py;
-       gint cx1, cy1, cx2, cy2;
+       gdouble x;
+       gdouble y;
+       gint px;
+       gint py;
+       gint cx1;
+       gint cy1;
+       gint cx2;
+       gint cy2;
 
        if (!pb) return;
 
@@ -1280,7 +1374,8 @@ static void pixbuf_draw_fade_linear(guchar *p_pix, gint prs, gboolean has_alpha,
        guchar *pp;
        gint p_step;
        guint8 n = a;
-       gint i, j;
+       gint i;
+       gint j;
 
        p_step = (has_alpha) ? 4 : 3;
        for (j = y1; j < y2; j++)
@@ -1304,11 +1399,12 @@ 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;
-       gint i, j;
+       gint i;
+       gint j;
 
        p_step = (has_alpha) ? 4 : 3;
        for (j = y1; j < y2; j++)
@@ -1319,7 +1415,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++;
@@ -1338,9 +1434,17 @@ void pixbuf_draw_shadow(GdkPixbuf *pb,
                        guint8 r, guint8 g, guint8 b, guint8 a)
 {
        gint has_alpha;
-       gint pw, ph, prs;
-       gint rx, ry, rw, rh;
-       gint fx, fy, fw, fh;
+       gint pw;
+       gint ph;
+       gint prs;
+       gint rx;
+       gint ry;
+       gint rw;
+       gint rh;
+       gint fx;
+       gint fy;
+       gint fw;
+       gint fh;
        guchar *p_pix;
 
        if (!pb) return;
@@ -1450,10 +1554,13 @@ void pixbuf_desaturate_rect(GdkPixbuf *pb,
                            gint x, gint y, gint w, gint h)
 {
        gboolean has_alpha;
-       gint pw, ph, prs;
+       gint pw;
+       gint ph;
+       gint prs;
        guchar *p_pix;
        guchar *pp;
-       gint i, j;
+       gint i;
+       gint j;
 
        if (!pb) return;
 
@@ -1493,10 +1600,13 @@ void pixbuf_desaturate_rect(GdkPixbuf *pb,
 void pixbuf_highlight_overunderexposed(GdkPixbuf *pb, gint x, gint y, gint w, gint h)
 {
        gboolean has_alpha;
-       gint pw, ph, prs;
+       gint pw;
+       gint ph;
+       gint prs;
        guchar *p_pix;
        guchar *pp;
-       gint i, j;
+       gint i;
+       gint j;
 
        if (!pb) return;
 
@@ -1543,10 +1653,13 @@ void pixbuf_ignore_alpha_rect(GdkPixbuf *pb,
                  gint x, gint y, gint w, gint h)
 {
    gboolean has_alpha;
-   gint pw, ph, prs;
+   gint pw;
+   gint ph;
+   gint prs;
    guchar *p_pix;
    guchar *pp;
-   gint i, j;
+   gint i;
+   gint j;
 
    if (!pb) return;