Skip to content

Commit ef197e3

Browse files
committed
much better performance for bad aspect ratios
we were not building the right shaped pyramids for very extreme aspect ratio images
1 parent f75e9b6 commit ef197e3

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
master
2+
3+
- much better performance for images which are very tall and thin or very wide
4+
and narrow
5+
16
## 3.1.0 28/10/24
27

38
- better behaviour for image interpretations like MATRIX

src/tilecache.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#include "vipsdisp.h"
22

33
/*
4-
#define DEBUG
5-
#define DEBUG_RENDER_TIME
64
#define DEBUG_VERBOSE
5+
#define DEBUG_RENDER_TIME
76
*/
7+
#define DEBUG
88

99
enum {
1010
/* Properties.
@@ -249,14 +249,15 @@ tilecache_build_pyramid(Tilecache *tilecache)
249249

250250
tilecache_free_pyramid(tilecache);
251251

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

@@ -283,8 +284,8 @@ tilecache_build_pyramid(Tilecache *tilecache)
283284
tilesource->rgb->Xres,
284285
tilesource->rgb->Yres);
285286

286-
level_width >>= 1;
287-
level_height >>= 1;
287+
level_width = VIPS_MAX(1, level_width >> 1);
288+
level_height = VIPS_MAX(1, level_height >> 1);
288289
}
289290

290291
tilecache->tiles = VIPS_ARRAY(NULL, n_levels, GSList *);

src/tilesource.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,14 @@ tilesource_display_image(Tilesource *tilesource, VipsImage **mask_out)
365365
* some layer other than the base one. Calculate the
366366
* subsample as (current_width / required_width).
367367
*/
368-
int subsample = image->Xsize /
369-
(tilesource->display_width >> tilesource->current_z);
370-
371-
if (vips_subsample(image, &x, subsample, subsample, NULL))
368+
int width =
369+
VIPS_MAX(1, tilesource->display_width >> tilesource->current_z);
370+
int height =
371+
VIPS_MAX(1, tilesource->display_height >> tilesource->current_z);
372+
int xfac = image->Xsize / width;
373+
int yfac = image->Ysize / height;
374+
375+
if (vips_subsample(image, &x, xfac, yfac, NULL))
372376
return NULL;
373377
VIPS_UNREF(image);
374378
image = x;

0 commit comments

Comments
 (0)