Fix #1240: Regression: Option to open new full-function window directly is missing
[geeqie.git] / src / renderer-tiles.cc
index 0c5d134..654fbbd 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "main.h"
 #include "renderer-tiles.h"
 
+#include <cmath>
+#include <cstdlib>
+#include <cstring>
+#include <utility>
+
+#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:
  *   - Sets the shift-click scroller pixbuf to a nice icon instead of a black box
@@ -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,9 @@ enum ExifOrientationType {
 };
 #endif
 
+namespace
+{
+
 struct QueueData;
 
 struct ImageTile
@@ -111,7 +125,6 @@ struct RendererTiles
 
        gint tile_width;
        gint tile_height;
-       gint tile_cols;         /* count of tile columns */
        GList *tiles;           /* list of buffer tiles */
        gint tile_cache_size;   /* allocated size of pixmaps/pixbufs */
        GList *draw_queue;      /* list of areas to redraw */
@@ -135,33 +148,33 @@ struct RendererTiles
        gint hidpi_scale;
 };
 
+constexpr size_t COLOR_BYTES = 3; /* rgb */
 
 
-static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h);
-static void rt_overlay_draw(RendererTiles *rt, gint x, gint y, gint w, gint h, ImageTile *it);
+inline gint get_right_pixbuf_offset(RendererTiles *rt)
+{
+       return (!!(rt->stereo_mode & PR_STEREO_RIGHT) != !!(rt->stereo_mode & PR_STEREO_SWAP)) ?
+              rt->pr->stereo_pixbuf_offset_right : rt->pr->stereo_pixbuf_offset_left;
+}
 
+inline gint get_left_pixbuf_offset(RendererTiles *rt)
+{
+       return (!!(rt->stereo_mode & PR_STEREO_RIGHT) == !!(rt->stereo_mode & PR_STEREO_SWAP)) ?
+              rt->pr->stereo_pixbuf_offset_right : rt->pr->stereo_pixbuf_offset_left;
+}
+
+} // namespace
+
+
+static void rt_overlay_draw(RendererTiles *rt, gint x, gint y, gint w, gint h, ImageTile *it);
 
-static void rt_tile_free_all(RendererTiles *rt);
-static void rt_tile_invalidate_region(RendererTiles *rt, gint x, gint y, gint w, gint h);
 static gboolean rt_tile_is_visible(RendererTiles *rt, ImageTile *it);
-static void rt_queue_clear(RendererTiles *rt);
 static void rt_queue_merge(QueueData *parent, QueueData *qd);
 static void rt_queue(RendererTiles *rt, gint x, gint y, gint w, gint h,
                     gint clamp, ImageRenderType render, gboolean new_data, gboolean only_existing);
 
-static void rt_hierarchy_changed_cb(GtkWidget *widget, GtkWidget *previous_toplevel, gpointer data);
 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 )
-
-#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 )
-
 
 static void rt_sync_scroll(RendererTiles *rt)
 {
@@ -187,7 +200,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);
@@ -197,6 +213,14 @@ static void rt_border_draw(RendererTiles *rt, gint x, gint y, gint w, gint h)
 
        cr = cairo_create(rt->surface);
 
+       auto draw = [rt, pr, cr](gint x, gint y, gint w, gint h)
+       {
+               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, x + rt->stereo_off_x, y + rt->stereo_off_y, w, h);
+               cairo_fill(cr);
+               rt_overlay_draw(rt, x, y, w, h, nullptr);
+       };
+
        if (!pr->pixbuf && !pr->source_tiles_enabled)
                {
                if (pr_clip_region(x, y, w, h,
@@ -204,10 +228,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_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);
+                       draw(rx, ry, rw, rh);
                        }
                cairo_destroy(cr);
                return;
@@ -221,10 +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_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);
+                       draw(rx, ry, rw, rh);
                        }
                if (pr->viewport_width - pr->vis_width - pr->x_offset > 0 &&
                    pr_clip_region(x, y, w, h,
@@ -232,10 +250,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_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);
+                       draw(rx, ry, rw, rh);
                        }
                }
        if (pr->vis_height < pr->viewport_height)
@@ -246,10 +261,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_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);
+                       draw(rx, ry, rw, rh);
                        }
                if (pr->viewport_height - pr->vis_height - pr->y_offset > 0 &&
                    pr_clip_region(x, y, w, h,
@@ -257,10 +269,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_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);
+                       draw(rx, ry, rw, rh);
                        }
                }
        cairo_destroy(cr);
@@ -281,9 +290,7 @@ static void rt_border_clear(RendererTiles *rt)
 
 static ImageTile *rt_tile_new(gint x, gint y, gint width, gint height)
 {
-       ImageTile *it;
-
-       it = g_new0(ImageTile, 1);
+       auto it = g_new0(ImageTile, 1);
 
        it->x = x;
        it->y = y;
@@ -307,20 +314,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;
 }
@@ -423,8 +417,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);
@@ -475,12 +471,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;
 }
 
@@ -539,37 +531,34 @@ static void rt_tile_prepare(RendererTiles *rt, ImageTile *it)
  *-------------------------------------------------------------------
  */
 
-static void rt_overlay_get_position(RendererTiles *rt, OverlayData *od,
-                                   gint *x, gint *y, gint *w, gint *h)
+static void rt_overlay_get_position(const RendererTiles *rt, const OverlayData *od,
+                                    gint &x, gint &y, gint &w, gint &h)
 {
        PixbufRenderer *pr = rt->pr;
-       gint px, py, pw, ph;
 
-       pw = gdk_pixbuf_get_width(od->pixbuf);
-       ph = gdk_pixbuf_get_height(od->pixbuf);
-       px = od->x;
-       py = od->y;
+       x = od->x;
+       y = od->y;
+       w = gdk_pixbuf_get_width(od->pixbuf);
+       h = gdk_pixbuf_get_height(od->pixbuf);
 
        if (od->flags & OVL_RELATIVE)
                {
-               if (px < 0) px = pr->viewport_width - pw + px;
-               if (py < 0) py = pr->viewport_height - ph + py;
+               if (x < 0) x = pr->viewport_width - w + x;
+               if (y < 0) y = pr->viewport_height - h + y;
                }
-
-       if (x) *x = px;
-       if (y) *y = py;
-       if (w) *w = pw;
-       if (h) *h = ph;
 }
 
 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;
 
-       rt_overlay_get_position(rt, od, &px, &py, &pw, &ph);
+       rt_overlay_get_position(rt, od, px, py, pw, ph);
 
        attributes.window_type = GDK_WINDOW_CHILD;
        attributes.wclass = GDK_INPUT_OUTPUT;
@@ -594,15 +583,21 @@ 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;
 
                if (!od->window) rt_overlay_init_window(rt, od);
 
-               rt_overlay_get_position(rt, od, &px, &py, &pw, &ph);
+               rt_overlay_get_position(rt, od, px, py, pw, ph);
                if (pr_clip_region(x, y, w, h, px, py, pw, ph, &rx, &ry, &rw, &rh))
                        {
                        if (!rt->overlay_buffer)
@@ -634,12 +629,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);
@@ -668,9 +665,12 @@ 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);
+       rt_overlay_get_position(rt, od, x, y, w, h);
 
        /* add borders */
        x -= x1;
@@ -714,9 +714,12 @@ 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);
+                       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);
                        }
                }
@@ -744,7 +747,6 @@ gint renderer_tiles_overlay_add(void *renderer, GdkPixbuf *pixbuf, gint x, gint
 {
        auto rt = static_cast<RendererTiles *>(renderer);
        PixbufRenderer *pr = rt->pr;
-       OverlayData *od;
        gint id;
 
        g_return_val_if_fail(IS_PIXBUF_RENDERER(pr), -1);
@@ -753,7 +755,7 @@ gint renderer_tiles_overlay_add(void *renderer, GdkPixbuf *pixbuf, gint x, gint
        id = 1;
        while (rt_overlay_find(rt, id)) id++;
 
-       od = g_new0(OverlayData, 1);
+       auto od = g_new0(OverlayData, 1);
        od->id = id;
        od->pixbuf = pixbuf;
        g_object_ref(G_OBJECT(od->pixbuf));
@@ -789,9 +791,7 @@ static void rt_overlay_list_clear(RendererTiles *rt)
 {
        while (rt->overlay_list)
                {
-               OverlayData *od;
-
-               od = static_cast<OverlayData *>(rt->overlay_list->data);
+               auto od = static_cast<OverlayData *>(rt->overlay_list->data);
                rt_overlay_free(rt, od);
                }
 }
@@ -813,7 +813,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;
@@ -856,7 +856,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);
@@ -874,17 +874,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);
@@ -916,11 +920,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);
@@ -952,11 +962,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;
 
@@ -989,11 +1004,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;
 
@@ -1025,10 +1044,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;
 
@@ -1109,7 +1132,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;
@@ -1123,7 +1146,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;
@@ -1151,8 +1177,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;
@@ -1175,8 +1205,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;
@@ -1261,6 +1297,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)
                {
@@ -1304,6 +1348,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);
@@ -1318,12 +1371,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
@@ -1336,12 +1385,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);
                        }
                }
 }
@@ -1414,10 +1459,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;
 
@@ -1443,14 +1492,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 */
@@ -1464,23 +1510,23 @@ static void rt_tile_render(RendererTiles *rt, ImageTile *it,
                if (pr->image_width > 32767) wide_image = TRUE;
 
                rt_tile_get_region(has_alpha, pr->ignore_alpha,
-                                  pr->pixbuf, it->pixbuf, pb_x, pb_y, pb_w, pb_h,
-                                  static_cast<gdouble>(0.0) - src_x - GET_RIGHT_PIXBUF_OFFSET(rt) * scale_x,
-                                  static_cast<gdouble>(0.0) - src_y,
-                                  scale_x, scale_y,
-                                  (fast) ? GDK_INTERP_NEAREST : pr->zoom_quality,
-                                  it->x + pb_x, it->y + pb_y, wide_image);
+                                  pr->pixbuf, it->pixbuf, pb_x, pb_y, pb_w, pb_h,
+                                  static_cast<gdouble>(0.0) - src_x - get_right_pixbuf_offset(rt) * scale_x,
+                                  static_cast<gdouble>(0.0) - src_y,
+                                  scale_x, scale_y,
+                                  (fast) ? GDK_INTERP_NEAREST : pr->zoom_quality,
+                                  it->x + pb_x, it->y + pb_y, wide_image);
                if (rt->stereo_mode & PR_STEREO_ANAGLYPH &&
                    (pr->stereo_pixbuf_offset_right > 0 || pr->stereo_pixbuf_offset_left > 0))
                        {
                        GdkPixbuf *right_pb = rt_get_spare_tile(rt);
                        rt_tile_get_region(has_alpha, pr->ignore_alpha,
-                                          pr->pixbuf, right_pb, pb_x, pb_y, pb_w, pb_h,
-                                          static_cast<gdouble>(0.0) - src_x - GET_LEFT_PIXBUF_OFFSET(rt) * scale_x,
-                                          static_cast<gdouble>(0.0) - src_y,
-                                          scale_x, scale_y,
-                                          (fast) ? GDK_INTERP_NEAREST : pr->zoom_quality,
-                                          it->x + pb_x, it->y + pb_y, wide_image);
+                                          pr->pixbuf, right_pb, pb_x, pb_y, pb_w, pb_h,
+                                          static_cast<gdouble>(0.0) - src_x - get_left_pixbuf_offset(rt) * scale_x,
+                                          static_cast<gdouble>(0.0) - src_y,
+                                          scale_x, scale_y,
+                                          (fast) ? GDK_INTERP_NEAREST : pr->zoom_quality,
+                                          it->x + pb_x, it->y + pb_y, wide_image);
                        pr_create_anaglyph(rt->stereo_mode, it->pixbuf, right_pb, pb_x, pb_y, pb_w, pb_h);
                        /* do not care about freeing spare_tile, it will be reused */
                        }
@@ -1492,7 +1538,7 @@ static void rt_tile_render(RendererTiles *rt, ImageTile *it,
                {
                cairo_t *cr;
 
-               if (pr->func_post_process && !(pr->post_process_slow && fast))
+               if (pr->func_post_process && (!pr->post_process_slow || !fast))
                        pr->func_post_process(pr, &it->pixbuf, x, y, w, h, pr->post_process_user_data);
 
                cr = cairo_create(it->surface);
@@ -1508,8 +1554,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 */
@@ -1536,9 +1580,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);
@@ -1723,32 +1764,21 @@ static gboolean rt_queue_draw_idle_cb(gpointer data)
                return rt_queue_schedule_next_draw(rt, FALSE);
 }
 
-static void rt_queue_list_free(GList *list)
+static void rt_queue_data_free(gpointer data)
 {
-       GList *work;
+       auto *qd = static_cast<QueueData *>(data);
 
-       work = list;
-       while (work)
-               {
-               QueueData *qd;
-
-               qd = static_cast<QueueData *>(work->data);
-               work = work->next;
-
-               qd->it->qd = nullptr;
-               qd->it->qd2 = nullptr;
-               g_free(qd);
-               }
-
-       g_list_free(list);
+       qd->it->qd = nullptr;
+       qd->it->qd2 = nullptr;
+       g_free(qd);
 }
 
 static void rt_queue_clear(RendererTiles *rt)
 {
-       rt_queue_list_free(rt->draw_queue);
+       g_list_free_full(rt->draw_queue, rt_queue_data_free);
        rt->draw_queue = nullptr;
 
-       rt_queue_list_free(rt->draw_queue_2pass);
+       g_list_free_full(rt->draw_queue_2pass, rt_queue_data_free);
        rt->draw_queue_2pass = nullptr;
 
        if (rt->draw_idle_id)
@@ -1787,10 +1817,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;
@@ -1820,9 +1854,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;
 
@@ -1846,15 +1883,13 @@ static gboolean rt_queue_to_tiles(RendererTiles *rt, gint x, gint y, gint w, gin
                                           j > rt->y_scroll + pr->vis_height)));
                        if (it)
                                {
-                               QueueData *qd;
-
                                if ((render == TILE_RENDER_ALL && it->render_done != TILE_RENDER_ALL) ||
                                    (render == TILE_RENDER_AREA && it->render_todo != TILE_RENDER_ALL))
                                        {
                                        it->render_todo = render;
                                        }
 
-                               qd = g_new(QueueData, 1);
+                               auto qd = g_new(QueueData, 1);
                                qd->it = it;
                                qd->new_data = new_data;
 
@@ -1906,7 +1941,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);
 
@@ -1948,10 +1984,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;
 
@@ -2011,22 +2048,28 @@ 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,
-                                    src_x - GET_RIGHT_PIXBUF_OFFSET(rt), src_y,
-                                    pr->image_width, pr->image_height,
-                                    src_w, src_h,
-                                    &x, &y,
-                                    &width, &height);
+                                         src_x - get_right_pixbuf_offset(rt), src_y,
+                                         pr->image_width, pr->image_height,
+                                         src_w, src_h,
+                                         &x, &y,
+                                         &width, &height);
 
        if (pr->scale != 1.0 && pr->zoom_quality != GDK_INTERP_NEAREST)
                {
@@ -2063,7 +2106,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));
 }
@@ -2154,7 +2197,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);
                }
@@ -2175,7 +2218,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);
@@ -2188,7 +2231,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;
@@ -2197,7 +2240,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)
                        {
@@ -2228,17 +2271,12 @@ 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;
-               pw = gdk_pixbuf_get_width(od->pixbuf);
-               ph = gdk_pixbuf_get_height(od->pixbuf);
-               px = od->x;
-               py = od->y;
+               gint px;
+               gint py;
+               gint pw;
+               gint ph;
 
-               if (od->flags & OVL_RELATIVE)
-                       {
-                       if (px < 0) px = rt->pr->viewport_width - pw + px;
-                       if (py < 0) py = rt->pr->viewport_height - ph + py;
-                       }
+               rt_overlay_get_position(rt, od, px, py, pw, ph);
 
                gdk_cairo_set_source_pixbuf(cr, od->pixbuf, px, py);
                cairo_paint(cr);