Fix #314: Remote commands for thumbnail maintenance
[geeqie.git] / src / renderer-tiles.c
index fe5ae57..6a034e1 100644 (file)
@@ -1,14 +1,22 @@
 /*
- * Geeqie
- * (C) 2006 John Ellis
- * Copyright (C) 2008 - 2012 The Geeqie Team
+ * Copyright (C) 2006 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
- * Author: Vladimir Nadvornik
  *
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <stdio.h>
@@ -127,18 +135,18 @@ struct _RendererTiles
 
        GList *overlay_list;
        cairo_surface_t *overlay_buffer;
-       
+
        guint draw_idle_id; /* event source id */
 
        GdkPixbuf *spare_tile;
-       
+
        gint stereo_mode;
        gint stereo_off_x;
        gint stereo_off_y;
-       
+
        gint x_scroll;  /* allow local adjustment and mirroring */
        gint y_scroll;
-       
+
 };
 
 
@@ -172,13 +180,13 @@ static gint rt_queue_draw_idle_cb(gpointer data);
 static void rt_sync_scroll(RendererTiles *rt)
 {
        PixbufRenderer *pr = rt->pr;
-       
-       rt->x_scroll = (rt->stereo_mode & PR_STEREO_MIRROR) ? 
-                      pr->width - pr->vis_width - pr->x_scroll 
+
+       rt->x_scroll = (rt->stereo_mode & PR_STEREO_MIRROR) ?
+                      pr->width - pr->vis_width - pr->x_scroll
                       : pr->x_scroll;
-       
-       rt->y_scroll = (rt->stereo_mode & PR_STEREO_FLIP) ? 
-                      pr->height - pr->vis_height - pr->y_scroll 
+
+       rt->y_scroll = (rt->stereo_mode & PR_STEREO_FLIP) ?
+                      pr->height - pr->vis_height - pr->y_scroll
                       : pr->y_scroll;
 }
 
@@ -211,12 +219,12 @@ 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, 0, 0, 0);
+                       cairo_set_source_rgb(cr, (double)pr->color.red/65535, (double)pr->color.green/65535, (double)pr->color.blue/65535);
                        cairo_rectangle(cr, rx + rt->stereo_off_x, ry + rt->stereo_off_y, rw, rh);
                        cairo_fill(cr);
-                       cairo_destroy(cr);
                        rt_overlay_draw(rt, rx, ry, rw, rh, NULL);
                        }
+               cairo_destroy(cr);
                return;
                }
 
@@ -228,7 +236,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, 0, 0, 0);
+                       cairo_set_source_rgb(cr, (double)pr->color.red/65535, (double)pr->color.green/65535, (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, NULL);
@@ -239,7 +247,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, 0, 0, 0);
+                       cairo_set_source_rgb(cr, (double)pr->color.red/65535, (double)pr->color.green/65535, (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, NULL);
@@ -253,7 +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, 0, 0, 0);
+                       cairo_set_source_rgb(cr, (double)pr->color.red/65535, (double)pr->color.green/65535, (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, NULL);
@@ -264,7 +272,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, 0, 0, 0);
+                       cairo_set_source_rgb(cr, (double)pr->color.red/65535, (double)pr->color.green/65535, (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, NULL);
@@ -581,11 +589,8 @@ static void rt_overlay_draw(RendererTiles *rt, gint x, gint y, gint w, gint h,
                            ImageTile *it)
 {
        PixbufRenderer *pr = rt->pr;
-       GtkWidget *box;
        GList *work;
 
-       box = GTK_WIDGET(pr);
-
        work = rt->overlay_list;
        while (work)
                {
@@ -597,7 +602,7 @@ static void rt_overlay_draw(RendererTiles *rt, gint x, gint y, gint w, gint h,
                work = work->next;
 
                if (!od->window) rt_overlay_init_window(rt, od);
-               
+
                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))
                        {
@@ -616,11 +621,11 @@ static void rt_overlay_draw(RendererTiles *rt, gint x, gint y, gint w, gint h,
                                cairo_set_source_surface(cr, it->surface, (pr->x_offset + (it->x - rt->x_scroll)) - rx, (pr->y_offset + (it->y - rt->y_scroll)) - ry);
                                cairo_rectangle(cr, 0, 0, rw, rh);
                                cairo_fill_preserve(cr);
-                               
+
                                gdk_cairo_set_source_pixbuf(cr, od->pixbuf, px - rx, py - ry);
                                cairo_fill (cr);
                                cairo_destroy (cr);
-                               
+
                                cr = gdk_cairo_create(od->window);
                                cairo_set_source_surface(cr, rt->overlay_buffer, rx - px, ry - py);
                                cairo_rectangle (cr, rx - px, ry - py, rw, rh);
@@ -645,11 +650,11 @@ static void rt_overlay_draw(RendererTiles *rt, gint x, gint y, gint w, gint h,
                                        cairo_set_source_rgb(cr, 0, 0, 0);
                                        cairo_rectangle(cr, 0, 0, sw, sh);
                                        cairo_fill_preserve(cr);
-                               
+
                                        gdk_cairo_set_source_pixbuf(cr, od->pixbuf, px - sx, py - sy);
                                        cairo_fill (cr);
                                        cairo_destroy (cr);
-                               
+
                                        cr = gdk_cairo_create(od->window);
                                        cairo_set_source_surface(cr, rt->overlay_buffer, sx - px, sy - py);
                                        cairo_rectangle (cr, sx - px, sy - py, sw, sh);
@@ -667,13 +672,13 @@ static void rt_overlay_queue_draw(RendererTiles *rt, OverlayData *od, gint x1, g
        gint x, y, w, h;
 
        rt_overlay_get_position(rt, od, &x, &y, &w, &h);
-       
+
        /* add borders */
        x -= x1;
        y -= y1;
        w += x1 + x2;
        h += y1 + y2;
-       
+
        rt_queue(rt, rt->x_scroll - pr->x_offset + x,
                 rt->y_scroll - pr->y_offset + y,
                 w, h,
@@ -705,9 +710,9 @@ static void rt_overlay_update_sizes(RendererTiles *rt)
                {
                OverlayData *od = work->data;
                work = work->next;
-               
+
                if (!od->window) rt_overlay_init_window(rt, od);
-               
+
                if (od->flags & OVL_RELATIVE)
                        {
                        gint x, y, w, h;
@@ -758,7 +763,7 @@ gint renderer_tiles_overlay_add(void *renderer, GdkPixbuf *pixbuf, gint x, gint
        od->flags = flags;
 
        rt_overlay_init_window(rt, od);
-       
+
        rt->overlay_list = g_list_append(rt->overlay_list, od);
 
        rt_overlay_queue_draw(rt, od, 0, 0, 0, 0);
@@ -998,14 +1003,13 @@ static void rt_tile_mirror_and_flip(RendererTiles *rt, GdkPixbuf **tile, gint x,
        gint srs, drs;
        guchar *s_pix, *d_pix;
        guchar *sp, *dp;
-       guchar *spi, *dpi;
+       guchar *dpi;
        gint i, j;
        gint tw = rt->tile_width;
        gint th = rt->tile_height;
 
        srs = gdk_pixbuf_get_rowstride(src);
        s_pix = gdk_pixbuf_get_pixels(src);
-       spi = s_pix + (x * COLOR_BYTES);
 
        dest = rt_get_spare_tile(rt);
        drs = gdk_pixbuf_get_rowstride(dest);
@@ -1119,13 +1123,10 @@ static gboolean rt_source_tile_render(RendererTiles *rt, ImageTile *it,
                                      gboolean new_data, gboolean fast)
 {
        PixbufRenderer *pr = rt->pr;
-       GtkWidget *box;
        GList *list;
        GList *work;
        gboolean draw = FALSE;
 
-       box = GTK_WIDGET(pr);
-
        if (pr->zoom == 1.0 || pr->scale == 1.0)
                {
                list = pr_source_tile_compute_region(pr, it->x + x, it->y + y, w, h, TRUE);
@@ -1235,7 +1236,7 @@ static gboolean rt_source_tile_render(RendererTiles *rt, ImageTile *it,
        return draw;
 }
 
-static void rt_tile_get_region(gboolean has_alpha, 
+static void rt_tile_get_region(gboolean has_alpha,
                                const GdkPixbuf *src, GdkPixbuf *dest,
                                int pb_x, int pb_y, int pb_w, int pb_h,
                                double offset_x, double offset_y, double scale_x, double scale_y,
@@ -1251,10 +1252,10 @@ static void rt_tile_get_region(gboolean has_alpha,
                                             pb_w, pb_h,
                                             dest,
                                             pb_x, pb_y);
-                       } 
+                       }
                else
                        {
-                       gdk_pixbuf_scale(src, dest, 
+                       gdk_pixbuf_scale(src, dest,
                                         pb_x, pb_y, pb_w, pb_h,
                                         offset_x,
                                         offset_y,
@@ -1264,14 +1265,20 @@ static void rt_tile_get_region(gboolean has_alpha,
                }
        else
                {
-               gdk_pixbuf_composite_color(src, dest, 
+               gdk_pixbuf_composite_color(src, dest,
                                         pb_x, pb_y, pb_w, pb_h,
                                         offset_x,
                                         offset_y,
                                         scale_x, scale_y,
                                         interp_type,
                                         255, check_x, check_y,
-                                        PR_ALPHA_CHECK_SIZE, PR_ALPHA_CHECK1, PR_ALPHA_CHECK2);
+                                        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)));
                }
 }
 
@@ -1295,7 +1302,6 @@ static void rt_tile_render(RendererTiles *rt, ImageTile *it,
                           gboolean new_data, gboolean fast)
 {
        PixbufRenderer *pr = rt->pr;
-       GtkWidget *box;
        gboolean has_alpha;
        gboolean draw = FALSE;
        gint orientation = rt_get_orientation(rt);
@@ -1323,8 +1329,6 @@ static void rt_tile_render(RendererTiles *rt, ImageTile *it,
        rt_tile_prepare(rt, it);
        has_alpha = (pr->pixbuf && gdk_pixbuf_get_has_alpha(pr->pixbuf));
 
-       box = GTK_WIDGET(pr);
-
        /* FIXME checker colors for alpha should be configurable,
         * also should be drawn for blank = TRUE
         */
@@ -1338,30 +1342,11 @@ static void rt_tile_render(RendererTiles *rt, ImageTile *it,
                cairo_set_source_rgb(cr, 0, 0, 0);
                cairo_fill (cr);
                cairo_destroy (cr);
-#if 0
-               gdk_draw_rectangle(it->pixmap, box->style->black_gc, TRUE,
-                                  0, 0, it->w, it->h);
-#endif
                }
        else if (pr->source_tiles_enabled)
                {
                draw = rt_source_tile_render(rt, it, x, y, w, h, new_data, fast);
                }
-       else if ((pr->zoom == 1.0 || pr->scale == 1.0) &&
-                pr->aspect_ratio == 1.0 &&
-                !has_alpha &&
-                orientation == EXIF_ORIENTATION_TOP_LEFT && 
-                !(pr->func_post_process && !(pr->post_process_slow && fast)) &&
-                !(rt->stereo_mode & PR_STEREO_ANAGLYPH))
-               {
-               /* special case: faster, simple, scale 1.0, base orientation, no postprocessing */
-               cairo_t *cr;
-               cr = cairo_create(it->surface);
-               cairo_rectangle (cr, x, y, w, h);
-               gdk_cairo_set_source_pixbuf(cr, pr->pixbuf, -it->x - GET_RIGHT_PIXBUF_OFFSET(rt), -it->y);
-               cairo_fill (cr);
-               cairo_destroy (cr);
-               }
        else
                {
                gdouble scale_x, scale_y;
@@ -1399,7 +1384,7 @@ static void rt_tile_render(RendererTiles *rt, ImageTile *it,
                                /* nothing to do */
                                break;
                        }
-               
+
                /* HACK: The pixbuf scalers get kinda buggy(crash) with extremely
                 * small sizes for anything but GDK_INTERP_NEAREST
                 */
@@ -1412,7 +1397,7 @@ static void rt_tile_render(RendererTiles *rt, ImageTile *it,
                                   scale_x, scale_y,
                                   (fast) ? GDK_INTERP_NEAREST : pr->zoom_quality,
                                   it->x + pb_x, it->y + pb_y);
-               if (rt->stereo_mode & PR_STEREO_ANAGLYPH && 
+               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);
@@ -1463,7 +1448,7 @@ static void rt_tile_expose(RendererTiles *rt, ImageTile *it,
                }
        if (it->x + x + w > rt->x_scroll + pr->vis_width)
                {
-               w = rt->x_scroll + pr->vis_width - it->x - x; 
+               w = rt->x_scroll + pr->vis_width - it->x - x;
                }
        if (w < 1) return;
        if (it->y + y < rt->y_scroll)
@@ -1473,7 +1458,7 @@ static void rt_tile_expose(RendererTiles *rt, ImageTile *it,
                }
        if (it->y + y + h > rt->y_scroll + pr->vis_height)
                {
-               h = rt->y_scroll + pr->vis_height - it->y - y; 
+               h = rt->y_scroll + pr->vis_height - it->y - y;
                }
        if (h < 1) return;
 
@@ -1514,8 +1499,8 @@ static gboolean rt_tile_is_visible(RendererTiles *rt, ImageTile *it)
 static gint rt_get_queued_area(GList *work)
 {
        gint area = 0;
-       
-       while (work) 
+
+       while (work)
                {
                QueueData *qd = work->data;
                area += qd->w * qd->h;
@@ -1530,15 +1515,15 @@ static gboolean rt_queue_schedule_next_draw(RendererTiles *rt, gboolean force_se
        PixbufRenderer *pr = rt->pr;
        gfloat percent;
        gint visible_area = pr->vis_width * pr->vis_height;
-       
+
        if (!pr->loading)
                {
-               /* 2pass prio */ 
+               /* 2pass prio */
                DEBUG_2("redraw priority: 2pass");
                rt->draw_idle_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, rt_queue_draw_idle_cb, rt, NULL);
                return FALSE;
                }
-       
+
        if (visible_area == 0)
                {
                /* not known yet */
@@ -1548,7 +1533,7 @@ static gboolean rt_queue_schedule_next_draw(RendererTiles *rt, gboolean force_se
                {
                percent = 100.0 * rt_get_queued_area(rt->draw_queue) / visible_area;
                }
-       
+
        if (percent > 10.0)
                {
                /* we have enough data for starting intensive redrawing */
@@ -1556,7 +1541,7 @@ static gboolean rt_queue_schedule_next_draw(RendererTiles *rt, gboolean force_se
                rt->draw_idle_id = g_idle_add_full(GDK_PRIORITY_REDRAW, rt_queue_draw_idle_cb, rt, NULL);
                return FALSE;
                }
-       
+
        if (percent < 1.0 || force_set)
                {
                /* queue is (almost) empty, wait  50 ms*/
@@ -1564,12 +1549,12 @@ static gboolean rt_queue_schedule_next_draw(RendererTiles *rt, gboolean force_se
                rt->draw_idle_id = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE, 50, rt_queue_draw_idle_cb, rt, NULL);
                return FALSE;
                }
-       
+
        /* keep the same priority as before */
        DEBUG_2("redraw priority: no change %.2f %%", percent);
        return TRUE;
 }
-               
+
 
 static gboolean rt_queue_draw_idle_cb(gpointer data)
 {
@@ -1878,7 +1863,7 @@ static void rt_scroll(void *renderer, gint x_off, gint y_off)
 
        rt_sync_scroll(rt);
        if (rt->stereo_mode & PR_STEREO_MIRROR) x_off = -x_off;
-       if (rt->stereo_mode & PR_STEREO_FLIP) y_off = -y_off; 
+       if (rt->stereo_mode & PR_STEREO_FLIP) y_off = -y_off;
 
        gint w = pr->vis_width - abs(x_off);
        gint h = pr->vis_height - abs(y_off);
@@ -1995,7 +1980,7 @@ static void renderer_redraw(RendererTiles *rt, gint x, gint y, gint w, gint h,
 
        x -= rt->stereo_off_x;
        y -= rt->stereo_off_y;
-       
+
        rt_border_draw(rt, x, y, w, h);
 
        x = MAX(0, x - pr->x_offset + pr->x_scroll);
@@ -2037,18 +2022,18 @@ static void renderer_update_viewport(void *renderer)
 
        rt->stereo_off_x = 0;
        rt->stereo_off_y = 0;
-       
-       if (rt->stereo_mode & PR_STEREO_RIGHT) 
+
+       if (rt->stereo_mode & PR_STEREO_RIGHT)
                {
-               if (rt->stereo_mode & PR_STEREO_HORIZ) 
+               if (rt->stereo_mode & PR_STEREO_HORIZ)
                        {
                        rt->stereo_off_x = rt->pr->viewport_width;
                        }
-               else if (rt->stereo_mode & PR_STEREO_VERT) 
+               else if (rt->stereo_mode & PR_STEREO_VERT)
                        {
                        rt->stereo_off_y = rt->pr->viewport_height;
                        }
-               else if (rt->stereo_mode & PR_STEREO_FIXED) 
+               else if (rt->stereo_mode & PR_STEREO_FIXED)
                        {
                        rt->stereo_off_x = rt->pr->stereo_fixed_x_right;
                        rt->stereo_off_y = rt->pr->stereo_fixed_y_right;
@@ -2056,7 +2041,7 @@ static void renderer_update_viewport(void *renderer)
                }
        else
                {
-               if (rt->stereo_mode & PR_STEREO_FIXED) 
+               if (rt->stereo_mode & PR_STEREO_FIXED)
                        {
                        rt->stereo_off_x = rt->pr->stereo_fixed_x_left;
                        rt->stereo_off_y = rt->pr->stereo_fixed_y_left;
@@ -2147,9 +2132,9 @@ static gboolean rt_expose_cb(GtkWidget *widget, GdkEventExpose *event, gpointer
 RendererFuncs *renderer_tiles_new(PixbufRenderer *pr)
 {
        RendererTiles *rt = g_new0(RendererTiles, 1);
-       
+
        rt->pr = pr;
-       
+
        rt->f.area_changed = renderer_area_changed;
        rt->f.update_pixbuf = renderer_update_pixbuf;
        rt->f.free = renderer_free;
@@ -2164,7 +2149,7 @@ RendererFuncs *renderer_tiles_new(PixbufRenderer *pr)
        rt->f.overlay_get = renderer_tiles_overlay_get;
 
        rt->f.stereo_set = renderer_stereo_set;
-       
+
        rt->tile_width = PR_TILE_SIZE;
        rt->tile_height = PR_TILE_SIZE;
 
@@ -2174,7 +2159,7 @@ RendererFuncs *renderer_tiles_new(PixbufRenderer *pr)
        rt->tile_cache_max = PR_CACHE_SIZE_DEFAULT;
 
        rt->draw_idle_id = 0;
-       
+
        rt->stereo_mode = 0;
        rt->stereo_off_x = 0;
        rt->stereo_off_y = 0;