OLD | NEW |
1 // Copyright 2012 Google Inc. All Rights Reserved. | 1 // Copyright 2012 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 // Author: Jyrki Alakuijala (jyrki@google.com) | 10 // Author: Jyrki Alakuijala (jyrki@google.com) |
11 // | 11 // |
12 | 12 |
13 #ifndef WEBP_ENC_BACKWARD_REFERENCES_H_ | 13 #ifndef WEBP_ENC_BACKWARD_REFERENCES_H_ |
14 #define WEBP_ENC_BACKWARD_REFERENCES_H_ | 14 #define WEBP_ENC_BACKWARD_REFERENCES_H_ |
15 | 15 |
16 #include <assert.h> | 16 #include <assert.h> |
17 #include <stdlib.h> | 17 #include <stdlib.h> |
18 #include "../webp/types.h" | 18 #include "../webp/types.h" |
19 #include "../webp/format_constants.h" | 19 #include "../webp/format_constants.h" |
20 | 20 |
21 #ifdef __cplusplus | 21 #ifdef __cplusplus |
22 extern "C" { | 22 extern "C" { |
23 #endif | 23 #endif |
24 | 24 |
25 // The spec allows 11, we use 9 bits to reduce memory consumption in encoding. | 25 // The maximum allowed limit is 11. |
26 // Having 9 instead of 11 only removes about 0.25 % of compression density. | 26 #define MAX_COLOR_CACHE_BITS 10 |
27 #define MAX_COLOR_CACHE_BITS 9 | |
28 | |
29 // Max ever number of codes we'll use: | |
30 #define PIX_OR_COPY_CODES_MAX \ | |
31 (NUM_LITERAL_CODES + NUM_LENGTH_CODES + (1 << MAX_COLOR_CACHE_BITS)) | |
32 | 27 |
33 // ----------------------------------------------------------------------------- | 28 // ----------------------------------------------------------------------------- |
34 // PixOrCopy | 29 // PixOrCopy |
35 | 30 |
36 enum Mode { | 31 enum Mode { |
37 kLiteral, | 32 kLiteral, |
38 kCacheIdx, | 33 kCacheIdx, |
39 kCopy, | 34 kCopy, |
40 kNone | 35 kNone |
41 }; | 36 }; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 static WEBP_INLINE void VP8LRefsCursorNext(VP8LRefsCursor* const c) { | 178 static WEBP_INLINE void VP8LRefsCursorNext(VP8LRefsCursor* const c) { |
184 assert(c != NULL); | 179 assert(c != NULL); |
185 assert(VP8LRefsCursorOk(c)); | 180 assert(VP8LRefsCursorOk(c)); |
186 if (++c->cur_pos == c->last_pos_) VP8LRefsCursorNextBlock(c); | 181 if (++c->cur_pos == c->last_pos_) VP8LRefsCursorNextBlock(c); |
187 } | 182 } |
188 | 183 |
189 // ----------------------------------------------------------------------------- | 184 // ----------------------------------------------------------------------------- |
190 // Main entry points | 185 // Main entry points |
191 | 186 |
192 // Evaluates best possible backward references for specified quality. | 187 // Evaluates best possible backward references for specified quality. |
193 // Further optimize for 2D locality if use_2d_locality flag is set. | 188 // The input cache_bits to 'VP8LGetBackwardReferences' sets the maximum cache |
| 189 // bits to use (passing 0 implies disabling the local color cache). |
| 190 // The optimal cache bits is evaluated and set for the *cache_bits parameter. |
194 // The return value is the pointer to the best of the two backward refs viz, | 191 // The return value is the pointer to the best of the two backward refs viz, |
195 // refs[0] or refs[1]. | 192 // refs[0] or refs[1]. |
196 VP8LBackwardRefs* VP8LGetBackwardReferences( | 193 VP8LBackwardRefs* VP8LGetBackwardReferences( |
197 int width, int height, const uint32_t* const argb, int quality, | 194 int width, int height, const uint32_t* const argb, int quality, |
198 int cache_bits, int use_2d_locality, VP8LHashChain* const hash_chain, | 195 int low_effort, int* const cache_bits, VP8LHashChain* const hash_chain, |
199 VP8LBackwardRefs refs[2]); | 196 VP8LBackwardRefs refs[2]); |
200 | 197 |
201 // Produce an estimate for a good color cache size for the image. | |
202 int VP8LCalculateEstimateForCacheSize(const uint32_t* const argb, | |
203 int xsize, int ysize, int quality, | |
204 VP8LHashChain* const hash_chain, | |
205 VP8LBackwardRefs* const ref, | |
206 int* const best_cache_bits); | |
207 | |
208 #ifdef __cplusplus | 198 #ifdef __cplusplus |
209 } | 199 } |
210 #endif | 200 #endif |
211 | 201 |
212 #endif // WEBP_ENC_BACKWARD_REFERENCES_H_ | 202 #endif // WEBP_ENC_BACKWARD_REFERENCES_H_ |
OLD | NEW |