Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Side by Side Diff: third_party/libwebp/dsp/lossless.h

Issue 2651883004: libwebp-0.6.0-rc1 (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libwebp/dsp/filters_sse2.c ('k') | third_party/libwebp/dsp/lossless.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Image transforms and color space conversion methods for lossless decoder. 10 // Image transforms and color space conversion methods for lossless decoder.
11 // 11 //
12 // Authors: Vikas Arora (vikaas.arora@gmail.com) 12 // Authors: Vikas Arora (vikaas.arora@gmail.com)
13 // Jyrki Alakuijala (jyrki@google.com) 13 // Jyrki Alakuijala (jyrki@google.com)
14 14
15 #ifndef WEBP_DSP_LOSSLESS_H_ 15 #ifndef WEBP_DSP_LOSSLESS_H_
16 #define WEBP_DSP_LOSSLESS_H_ 16 #define WEBP_DSP_LOSSLESS_H_
17 17
18 #include "../webp/types.h" 18 #include "../webp/types.h"
19 #include "../webp/decode.h" 19 #include "../webp/decode.h"
20 20
21 #include "../enc/histogram.h" 21 #include "../enc/histogram_enc.h"
22 #include "../utils/utils.h" 22 #include "../utils/utils.h"
23 23
24 #ifdef __cplusplus 24 #ifdef __cplusplus
25 extern "C" { 25 extern "C" {
26 #endif 26 #endif
27 27
28 #ifdef WEBP_EXPERIMENTAL_FEATURES 28 #ifdef WEBP_EXPERIMENTAL_FEATURES
29 #include "../enc/delta_palettization.h" 29 #include "../enc/delta_palettization_enc.h"
30 #endif // WEBP_EXPERIMENTAL_FEATURES 30 #endif // WEBP_EXPERIMENTAL_FEATURES
31 31
32 //------------------------------------------------------------------------------ 32 //------------------------------------------------------------------------------
33 // Decoding 33 // Decoding
34 34
35 typedef uint32_t (*VP8LPredictorFunc)(uint32_t left, const uint32_t* const top); 35 typedef uint32_t (*VP8LPredictorFunc)(uint32_t left, const uint32_t* const top);
36 extern VP8LPredictorFunc VP8LPredictors[16]; 36 extern VP8LPredictorFunc VP8LPredictors[16];
37 extern VP8LPredictorFunc VP8LPredictors_C[16];
38 // These Add/Sub function expects upper[-1] and out[-1] to be readable.
39 typedef void (*VP8LPredictorAddSubFunc)(const uint32_t* in,
40 const uint32_t* upper, int num_pixels,
41 uint32_t* out);
42 extern VP8LPredictorAddSubFunc VP8LPredictorsAdd[16];
43 extern VP8LPredictorAddSubFunc VP8LPredictorsAdd_C[16];
37 44
38 typedef void (*VP8LProcessBlueAndRedFunc)(uint32_t* argb_data, int num_pixels); 45 typedef void (*VP8LProcessDecBlueAndRedFunc)(const uint32_t* src,
39 extern VP8LProcessBlueAndRedFunc VP8LAddGreenToBlueAndRed; 46 int num_pixels, uint32_t* dst);
47 extern VP8LProcessDecBlueAndRedFunc VP8LAddGreenToBlueAndRed;
40 48
41 typedef struct { 49 typedef struct {
42 // Note: the members are uint8_t, so that any negative values are 50 // Note: the members are uint8_t, so that any negative values are
43 // automatically converted to "mod 256" values. 51 // automatically converted to "mod 256" values.
44 uint8_t green_to_red_; 52 uint8_t green_to_red_;
45 uint8_t green_to_blue_; 53 uint8_t green_to_blue_;
46 uint8_t red_to_blue_; 54 uint8_t red_to_blue_;
47 } VP8LMultipliers; 55 } VP8LMultipliers;
48 typedef void (*VP8LTransformColorFunc)(const VP8LMultipliers* const m, 56 typedef void (*VP8LTransformColorInverseFunc)(const VP8LMultipliers* const m,
49 uint32_t* argb_data, int num_pixels); 57 const uint32_t* src,
50 extern VP8LTransformColorFunc VP8LTransformColorInverse; 58 int num_pixels, uint32_t* dst);
59 extern VP8LTransformColorInverseFunc VP8LTransformColorInverse;
51 60
52 struct VP8LTransform; // Defined in dec/vp8li.h. 61 struct VP8LTransform; // Defined in dec/vp8li.h.
53 62
54 // Performs inverse transform of data given transform information, start and end 63 // Performs inverse transform of data given transform information, start and end
55 // rows. Transform will be applied to rows [row_start, row_end[. 64 // rows. Transform will be applied to rows [row_start, row_end[.
56 // The *in and *out pointers refer to source and destination data respectively 65 // The *in and *out pointers refer to source and destination data respectively
57 // corresponding to the intermediate row (row_start). 66 // corresponding to the intermediate row (row_start).
58 void VP8LInverseTransform(const struct VP8LTransform* const transform, 67 void VP8LInverseTransform(const struct VP8LTransform* const transform,
59 int row_start, int row_end, 68 int row_start, int row_end,
60 const uint32_t* const in, uint32_t* const out); 69 const uint32_t* const in, uint32_t* const out);
61 70
62 // Color space conversion. 71 // Color space conversion.
63 typedef void (*VP8LConvertFunc)(const uint32_t* src, int num_pixels, 72 typedef void (*VP8LConvertFunc)(const uint32_t* src, int num_pixels,
64 uint8_t* dst); 73 uint8_t* dst);
65 extern VP8LConvertFunc VP8LConvertBGRAToRGB; 74 extern VP8LConvertFunc VP8LConvertBGRAToRGB;
66 extern VP8LConvertFunc VP8LConvertBGRAToRGBA; 75 extern VP8LConvertFunc VP8LConvertBGRAToRGBA;
67 extern VP8LConvertFunc VP8LConvertBGRAToRGBA4444; 76 extern VP8LConvertFunc VP8LConvertBGRAToRGBA4444;
68 extern VP8LConvertFunc VP8LConvertBGRAToRGB565; 77 extern VP8LConvertFunc VP8LConvertBGRAToRGB565;
69 extern VP8LConvertFunc VP8LConvertBGRAToBGR; 78 extern VP8LConvertFunc VP8LConvertBGRAToBGR;
70 79
71 // Converts from BGRA to other color spaces. 80 // Converts from BGRA to other color spaces.
72 void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels, 81 void VP8LConvertFromBGRA(const uint32_t* const in_data, int num_pixels,
73 WEBP_CSP_MODE out_colorspace, uint8_t* const rgba); 82 WEBP_CSP_MODE out_colorspace, uint8_t* const rgba);
74 83
75 // color mapping related functions.
76 static WEBP_INLINE uint32_t VP8GetARGBIndex(uint32_t idx) {
77 return (idx >> 8) & 0xff;
78 }
79
80 static WEBP_INLINE uint8_t VP8GetAlphaIndex(uint8_t idx) {
81 return idx;
82 }
83
84 static WEBP_INLINE uint32_t VP8GetARGBValue(uint32_t val) {
85 return val;
86 }
87
88 static WEBP_INLINE uint8_t VP8GetAlphaValue(uint32_t val) {
89 return (val >> 8) & 0xff;
90 }
91
92 typedef void (*VP8LMapARGBFunc)(const uint32_t* src, 84 typedef void (*VP8LMapARGBFunc)(const uint32_t* src,
93 const uint32_t* const color_map, 85 const uint32_t* const color_map,
94 uint32_t* dst, int y_start, 86 uint32_t* dst, int y_start,
95 int y_end, int width); 87 int y_end, int width);
96 typedef void (*VP8LMapAlphaFunc)(const uint8_t* src, 88 typedef void (*VP8LMapAlphaFunc)(const uint8_t* src,
97 const uint32_t* const color_map, 89 const uint32_t* const color_map,
98 uint8_t* dst, int y_start, 90 uint8_t* dst, int y_start,
99 int y_end, int width); 91 int y_end, int width);
100 92
101 extern VP8LMapARGBFunc VP8LMapColor32b; 93 extern VP8LMapARGBFunc VP8LMapColor32b;
102 extern VP8LMapAlphaFunc VP8LMapColor8b; 94 extern VP8LMapAlphaFunc VP8LMapColor8b;
103 95
104 // Similar to the static method ColorIndexInverseTransform() that is part of 96 // Similar to the static method ColorIndexInverseTransform() that is part of
105 // lossless.c, but used only for alpha decoding. It takes uint8_t (rather than 97 // lossless.c, but used only for alpha decoding. It takes uint8_t (rather than
106 // uint32_t) arguments for 'src' and 'dst'. 98 // uint32_t) arguments for 'src' and 'dst'.
107 void VP8LColorIndexInverseTransformAlpha( 99 void VP8LColorIndexInverseTransformAlpha(
108 const struct VP8LTransform* const transform, int y_start, int y_end, 100 const struct VP8LTransform* const transform, int y_start, int y_end,
109 const uint8_t* src, uint8_t* dst); 101 const uint8_t* src, uint8_t* dst);
110 102
111 // Expose some C-only fallback functions 103 // Expose some C-only fallback functions
112 void VP8LTransformColorInverse_C(const VP8LMultipliers* const m, 104 void VP8LTransformColorInverse_C(const VP8LMultipliers* const m,
113 uint32_t* data, int num_pixels); 105 const uint32_t* src, int num_pixels,
106 uint32_t* dst);
114 107
115 void VP8LConvertBGRAToRGB_C(const uint32_t* src, int num_pixels, uint8_t* dst); 108 void VP8LConvertBGRAToRGB_C(const uint32_t* src, int num_pixels, uint8_t* dst);
116 void VP8LConvertBGRAToRGBA_C(const uint32_t* src, int num_pixels, uint8_t* dst); 109 void VP8LConvertBGRAToRGBA_C(const uint32_t* src, int num_pixels, uint8_t* dst);
117 void VP8LConvertBGRAToRGBA4444_C(const uint32_t* src, 110 void VP8LConvertBGRAToRGBA4444_C(const uint32_t* src,
118 int num_pixels, uint8_t* dst); 111 int num_pixels, uint8_t* dst);
119 void VP8LConvertBGRAToRGB565_C(const uint32_t* src, 112 void VP8LConvertBGRAToRGB565_C(const uint32_t* src,
120 int num_pixels, uint8_t* dst); 113 int num_pixels, uint8_t* dst);
121 void VP8LConvertBGRAToBGR_C(const uint32_t* src, int num_pixels, uint8_t* dst); 114 void VP8LConvertBGRAToBGR_C(const uint32_t* src, int num_pixels, uint8_t* dst);
122 void VP8LAddGreenToBlueAndRed_C(uint32_t* data, int num_pixels); 115 void VP8LAddGreenToBlueAndRed_C(const uint32_t* src, int num_pixels,
116 uint32_t* dst);
123 117
124 // Must be called before calling any of the above methods. 118 // Must be called before calling any of the above methods.
125 void VP8LDspInit(void); 119 void VP8LDspInit(void);
126 120
127 //------------------------------------------------------------------------------ 121 //------------------------------------------------------------------------------
128 // Encoding 122 // Encoding
129 123
130 extern VP8LProcessBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed; 124 typedef void (*VP8LProcessEncBlueAndRedFunc)(uint32_t* dst, int num_pixels);
125 extern VP8LProcessEncBlueAndRedFunc VP8LSubtractGreenFromBlueAndRed;
126 typedef void (*VP8LTransformColorFunc)(const VP8LMultipliers* const m,
127 uint32_t* const dst, int num_pixels);
131 extern VP8LTransformColorFunc VP8LTransformColor; 128 extern VP8LTransformColorFunc VP8LTransformColor;
132 typedef void (*VP8LCollectColorBlueTransformsFunc)( 129 typedef void (*VP8LCollectColorBlueTransformsFunc)(
133 const uint32_t* argb, int stride, 130 const uint32_t* argb, int stride,
134 int tile_width, int tile_height, 131 int tile_width, int tile_height,
135 int green_to_blue, int red_to_blue, int histo[]); 132 int green_to_blue, int red_to_blue, int histo[]);
136 extern VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms; 133 extern VP8LCollectColorBlueTransformsFunc VP8LCollectColorBlueTransforms;
137 134
138 typedef void (*VP8LCollectColorRedTransformsFunc)( 135 typedef void (*VP8LCollectColorRedTransformsFunc)(
139 const uint32_t* argb, int stride, 136 const uint32_t* argb, int stride,
140 int tile_width, int tile_height, 137 int tile_width, int tile_height,
141 int green_to_red, int histo[]); 138 int green_to_red, int histo[]);
142 extern VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms; 139 extern VP8LCollectColorRedTransformsFunc VP8LCollectColorRedTransforms;
143 140
144 // Expose some C-only fallback functions 141 // Expose some C-only fallback functions
145 void VP8LTransformColor_C(const VP8LMultipliers* const m, 142 void VP8LTransformColor_C(const VP8LMultipliers* const m,
146 uint32_t* data, int num_pixels); 143 uint32_t* data, int num_pixels);
147 void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels); 144 void VP8LSubtractGreenFromBlueAndRed_C(uint32_t* argb_data, int num_pixels);
148 void VP8LCollectColorRedTransforms_C(const uint32_t* argb, int stride, 145 void VP8LCollectColorRedTransforms_C(const uint32_t* argb, int stride,
149 int tile_width, int tile_height, 146 int tile_width, int tile_height,
150 int green_to_red, int histo[]); 147 int green_to_red, int histo[]);
151 void VP8LCollectColorBlueTransforms_C(const uint32_t* argb, int stride, 148 void VP8LCollectColorBlueTransforms_C(const uint32_t* argb, int stride,
152 int tile_width, int tile_height, 149 int tile_width, int tile_height,
153 int green_to_blue, int red_to_blue, 150 int green_to_blue, int red_to_blue,
154 int histo[]); 151 int histo[]);
155 152
156 //------------------------------------------------------------------------------ 153 extern VP8LPredictorAddSubFunc VP8LPredictorsSub[16];
157 // Image transforms. 154 extern VP8LPredictorAddSubFunc VP8LPredictorsSub_C[16];
158
159 void VP8LResidualImage(int width, int height, int bits, int low_effort,
160 uint32_t* const argb, uint32_t* const argb_scratch,
161 uint32_t* const image, int near_lossless, int exact,
162 int used_subtract_green);
163
164 void VP8LColorSpaceTransform(int width, int height, int bits, int quality,
165 uint32_t* const argb, uint32_t* image);
166
167 //------------------------------------------------------------------------------
168 // Misc methods.
169
170 // Computes sampled size of 'size' when sampling using 'sampling bits'.
171 static WEBP_INLINE uint32_t VP8LSubSampleSize(uint32_t size,
172 uint32_t sampling_bits) {
173 return (size + (1 << sampling_bits) - 1) >> sampling_bits;
174 }
175
176 // Converts near lossless quality into max number of bits shaved off.
177 static WEBP_INLINE int VP8LNearLosslessBits(int near_lossless_quality) {
178 // 100 -> 0
179 // 80..99 -> 1
180 // 60..79 -> 2
181 // 40..59 -> 3
182 // 20..39 -> 4
183 // 0..19 -> 5
184 return 5 - near_lossless_quality / 20;
185 }
186
187 // -----------------------------------------------------------------------------
188 // Faster logarithm for integers. Small values use a look-up table.
189
190 // The threshold till approximate version of log_2 can be used.
191 // Practically, we can get rid of the call to log() as the two values match to
192 // very high degree (the ratio of these two is 0.99999x).
193 // Keeping a high threshold for now.
194 #define APPROX_LOG_WITH_CORRECTION_MAX 65536
195 #define APPROX_LOG_MAX 4096
196 #define LOG_2_RECIPROCAL 1.44269504088896338700465094007086
197 #define LOG_LOOKUP_IDX_MAX 256
198 extern const float kLog2Table[LOG_LOOKUP_IDX_MAX];
199 extern const float kSLog2Table[LOG_LOOKUP_IDX_MAX];
200 typedef float (*VP8LFastLog2SlowFunc)(uint32_t v);
201
202 extern VP8LFastLog2SlowFunc VP8LFastLog2Slow;
203 extern VP8LFastLog2SlowFunc VP8LFastSLog2Slow;
204
205 static WEBP_INLINE float VP8LFastLog2(uint32_t v) {
206 return (v < LOG_LOOKUP_IDX_MAX) ? kLog2Table[v] : VP8LFastLog2Slow(v);
207 }
208 // Fast calculation of v * log2(v) for integer input.
209 static WEBP_INLINE float VP8LFastSLog2(uint32_t v) {
210 return (v < LOG_LOOKUP_IDX_MAX) ? kSLog2Table[v] : VP8LFastSLog2Slow(v);
211 }
212 155
213 // ----------------------------------------------------------------------------- 156 // -----------------------------------------------------------------------------
214 // Huffman-cost related functions. 157 // Huffman-cost related functions.
215 158
216 typedef double (*VP8LCostFunc)(const uint32_t* population, int length); 159 typedef double (*VP8LCostFunc)(const uint32_t* population, int length);
217 typedef double (*VP8LCostCombinedFunc)(const uint32_t* X, const uint32_t* Y, 160 typedef double (*VP8LCostCombinedFunc)(const uint32_t* X, const uint32_t* Y,
218 int length); 161 int length);
219 typedef float (*VP8LCombinedShannonEntropyFunc)(const int X[256], 162 typedef float (*VP8LCombinedShannonEntropyFunc)(const int X[256],
220 const int Y[256]); 163 const int Y[256]);
221 164
222 extern VP8LCostFunc VP8LExtraCost; 165 extern VP8LCostFunc VP8LExtraCost;
223 extern VP8LCostCombinedFunc VP8LExtraCostCombined; 166 extern VP8LCostCombinedFunc VP8LExtraCostCombined;
224 extern VP8LCombinedShannonEntropyFunc VP8LCombinedShannonEntropy; 167 extern VP8LCombinedShannonEntropyFunc VP8LCombinedShannonEntropy;
225 168
226 typedef struct { // small struct to hold counters 169 typedef struct { // small struct to hold counters
227 int counts[2]; // index: 0=zero steak, 1=non-zero streak 170 int counts[2]; // index: 0=zero steak, 1=non-zero streak
228 int streaks[2][2]; // [zero/non-zero][streak<3 / streak>=3] 171 int streaks[2][2]; // [zero/non-zero][streak<3 / streak>=3]
229 } VP8LStreaks; 172 } VP8LStreaks;
230 173
231 typedef VP8LStreaks (*VP8LCostCombinedCountFunc)(const uint32_t* X,
232 const uint32_t* Y, int length);
233
234 extern VP8LCostCombinedCountFunc VP8LHuffmanCostCombinedCount;
235
236 typedef struct { // small struct to hold bit entropy results 174 typedef struct { // small struct to hold bit entropy results
237 double entropy; // entropy 175 double entropy; // entropy
238 uint32_t sum; // sum of the population 176 uint32_t sum; // sum of the population
239 int nonzeros; // number of non-zero elements in the population 177 int nonzeros; // number of non-zero elements in the population
240 uint32_t max_val; // maximum value in the population 178 uint32_t max_val; // maximum value in the population
241 uint32_t nonzero_code; // index of the last non-zero in the population 179 uint32_t nonzero_code; // index of the last non-zero in the population
242 } VP8LBitEntropy; 180 } VP8LBitEntropy;
243 181
244 void VP8LBitEntropyInit(VP8LBitEntropy* const entropy); 182 void VP8LBitEntropyInit(VP8LBitEntropy* const entropy);
245 183
246 // Get the combined symbol bit entropy and Huffman cost stats for the 184 // Get the combined symbol bit entropy and Huffman cost stats for the
247 // distributions 'X' and 'Y'. Those results can then be refined according to 185 // distributions 'X' and 'Y'. Those results can then be refined according to
248 // codec specific heuristics. 186 // codec specific heuristics.
249 void VP8LGetCombinedEntropyUnrefined(const uint32_t* const X, 187 typedef void (*VP8LGetCombinedEntropyUnrefinedFunc)(
250 const uint32_t* const Y, int length, 188 const uint32_t X[], const uint32_t Y[], int length,
251 VP8LBitEntropy* const bit_entropy, 189 VP8LBitEntropy* const bit_entropy, VP8LStreaks* const stats);
252 VP8LStreaks* const stats); 190 extern VP8LGetCombinedEntropyUnrefinedFunc VP8LGetCombinedEntropyUnrefined;
191
253 // Get the entropy for the distribution 'X'. 192 // Get the entropy for the distribution 'X'.
254 void VP8LGetEntropyUnrefined(const uint32_t* const X, int length, 193 typedef void (*VP8LGetEntropyUnrefinedFunc)(const uint32_t X[], int length,
255 VP8LBitEntropy* const bit_entropy, 194 VP8LBitEntropy* const bit_entropy,
256 VP8LStreaks* const stats); 195 VP8LStreaks* const stats);
196 extern VP8LGetEntropyUnrefinedFunc VP8LGetEntropyUnrefined;
257 197
258 void VP8LBitsEntropyUnrefined(const uint32_t* const array, int n, 198 void VP8LBitsEntropyUnrefined(const uint32_t* const array, int n,
259 VP8LBitEntropy* const entropy); 199 VP8LBitEntropy* const entropy);
260 200
261 typedef void (*GetEntropyUnrefinedHelperFunc)(uint32_t val, int i,
262 uint32_t* const val_prev,
263 int* const i_prev,
264 VP8LBitEntropy* const bit_entropy,
265 VP8LStreaks* const stats);
266 // Internal function used by VP8LGet*EntropyUnrefined.
267 extern GetEntropyUnrefinedHelperFunc VP8LGetEntropyUnrefinedHelper;
268
269 typedef void (*VP8LHistogramAddFunc)(const VP8LHistogram* const a, 201 typedef void (*VP8LHistogramAddFunc)(const VP8LHistogram* const a,
270 const VP8LHistogram* const b, 202 const VP8LHistogram* const b,
271 VP8LHistogram* const out); 203 VP8LHistogram* const out);
272 extern VP8LHistogramAddFunc VP8LHistogramAdd; 204 extern VP8LHistogramAddFunc VP8LHistogramAdd;
273 205
274 // ----------------------------------------------------------------------------- 206 // -----------------------------------------------------------------------------
275 // PrefixEncode() 207 // PrefixEncode()
276 208
277 typedef int (*VP8LVectorMismatchFunc)(const uint32_t* const array1, 209 typedef int (*VP8LVectorMismatchFunc)(const uint32_t* const array1,
278 const uint32_t* const array2, int length); 210 const uint32_t* const array2, int length);
279 // Returns the first index where array1 and array2 are different. 211 // Returns the first index where array1 and array2 are different.
280 extern VP8LVectorMismatchFunc VP8LVectorMismatch; 212 extern VP8LVectorMismatchFunc VP8LVectorMismatch;
281 213
282 static WEBP_INLINE int VP8LBitsLog2Ceiling(uint32_t n) { 214 typedef void (*VP8LBundleColorMapFunc)(const uint8_t* const row, int width,
283 const int log_floor = BitsLog2Floor(n); 215 int xbits, uint32_t* dst);
284 if (n == (n & ~(n - 1))) // zero or a power of two. 216 extern VP8LBundleColorMapFunc VP8LBundleColorMap;
285 return log_floor; 217 void VP8LBundleColorMap_C(const uint8_t* const row, int width, int xbits,
286 else 218 uint32_t* dst);
287 return log_floor + 1;
288 }
289
290 // Splitting of distance and length codes into prefixes and
291 // extra bits. The prefixes are encoded with an entropy code
292 // while the extra bits are stored just as normal bits.
293 static WEBP_INLINE void VP8LPrefixEncodeBitsNoLUT(int distance, int* const code,
294 int* const extra_bits) {
295 const int highest_bit = BitsLog2Floor(--distance);
296 const int second_highest_bit = (distance >> (highest_bit - 1)) & 1;
297 *extra_bits = highest_bit - 1;
298 *code = 2 * highest_bit + second_highest_bit;
299 }
300
301 static WEBP_INLINE void VP8LPrefixEncodeNoLUT(int distance, int* const code,
302 int* const extra_bits,
303 int* const extra_bits_value) {
304 const int highest_bit = BitsLog2Floor(--distance);
305 const int second_highest_bit = (distance >> (highest_bit - 1)) & 1;
306 *extra_bits = highest_bit - 1;
307 *extra_bits_value = distance & ((1 << *extra_bits) - 1);
308 *code = 2 * highest_bit + second_highest_bit;
309 }
310
311 #define PREFIX_LOOKUP_IDX_MAX 512
312 typedef struct {
313 int8_t code_;
314 int8_t extra_bits_;
315 } VP8LPrefixCode;
316
317 // These tables are derived using VP8LPrefixEncodeNoLUT.
318 extern const VP8LPrefixCode kPrefixEncodeCode[PREFIX_LOOKUP_IDX_MAX];
319 extern const uint8_t kPrefixEncodeExtraBitsValue[PREFIX_LOOKUP_IDX_MAX];
320 static WEBP_INLINE void VP8LPrefixEncodeBits(int distance, int* const code,
321 int* const extra_bits) {
322 if (distance < PREFIX_LOOKUP_IDX_MAX) {
323 const VP8LPrefixCode prefix_code = kPrefixEncodeCode[distance];
324 *code = prefix_code.code_;
325 *extra_bits = prefix_code.extra_bits_;
326 } else {
327 VP8LPrefixEncodeBitsNoLUT(distance, code, extra_bits);
328 }
329 }
330
331 static WEBP_INLINE void VP8LPrefixEncode(int distance, int* const code,
332 int* const extra_bits,
333 int* const extra_bits_value) {
334 if (distance < PREFIX_LOOKUP_IDX_MAX) {
335 const VP8LPrefixCode prefix_code = kPrefixEncodeCode[distance];
336 *code = prefix_code.code_;
337 *extra_bits = prefix_code.extra_bits_;
338 *extra_bits_value = kPrefixEncodeExtraBitsValue[distance];
339 } else {
340 VP8LPrefixEncodeNoLUT(distance, code, extra_bits, extra_bits_value);
341 }
342 }
343
344 // Sum of each component, mod 256.
345 static WEBP_INLINE uint32_t VP8LAddPixels(uint32_t a, uint32_t b) {
346 const uint32_t alpha_and_green = (a & 0xff00ff00u) + (b & 0xff00ff00u);
347 const uint32_t red_and_blue = (a & 0x00ff00ffu) + (b & 0x00ff00ffu);
348 return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu);
349 }
350
351 // Difference of each component, mod 256.
352 static WEBP_INLINE uint32_t VP8LSubPixels(uint32_t a, uint32_t b) {
353 const uint32_t alpha_and_green =
354 0x00ff00ffu + (a & 0xff00ff00u) - (b & 0xff00ff00u);
355 const uint32_t red_and_blue =
356 0xff00ff00u + (a & 0x00ff00ffu) - (b & 0x00ff00ffu);
357 return (alpha_and_green & 0xff00ff00u) | (red_and_blue & 0x00ff00ffu);
358 }
359
360 void VP8LBundleColorMap(const uint8_t* const row, int width,
361 int xbits, uint32_t* const dst);
362 219
363 // Must be called before calling any of the above methods. 220 // Must be called before calling any of the above methods.
364 void VP8LEncDspInit(void); 221 void VP8LEncDspInit(void);
365 222
366 //------------------------------------------------------------------------------ 223 //------------------------------------------------------------------------------
367 224
368 #ifdef __cplusplus 225 #ifdef __cplusplus
369 } // extern "C" 226 } // extern "C"
370 #endif 227 #endif
371 228
372 #endif // WEBP_DSP_LOSSLESS_H_ 229 #endif // WEBP_DSP_LOSSLESS_H_
OLDNEW
« no previous file with comments | « third_party/libwebp/dsp/filters_sse2.c ('k') | third_party/libwebp/dsp/lossless.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698