Skip to content

Commit 10dc065

Browse files
committed
better tile boundary handling
1 parent f1d7225 commit 10dc065

File tree

3 files changed

+55
-41
lines changed

3 files changed

+55
-41
lines changed

src/imagedisplay.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,17 @@ imagedisplay_snapshot(GtkWidget *widget, GtkSnapshot *snapshot)
658658
&GRAPHENE_RECT_INIT(0, 0,
659659
gtk_widget_get_width(widget), gtk_widget_get_height(widget)));
660660

661+
graphene_rect_t paint;
662+
paint.origin.x = imagedisplay->paint_rect.left;
663+
paint.origin.y = imagedisplay->paint_rect.top;
664+
paint.size.width = imagedisplay->paint_rect.width;
665+
paint.size.height = imagedisplay->paint_rect.height;
666+
661667
if (imagedisplay->tilecache &&
662668
imagedisplay->tilecache->tiles)
663669
tilecache_snapshot(imagedisplay->tilecache, snapshot,
664670
imagedisplay->scale, imagedisplay->x, imagedisplay->y,
665-
&imagedisplay->paint_rect,
666-
imagedisplay->debug);
671+
&paint, imagedisplay->debug);
667672

668673
// draw any overlays
669674
imagedisplay_overlay_snapshot(imagedisplay, snapshot);

src/tilecache.c

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ tilecache_request(Tilecache *tilecache, VipsRect *tile_rect, int z)
391391
* already (very common for thumbnails, for example).
392392
*/
393393
static void
394-
tilecache_request_area(Tilecache *tilecache, VipsRect *viewport, int z)
394+
tilecache_request_area(Tilecache *tilecache, graphene_rect_t *grect, int z)
395395
{
396396
int size0 = TILE_SIZE << z;
397397

@@ -400,12 +400,19 @@ tilecache_request_area(Tilecache *tilecache, VipsRect *viewport, int z)
400400
!tilecache->tilesource->rgb)
401401
return;
402402

403+
/* Only interested in bounding int pixel coordinates.
404+
*/
405+
graphene_rect_t bounds;
406+
graphene_rect_round_extents(grect, &bounds);
407+
403408
/* All the tiles rect touches in this pyr level.
404409
*/
405-
int left = VIPS_ROUND_DOWN(viewport->left, size0);
406-
int top = VIPS_ROUND_DOWN(viewport->top, size0);
407-
int right = VIPS_ROUND_UP(VIPS_RECT_RIGHT(viewport), size0);
408-
int bottom = VIPS_ROUND_UP(VIPS_RECT_BOTTOM(viewport), size0);
410+
int left = VIPS_ROUND_DOWN((int) bounds.origin.x, size0);
411+
int top = VIPS_ROUND_DOWN((int) bounds.origin.y, size0);
412+
int right =
413+
VIPS_ROUND_UP((int) (bounds.origin.x + bounds.size.width), size0);
414+
int bottom =
415+
VIPS_ROUND_UP((int) (bounds.origin.y + bounds.size.height), size0);
409416

410417
/* Do the four edges, then step in. Loop until the centre is empty.
411418
*/
@@ -771,7 +778,7 @@ tilecache_print(Tilecache *tilecache)
771778

772779
static void
773780
tilecache_compute_visibility(Tilecache *tilecache,
774-
VipsRect *viewport, int z)
781+
graphene_rect_t *grect, int z)
775782
{
776783
int size0 = TILE_SIZE << z;
777784
int start_time = tile_get_time();
@@ -786,6 +793,16 @@ tilecache_compute_visibility(Tilecache *tilecache,
786793
printf("tilecache_compute_visibility: z = %d\n", z);
787794
#endif /*DEBUG_VERBOSE*/
788795

796+
/* Only interested in bounding int pixel coordinates.
797+
*/
798+
graphene_rect_t bounding_grect;
799+
graphene_rect_round_extents(grect, &bounding_grect);
800+
VipsRect viewport;
801+
viewport.left = bounding_grect.origin.x;
802+
viewport.top = bounding_grect.origin.y;
803+
viewport.width = bounding_grect.size.width;
804+
viewport.height = bounding_grect.size.height;
805+
789806
/* We're rebuilding these.
790807
*/
791808
for (i = 0; i < tilecache->n_levels; i++) {
@@ -795,13 +812,13 @@ tilecache_compute_visibility(Tilecache *tilecache,
795812

796813
/* The rect of tiles touched by the viewport.
797814
*/
798-
tilecache_tiles_for_rect(tilecache, viewport, z, &touches);
815+
tilecache_tiles_for_rect(tilecache, &viewport, z, &touches);
799816

800817
#ifdef DEBUG_VERBOSE
801818
printf("viewport in level0 coordinates: left = %d, top = %d, "
802-
"width = %d, height = %d\n",
803-
touches.left, touches.top,
804-
touches.width, touches.height);
819+
"width = %d, height = %d\n",
820+
touches.left, touches.top,
821+
touches.width, touches.height);
805822
#endif /*DEBUG_VERBOSE*/
806823

807824
/* Search for the highest res tile for every position in the
@@ -908,11 +925,9 @@ tilecache_draw_bounds(GtkSnapshot *snapshot,
908925
*/
909926
void
910927
tilecache_snapshot(Tilecache *tilecache, GtkSnapshot *snapshot,
911-
double scale, double x, double y,
912-
VipsRect *paint_rect,
913-
gboolean debug)
928+
double scale, double x, double y, graphene_rect_t *paint, gboolean debug)
914929
{
915-
VipsRect viewport;
930+
graphene_rect_t viewport;
916931
int z;
917932
int i;
918933

@@ -938,10 +953,10 @@ tilecache_snapshot(Tilecache *tilecache, GtkSnapshot *snapshot,
938953
#endif /*DEBUG*/
939954

940955
#ifdef DEBUG_VERBOSE
941-
printf(" paint_rect left = %d, top = %d, "
942-
"width = %d, height = %d\n",
943-
paint_rect->left, paint_rect->top,
944-
paint_rect->width, paint_rect->height);
956+
printf(" paint x = %g, y = %g, "
957+
"width = %g, height = %g\n",
958+
paint->origin.x, paint->origin.y,
959+
paint->size.width, paint->size.height);
945960
#endif /*DEBUG_VERBOSE*/
946961

947962
#ifdef DEBUG_VERBOSE
@@ -960,10 +975,10 @@ tilecache_snapshot(Tilecache *tilecache, GtkSnapshot *snapshot,
960975

961976
/* paint_rect in level0 coordinates.
962977
*/
963-
viewport.left = x / scale;
964-
viewport.top = y / scale;
965-
viewport.width = VIPS_MAX(1, paint_rect->width / scale);
966-
viewport.height = VIPS_MAX(1, paint_rect->height / scale);
978+
viewport.origin.x = x / scale;
979+
viewport.origin.y = y / scale;
980+
viewport.size.width = VIPS_MAX(1, paint->size.width / scale);
981+
viewport.size.height = VIPS_MAX(1, paint->size.height / scale);
967982

968983
/* Fetch any tiles we are missing, update any tiles we have that have
969984
* been flagged as having pixels ready for fetching.
@@ -986,10 +1001,7 @@ tilecache_snapshot(Tilecache *tilecache, GtkSnapshot *snapshot,
9861001
printf("tilecache_snapshot: drawing background\n");
9871002
#endif /*DEBUG_VERBOSE*/
9881003

989-
bounds.origin.x = paint_rect->left;
990-
bounds.origin.y = paint_rect->top;
991-
bounds.size.width = paint_rect->width;
992-
bounds.size.height = paint_rect->height;
1004+
bounds = *paint;
9931005
gtk_snapshot_push_repeat(snapshot, &bounds, NULL);
9941006

9951007
bounds.origin.x = 0;
@@ -1020,12 +1032,11 @@ tilecache_snapshot(Tilecache *tilecache, GtkSnapshot *snapshot,
10201032

10211033
graphene_rect_t bounds;
10221034

1023-
// add a margin along the right and bottom to prevent black seams
1024-
// at tile joins
1025-
bounds.origin.x = tile->bounds.left * scale - x + paint_rect->left;
1026-
bounds.origin.y = tile->bounds.top * scale - y + paint_rect->top;
1027-
bounds.size.width = tile->bounds.width * scale + 2;
1028-
bounds.size.height = tile->bounds.height * scale + 2;
1035+
// +1 to hide tile boundaries
1036+
bounds.origin.x = tile->bounds.left * scale - x + paint->origin.x;
1037+
bounds.origin.y = tile->bounds.top * scale - y + paint->origin.y;
1038+
bounds.size.width = tile->bounds.width * scale + 1;
1039+
bounds.size.height = tile->bounds.height * scale + 1;
10291040

10301041
gtk_snapshot_append_scaled_texture(snapshot,
10311042
tile_get_texture(tile), filter, &bounds);
@@ -1047,10 +1058,10 @@ tilecache_snapshot(Tilecache *tilecache, GtkSnapshot *snapshot,
10471058

10481059
gsk_rounded_rect_init_from_rect(&outline,
10491060
&GRAPHENE_RECT_INIT(
1050-
viewport.left * scale - x + paint_rect->left,
1051-
viewport.top * scale - y + paint_rect->top,
1052-
viewport.width * scale,
1053-
viewport.height * scale),
1061+
viewport.origin.x * scale - x + paint->origin.x,
1062+
viewport.origin.y * scale - y + paint->origin.y,
1063+
viewport.size.width * scale,
1064+
viewport.size.height * scale),
10541065
0);
10551066

10561067
gtk_snapshot_append_border(snapshot,

src/tilecache.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ Tilecache *tilecache_new();
110110
/* Render the tiles to a snapshot.
111111
*/
112112
void tilecache_snapshot(Tilecache *tilecache, GtkSnapshot *snapshot,
113-
double scale, double x, double y,
114-
VipsRect *paint_rect,
115-
gboolean debug);
113+
double scale, double x, double y, graphene_rect_t *paint, gboolean debug);
116114

117115
#endif /*__TILECACHE_H*/

0 commit comments

Comments
 (0)