| 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 "./vp8i_enc.h" |
| 18 #include "../dsp/dsp.h" | 18 #include "../dsp/dsp.h" |
| 19 #include "../utils/filters.h" | 19 #include "../utils/filters_utils.h" |
| 20 #include "../utils/quant_levels.h" | 20 #include "../utils/quant_levels_utils.h" |
| 21 #include "../utils/utils.h" | 21 #include "../utils/utils.h" |
| 22 #include "../webp/format_constants.h" | 22 #include "../webp/format_constants.h" |
| 23 | 23 |
| 24 // ----------------------------------------------------------------------------- | 24 // ----------------------------------------------------------------------------- |
| 25 // Encodes the given alpha data via specified compression method 'method'. | 25 // Encodes the given alpha data via specified compression method 'method'. |
| 26 // The pre-processing (quantization) is performed if 'quality' is less than 100. | 26 // The pre-processing (quantization) is performed if 'quality' is less than 100. |
| 27 // For such cases, the encoding is lossy. The valid range is [0, 100] for | 27 // For such cases, the encoding is lossy. The valid range is [0, 100] for |
| 28 // 'quality' and [0, 1] for 'method': | 28 // 'quality' and [0, 1] for 'method': |
| 29 // 'method = 0' - No compression; | 29 // 'method = 0' - No compression; |
| 30 // 'method = 1' - Use lossless coder on the alpha plane only | 30 // 'method = 1' - Use lossless coder on the alpha plane only |
| 31 // 'filter' values [0, 4] correspond to prediction modes none, horizontal, | 31 // 'filter' values [0, 4] correspond to prediction modes none, horizontal, |
| 32 // vertical & gradient filters. The prediction mode 4 will try all the | 32 // vertical & gradient filters. The prediction mode 4 will try all the |
| 33 // prediction modes 0 to 3 and pick the best one. | 33 // prediction modes 0 to 3 and pick the best one. |
| 34 // 'effort_level': specifies how much effort must be spent to try and reduce | 34 // 'effort_level': specifies how much effort must be spent to try and reduce |
| 35 // the compressed output size. In range 0 (quick) to 6 (slow). | 35 // the compressed output size. In range 0 (quick) to 6 (slow). |
| 36 // | 36 // |
| 37 // 'output' corresponds to the buffer containing compressed alpha data. | 37 // 'output' corresponds to the buffer containing compressed alpha data. |
| 38 // This buffer is allocated by this method and caller should call | 38 // This buffer is allocated by this method and caller should call |
| 39 // WebPSafeFree(*output) when done. | 39 // WebPSafeFree(*output) when done. |
| 40 // 'output_size' corresponds to size of this compressed alpha buffer. | 40 // 'output_size' corresponds to size of this compressed alpha buffer. |
| 41 // | 41 // |
| 42 // Returns 1 on successfully encoding the alpha and | 42 // Returns 1 on successfully encoding the alpha and |
| 43 // 0 if either: | 43 // 0 if either: |
| 44 // invalid quality or method, or | 44 // invalid quality or method, or |
| 45 // memory allocation for the compressed data fails. | 45 // memory allocation for the compressed data fails. |
| 46 | 46 |
| 47 #include "../enc/vp8li.h" | 47 #include "../enc/vp8li_enc.h" |
| 48 | 48 |
| 49 static int EncodeLossless(const uint8_t* const data, int width, int height, | 49 static int EncodeLossless(const uint8_t* const data, int width, int height, |
| 50 int effort_level, // in [0..6] range | 50 int effort_level, // in [0..6] range |
| 51 VP8LBitWriter* const bw, | 51 VP8LBitWriter* const bw, |
| 52 WebPAuxStats* const stats) { | 52 WebPAuxStats* const stats) { |
| 53 int ok = 0; | 53 int ok = 0; |
| 54 WebPConfig config; | 54 WebPConfig config; |
| 55 WebPPicture picture; | 55 WebPPicture picture; |
| 56 | 56 |
| 57 WebPPictureInit(&picture); | 57 WebPPictureInit(&picture); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 ok = WebPGetWorkerInterface()->Sync(worker); | 424 ok = WebPGetWorkerInterface()->Sync(worker); |
| 425 // still need to end the worker, even if !ok | 425 // still need to end the worker, even if !ok |
| 426 WebPGetWorkerInterface()->End(worker); | 426 WebPGetWorkerInterface()->End(worker); |
| 427 } | 427 } |
| 428 WebPSafeFree(enc->alpha_data_); | 428 WebPSafeFree(enc->alpha_data_); |
| 429 enc->alpha_data_ = NULL; | 429 enc->alpha_data_ = NULL; |
| 430 enc->alpha_data_size_ = 0; | 430 enc->alpha_data_size_ = 0; |
| 431 enc->has_alpha_ = 0; | 431 enc->has_alpha_ = 0; |
| 432 return ok; | 432 return ok; |
| 433 } | 433 } |
| OLD | NEW |