From 774c969d43aee1538d7dfd06f60085da77990708 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 18 Jan 2022 18:15:38 +0000 Subject: [PATCH] fix GIF save change detector We were only using the top 25% of the frame for GIF pallette change detection. Thanks TheEssem See: https://github.com/libvips/libvips/issues/2622 --- ChangeLog | 1 + libvips/foreign/cgifsave.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index a359be0d..a4b77f65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,6 +8,7 @@ - fix TTF load [chregu] - revise GIF save alpha threshold [jfcalvo] - raise libpng pixel size limit from 1m to 10m pixels [jskrzypek] +- fix gif save change detector [TheEssem] 21/11/21 started 8.12.1 - fix insert [chregu] diff --git a/libvips/foreign/cgifsave.c b/libvips/foreign/cgifsave.c index ee287e0e..3bccdd41 100644 --- a/libvips/foreign/cgifsave.c +++ b/libvips/foreign/cgifsave.c @@ -1,6 +1,8 @@ /* save as GIF * * 22/8/21 lovell + * 18/1/22 TheEssem + * - fix change detector */ /* @@ -162,7 +164,7 @@ vips_foreign_save_cgif_write_frame( VipsForeignSaveCgif *cgif ) /* We know this fits in an int since we limit frame size. */ int n_pels = frame_rect->height * frame_rect->width; - guint max_sum = 256 * n_pels * 3; + guint max_sum = 256 * n_pels * 4; VipsPel *frame_bytes = VIPS_REGION_ADDR( cgif->frame, 0, frame_rect->top ); @@ -199,7 +201,7 @@ vips_foreign_save_cgif_write_frame( VipsForeignSaveCgif *cgif ) */ sum = 0; p = frame_bytes; - for( i = 0; i < n_pels; i++ ) + for( i = 0; i < n_pels * 4; i++ ) sum += p[i]; percent_change = 100 * fabs( ((double) sum / max_sum) - @@ -433,7 +435,7 @@ vips_foreign_save_cgif_build( VipsObject *object ) frame_rect.width = cgif->in->Xsize; frame_rect.height = page_height; if( (guint64) frame_rect.width * frame_rect.height > 2000 * 2000 ) { - /* RGB sum may overflow a 32-bit uint. + /* RGBA sum may overflow a 32-bit uint. */ vips_error( class->nickname, "%s", _( "frame too large" ) ); return( -1 );