From 8cf0701eb06658abb921495bc44f5b1d9bdca156 Mon Sep 17 00:00:00 2001 From: Urvang Joshi Date: Fri, 14 Jun 2013 13:32:51 -0700 Subject: [PATCH] Alpha encoding: never filter in case of NO_COMPRESSION This is because, filtering would never affect compression density for this case. Change-Id: I4bb14d3eb7da0a3805fda140eb1dfbf9ccc134f5 --- src/enc/alpha.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/enc/alpha.c b/src/enc/alpha.c index 2add8f02..2f15c1f7 100644 --- a/src/enc/alpha.c +++ b/src/enc/alpha.c @@ -217,6 +217,8 @@ static void InitFilterTrial(FilterTrial* const score) { VP8BitWriterInit(&score->bw, 0); } +// TODO(urvang): This method name is misleading. Should be renamed to +// ApplyFiltersAndEncode() perhaps. static int ApplyFilters(const uint8_t* alpha, int width, int height, size_t data_size, int method, int filter, int reduce_levels, int effort_level, @@ -224,8 +226,11 @@ static int ApplyFilters(const uint8_t* alpha, int width, int height, WebPAuxStats* const stats) { int ok = 1; uint8_t* filtered_alpha = NULL; - uint32_t try_map = GetFilterMap(alpha, width, height, filter, effort_level); + uint32_t try_map = + GetFilterMap(alpha, width, height, filter, effort_level); + // TODO(urvang): In case of no filtering, this malloc is unnecessary. Also, + // the whole loop below should be avoided in that case. filtered_alpha = (uint8_t*)malloc(data_size); ok = (filtered_alpha != NULL); @@ -296,6 +301,11 @@ static int EncodeAlpha(VP8Encoder* const enc, return 0; } + if (method == ALPHA_NO_COMPRESSION) { + // Don't filter, as filtering will make no impact on compressed size. + filter = WEBP_FILTER_NONE; + } + quant_alpha = (uint8_t*)malloc(data_size); if (quant_alpha == NULL) { return 0;