* 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:
#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,
};
#endif
+namespace
+{
+
+constexpr size_t COLOR_BYTES = 3; /* rgb */
+
+} // namespace
+
struct QueueData;
struct ImageTile
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)
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);
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);
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);
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);
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);
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);
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;
}
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);
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;
}
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);
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;
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;
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);
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);
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);
}
}
-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;
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);
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);
{
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);
{
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;
{
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;
{
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;
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;
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;
}
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;
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;
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)
{
}
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);
(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
(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);
}
}
}
}
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;
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 */
gboolean new_data, gboolean fast)
{
PixbufRenderer *pr = rt->pr;
- //~ GtkWidget *box;
- //~ GdkWindow *window;
cairo_t *cr;
/* clamp to visible */
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);
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;
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;
gboolean new_data, gboolean only_existing)
{
PixbufRenderer *pr = rt->pr;
- gint nx, ny;
+ gint nx;
+ gint ny;
rt_sync_scroll(rt);
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;
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,
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));
}
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);
}
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);
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;
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)
{
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;