Skip to content

Commit

Permalink
much better performance for bad aspect ratios
Browse files Browse the repository at this point in the history
we were not building the right shaped pyramids for very extreme aspect
ratio images
  • Loading branch information
jcupitt committed Jan 26, 2025
1 parent f75e9b6 commit ef197e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
master

- much better performance for images which are very tall and thin or very wide
and narrow

## 3.1.0 28/10/24

- better behaviour for image interpretations like MATRIX
Expand Down
15 changes: 8 additions & 7 deletions src/tilecache.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "vipsdisp.h"

/*
#define DEBUG
#define DEBUG_RENDER_TIME
#define DEBUG_VERBOSE
#define DEBUG_RENDER_TIME
*/
#define DEBUG

enum {
/* Properties.
Expand Down Expand Up @@ -249,14 +249,15 @@ tilecache_build_pyramid(Tilecache *tilecache)

tilecache_free_pyramid(tilecache);

/* How many levels? Keep shrinking until we get down to one tile on
* one axis.
/* How many levels? Keep shrinking until we get both axies in one tile. We
* need to handle very lopsided images, like LUTs and multi-page images,
* do we must shrink both dimensions.
*/
level_width = tilesource->display_width;
level_height = tilesource->display_height;
n_levels = 1;
for (;;) {
if (level_width <= TILE_SIZE ||
if (level_width <= TILE_SIZE &&
level_height <= TILE_SIZE)
break;

Expand All @@ -283,8 +284,8 @@ tilecache_build_pyramid(Tilecache *tilecache)
tilesource->rgb->Xres,
tilesource->rgb->Yres);

level_width >>= 1;
level_height >>= 1;
level_width = VIPS_MAX(1, level_width >> 1);
level_height = VIPS_MAX(1, level_height >> 1);
}

tilecache->tiles = VIPS_ARRAY(NULL, n_levels, GSList *);
Expand Down
12 changes: 8 additions & 4 deletions src/tilesource.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,14 @@ tilesource_display_image(Tilesource *tilesource, VipsImage **mask_out)
* some layer other than the base one. Calculate the
* subsample as (current_width / required_width).
*/
int subsample = image->Xsize /
(tilesource->display_width >> tilesource->current_z);

if (vips_subsample(image, &x, subsample, subsample, NULL))
int width =
VIPS_MAX(1, tilesource->display_width >> tilesource->current_z);
int height =
VIPS_MAX(1, tilesource->display_height >> tilesource->current_z);
int xfac = image->Xsize / width;
int yfac = image->Ysize / height;

if (vips_subsample(image, &x, xfac, yfac, NULL))
return NULL;
VIPS_UNREF(image);
image = x;
Expand Down

0 comments on commit ef197e3

Please sign in to comment.