From 6eaf1eda30cedb11be31a6f82401da0ebb019c68 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 4 Dec 2020 13:53:24 +0000 Subject: [PATCH] make webp frame blend do doround to nearest see https://github.com/libvips/libvips/pull/1918 --- ChangeLog | 1 + libvips/foreign/webp2vips.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d55c0cd..5498c33b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ - force binary mode on win for connection read / write [Alreiber] - better testing for output to target [barryspearce] - ppmload_source was missing is_a [ewelot] +- improve webpload rounding and blending behaviour [lovell] 6/9/20 started 8.10.2 - update magicksave/load profile handling [kelilevi] diff --git a/libvips/foreign/webp2vips.c b/libvips/foreign/webp2vips.c index c9518eec..e0e91e99 100644 --- a/libvips/foreign/webp2vips.c +++ b/libvips/foreign/webp2vips.c @@ -232,7 +232,7 @@ vips_image_paint_area( VipsImage *image, const VipsRect *r, const VipsPel *ink ) /* Blend two guint8. */ #define BLEND( X, aX, Y, aY, scale ) \ - ((X * aX + Y * aY) * scale >> 24) + (((X * aX + Y * aY) * scale + (1 << 12)) >> 24) /* Extract R, G, B, A, assuming little-endian. */ @@ -260,7 +260,7 @@ blend_pixel( guint32 A, guint32 B ) guint8 aB = getA( B ); - guint8 fac = (aB * (256 - aA)) >> 8; + guint8 fac = (aB * (256 - aA) + 128) >> 8; guint8 aR = aA + fac; int scale = (1 << 24) / aR; @@ -693,7 +693,7 @@ read_next_frame( Read *read ) vips_image_paint_image( read->frame, frame, area.left, area.top, read->iter.frame_num > 1 && - read->iter.blend_method == WEBP_MUX_BLEND ); + read->iter.blend_method == WEBP_MUX_BLEND ); g_object_unref( frame );