From 9a950c53754d9507f1f9424d3a975ecac3aa7bf7 Mon Sep 17 00:00:00 2001 From: Urvang Joshi Date: Thu, 31 Mar 2016 17:25:22 +0000 Subject: [PATCH] WebPAnimEncoder: Disable filtering when blending is used with lossy encoding. When FlattenSimilarBlocks() was making some blocks transparent with averaged RGB values, filtering in lossy compression was causing blockiness just outside the edge of these blocks. Disabling filtering for that particular case avoid these block artifacts. The total encoded size of the 6k GIF set remains roughly the same (in fact, reduces a bit). Change-Id: Ida71cbabd59d851e16d871f53d19473312b3cc77 --- src/mux/anim_encode.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/mux/anim_encode.c b/src/mux/anim_encode.c index c07ab7e5..9f46d3f3 100644 --- a/src/mux/anim_encode.c +++ b/src/mux/anim_encode.c @@ -768,9 +768,10 @@ typedef struct { // Generates a candidate encoded frame given a picture and metadata. static WebPEncodingError EncodeCandidate(WebPPicture* const sub_frame, const FrameRect* const rect, - const WebPConfig* const config, + const WebPConfig* const encoder_config, int use_blending, Candidate* const candidate) { + WebPConfig config = *encoder_config; WebPEncodingError error_code = VP8_ENC_OK; assert(candidate != NULL); memset(candidate, 0, sizeof(*candidate)); @@ -788,7 +789,13 @@ static WebPEncodingError EncodeCandidate(WebPPicture* const sub_frame, // Encode picture. WebPMemoryWriterInit(&candidate->mem_); - if (!EncodeFrame(config, sub_frame, &candidate->mem_)) { + if (!config.lossless && use_blending) { + // Disable filtering to avoid blockiness in reconstructed frames at the + // time of decoding. + config.autofilter = 0; + config.filter_strength = 0; + } + if (!EncodeFrame(&config, sub_frame, &candidate->mem_)) { error_code = sub_frame->error_code; goto Err; }