| OLD | NEW |
| 1 // Copyright 2011 Google Inc. All Rights Reserved. | 1 // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Use of this source code is governed by a BSD-style license | 3 // Use of this source code is governed by a BSD-style license |
| 4 // that can be found in the COPYING file in the root of the source | 4 // that can be found in the COPYING file in the root of the source |
| 5 // tree. An additional intellectual property rights grant can be found | 5 // tree. An additional intellectual property rights grant can be found |
| 6 // in the file PATENTS. All contributing project authors may | 6 // in the file PATENTS. All contributing project authors may |
| 7 // be found in the AUTHORS file in the root of the source tree. | 7 // be found in the AUTHORS file in the root of the source tree. |
| 8 // ----------------------------------------------------------------------------- | 8 // ----------------------------------------------------------------------------- |
| 9 // | 9 // |
| 10 // Alpha-plane compression. | 10 // Alpha-plane compression. |
| 11 // | 11 // |
| 12 // Author: Skal (pascal.massimino@gmail.com) | 12 // Author: Skal (pascal.massimino@gmail.com) |
| 13 | 13 |
| 14 #include <assert.h> | 14 #include <assert.h> |
| 15 #include <stdlib.h> | 15 #include <stdlib.h> |
| 16 | 16 |
| 17 #include "./vp8enci.h" | 17 #include "./vp8enci.h" |
| 18 #include "../utils/filters.h" | 18 #include "../utils/filters.h" |
| 19 #include "../utils/quant_levels.h" | 19 #include "../utils/quant_levels.h" |
| 20 #include "../webp/format_constants.h" | 20 #include "../webp/format_constants.h" |
| 21 | 21 |
| 22 #if defined(__cplusplus) || defined(c_plusplus) | |
| 23 extern "C" { | |
| 24 #endif | |
| 25 | |
| 26 // ----------------------------------------------------------------------------- | 22 // ----------------------------------------------------------------------------- |
| 27 // Encodes the given alpha data via specified compression method 'method'. | 23 // Encodes the given alpha data via specified compression method 'method'. |
| 28 // The pre-processing (quantization) is performed if 'quality' is less than 100. | 24 // The pre-processing (quantization) is performed if 'quality' is less than 100. |
| 29 // For such cases, the encoding is lossy. The valid range is [0, 100] for | 25 // For such cases, the encoding is lossy. The valid range is [0, 100] for |
| 30 // 'quality' and [0, 1] for 'method': | 26 // 'quality' and [0, 1] for 'method': |
| 31 // 'method = 0' - No compression; | 27 // 'method = 0' - No compression; |
| 32 // 'method = 1' - Use lossless coder on the alpha plane only | 28 // 'method = 1' - Use lossless coder on the alpha plane only |
| 33 // 'filter' values [0, 4] correspond to prediction modes none, horizontal, | 29 // 'filter' values [0, 4] correspond to prediction modes none, horizontal, |
| 34 // vertical & gradient filters. The prediction mode 4 will try all the | 30 // vertical & gradient filters. The prediction mode 4 will try all the |
| 35 // prediction modes 0 to 3 and pick the best one. | 31 // prediction modes 0 to 3 and pick the best one. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 64 picture.stats = stats; | 60 picture.stats = stats; |
| 65 if (!WebPPictureAlloc(&picture)) return 0; | 61 if (!WebPPictureAlloc(&picture)) return 0; |
| 66 | 62 |
| 67 // Transfer the alpha values to the green channel. | 63 // Transfer the alpha values to the green channel. |
| 68 { | 64 { |
| 69 int i, j; | 65 int i, j; |
| 70 uint32_t* dst = picture.argb; | 66 uint32_t* dst = picture.argb; |
| 71 const uint8_t* src = data; | 67 const uint8_t* src = data; |
| 72 for (j = 0; j < picture.height; ++j) { | 68 for (j = 0; j < picture.height; ++j) { |
| 73 for (i = 0; i < picture.width; ++i) { | 69 for (i = 0; i < picture.width; ++i) { |
| 74 dst[i] = (src[i] << 8) | 0xff000000u; | 70 dst[i] = src[i] << 8; // we leave A/R/B channels zero'd. |
| 75 } | 71 } |
| 76 src += width; | 72 src += width; |
| 77 dst += picture.argb_stride; | 73 dst += picture.argb_stride; |
| 78 } | 74 } |
| 79 } | 75 } |
| 80 | 76 |
| 81 WebPConfigInit(&config); | 77 WebPConfigInit(&config); |
| 82 config.lossless = 1; | 78 config.lossless = 1; |
| 83 config.method = effort_level; // impact is very small | 79 config.method = effort_level; // impact is very small |
| 84 // Set a moderate default quality setting for alpha. | 80 // Set a low default quality for encoding alpha. Ensure that Alpha quality at |
| 85 config.quality = 10.f * effort_level; | 81 // lower methods (3 and below) is less than the threshold for triggering |
| 82 // costly 'BackwardReferencesTraceBackwards'. |
| 83 config.quality = 8.f * effort_level; |
| 86 assert(config.quality >= 0 && config.quality <= 100.f); | 84 assert(config.quality >= 0 && config.quality <= 100.f); |
| 87 | 85 |
| 88 ok = VP8LBitWriterInit(&tmp_bw, (width * height) >> 3); | 86 ok = VP8LBitWriterInit(&tmp_bw, (width * height) >> 3); |
| 89 ok = ok && (VP8LEncodeStream(&config, &picture, &tmp_bw) == VP8_ENC_OK); | 87 ok = ok && (VP8LEncodeStream(&config, &picture, &tmp_bw) == VP8_ENC_OK); |
| 90 WebPPictureFree(&picture); | 88 WebPPictureFree(&picture); |
| 91 if (ok) { | 89 if (ok) { |
| 92 const uint8_t* const buffer = VP8LBitWriterFinish(&tmp_bw); | 90 const uint8_t* const buffer = VP8LBitWriterFinish(&tmp_bw); |
| 93 const size_t buffer_size = VP8LBitWriterNumBytes(&tmp_bw); | 91 const size_t buffer_size = VP8LBitWriterNumBytes(&tmp_bw); |
| 94 VP8BitWriterAppend(bw, buffer, buffer_size); | 92 VP8BitWriterAppend(bw, buffer, buffer_size); |
| 95 } | 93 } |
| 96 VP8LBitWriterDestroy(&tmp_bw); | 94 VP8LBitWriterDestroy(&tmp_bw); |
| 97 return ok && !bw->error_; | 95 return ok && !bw->error_; |
| 98 } | 96 } |
| 99 | 97 |
| 100 // ----------------------------------------------------------------------------- | 98 // ----------------------------------------------------------------------------- |
| 101 | 99 |
| 100 // Small struct to hold the result of a filter mode compression attempt. |
| 101 typedef struct { |
| 102 size_t score; |
| 103 VP8BitWriter bw; |
| 104 WebPAuxStats stats; |
| 105 } FilterTrial; |
| 106 |
| 107 // This function always returns an initialized 'bw' object, even upon error. |
| 102 static int EncodeAlphaInternal(const uint8_t* const data, int width, int height, | 108 static int EncodeAlphaInternal(const uint8_t* const data, int width, int height, |
| 103 int method, int filter, int reduce_levels, | 109 int method, int filter, int reduce_levels, |
| 104 int effort_level, // in [0..6] range | 110 int effort_level, // in [0..6] range |
| 105 uint8_t* const tmp_alpha, | 111 uint8_t* const tmp_alpha, |
| 106 VP8BitWriter* const bw, | 112 FilterTrial* result) { |
| 107 WebPAuxStats* const stats) { | |
| 108 int ok = 0; | 113 int ok = 0; |
| 109 const uint8_t* alpha_src; | 114 const uint8_t* alpha_src; |
| 110 WebPFilterFunc filter_func; | 115 WebPFilterFunc filter_func; |
| 111 uint8_t header; | 116 uint8_t header; |
| 112 size_t expected_size; | 117 size_t expected_size; |
| 113 const size_t data_size = width * height; | 118 const size_t data_size = width * height; |
| 114 | 119 |
| 115 assert((uint64_t)data_size == (uint64_t)width * height); // as per spec | 120 assert((uint64_t)data_size == (uint64_t)width * height); // as per spec |
| 116 assert(filter >= 0 && filter < WEBP_FILTER_LAST); | 121 assert(filter >= 0 && filter < WEBP_FILTER_LAST); |
| 117 assert(method >= ALPHA_NO_COMPRESSION); | 122 assert(method >= ALPHA_NO_COMPRESSION); |
| 118 assert(method <= ALPHA_LOSSLESS_COMPRESSION); | 123 assert(method <= ALPHA_LOSSLESS_COMPRESSION); |
| 119 assert(sizeof(header) == ALPHA_HEADER_LEN); | 124 assert(sizeof(header) == ALPHA_HEADER_LEN); |
| 120 // TODO(skal): have a common function and #define's to validate alpha params. | 125 // TODO(skal): have a common function and #define's to validate alpha params. |
| 121 | 126 |
| 122 expected_size = | 127 expected_size = |
| 123 (method == ALPHA_NO_COMPRESSION) ? (ALPHA_HEADER_LEN + data_size) | 128 (method == ALPHA_NO_COMPRESSION) ? (ALPHA_HEADER_LEN + data_size) |
| 124 : (data_size >> 5); | 129 : (data_size >> 5); |
| 125 header = method | (filter << 2); | 130 header = method | (filter << 2); |
| 126 if (reduce_levels) header |= ALPHA_PREPROCESSED_LEVELS << 4; | 131 if (reduce_levels) header |= ALPHA_PREPROCESSED_LEVELS << 4; |
| 127 | 132 |
| 128 VP8BitWriterInit(bw, expected_size); | 133 VP8BitWriterInit(&result->bw, expected_size); |
| 129 VP8BitWriterAppend(bw, &header, ALPHA_HEADER_LEN); | 134 VP8BitWriterAppend(&result->bw, &header, ALPHA_HEADER_LEN); |
| 130 | 135 |
| 131 filter_func = WebPFilters[filter]; | 136 filter_func = WebPFilters[filter]; |
| 132 if (filter_func != NULL) { | 137 if (filter_func != NULL) { |
| 133 filter_func(data, width, height, width, tmp_alpha); | 138 filter_func(data, width, height, width, tmp_alpha); |
| 134 alpha_src = tmp_alpha; | 139 alpha_src = tmp_alpha; |
| 135 } else { | 140 } else { |
| 136 alpha_src = data; | 141 alpha_src = data; |
| 137 } | 142 } |
| 138 | 143 |
| 139 if (method == ALPHA_NO_COMPRESSION) { | 144 if (method == ALPHA_NO_COMPRESSION) { |
| 140 ok = VP8BitWriterAppend(bw, alpha_src, width * height); | 145 ok = VP8BitWriterAppend(&result->bw, alpha_src, width * height); |
| 141 ok = ok && !bw->error_; | 146 ok = ok && !result->bw.error_; |
| 142 } else { | 147 } else { |
| 143 ok = EncodeLossless(alpha_src, width, height, effort_level, bw, stats); | 148 ok = EncodeLossless(alpha_src, width, height, effort_level, |
| 144 VP8BitWriterFinish(bw); | 149 &result->bw, &result->stats); |
| 150 VP8BitWriterFinish(&result->bw); |
| 145 } | 151 } |
| 152 result->score = VP8BitWriterSize(&result->bw); |
| 146 return ok; | 153 return ok; |
| 147 } | 154 } |
| 148 | 155 |
| 149 // ----------------------------------------------------------------------------- | 156 // ----------------------------------------------------------------------------- |
| 150 | 157 |
| 151 // TODO(skal): move to dsp/ ? | 158 // TODO(skal): move to dsp/ ? |
| 152 static void CopyPlane(const uint8_t* src, int src_stride, | 159 static void CopyPlane(const uint8_t* src, int src_stride, |
| 153 uint8_t* dst, int dst_stride, int width, int height) { | 160 uint8_t* dst, int dst_stride, int width, int height) { |
| 154 while (height-- > 0) { | 161 while (height-- > 0) { |
| 155 memcpy(dst, src, width); | 162 memcpy(dst, src, width); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 170 for (i = 0; i < width; ++i) { | 177 for (i = 0; i < width; ++i) { |
| 171 color[p[i]] = 1; | 178 color[p[i]] = 1; |
| 172 } | 179 } |
| 173 } | 180 } |
| 174 for (j = 0; j < 256; ++j) { | 181 for (j = 0; j < 256; ++j) { |
| 175 if (color[j] > 0) ++colors; | 182 if (color[j] > 0) ++colors; |
| 176 } | 183 } |
| 177 return colors; | 184 return colors; |
| 178 } | 185 } |
| 179 | 186 |
| 187 #define FILTER_TRY_NONE (1 << WEBP_FILTER_NONE) |
| 188 #define FILTER_TRY_ALL ((1 << WEBP_FILTER_LAST) - 1) |
| 189 |
| 190 // Given the input 'filter' option, return an OR'd bit-set of filters to try. |
| 191 static uint32_t GetFilterMap(const uint8_t* alpha, int width, int height, |
| 192 int filter, int effort_level) { |
| 193 uint32_t bit_map = 0U; |
| 194 if (filter == WEBP_FILTER_FAST) { |
| 195 // Quick estimate of the best candidate. |
| 196 int try_filter_none = (effort_level > 3); |
| 197 const int kMinColorsForFilterNone = 16; |
| 198 const int kMaxColorsForFilterNone = 192; |
| 199 const int num_colors = GetNumColors(alpha, width, height, width); |
| 200 // For low number of colors, NONE yields better compression. |
| 201 filter = (num_colors <= kMinColorsForFilterNone) ? WEBP_FILTER_NONE : |
| 202 EstimateBestFilter(alpha, width, height, width); |
| 203 bit_map |= 1 << filter; |
| 204 // For large number of colors, try FILTER_NONE in addition to the best |
| 205 // filter as well. |
| 206 if (try_filter_none || num_colors > kMaxColorsForFilterNone) { |
| 207 bit_map |= FILTER_TRY_NONE; |
| 208 } |
| 209 } else if (filter == WEBP_FILTER_NONE) { |
| 210 bit_map = FILTER_TRY_NONE; |
| 211 } else { // WEBP_FILTER_BEST -> try all |
| 212 bit_map = FILTER_TRY_ALL; |
| 213 } |
| 214 return bit_map; |
| 215 } |
| 216 |
| 217 static void InitFilterTrial(FilterTrial* const score) { |
| 218 score->score = (size_t)~0U; |
| 219 VP8BitWriterInit(&score->bw, 0); |
| 220 } |
| 221 |
| 222 static int ApplyFiltersAndEncode(const uint8_t* alpha, int width, int height, |
| 223 size_t data_size, int method, int filter, |
| 224 int reduce_levels, int effort_level, |
| 225 uint8_t** const output, |
| 226 size_t* const output_size, |
| 227 WebPAuxStats* const stats) { |
| 228 int ok = 1; |
| 229 FilterTrial best; |
| 230 uint32_t try_map = |
| 231 GetFilterMap(alpha, width, height, filter, effort_level); |
| 232 InitFilterTrial(&best); |
| 233 if (try_map != FILTER_TRY_NONE) { |
| 234 uint8_t* filtered_alpha = (uint8_t*)malloc(data_size); |
| 235 if (filtered_alpha == NULL) return 0; |
| 236 |
| 237 for (filter = WEBP_FILTER_NONE; ok && try_map; ++filter, try_map >>= 1) { |
| 238 if (try_map & 1) { |
| 239 FilterTrial trial; |
| 240 ok = EncodeAlphaInternal(alpha, width, height, method, filter, |
| 241 reduce_levels, effort_level, filtered_alpha, |
| 242 &trial); |
| 243 if (ok && trial.score < best.score) { |
| 244 VP8BitWriterWipeOut(&best.bw); |
| 245 best = trial; |
| 246 } else { |
| 247 VP8BitWriterWipeOut(&trial.bw); |
| 248 } |
| 249 } |
| 250 } |
| 251 free(filtered_alpha); |
| 252 } else { |
| 253 ok = EncodeAlphaInternal(alpha, width, height, method, WEBP_FILTER_NONE, |
| 254 reduce_levels, effort_level, NULL, &best); |
| 255 } |
| 256 if (ok) { |
| 257 if (stats != NULL) *stats = best.stats; |
| 258 *output_size = VP8BitWriterSize(&best.bw); |
| 259 *output = VP8BitWriterBuf(&best.bw); |
| 260 } else { |
| 261 VP8BitWriterWipeOut(&best.bw); |
| 262 } |
| 263 return ok; |
| 264 } |
| 265 |
| 180 static int EncodeAlpha(VP8Encoder* const enc, | 266 static int EncodeAlpha(VP8Encoder* const enc, |
| 181 int quality, int method, int filter, | 267 int quality, int method, int filter, |
| 182 int effort_level, | 268 int effort_level, |
| 183 uint8_t** const output, size_t* const output_size) { | 269 uint8_t** const output, size_t* const output_size) { |
| 184 const WebPPicture* const pic = enc->pic_; | 270 const WebPPicture* const pic = enc->pic_; |
| 185 const int width = pic->width; | 271 const int width = pic->width; |
| 186 const int height = pic->height; | 272 const int height = pic->height; |
| 187 | 273 |
| 188 uint8_t* quant_alpha = NULL; | 274 uint8_t* quant_alpha = NULL; |
| 189 const size_t data_size = width * height; | 275 const size_t data_size = width * height; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 200 assert(filter >= WEBP_FILTER_NONE && filter <= WEBP_FILTER_FAST); | 286 assert(filter >= WEBP_FILTER_NONE && filter <= WEBP_FILTER_FAST); |
| 201 | 287 |
| 202 if (quality < 0 || quality > 100) { | 288 if (quality < 0 || quality > 100) { |
| 203 return 0; | 289 return 0; |
| 204 } | 290 } |
| 205 | 291 |
| 206 if (method < ALPHA_NO_COMPRESSION || method > ALPHA_LOSSLESS_COMPRESSION) { | 292 if (method < ALPHA_NO_COMPRESSION || method > ALPHA_LOSSLESS_COMPRESSION) { |
| 207 return 0; | 293 return 0; |
| 208 } | 294 } |
| 209 | 295 |
| 296 if (method == ALPHA_NO_COMPRESSION) { |
| 297 // Don't filter, as filtering will make no impact on compressed size. |
| 298 filter = WEBP_FILTER_NONE; |
| 299 } |
| 300 |
| 210 quant_alpha = (uint8_t*)malloc(data_size); | 301 quant_alpha = (uint8_t*)malloc(data_size); |
| 211 if (quant_alpha == NULL) { | 302 if (quant_alpha == NULL) { |
| 212 return 0; | 303 return 0; |
| 213 } | 304 } |
| 214 | 305 |
| 215 // Extract alpha data (width x height) from raw_data (stride x height). | 306 // Extract alpha data (width x height) from raw_data (stride x height). |
| 216 CopyPlane(pic->a, pic->a_stride, quant_alpha, width, width, height); | 307 CopyPlane(pic->a, pic->a_stride, quant_alpha, width, width, height); |
| 217 | 308 |
| 218 if (reduce_levels) { // No Quantization required for 'quality = 100'. | 309 if (reduce_levels) { // No Quantization required for 'quality = 100'. |
| 219 // 16 alpha levels gives quite a low MSE w.r.t original alpha plane hence | 310 // 16 alpha levels gives quite a low MSE w.r.t original alpha plane hence |
| 220 // mapped to moderate quality 70. Hence Quality:[0, 70] -> Levels:[2, 16] | 311 // mapped to moderate quality 70. Hence Quality:[0, 70] -> Levels:[2, 16] |
| 221 // and Quality:]70, 100] -> Levels:]16, 256]. | 312 // and Quality:]70, 100] -> Levels:]16, 256]. |
| 222 const int alpha_levels = (quality <= 70) ? (2 + quality / 5) | 313 const int alpha_levels = (quality <= 70) ? (2 + quality / 5) |
| 223 : (16 + (quality - 70) * 8); | 314 : (16 + (quality - 70) * 8); |
| 224 ok = QuantizeLevels(quant_alpha, width, height, alpha_levels, &sse); | 315 ok = QuantizeLevels(quant_alpha, width, height, alpha_levels, &sse); |
| 225 } | 316 } |
| 226 | 317 |
| 227 if (ok) { | 318 if (ok) { |
| 228 VP8BitWriter bw; | 319 ok = ApplyFiltersAndEncode(quant_alpha, width, height, data_size, method, |
| 229 int test_filter; | 320 filter, reduce_levels, effort_level, output, |
| 230 uint8_t* filtered_alpha = NULL; | 321 output_size, pic->stats); |
| 231 int try_filter_none = (effort_level > 3); | 322 if (pic->stats != NULL) { // need stats? |
| 323 pic->stats->coded_size += (int)(*output_size); |
| 324 enc->sse_[3] = sse; |
| 325 } |
| 326 } |
| 232 | 327 |
| 233 if (filter == WEBP_FILTER_FAST) { // Quick estimate of the best candidate. | |
| 234 const int kMinColorsForFilterNone = 16; | |
| 235 const int kMaxColorsForFilterNone = 192; | |
| 236 const int num_colors = GetNumColors(quant_alpha, width, height, width); | |
| 237 // For low number of colors, NONE yeilds better compression. | |
| 238 filter = (num_colors <= kMinColorsForFilterNone) ? WEBP_FILTER_NONE : | |
| 239 EstimateBestFilter(quant_alpha, width, height, width); | |
| 240 // For large number of colors, try FILTER_NONE in addition to the best | |
| 241 // filter as well. | |
| 242 if (num_colors > kMaxColorsForFilterNone) { | |
| 243 try_filter_none = 1; | |
| 244 } | |
| 245 } | |
| 246 | |
| 247 // Test for WEBP_FILTER_NONE for higher effort levels. | |
| 248 if (try_filter_none || filter == WEBP_FILTER_NONE) { | |
| 249 ok = EncodeAlphaInternal(quant_alpha, width, height, | |
| 250 method, WEBP_FILTER_NONE, reduce_levels, | |
| 251 effort_level, NULL, &bw, pic->stats); | |
| 252 | |
| 253 if (!ok) { | |
| 254 VP8BitWriterWipeOut(&bw); | |
| 255 goto End; | |
| 256 } | |
| 257 } | |
| 258 // Stop? | |
| 259 if (filter == WEBP_FILTER_NONE) { | |
| 260 goto Ok; | |
| 261 } | |
| 262 | |
| 263 filtered_alpha = (uint8_t*)malloc(data_size); | |
| 264 ok = (filtered_alpha != NULL); | |
| 265 if (!ok) { | |
| 266 goto End; | |
| 267 } | |
| 268 | |
| 269 // Try the other mode(s). | |
| 270 { | |
| 271 WebPAuxStats best_stats; | |
| 272 size_t best_score = try_filter_none ? | |
| 273 VP8BitWriterSize(&bw) : (size_t)~0U; | |
| 274 int wipe_tmp_bw = try_filter_none; | |
| 275 | |
| 276 memset(&best_stats, 0, sizeof(best_stats)); // prevent spurious warning | |
| 277 if (pic->stats != NULL) best_stats = *pic->stats; | |
| 278 for (test_filter = | |
| 279 try_filter_none ? WEBP_FILTER_HORIZONTAL : WEBP_FILTER_NONE; | |
| 280 ok && (test_filter <= WEBP_FILTER_GRADIENT); | |
| 281 ++test_filter) { | |
| 282 VP8BitWriter tmp_bw; | |
| 283 if (filter != WEBP_FILTER_BEST && test_filter != filter) { | |
| 284 continue; | |
| 285 } | |
| 286 ok = EncodeAlphaInternal(quant_alpha, width, height, | |
| 287 method, test_filter, reduce_levels, | |
| 288 effort_level, filtered_alpha, &tmp_bw, | |
| 289 pic->stats); | |
| 290 if (ok) { | |
| 291 const size_t score = VP8BitWriterSize(&tmp_bw); | |
| 292 if (score < best_score) { | |
| 293 // swap bitwriter objects. | |
| 294 VP8BitWriter tmp = tmp_bw; | |
| 295 tmp_bw = bw; | |
| 296 bw = tmp; | |
| 297 best_score = score; | |
| 298 if (pic->stats != NULL) best_stats = *pic->stats; | |
| 299 } | |
| 300 } else { | |
| 301 VP8BitWriterWipeOut(&bw); | |
| 302 } | |
| 303 if (wipe_tmp_bw) { | |
| 304 VP8BitWriterWipeOut(&tmp_bw); | |
| 305 } | |
| 306 wipe_tmp_bw = 1; // For next filter trial for WEBP_FILTER_BEST. | |
| 307 } | |
| 308 if (pic->stats != NULL) *pic->stats = best_stats; | |
| 309 } | |
| 310 Ok: | |
| 311 if (ok) { | |
| 312 *output_size = VP8BitWriterSize(&bw); | |
| 313 *output = VP8BitWriterBuf(&bw); | |
| 314 if (pic->stats != NULL) { // need stats? | |
| 315 pic->stats->coded_size += (int)(*output_size); | |
| 316 enc->sse_[3] = sse; | |
| 317 } | |
| 318 } | |
| 319 free(filtered_alpha); | |
| 320 } | |
| 321 End: | |
| 322 free(quant_alpha); | 328 free(quant_alpha); |
| 323 return ok; | 329 return ok; |
| 324 } | 330 } |
| 325 | 331 |
| 326 | |
| 327 //------------------------------------------------------------------------------ | 332 //------------------------------------------------------------------------------ |
| 328 // Main calls | 333 // Main calls |
| 329 | 334 |
| 330 static int CompressAlphaJob(VP8Encoder* const enc, void* dummy) { | 335 static int CompressAlphaJob(VP8Encoder* const enc, void* dummy) { |
| 331 const WebPConfig* config = enc->config_; | 336 const WebPConfig* config = enc->config_; |
| 332 uint8_t* alpha_data = NULL; | 337 uint8_t* alpha_data = NULL; |
| 333 size_t alpha_size = 0; | 338 size_t alpha_size = 0; |
| 334 const int effort_level = config->method; // maps to [0..6] | 339 const int effort_level = config->method; // maps to [0..6] |
| 335 const WEBP_FILTER_TYPE filter = | 340 const WEBP_FILTER_TYPE filter = |
| 336 (config->alpha_filtering == 0) ? WEBP_FILTER_NONE : | 341 (config->alpha_filtering == 0) ? WEBP_FILTER_NONE : |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 ok = WebPWorkerSync(worker); // finish anything left in flight | 401 ok = WebPWorkerSync(worker); // finish anything left in flight |
| 397 WebPWorkerEnd(worker); // still need to end the worker, even if !ok | 402 WebPWorkerEnd(worker); // still need to end the worker, even if !ok |
| 398 } | 403 } |
| 399 free(enc->alpha_data_); | 404 free(enc->alpha_data_); |
| 400 enc->alpha_data_ = NULL; | 405 enc->alpha_data_ = NULL; |
| 401 enc->alpha_data_size_ = 0; | 406 enc->alpha_data_size_ = 0; |
| 402 enc->has_alpha_ = 0; | 407 enc->has_alpha_ = 0; |
| 403 return ok; | 408 return ok; |
| 404 } | 409 } |
| 405 | 410 |
| 406 #if defined(__cplusplus) || defined(c_plusplus) | |
| 407 } // extern "C" | |
| 408 #endif | |
| OLD | NEW |