| 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. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // internal encoding-related image containing necessary exact information in | 72 // internal encoding-related image containing necessary exact information in |
| 73 // RGB channels. | 73 // RGB channels. |
| 74 config.exact = 1; | 74 config.exact = 1; |
| 75 config.method = effort_level; // impact is very small | 75 config.method = effort_level; // impact is very small |
| 76 // Set a low default quality for encoding alpha. Ensure that Alpha quality at | 76 // Set a low default quality for encoding alpha. Ensure that Alpha quality at |
| 77 // lower methods (3 and below) is less than the threshold for triggering | 77 // lower methods (3 and below) is less than the threshold for triggering |
| 78 // costly 'BackwardReferencesTraceBackwards'. | 78 // costly 'BackwardReferencesTraceBackwards'. |
| 79 config.quality = 8.f * effort_level; | 79 config.quality = 8.f * effort_level; |
| 80 assert(config.quality >= 0 && config.quality <= 100.f); | 80 assert(config.quality >= 0 && config.quality <= 100.f); |
| 81 | 81 |
| 82 ok = (VP8LEncodeStream(&config, &picture, bw) == VP8_ENC_OK); | 82 // TODO(urvang): Temporary fix to avoid generating images that trigger |
| 83 // a decoder bug related to alpha with color cache. |
| 84 // See: https://code.google.com/p/webp/issues/detail?id=239 |
| 85 // Need to re-enable this later. |
| 86 ok = (VP8LEncodeStream(&config, &picture, bw, 0 /*use_cache*/) == VP8_ENC_OK); |
| 83 WebPPictureFree(&picture); | 87 WebPPictureFree(&picture); |
| 84 ok = ok && !bw->error_; | 88 ok = ok && !bw->error_; |
| 85 if (!ok) { | 89 if (!ok) { |
| 86 VP8LBitWriterWipeOut(bw); | 90 VP8LBitWriterWipeOut(bw); |
| 87 return 0; | 91 return 0; |
| 88 } | 92 } |
| 89 return 1; | 93 return 1; |
| 90 } | 94 } |
| 91 | 95 |
| 92 // ----------------------------------------------------------------------------- | 96 // ----------------------------------------------------------------------------- |
| (...skipping 18 matching lines...) Expand all Loading... |
| 111 const size_t data_size = width * height; | 115 const size_t data_size = width * height; |
| 112 const uint8_t* output = NULL; | 116 const uint8_t* output = NULL; |
| 113 size_t output_size = 0; | 117 size_t output_size = 0; |
| 114 VP8LBitWriter tmp_bw; | 118 VP8LBitWriter tmp_bw; |
| 115 | 119 |
| 116 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 |
| 117 assert(filter >= 0 && filter < WEBP_FILTER_LAST); | 121 assert(filter >= 0 && filter < WEBP_FILTER_LAST); |
| 118 assert(method >= ALPHA_NO_COMPRESSION); | 122 assert(method >= ALPHA_NO_COMPRESSION); |
| 119 assert(method <= ALPHA_LOSSLESS_COMPRESSION); | 123 assert(method <= ALPHA_LOSSLESS_COMPRESSION); |
| 120 assert(sizeof(header) == ALPHA_HEADER_LEN); | 124 assert(sizeof(header) == ALPHA_HEADER_LEN); |
| 121 // TODO(skal): have a common function and #define's to validate alpha params. | |
| 122 | 125 |
| 123 filter_func = WebPFilters[filter]; | 126 filter_func = WebPFilters[filter]; |
| 124 if (filter_func != NULL) { | 127 if (filter_func != NULL) { |
| 125 filter_func(data, width, height, width, tmp_alpha); | 128 filter_func(data, width, height, width, tmp_alpha); |
| 126 alpha_src = tmp_alpha; | 129 alpha_src = tmp_alpha; |
| 127 } else { | 130 } else { |
| 128 alpha_src = data; | 131 alpha_src = data; |
| 129 } | 132 } |
| 130 | 133 |
| 131 if (method != ALPHA_NO_COMPRESSION) { | 134 if (method != ALPHA_NO_COMPRESSION) { |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 ok = WebPGetWorkerInterface()->Sync(worker); | 424 ok = WebPGetWorkerInterface()->Sync(worker); |
| 422 // still need to end the worker, even if !ok | 425 // still need to end the worker, even if !ok |
| 423 WebPGetWorkerInterface()->End(worker); | 426 WebPGetWorkerInterface()->End(worker); |
| 424 } | 427 } |
| 425 WebPSafeFree(enc->alpha_data_); | 428 WebPSafeFree(enc->alpha_data_); |
| 426 enc->alpha_data_ = NULL; | 429 enc->alpha_data_ = NULL; |
| 427 enc->alpha_data_size_ = 0; | 430 enc->alpha_data_size_ = 0; |
| 428 enc->has_alpha_ = 0; | 431 enc->has_alpha_ = 0; |
| 429 return ok; | 432 return ok; |
| 430 } | 433 } |
| OLD | NEW |