From edf63dfeeb6f2ca199beb2a81d79f9f87103be72 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 21 Nov 2021 14:50:55 +0000 Subject: [PATCH] fix insert We were not detecting the shortcut cases for insert correctly, thanks chreru. See https://github.com/libvips/libvips/issues/2548 --- ChangeLog | 3 +++ configure.ac | 6 +++--- libvips/conversion/insert.c | 42 +++++++++++++++++++++---------------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7f88c7b2..08e71bd9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +21/11/21 started 8.12.1 +- fix insert [chregu] + 14/6/21 started 8.12 - all tools support `--version` - add vips_svgload_string() convenience function diff --git a/configure.ac b/configure.ac index 05235e41..d3a1d693 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # also update the version number in the m4 macros below -AC_INIT([vips], [8.12.0], [vipsip@jiscmail.ac.uk]) +AC_INIT([vips], [8.12.1], [vipsip@jiscmail.ac.uk]) # required for gobject-introspection AC_PREREQ([2.69]) @@ -18,7 +18,7 @@ AC_CONFIG_MACRO_DIR([m4]) # user-visible library versioning m4_define([vips_major_version], [8]) m4_define([vips_minor_version], [12]) -m4_define([vips_micro_version], [0]) +m4_define([vips_micro_version], [1]) m4_define([vips_version], [vips_major_version.vips_minor_version.vips_micro_version]) @@ -41,7 +41,7 @@ VIPS_LIBS="" # binary interface changed: increment current, reset revision to 0 # binary interface changes backwards compatible?: increment age # binary interface changes not backwards compatible?: reset age to 0 -LIBRARY_REVISION=0 +LIBRARY_REVISION=1 LIBRARY_CURRENT=56 LIBRARY_AGE=14 diff --git a/libvips/conversion/insert.c b/libvips/conversion/insert.c index a77c4beb..eaad53f5 100644 --- a/libvips/conversion/insert.c +++ b/libvips/conversion/insert.c @@ -95,14 +95,15 @@ typedef struct _VipsInsert { */ VipsPel *ink; - /* Inputs cast and banded up, plus a NULL at the end. + /* Inputs cast and banded up, plus a NULL at the end. main is 0, sub + * is 1. */ VipsImage *processed[3]; /* Geometry. */ VipsRect rout; /* Output space */ - VipsRect rimage[2]; /* Position of main in output */ + VipsRect rimage[2]; /* Position of input in output */ /* TRUE if we've minimised an input. */ @@ -179,24 +180,29 @@ vips_insert_gen( VipsRegion *or, void *seq, void *a, void *b, gboolean *stop ) int i; - /* First, does this request fall entirely inside one of our inputs? If - * it does, we can just redirect the request there. Test sub first. + /* Three cases: + * + * 1. If r is entirely within sub, we can just paint from sub. + * 2. If r is entirely within main and does not touch sub, we can + * paint from main. + * 3. We must paint from both, and the background. */ - for( i = 1; i >= 0; i-- ) { - VipsRect *rimage = &insert->rimage[i]; - - if( vips_rect_includesrect( rimage, r ) ) { - if( vips__insert_just_one( or, ir[i], - rimage->left, rimage->top ) ) - return( -1 ); - - break; - } + if( vips_rect_includesrect( &insert->rimage[1], r ) ) { + /* Just the subimage. + */ + if( vips__insert_just_one( or, ir[1], + insert->rimage[1].left, insert->rimage[1].top ) ) + return( -1 ); } - - /* Otherwise, it requires both (or neither) input. - */ - if( i < 0 ) { + else if( vips_rect_includesrect( &insert->rimage[0], r ) && + !vips_rect_overlapsrect( &insert->rimage[1], r ) ) { + /* Just the main image. + */ + if( vips__insert_just_one( or, ir[0], + insert->rimage[0].left, insert->rimage[0].top ) ) + return( -1 ); + } + else { /* Output requires both (or neither) input. If it is not * entirely inside both the main and the sub, then there is * going to be some background.