Use util_clip_triangle() in pan_item_tri_new()
[geeqie.git] / src / pixbuf-renderer.h
index ef3d976..fb4b298 100644 (file)
@@ -1,21 +1,36 @@
 /*
- * Geeqie
- * (C) 2006 John Ellis
- * Copyright (C) 2008 - 2010 The Geeqie Team
+ * Copyright (C) 2006 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
  *
  * Author: John Ellis
  *
- * 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.
  */
 
 #ifndef PIXBUF_RENDERER_H
 #define PIXBUF_RENDERER_H
 
-#include <gtk/gtkeventbox.h>
-#include <gtk/gtkwindow.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gdk/gdk.h>
+#include <glib-object.h>
+#include <glib.h>
+#include <gtk/gtk.h>
 
+#include "typedefs.h"
+
+struct PixbufRenderer;
 
 #define TYPE_PIXBUF_RENDERER           (pixbuf_renderer_get_type())
 #define PIXBUF_RENDERER(obj)           (G_TYPE_CHECK_INSTANCE_CAST((obj), TYPE_PIXBUF_RENDERER, PixbufRenderer))
 #define IS_PIXBUF_RENDERER_CLASS(klass)        (G_TYPE_CHECK_CLASS_TYPE((klass), TYPE_PIXBUF_RENDERER))
 #define PIXBUF_RENDERER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), TYPE_PIXBUF_RENDERER, PixbufRendererClass))
 
+/**
+ * @def PR_ALPHA_CHECK_SIZE
+ * alpha channel checkerboard (same as gimp)
+ */
+#define PR_ALPHA_CHECK_SIZE 16
 
-typedef struct _PixbufRenderer PixbufRenderer;
-typedef struct _PixbufRendererClass PixbufRendererClass;
+/**
+ * @def PR_MIN_SCALE_SIZE
+ * when scaling image to below this size, use nearest pixel for scaling
+ * (below about 4, the other scale types become slow generating their conversion tables)
+ */
+#define PR_MIN_SCALE_SIZE 8
 
+/**
+ * @def PR_CACHE_SIZE_DEFAULT
+ * default size of tile cache (MiB)
+ */
+#define PR_CACHE_SIZE_DEFAULT 8
 
-typedef gint (* PixbufRendererTileRequestFunc)(PixbufRenderer *pr, gint x, gint y,
-                                              gint width, gint height, GdkPixbuf *pixbuf, gpointer user_data);
-typedef void (* PixbufRendererTileDisposeFunc)(PixbufRenderer *pr, gint x, gint y,
-                                              gint width, gint height, GdkPixbuf *pixbuf, gpointer user_data);
+/**
+ * @def ROUND_UP
+ * round A up to integer count of B
+ */
+#define ROUND_UP(A,B)   ((gint)(((A)+(B)-1)/(B))*(B))
 
-typedef void (* PixbufRendererPostProcessFunc)(PixbufRenderer *pr, GdkPixbuf **pixbuf, gint x, gint y,
-                                              gint width, gint height, gpointer user_data);
+/**
+ * @def ROUND_DOWN
+ * round A down to integer count of B
+ */
+#define ROUND_DOWN(A,B) ((gint)(((A))/(B))*(B))
 
-typedef enum {
-       PR_SCROLL_RESET_TOPLEFT = 0,
-       PR_SCROLL_RESET_CENTER,
-       PR_SCROLL_RESET_NOCHANGE,
-       PR_SCROLL_RESET_COUNT,
-} PixbufRendererScrollResetType;
 
-struct _PixbufRenderer
+using PixbufRendererTileRequestFunc = gint (*)(PixbufRenderer *, gint, gint, gint, gint, GdkPixbuf *, gpointer);
+using PixbufRendererTileDisposeFunc = void (*)(PixbufRenderer *, gint, gint, gint, gint, GdkPixbuf *, gpointer);
+
+using PixbufRendererPostProcessFunc = void (*)(PixbufRenderer *, GdkPixbuf **, gint, gint, gint, gint, gpointer);
+
+enum ImageRenderType {
+       TILE_RENDER_NONE = 0, /**< do nothing */
+       TILE_RENDER_AREA, /**< render an area of the tile */
+       TILE_RENDER_ALL /**< render the whole tile */
+};
+
+enum OverlayRendererFlags {
+       OVL_NORMAL      = 0,
+       OVL_RELATIVE    = 1 << 0, /**< x,y coordinates are relative, negative values start bottom right */
+       /* OVL_HIDE_ON_SCROLL = 1 << 1*/ /**< hide temporarily when scrolling (not yet implemented) */
+};
+
+struct RendererFuncs
+{
+    void (*area_changed)(void *renderer, gint src_x, gint src_y, gint src_w, gint src_h); /**< pixbuf area changed */
+       void (*invalidate_region)(void *renderer, gint x, gint y, gint w, gint h);
+       void (*scroll)(void *renderer, gint x_off, gint y_off); /**< scroll */
+       void (*update_viewport)(void *renderer); /**< window / wiewport / border color has changed */
+       void (*update_pixbuf)(void *renderer, gboolean lazy); /**< pixbuf has changed */
+       void (*update_zoom)(void *renderer, gboolean lazy); /**< zoom has changed */
+
+       gint (*overlay_add)(void *renderer, GdkPixbuf *pixbuf, gint x, gint y, OverlayRendererFlags flags);
+       void (*overlay_set)(void *renderer, gint id, GdkPixbuf *pixbuf, gint x, gint y);
+       gboolean (*overlay_get)(void *renderer, gint id, GdkPixbuf **pixbuf, gint *x, gint *y);
+
+       void (*stereo_set)(void *renderer, gint stereo_mode); /**< set stereo mode */
+
+       void (*free)(void *renderer);
+};
+
+struct PixbufRenderer
 {
        GtkEventBox eventbox;
 
-       gint image_width;       /* image actual dimensions (pixels) */
+       gint image_width;       /**< image actual dimensions (pixels) */
        gint image_height;
+       gint stereo_pixbuf_offset_right; /**< offset of the right part of the stereo image in pixbuf */
+       gint stereo_pixbuf_offset_left; /**< offset of the left part of the stereo image in pixbuf */
 
        GdkPixbuf *pixbuf;
 
-       gint window_width;      /* allocated size of window (drawing area) */
+       gint window_width;      /**< allocated size of window (drawing area) */
        gint window_height;
 
-       gint x_offset;          /* offset of image start (non-zero when image < window) */
+       gint viewport_width;    /**< allocated size of viewport (same as window for normal mode, half of window for SBS mode) */
+       gint viewport_height;
+
+       gint x_offset;          /**< offset of image start (non-zero when viewport < window) */
        gint y_offset;
-       
-       gint x_mouse; /* coordinates of the mouse taken from GtkEvent */
+
+       gint x_mouse; /**< coordinates of the mouse taken from GtkEvent */
        gint y_mouse;
 
-       gint vis_width;         /* dimensions of visible part of image */
+       gint vis_width;         /**< dimensions of visible part of image */
        gint vis_height;
 
-       gint width;             /* size of scaled image (result) */
+       gint width;             /**< size of scaled image (result) */
        gint height;
 
-       gint x_scroll;          /* scroll offset of image (into width, height to start drawing) */
+       gint x_scroll;          /**< scroll offset of image (into width, height to start drawing) */
        gint y_scroll;
 
-       gdouble norm_center_x;  /* coordinates of viewport center in the image, in range 0.0 - 1.0 */
-       gdouble norm_center_y;  /* these coordinates are used for PR_SCROLL_RESET_NOCHANGE and should be preserved over periods with NULL pixbuf */
-       
-       gdouble subpixel_x_scroll; /* subpixel scroll alignment, used to prevent acumulation of rounding errors */
+       gdouble norm_center_x;  /**< coordinates of viewport center in the image, in range 0.0 - 1.0 */
+       gdouble norm_center_y;  /**< these coordinates are used for ScrollReset::NOCHANGE and should be preserved over periods with NULL pixbuf */
+
+       gdouble subpixel_x_scroll; /**< subpixel scroll alignment, used to prevent accumulation of rounding errors */
        gdouble subpixel_y_scroll;
 
        gdouble zoom_min;
        gdouble zoom_max;
-       gdouble zoom;           /* zoom we want (0 is auto) */
-       gdouble scale;          /* zoom we got (should never be 0) */
+       gdouble zoom;           /**< zoom we want (0 is auto) */
+       gdouble scale;          /**< zoom we got (should never be 0) */
+
+       gdouble aspect_ratio;   /**< screen pixel aspect ratio (2.0 for 3DTV SBS mode) */
 
        GdkInterpType zoom_quality;
        gboolean zoom_2pass;
        gboolean zoom_expand;
 
-       GdkRgbDither dither_quality;
-
-       PixbufRendererScrollResetType scroll_reset;
+       ScrollReset scroll_reset;
 
        gboolean has_frame;
 
-       GtkWidget *parent_window;       /* resize parent_window when image dimensions change */
+       GtkWidget *parent_window;       /**< resize parent_window when image dimensions change */
 
        gboolean window_fit;
        gboolean window_limit;
@@ -100,22 +167,11 @@ struct _PixbufRenderer
 
        gboolean autofit_limit;
        gint autofit_limit_size;
+       gint enlargement_limit_size;
 
-
-       gint tile_cache_max;            /* max mb to use for offscreen buffer */
+       GdkRGBA color;
 
        /*< private >*/
-
-       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 */
-       GList *draw_queue_2pass;/* list when 2 pass is enabled */
-
-       guint draw_idle_id; /* event source id */
-
        gboolean in_drag;
        gint drag_last_x;
        gint drag_last_y;
@@ -124,7 +180,7 @@ struct _PixbufRenderer
        gboolean source_tiles_enabled;
        gint source_tiles_cache_size;
 
-       GList *source_tiles;    /* list of active source tiles */
+       GList *source_tiles;    /**< list of active source tiles */
        gint source_tile_width;
        gint source_tile_height;
 
@@ -140,9 +196,9 @@ struct _PixbufRenderer
        gboolean delay_flip;
        gboolean loading;
        gboolean complete;
-       gboolean debug_updated; /* debug only */
+       gboolean debug_updated; /**< debug only */
 
-       guint scroller_id; /* event source id */
+       guint scroller_id; /**< event source id */
        gint scroller_overlay;
        gint scroller_x;
        gint scroller_y;
@@ -151,15 +207,26 @@ struct _PixbufRenderer
        gint scroller_xinc;
        gint scroller_yinc;
 
-       GList *overlay_list;
-       GdkPixmap *overlay_buffer;
+       gint orientation;
+
+       gint stereo_mode;
 
-       GdkPixbuf *spare_tile;
+       StereoPixbufData stereo_data;
+       gboolean stereo_temp_disable;
+       gint stereo_fixed_width;
+       gint stereo_fixed_height;
+       gint stereo_fixed_x_left;
+       gint stereo_fixed_y_left;
+       gint stereo_fixed_x_right;
+       gint stereo_fixed_y_right;
 
-       gint orientation;
+       RendererFuncs *renderer;
+       RendererFuncs *renderer2;
+
+       gboolean ignore_alpha;
 };
 
-struct _PixbufRendererClass
+struct PixbufRendererClass
 {
        GtkEventBoxClass parent_class;
 
@@ -169,34 +236,46 @@ struct _PixbufRendererClass
        void (*update_pixel)(PixbufRenderer *pr);
 
        void (*render_complete)(PixbufRenderer *pr);
-       void (*drag)(PixbufRenderer *pr, GdkEventButton *event);
+       void (*drag)(PixbufRenderer *pr, GdkEventMotion *event);
 };
 
 
-GType pixbuf_renderer_get_type(void);
 
-PixbufRenderer *pixbuf_renderer_new(void);
 
-void pixbuf_renderer_set_parent(PixbufRenderer *pr, GtkWindow *window);
-GtkWindow *pixbuf_renderer_get_parent(PixbufRenderer *pr);
+GType pixbuf_renderer_get_type();
 
-/* display a pixbuf */
+PixbufRenderer *pixbuf_renderer_new();
+
+void pixbuf_renderer_set_parent(PixbufRenderer *pr, GtkWindow *window);
 
+/**
+ * @headerfile pixbuf_renderer_set_pixbuf
+ * display a pixbuf
+ */
 void pixbuf_renderer_set_pixbuf(PixbufRenderer *pr, GdkPixbuf *pixbuf, gdouble zoom);
 
-/* same as pixbuf_renderer_set_pixbuf but waits with redrawing for pixbuf_renderer_area_changed */
-void pixbuf_renderer_set_pixbuf_lazy(PixbufRenderer *pr, GdkPixbuf *pixbuf, gdouble zoom, gint orientation);
+/**
+ * @headerfile  pixbuf_renderer_set_pixbuf_lazy
+ * same as pixbuf_renderer_set_pixbuf but waits with redrawing for pixbuf_renderer_area_changed */
+void pixbuf_renderer_set_pixbuf_lazy(PixbufRenderer *pr, GdkPixbuf *pixbuf, gdouble zoom, gint orientation, StereoPixbufData stereo_data);
 
 
 GdkPixbuf *pixbuf_renderer_get_pixbuf(PixbufRenderer *pr);
 
 void pixbuf_renderer_set_orientation(PixbufRenderer *pr, gint orientation);
-gint pixbuf_renderer_get_orientation(PixbufRenderer *pr);
 
-void pixbuf_renderer_set_post_process_func(PixbufRenderer *pr, PixbufRendererPostProcessFunc func, gpointer user_data, gboolean slow);
+/**
+ * @headerfile pixbuf_renderer_set_stereo_data
+ * sets the format of stereo data in the input pixbuf
+ */
+void pixbuf_renderer_set_stereo_data(PixbufRenderer *pr, StereoPixbufData stereo_data);
 
-/* display an on-request array of pixbuf tiles */
+void pixbuf_renderer_set_post_process_func(PixbufRenderer *pr, PixbufRendererPostProcessFunc func, gpointer user_data, gboolean slow);
 
+/**
+ * @headerfile pixbuf_renderer_set_tiles
+ * display an on-request array of pixbuf tiles
+ */
 void pixbuf_renderer_set_tiles(PixbufRenderer *pr, gint width, gint height,
                               gint tile_width, gint tile_height, gint cache_size,
                               PixbufRendererTileRequestFunc func_request,
@@ -206,12 +285,17 @@ void pixbuf_renderer_set_tiles(PixbufRenderer *pr, gint width, gint height,
 void pixbuf_renderer_set_tiles_size(PixbufRenderer *pr, gint width, gint height);
 gint pixbuf_renderer_get_tiles(PixbufRenderer *pr);
 
-/* move image data from source to pr, source is then set to NULL image */
-
+/**
+ * @headerfile pixbuf_renderer_move
+ * move image data from source to pr, source is then set to NULL image
+ */
 void pixbuf_renderer_move(PixbufRenderer *pr, PixbufRenderer *source);
+void pixbuf_renderer_copy(PixbufRenderer *pr, PixbufRenderer *source);
 
-/* update region of existing image */
-
+/**
+ * @headerfile pixbuf_renderer_area_changed
+ * update region of existing image
+ */
 void pixbuf_renderer_area_changed(PixbufRenderer *pr, gint x, gint y, gint width, gint height);
 
 /* scrolling */
@@ -238,23 +322,19 @@ void pixbuf_renderer_zoom_set_limits(PixbufRenderer *pr, gdouble min, gdouble ma
 gboolean pixbuf_renderer_get_image_size(PixbufRenderer *pr, gint *width, gint *height);
 gboolean pixbuf_renderer_get_scaled_size(PixbufRenderer *pr, gint *width, gint *height);
 
-/* region of image in pixel coordinates */
+/**
+ * @headerfile pixbuf_renderer_get_visible_rect
+ * region of image in pixel coordinates
+ */
 gboolean pixbuf_renderer_get_visible_rect(PixbufRenderer *pr, GdkRectangle *rect);
 
-/* actual size of the PixbufRenderer window minus borders,
- * x and y are the scroll offset and include zoom factor.
+/**
+ * @headerfile pixbuf_renderer_set_color
+ *  background color
  */
-gboolean pixbuf_renderer_get_virtual_rect(PixbufRenderer *pr, GdkRectangle *rect);
-
-/* background color */
-void pixbuf_renderer_set_color(PixbufRenderer *pr, GdkColor *color);
+void pixbuf_renderer_set_color(PixbufRenderer *pr, GdkRGBA *color);
 
 /* overlay */
-typedef enum {
-       OVL_NORMAL      = 0,
-       OVL_RELATIVE    = 1 << 0, /* x,y coordinates are relative, negative values start bottom right */
-       /* OVL_HIDE_ON_SCROLL = 1 << 1*/ /* hide temporarily when scrolling (not yet implemented) */
-} OverlayRendererFlags;
 
 gint pixbuf_renderer_overlay_add(PixbufRenderer *pr, GdkPixbuf *pixbuf, gint x, gint y,
                                 OverlayRendererFlags flags);
@@ -263,11 +343,61 @@ gboolean pixbuf_renderer_overlay_get(PixbufRenderer *pr, gint id, GdkPixbuf **pi
 void pixbuf_renderer_overlay_remove(PixbufRenderer *pr, gint id);
 
 gboolean pixbuf_renderer_get_mouse_position(PixbufRenderer *pr, gint *x_pixel, gint *y_pixel);
-/* x_pixel and y_pixel are the pixel coordinates \see pixbuf_renderer_get_mouse_position */
+
+/**
+ * @headerfile pixbuf_renderer_get_pixel_colors
+ * x_pixel and y_pixel are the pixel coordinates see #pixbuf_renderer_get_mouse_position
+ */
 gboolean pixbuf_renderer_get_pixel_colors(PixbufRenderer *pr, gint x_pixel, gint y_pixel,
-                                                                                                                                                       gint *r_mouse, gint *g_mouse, gint *b_mouse);
+                                       gint *r_mouse, gint *g_mouse, gint *b_mouse);
 
 void pixbuf_renderer_set_size_early(PixbufRenderer *pr, guint width, guint height);
 
+/* stereo */
+void pixbuf_renderer_stereo_set(PixbufRenderer *pr, gint stereo_mode);
+gint pixbuf_renderer_stereo_get(PixbufRenderer *pr);
+void pixbuf_renderer_stereo_fixed_set(PixbufRenderer *pr, gint width, gint height, gint x1, gint y1, gint x2, gint y2);
+
+/**
+ * @struct SourceTile
+ * protected - for renderer use only
+ */
+struct SourceTile
+{
+       gint x;
+       gint y;
+       GdkPixbuf *pixbuf;
+       gboolean blank;
+};
+
+
+gboolean pr_clip_region(gint x, gint y, gint w, gint h,
+                              gint clip_x, gint clip_y, gint clip_w, gint clip_h,
+                              gint *rx, gint *ry, gint *rw, gint *rh);
+void pr_render_complete_signal(PixbufRenderer *pr);
+
+void pr_tile_coords_map_orientation(gint orientation,
+                                    gdouble tile_x, gdouble tile_y, /**< coordinates of the tile */
+                                    gdouble image_w, gdouble image_h,
+                                    gdouble tile_w, gdouble tile_h,
+                                    gdouble *res_x, gdouble *res_y);
+void pr_tile_region_map_orientation(gint orientation,
+                                    gint area_x, gint area_y, /**< coordinates of the area inside tile */
+                                    gint tile_w, gint tile_h,
+                                    gint area_w, gint area_h,
+                                    gint *res_x, gint *res_y,
+                                    gint *res_w, gint *res_h);
+void pr_coords_map_orientation_reverse(gint orientation,
+                                    gint area_x, gint area_y,
+                                    gint tile_w, gint tile_h,
+                                    gint area_w, gint area_h,
+                                    gint *res_x, gint *res_y,
+                                    gint *res_w, gint *res_h);
+
+GList *pr_source_tile_compute_region(PixbufRenderer *pr, gint x, gint y, gint w, gint h, gboolean request);
+
+void pr_create_anaglyph(guint mode, GdkPixbuf *pixbuf, GdkPixbuf *right, gint x, gint y, gint w, gint h);
+
+void pixbuf_renderer_set_ignore_alpha(PixbufRenderer *pr, gint ignore_alpha);
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */