Use std::swap instead of temporary values
[geeqie.git] / src / renderer-tiles.cc
index 924dfb8..5e3068c 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include "renderer-tiles.h"
+
 #include <cmath>
 #include <cstdlib>
 #include <cstring>
+#include <utility>
 
-#include "main.h"
-#include "renderer-tiles.h"
+#include <cairo.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gdk/gdk.h>
+#include <glib-object.h>
+#include <glib.h>
+#include <gtk/gtk.h>
+
+#include "debug.h"
+#include "options.h"
+#include "pixbuf-renderer.h"
+#include "typedefs.h"
 
 /* comment this out if not using this from within Geeqie
  * defining GQ_BUILD does these things:
@@ -33,9 +45,8 @@
 #define GQ_BUILD 1
 
 #ifdef GQ_BUILD
-#include "main.h"
-#include "pixbuf-util.h"
 #include "exif.h"
+#include "pixbuf-util.h"
 #else
 enum ExifOrientationType {
        EXIF_ORIENTATION_UNKNOWN        = 0,
@@ -50,6 +61,13 @@ enum ExifOrientationType {
 };
 #endif
 
+namespace
+{
+
+constexpr size_t COLOR_BYTES = 3; /* rgb */
+
+} // namespace
+
 struct QueueData;
 
 struct ImageTile
@@ -153,14 +171,14 @@ static void rt_hierarchy_changed_cb(GtkWidget *widget, GtkWidget *previous_tople
 static gint rt_queue_draw_idle_cb(gpointer data);
 
 #define GET_RIGHT_PIXBUF_OFFSET(rt) \
-        (( (rt->stereo_mode & PR_STEREO_RIGHT) && !(rt->stereo_mode & PR_STEREO_SWAP)) || \
-         (!(rt->stereo_mode & PR_STEREO_RIGHT) &&  (rt->stereo_mode & PR_STEREO_SWAP)) ?  \
-          rt->pr->stereo_pixbuf_offset_right : rt->pr->stereo_pixbuf_offset_left )
+        (( ((rt)->stereo_mode & PR_STEREO_RIGHT) && !((rt)->stereo_mode & PR_STEREO_SWAP)) || \
+         (!((rt)->stereo_mode & PR_STEREO_RIGHT) &&  ((rt)->stereo_mode & PR_STEREO_SWAP)) ?  \
+          (rt)->pr->stereo_pixbuf_offset_right : (rt)->pr->stereo_pixbuf_offset_left )
 
 #define GET_LEFT_PIXBUF_OFFSET(rt) \
-        ((!(rt->stereo_mode & PR_STEREO_RIGHT) && !(rt->stereo_mode & PR_STEREO_SWAP)) || \
-         ( (rt->stereo_mode & PR_STEREO_RIGHT) &&  (rt->stereo_mode & PR_STEREO_SWAP)) ?  \
-          rt->pr->stereo_pixbuf_offset_right : rt->pr->stereo_pixbuf_offset_left )
+        ((!((rt)->stereo_mode & PR_STEREO_RIGHT) && !((rt)->stereo_mode & PR_STEREO_SWAP)) || \
+         ( ((rt)->stereo_mode & PR_STEREO_RIGHT) &&  ((rt)->stereo_mode & PR_STEREO_SWAP)) ?  \
+          (rt)->pr->stereo_pixbuf_offset_right : (rt)->pr->stereo_pixbuf_offset_left )
 
 
 static void rt_sync_scroll(RendererTiles *rt)
@@ -187,7 +205,10 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h)
        PixbufRenderer *pr = rt->pr;
        GtkWidget *box;
        GdkWindow *window;
-       gint rx, ry, rw, rh;
+       gint rx;
+       gint ry;
+       gint rw;
+       gint rh;
        cairo_t *cr;
 
        box = GTK_WIDGET(pr);
@@ -204,7 +225,7 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h)
                                   pr->viewport_width, pr->viewport_height,
                                   &rx, &ry, &rw, &rh))
                        {
-                       cairo_set_source_rgb(cr, static_cast<double>(pr->color.red)/65535, static_cast<double>(pr->color.green)/65535, static_cast<double>(pr->color.blue)/65535);
+                       cairo_set_source_rgb(cr, static_cast<double>(pr->color.red), static_cast<double>(pr->color.green), static_cast<double>(pr->color.blue));
                        cairo_rectangle(cr, rx + rt->stereo_off_x, ry + rt->stereo_off_y, rw, rh);
                        cairo_fill(cr);
                        rt_overlay_draw(rt, rx, ry, rw, rh, nullptr);
@@ -221,7 +242,7 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h)
                                   pr->x_offset, pr->viewport_height,
                                   &rx, &ry, &rw, &rh))
                        {
-                       cairo_set_source_rgb(cr, static_cast<double>(pr->color.red)/65535, static_cast<double>(pr->color.green)/65535, static_cast<double>(pr->color.blue)/65535);
+                       cairo_set_source_rgb(cr, static_cast<double>(pr->color.red), static_cast<double>(pr->color.green), static_cast<double>(pr->color.blue));
                        cairo_rectangle(cr, rx + rt->stereo_off_x, ry + rt->stereo_off_y, rw, rh);
                        cairo_fill(cr);
                        rt_overlay_draw(rt, rx, ry, rw, rh, nullptr);
@@ -232,7 +253,7 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h)
                                   pr->viewport_width - pr->vis_width - pr->x_offset, pr->viewport_height,
                                   &rx, &ry, &rw, &rh))
                        {
-                       cairo_set_source_rgb(cr, static_cast<double>(pr->color.red)/65535, static_cast<double>(pr->color.green)/65535, static_cast<double>(pr->color.blue)/65535);
+                       cairo_set_source_rgb(cr, static_cast<double>(pr->color.red), static_cast<double>(pr->color.green), static_cast<double>(pr->color.blue));
                        cairo_rectangle(cr, rx + rt->stereo_off_x, ry + rt->stereo_off_y, rw, rh);
                        cairo_fill(cr);
                        rt_overlay_draw(rt, rx, ry, rw, rh, nullptr);
@@ -246,7 +267,7 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h)
                                   pr->vis_width, pr->y_offset,
                                   &rx, &ry, &rw, &rh))
                        {
-                       cairo_set_source_rgb(cr, static_cast<double>(pr->color.red)/65535, static_cast<double>(pr->color.green)/65535, static_cast<double>(pr->color.blue)/65535);
+                       cairo_set_source_rgb(cr, static_cast<double>(pr->color.red), static_cast<double>(pr->color.green), static_cast<double>(pr->color.blue));
                        cairo_rectangle(cr, rx + rt->stereo_off_x, ry + rt->stereo_off_y, rw, rh);
                        cairo_fill(cr);
                        rt_overlay_draw(rt, rx, ry, rw, rh, nullptr);
@@ -257,7 +278,7 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h)
                                   pr->vis_width, pr->viewport_height - pr->vis_height - pr->y_offset,
                                   &rx, &ry, &rw, &rh))
                        {
-                       cairo_set_source_rgb(cr, static_cast<double>(pr->color.red)/65535, static_cast<double>(pr->color.green)/65535, static_cast<double>(pr->color.blue)/65535);
+                       cairo_set_source_rgb(cr, static_cast<double>(pr->color.red), static_cast<double>(pr->color.green), static_cast<double>(pr->color.blue));
                        cairo_rectangle(cr, rx + rt->stereo_off_x, ry + rt->stereo_off_y, rw, rh);
                        cairo_fill(cr);
                        rt_overlay_draw(rt, rx, ry, rw, rh, nullptr);
@@ -305,20 +326,7 @@ static void rt_tile_free(ImageTile *it)
 
 static void rt_tile_free_all(RendererTiles *rt)
 {
-       GList *work;
-
-       work = rt->tiles;
-       while (work)
-               {
-               ImageTile *it;
-
-               it = static_cast<ImageTile *>(work->data);
-               work = work->next;
-
-               rt_tile_free(it);
-               }
-
-       g_list_free(rt->tiles);
+       g_list_free_full(rt->tiles, reinterpret_cast<GDestroyNotify>(rt_tile_free));
        rt->tiles = nullptr;
        rt->tile_cache_size = 0;
 }
@@ -421,8 +429,10 @@ static void rt_tile_invalidate_all(RendererTiles *rt)
 
 static void rt_tile_invalidate_region(RendererTiles *rt, gint x, gint y, gint w, gint h)
 {
-       gint x1, x2;
-       gint y1, y2;
+       gint x1;
+       gint x2;
+       gint y1;
+       gint y2;
        GList *work;
 
        x1 = ROUND_DOWN(x, rt->tile_width);
@@ -473,12 +483,8 @@ static ImageTile *rt_tile_get(RendererTiles *rt, gint x, gint y, gboolean only_e
        return rt_tile_add(rt, x, y);
 }
 
-static gint pixmap_calc_size(cairo_surface_t *UNUSED(surface))
+static gint pixmap_calc_size(cairo_surface_t *)
 {
-//     gint w, h, d;
-
-//     d = gdk_drawable_get_depth(pixmap);
-//     gdk_drawable_get_size(pixmap, &w, &h);
        return options->image.tile_size * options->image.tile_size * 4 / 8;
 }
 
@@ -541,7 +547,10 @@ static void rt_overlay_get_position(RendererTiles *rt, OverlayData *od,
                                    gint *x, gint *y, gint *w, gint *h)
 {
        PixbufRenderer *pr = rt->pr;
-       gint px, py, pw, ph;
+       gint px;
+       gint py;
+       gint pw;
+       gint ph;
 
        pw = gdk_pixbuf_get_width(od->pixbuf);
        ph = gdk_pixbuf_get_height(od->pixbuf);
@@ -563,7 +572,10 @@ static void rt_overlay_get_position(RendererTiles *rt, OverlayData *od,
 static void rt_overlay_init_window(RendererTiles *rt, OverlayData *od)
 {
        PixbufRenderer *pr = rt->pr;
-       gint px, py, pw, ph;
+       gint px;
+       gint py;
+       gint pw;
+       gint ph;
        GdkWindowAttr attributes;
        gint attributes_mask;
 
@@ -592,8 +604,14 @@ static void rt_overlay_draw(RendererTiles *rt, gint x, gint y, gint w, gint h,
        while (work)
                {
                OverlayData *od;
-               gint px, py, pw, ph;
-               gint rx, ry, rw, rh;
+               gint px;
+               gint py;
+               gint pw;
+               gint ph;
+               gint rx;
+               gint ry;
+               gint rw;
+               gint rh;
 
                od = static_cast<OverlayData *>(work->data);
                work = work->next;
@@ -632,12 +650,14 @@ static void rt_overlay_draw(RendererTiles *rt, gint x, gint y, gint w, gint h,
                        else
                                {
                                /* no ImageTile means region may be larger than our scratch buffer */
-                               gint sx, sy;
+                               gint sx;
+                               gint sy;
 
                                for (sx = rx; sx < rx + rw; sx += rt->tile_width)
                                    for (sy = ry; sy < ry + rh; sy += rt->tile_height)
                                        {
-                                       gint sw, sh;
+                                       gint sw;
+                                       gint sh;
                                        cairo_t *cr;
 
                                        sw = MIN(rx + rw - sx, rt->tile_width);
@@ -666,7 +686,10 @@ static void rt_overlay_draw(RendererTiles *rt, gint x, gint y, gint w, gint h,
 static void rt_overlay_queue_draw(RendererTiles *rt, OverlayData *od, gint x1, gint y1, gint x2, gint y2)
 {
        PixbufRenderer *pr = rt->pr;
-       gint x, y, w, h;
+       gint x;
+       gint y;
+       gint w;
+       gint h;
 
        rt_overlay_get_position(rt, od, &x, &y, &w, &h);
 
@@ -712,7 +735,10 @@ static void rt_overlay_update_sizes(RendererTiles *rt)
 
                if (od->flags & OVL_RELATIVE)
                        {
-                       gint x, y, w, h;
+                       gint x;
+                       gint y;
+                       gint w;
+                       gint h;
 
                        rt_overlay_get_position(rt, od, &x, &y, &w, &h);
                        gdk_window_move_resize(od->window, x + rt->stereo_off_x, y + rt->stereo_off_y, w, h);
@@ -808,7 +834,7 @@ static void rt_overlay_list_reset_window(RendererTiles *rt)
                }
 }
 
-void renderer_tiles_overlay_set(void *renderer, gint id, GdkPixbuf *pixbuf, gint UNUSED(x), gint UNUSED(y))
+void renderer_tiles_overlay_set(void *renderer, gint id, GdkPixbuf *pixbuf, gint, gint)
 {
        auto rc = static_cast<RendererTiles *>(renderer);
        PixbufRenderer *pr = rc->pr;
@@ -851,7 +877,7 @@ gboolean renderer_tiles_overlay_get(void *renderer, gint id, GdkPixbuf **pixbuf,
        return TRUE;
 }
 
-static void rt_hierarchy_changed_cb(GtkWidget *UNUSED(widget), GtkWidget *UNUSED(previous_toplevel), gpointer data)
+static void rt_hierarchy_changed_cb(GtkWidget *, GtkWidget *, gpointer data)
 {
        auto rt = static_cast<RendererTiles *>(data);
        rt_overlay_list_reset_window(rt);
@@ -869,17 +895,21 @@ static GdkPixbuf *rt_get_spare_tile(RendererTiles *rt)
        return rt->spare_tile;
 }
 
-#define COLOR_BYTES 3  /* rgb */
-
 static void rt_tile_rotate_90_clockwise(RendererTiles *rt, GdkPixbuf **tile, gint x, gint y, gint w, gint h)
 {
        GdkPixbuf *src = *tile;
        GdkPixbuf *dest;
-       gint srs, drs;
-       guchar *s_pix, *d_pix;
-       guchar *sp, *dp;
-       guchar *ip, *spi, *dpi;
-       gint i, j;
+       gint srs;
+       gint drs;
+       guchar *s_pix;
+       guchar *d_pix;
+       guchar *sp;
+       guchar *dp;
+       guchar *ip;
+       guchar *spi;
+       guchar *dpi;
+       gint i;
+       gint j;
        gint tw = rt->tile_width * rt->hidpi_scale;
 
        srs = gdk_pixbuf_get_rowstride(src);
@@ -911,11 +941,17 @@ static void rt_tile_rotate_90_counter_clockwise(RendererTiles *rt, GdkPixbuf **t
 {
        GdkPixbuf *src = *tile;
        GdkPixbuf *dest;
-       gint srs, drs;
-       guchar *s_pix, *d_pix;
-       guchar *sp, *dp;
-       guchar *ip, *spi, *dpi;
-       gint i, j;
+       gint srs;
+       gint drs;
+       guchar *s_pix;
+       guchar *d_pix;
+       guchar *sp;
+       guchar *dp;
+       guchar *ip;
+       guchar *spi;
+       guchar *dpi;
+       gint i;
+       gint j;
        gint th = rt->tile_height * rt->hidpi_scale;
 
        srs = gdk_pixbuf_get_rowstride(src);
@@ -947,11 +983,16 @@ static void rt_tile_mirror_only(RendererTiles *rt, GdkPixbuf **tile, gint x, gin
 {
        GdkPixbuf *src = *tile;
        GdkPixbuf *dest;
-       gint srs, drs;
-       guchar *s_pix, *d_pix;
-       guchar *sp, *dp;
-       guchar *spi, *dpi;
-       gint i, j;
+       gint srs;
+       gint drs;
+       guchar *s_pix;
+       guchar *d_pix;
+       guchar *sp;
+       guchar *dp;
+       guchar *spi;
+       guchar *dpi;
+       gint i;
+       gint j;
 
        gint tw = rt->tile_width * rt->hidpi_scale;
 
@@ -984,11 +1025,15 @@ static void rt_tile_mirror_and_flip(RendererTiles *rt, GdkPixbuf **tile, gint x,
 {
        GdkPixbuf *src = *tile;
        GdkPixbuf *dest;
-       gint srs, drs;
-       guchar *s_pix, *d_pix;
-       guchar *sp, *dp;
+       gint srs;
+       gint drs;
+       guchar *s_pix;
+       guchar *d_pix;
+       guchar *sp;
+       guchar *dp;
        guchar *dpi;
-       gint i, j;
+       gint i;
+       gint j;
        gint tw = rt->tile_width * rt->hidpi_scale;
        gint th = rt->tile_height * rt->hidpi_scale;
 
@@ -1020,10 +1065,14 @@ static void rt_tile_flip_only(RendererTiles *rt, GdkPixbuf **tile, gint x, gint
 {
        GdkPixbuf *src = *tile;
        GdkPixbuf *dest;
-       gint srs, drs;
-       guchar *s_pix, *d_pix;
-       guchar *sp, *dp;
-       guchar *spi, *dpi;
+       gint srs;
+       gint drs;
+       guchar *s_pix;
+       guchar *d_pix;
+       guchar *sp;
+       guchar *dp;
+       guchar *spi;
+       guchar *dpi;
        gint i;
        gint th = rt->tile_height * rt->hidpi_scale;
 
@@ -1104,7 +1153,7 @@ static void rt_tile_apply_orientation(RendererTiles *rt, gint orientation, GdkPi
 
 static gboolean rt_source_tile_render(RendererTiles *rt, ImageTile *it,
                                      gint x, gint y, gint w, gint h,
-                                     gboolean UNUSED(new_data), gboolean fast)
+                                     gboolean, gboolean fast)
 {
        PixbufRenderer *pr = rt->pr;
        GList *list;
@@ -1118,7 +1167,10 @@ static gboolean rt_source_tile_render(RendererTiles *rt, ImageTile *it,
                while (work)
                        {
                        SourceTile *st;
-                       gint rx, ry, rw, rh;
+                       gint rx;
+                       gint ry;
+                       gint rw;
+                       gint rh;
 
                        st = static_cast<SourceTile *>(work->data);
                        work = work->next;
@@ -1146,8 +1198,12 @@ static gboolean rt_source_tile_render(RendererTiles *rt, ImageTile *it,
                }
        else
                {
-               gdouble scale_x, scale_y;
-               gint sx, sy, sw, sh;
+               gdouble scale_x;
+               gdouble scale_y;
+               gint sx;
+               gint sy;
+               gint sw;
+               gint sh;
 
                if (pr->image_width == 0 || pr->image_height == 0) return FALSE;
                scale_x = static_cast<gdouble>(pr->width) / pr->image_width;
@@ -1170,8 +1226,14 @@ static gboolean rt_source_tile_render(RendererTiles *rt, ImageTile *it,
                while (work)
                        {
                        SourceTile *st;
-                       gint rx, ry, rw, rh;
-                       gint stx, sty, stw, sth;
+                       gint rx;
+                       gint ry;
+                       gint rw;
+                       gint rh;
+                       gint stx;
+                       gint sty;
+                       gint stw;
+                       gint sth;
 
                        st = static_cast<SourceTile *>(work->data);
                        work = work->next;
@@ -1256,6 +1318,14 @@ static void rt_tile_get_region(gboolean has_alpha, gboolean ignore_alpha,
        gint c;
        guchar *psrc;
        guchar *pdst;
+       guint32 red_1;
+       guint32 green_1;
+       guint32 blue_1;
+       guint32 red_2;
+       guint32 green_2;
+       guint32 blue_2;
+       guint32 alpha_1;
+       guint32 alpha_2;
 
        if (!has_alpha)
                {
@@ -1299,6 +1369,15 @@ static void rt_tile_get_region(gboolean has_alpha, gboolean ignore_alpha,
                }
        else
                {
+               red_1=static_cast<guint32>(options->image.alpha_color_1.red * 255) << 16 & 0x00FF0000;
+               green_1=static_cast<guint32>(options->image.alpha_color_1.green * 255) << 8 & 0x0000FF00;
+               blue_1=static_cast<guint32>(options->image.alpha_color_1.blue * 255) & 0x000000FF;
+               red_2=static_cast<guint32>(options->image.alpha_color_2.red * 255) << 16 & 0x00FF0000;
+               green_2=static_cast<guint32>(options->image.alpha_color_2.green * 255) << 8 & 0x0000FF00;
+               blue_2=static_cast<guint32>(options->image.alpha_color_2.blue * 255) & 0x000000FF;
+               alpha_1 = red_1 + green_1 + blue_1;
+               alpha_2 = red_2 + green_2 + blue_2;
+
                if (ignore_alpha)
                        {
                        tmppixbuf = gdk_pixbuf_add_alpha(src, FALSE, 0, 0, 0);
@@ -1313,12 +1392,8 @@ static void rt_tile_get_region(gboolean has_alpha, gboolean ignore_alpha,
                                        (scale_x == 1.0 && scale_y == 1.0) ? GDK_INTERP_NEAREST : interp_type,
                                        255, check_x, check_y,
                                        PR_ALPHA_CHECK_SIZE,
-                                       ((options->image.alpha_color_1.red << 8 & 0x00FF0000) +
-                                       (options->image.alpha_color_1.green & 0x00FF00) +
-                                       (options->image.alpha_color_1.blue >> 8 & 0x00FF)),
-                                       ((options->image.alpha_color_2.red << 8 & 0x00FF0000) +
-                                       (options->image.alpha_color_2.green & 0x00FF00) +
-                                       (options->image.alpha_color_2.blue >> 8 & 0x00FF)));
+                                       alpha_1,
+                                       alpha_2);
                        g_object_unref(tmppixbuf);
                        }
                else
@@ -1331,12 +1406,8 @@ static void rt_tile_get_region(gboolean has_alpha, gboolean ignore_alpha,
                                        (scale_x == 1.0 && scale_y == 1.0) ? GDK_INTERP_NEAREST : interp_type,
                                        255, check_x, check_y,
                                        PR_ALPHA_CHECK_SIZE,
-                                       ((options->image.alpha_color_1.red << 8 & 0x00FF0000) +
-                                       (options->image.alpha_color_1.green & 0x00FF00) +
-                                       (options->image.alpha_color_1.blue >> 8 & 0x00FF)),
-                                       ((options->image.alpha_color_2.red << 8 & 0x00FF0000) +
-                                       (options->image.alpha_color_2.green & 0x00FF00) +
-                                       (options->image.alpha_color_2.blue >> 8 & 0x00FF)));
+                                       alpha_1,
+                                       alpha_2);
                        }
                }
 }
@@ -1409,10 +1480,14 @@ static void rt_tile_render(RendererTiles *rt, ImageTile *it,
                }
        else
                {
-               gdouble scale_x, scale_y;
-               gdouble src_x, src_y;
-               gint pb_x, pb_y;
-               gint pb_w, pb_h;
+               gdouble scale_x;
+               gdouble scale_y;
+               gdouble src_x;
+               gdouble src_y;
+               gint pb_x;
+               gint pb_y;
+               gint pb_w;
+               gint pb_h;
 
                if (pr->image_width == 0 || pr->image_height == 0) return;
 
@@ -1438,14 +1513,11 @@ static void rt_tile_render(RendererTiles *rt, ImageTile *it,
 
                switch (orientation)
                        {
-                       gdouble tmp;
                        case EXIF_ORIENTATION_LEFT_TOP:
                        case EXIF_ORIENTATION_RIGHT_TOP:
                        case EXIF_ORIENTATION_RIGHT_BOTTOM:
                        case EXIF_ORIENTATION_LEFT_BOTTOM:
-                               tmp = scale_x;
-                               scale_x = scale_y;
-                               scale_y = tmp;
+                               std::swap(scale_x, scale_y);
                                break;
                        default:
                                /* nothing to do */
@@ -1503,8 +1575,6 @@ static void rt_tile_expose(RendererTiles *rt, ImageTile *it,
                           gboolean new_data, gboolean fast)
 {
        PixbufRenderer *pr = rt->pr;
-       //~ GtkWidget *box;
-       //~ GdkWindow *window;
        cairo_t *cr;
 
        /* clamp to visible */
@@ -1531,9 +1601,6 @@ static void rt_tile_expose(RendererTiles *rt, ImageTile *it,
 
        rt_tile_render(rt, it, x, y, w, h, new_data, fast);
 
-       //~ box = GTK_WIDGET(pr);
-       //~ window = gtk_widget_get_window(box);
-
        cr = cairo_create(rt->surface);
        cairo_set_source_surface(cr, it->surface, pr->x_offset + (it->x - rt->x_scroll) + rt->stereo_off_x, pr->y_offset + (it->y - rt->y_scroll) + rt->stereo_off_y);
        cairo_rectangle (cr, pr->x_offset + (it->x - rt->x_scroll) + x + rt->stereo_off_x, pr->y_offset + (it->y - rt->y_scroll) + y + rt->stereo_off_y, w, h);
@@ -1782,10 +1849,14 @@ static void rt_queue_merge(QueueData *parent, QueueData *qd)
 static gboolean rt_clamp_to_visible(RendererTiles *rt, gint *x, gint *y, gint *w, gint *h)
 {
        PixbufRenderer *pr = rt->pr;
-       gint nx, ny;
-       gint nw, nh;
-       gint vx, vy;
-       gint vw, vh;
+       gint nx;
+       gint ny;
+       gint nw;
+       gint nh;
+       gint vx;
+       gint vy;
+       gint vw;
+       gint vh;
 
        vw = pr->vis_width;
        vh = pr->vis_height;
@@ -1815,9 +1886,12 @@ static gboolean rt_queue_to_tiles(RendererTiles *rt, gint x, gint y, gint w, gin
                                  gboolean new_data, gboolean only_existing)
 {
        PixbufRenderer *pr = rt->pr;
-       gint i, j;
-       gint x1, x2;
-       gint y1, y2;
+       gint i;
+       gint j;
+       gint x1;
+       gint x2;
+       gint y1;
+       gint y2;
 
        if (clamp && !rt_clamp_to_visible(rt, &x, &y, &w, &h)) return FALSE;
 
@@ -1899,7 +1973,8 @@ static void rt_queue(RendererTiles *rt, gint x, gint y, gint w, gint h,
                     gboolean new_data, gboolean only_existing)
 {
        PixbufRenderer *pr = rt->pr;
-       gint nx, ny;
+       gint nx;
+       gint ny;
 
        rt_sync_scroll(rt);
 
@@ -1941,10 +2016,11 @@ static void rt_scroll(void *renderer, gint x_off, gint y_off)
                rt_queue(rt, 0, 0, pr->width, pr->height, TRUE, TILE_RENDER_ALL, FALSE, FALSE);
                return;
                }
-       else
-               {
-               gint x1, y1;
-               gint x2, y2;
+
+               gint x1;
+               gint y1;
+               gint x2;
+               gint y2;
                cairo_t *cr;
                cairo_surface_t *surface;
 
@@ -2004,14 +2080,20 @@ static void rt_scroll(void *renderer, gint x_off, gint y_off)
                                    rt->x_scroll, y_off > 0 ? rt->y_scroll + (pr->vis_height - h) : rt->y_scroll,
                                    pr->vis_width, h, TRUE, TILE_RENDER_ALL, FALSE, FALSE);
                        }
-               }
 }
 
 static void renderer_area_changed(void *renderer, gint src_x, gint src_y, gint src_w, gint src_h)
 {
        auto rt = static_cast<RendererTiles *>(renderer);
        PixbufRenderer *pr = rt->pr;
-       gint x, y, width, height,  x1, y1, x2, y2;
+       gint x;
+       gint y;
+       gint width;
+       gint height;
+       gint x1;
+       gint y1;
+       gint x2;
+       gint y2;
 
        gint orientation = rt_get_orientation(rt);
        pr_coords_map_orientation_reverse(orientation,
@@ -2056,7 +2138,7 @@ static void renderer_redraw(RendererTiles *rt, gint x, gint y, gint w, gint h,
                 clamp, render, new_data, only_existing);
 }
 
-static void renderer_update_pixbuf(void *renderer, gboolean UNUSED(lazy))
+static void renderer_update_pixbuf(void *renderer, gboolean)
 {
        rt_queue_clear(static_cast<RendererTiles *>(renderer));
 }
@@ -2147,7 +2229,7 @@ static gboolean rt_realize_cb(GtkWidget *widget, gpointer data)
                rt->surface = gdk_window_create_similar_surface(gtk_widget_get_window(widget), CAIRO_CONTENT_COLOR, gtk_widget_get_allocated_width(widget), gtk_widget_get_allocated_height(widget));
 
                cr = cairo_create(rt->surface);
-               cairo_set_source_rgb(cr, static_cast<gdouble>(rt->pr->color.red) / 65535, static_cast<gdouble>(rt->pr->color.green) / 65535, static_cast<gdouble>(rt->pr->color.blue) / 65535);
+               cairo_set_source_rgb(cr, static_cast<gdouble>(rt->pr->color.red), static_cast<gdouble>(rt->pr->color.green), static_cast<gdouble>(rt->pr->color.blue));
                cairo_paint(cr);
                cairo_destroy(cr);
                }
@@ -2168,7 +2250,7 @@ static gboolean rt_size_allocate_cb(GtkWidget *widget,  GdkRectangle *allocation
 
                cr = cairo_create(rt->surface);
 
-               cairo_set_source_rgb(cr, static_cast<gdouble>(options->image.border_color.red) / 65535, static_cast<gdouble>(options->image.border_color.green) / 65535, static_cast<gdouble>(options->image.border_color.blue) / 65535);
+               cairo_set_source_rgb(cr, static_cast<gdouble>(options->image.border_color.red), static_cast<gdouble>(options->image.border_color.green), static_cast<gdouble>(options->image.border_color.blue));
                cairo_paint(cr);
                cairo_set_source_surface(cr, old_surface, 0, 0);
                cairo_paint(cr);
@@ -2181,7 +2263,7 @@ static gboolean rt_size_allocate_cb(GtkWidget *widget,  GdkRectangle *allocation
        return FALSE;
 }
 
-static gboolean rt_draw_cb(GtkWidget *UNUSED(widget), cairo_t *cr, gpointer data)
+static gboolean rt_draw_cb(GtkWidget *, cairo_t *cr, gpointer data)
 {
        auto rt = static_cast<RendererTiles *>(data);
        GList *work;
@@ -2190,7 +2272,7 @@ static gboolean rt_draw_cb(GtkWidget *UNUSED(widget), cairo_t *cr, gpointer data
        if (rt->stereo_mode & (PR_STEREO_HORIZ | PR_STEREO_VERT))
                {
                cairo_push_group(cr);
-               cairo_set_source_rgb(cr, static_cast<double>(rt->pr->color.red) / 65535, static_cast<double>(rt->pr->color.green) / 65535, static_cast<double>(rt->pr->color.blue) / 65535);
+               cairo_set_source_rgb(cr, static_cast<double>(rt->pr->color.red), static_cast<double>(rt->pr->color.green), static_cast<double>(rt->pr->color.blue));
 
                if (rt->stereo_mode & PR_STEREO_HORIZ)
                        {
@@ -2221,7 +2303,10 @@ static gboolean rt_draw_cb(GtkWidget *UNUSED(widget), cairo_t *cr, gpointer data
        while (work)
                {
                od = static_cast<OverlayData *>(work->data);
-               gint px, py, pw, ph;
+               gint px;
+               gint py;
+               gint pw;
+               gint ph;
                pw = gdk_pixbuf_get_width(od->pixbuf);
                ph = gdk_pixbuf_get_height(od->pixbuf);
                px = od->x;