1 | // Copyright 2011 Google Inc. All Rights Reserved. |
2 | // |
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 |
5 | // tree. An additional intellectual property rights grant can be found |
6 | // in the file PATENTS. All contributing project authors may |
7 | // be found in the AUTHORS file in the root of the source tree. |
8 | // ----------------------------------------------------------------------------- |
9 | // |
10 | // Speed-critical functions. |
11 | // |
12 | // Author: Skal (pascal.massimino@gmail.com) |
13 | |
14 | #ifndef WEBP_DSP_DSP_H_ |
15 | #define WEBP_DSP_DSP_H_ |
16 | |
17 | #ifdef HAVE_CONFIG_H |
18 | #include "src/webp/config.h" |
19 | #endif |
20 | |
21 | #include "src/dsp/cpu.h" |
22 | #include "src/webp/types.h" |
23 | |
24 | #ifdef __cplusplus |
25 | extern "C" { |
26 | #endif |
27 | |
28 | #define BPS 32 // this is the common stride for enc/dec |
29 | |
30 | //------------------------------------------------------------------------------ |
31 | // WEBP_RESTRICT |
32 | |
33 | // Declares a pointer with the restrict type qualifier if available. |
34 | // This allows code to hint to the compiler that only this pointer references a |
35 | // particular object or memory region within the scope of the block in which it |
36 | // is declared. This may allow for improved optimizations due to the lack of |
37 | // pointer aliasing. See also: |
38 | // https://en.cppreference.com/w/c/language/restrict |
39 | #if defined(__GNUC__) |
40 | #define WEBP_RESTRICT __restrict__ |
41 | #elif defined(_MSC_VER) |
42 | #define WEBP_RESTRICT __restrict |
43 | #else |
44 | #define WEBP_RESTRICT |
45 | #endif |
46 | |
47 | |
48 | //------------------------------------------------------------------------------ |
49 | // Init stub generator |
50 | |
51 | // Defines an init function stub to ensure each module exposes a symbol, |
52 | // avoiding a compiler warning. |
53 | #define WEBP_DSP_INIT_STUB(func) \ |
54 | extern void func(void); \ |
55 | void func(void) {} |
56 | |
57 | //------------------------------------------------------------------------------ |
58 | // Encoding |
59 | |
60 | // Transforms |
61 | // VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms |
62 | // will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4). |
63 | typedef void (*VP8Idct)(const uint8_t* ref, const int16_t* in, uint8_t* dst, |
64 | int do_two); |
65 | typedef void (*VP8Fdct)(const uint8_t* src, const uint8_t* ref, int16_t* out); |
66 | typedef void (*VP8WHT)(const int16_t* in, int16_t* out); |
67 | extern VP8Idct VP8ITransform; |
68 | extern VP8Fdct VP8FTransform; |
69 | extern VP8Fdct VP8FTransform2; // performs two transforms at a time |
70 | extern VP8WHT VP8FTransformWHT; |
71 | // Predictions |
72 | // *dst is the destination block. *top and *left can be NULL. |
73 | typedef void (*VP8IntraPreds)(uint8_t* dst, const uint8_t* left, |
74 | const uint8_t* top); |
75 | typedef void (*VP8Intra4Preds)(uint8_t* dst, const uint8_t* top); |
76 | extern VP8Intra4Preds VP8EncPredLuma4; |
77 | extern VP8IntraPreds VP8EncPredLuma16; |
78 | extern VP8IntraPreds VP8EncPredChroma8; |
79 | |
80 | typedef int (*VP8Metric)(const uint8_t* pix, const uint8_t* ref); |
81 | extern VP8Metric VP8SSE16x16, VP8SSE16x8, VP8SSE8x8, VP8SSE4x4; |
82 | typedef int (*VP8WMetric)(const uint8_t* pix, const uint8_t* ref, |
83 | const uint16_t* const weights); |
84 | // The weights for VP8TDisto4x4 and VP8TDisto16x16 contain a row-major |
85 | // 4 by 4 symmetric matrix. |
86 | extern VP8WMetric VP8TDisto4x4, VP8TDisto16x16; |
87 | |
88 | // Compute the average (DC) of four 4x4 blocks. |
89 | // Each sub-4x4 block #i sum is stored in dc[i]. |
90 | typedef void (*VP8MeanMetric)(const uint8_t* ref, uint32_t dc[4]); |
91 | extern VP8MeanMetric VP8Mean16x4; |
92 | |
93 | typedef void (*VP8BlockCopy)(const uint8_t* src, uint8_t* dst); |
94 | extern VP8BlockCopy VP8Copy4x4; |
95 | extern VP8BlockCopy VP8Copy16x8; |
96 | // Quantization |
97 | struct VP8Matrix; // forward declaration |
98 | typedef int (*VP8QuantizeBlock)(int16_t in[16], int16_t out[16], |
99 | const struct VP8Matrix* const mtx); |
100 | // Same as VP8QuantizeBlock, but quantizes two consecutive blocks. |
101 | typedef int (*VP8Quantize2Blocks)(int16_t in[32], int16_t out[32], |
102 | const struct VP8Matrix* const mtx); |
103 | |
104 | extern VP8QuantizeBlock VP8EncQuantizeBlock; |
105 | extern VP8Quantize2Blocks VP8EncQuantize2Blocks; |
106 | |
107 | // specific to 2nd transform: |
108 | typedef int (*VP8QuantizeBlockWHT)(int16_t in[16], int16_t out[16], |
109 | const struct VP8Matrix* const mtx); |
110 | extern VP8QuantizeBlockWHT VP8EncQuantizeBlockWHT; |
111 | |
112 | extern const int VP8DspScan[16 + 4 + 4]; |
113 | |
114 | // Collect histogram for susceptibility calculation. |
115 | #define MAX_COEFF_THRESH 31 // size of histogram used by CollectHistogram. |
116 | typedef struct { |
117 | // We only need to store max_value and last_non_zero, not the distribution. |
118 | int max_value; |
119 | int last_non_zero; |
120 | } VP8Histogram; |
121 | typedef void (*VP8CHisto)(const uint8_t* ref, const uint8_t* pred, |
122 | int start_block, int end_block, |
123 | VP8Histogram* const histo); |
124 | extern VP8CHisto VP8CollectHistogram; |
125 | // General-purpose util function to help VP8CollectHistogram(). |
126 | void VP8SetHistogramData(const int distribution[MAX_COEFF_THRESH + 1], |
127 | VP8Histogram* const histo); |
128 | |
129 | // must be called before using any of the above |
130 | void VP8EncDspInit(void); |
131 | |
132 | //------------------------------------------------------------------------------ |
133 | // cost functions (encoding) |
134 | |
135 | extern const uint16_t VP8EntropyCost[256]; // 8bit fixed-point log(p) |
136 | // approximate cost per level: |
137 | extern const uint16_t VP8LevelFixedCosts[2047 /*MAX_LEVEL*/ + 1]; |
138 | extern const uint8_t VP8EncBands[16 + 1]; |
139 | |
140 | struct VP8Residual; |
141 | typedef void (*VP8SetResidualCoeffsFunc)(const int16_t* const coeffs, |
142 | struct VP8Residual* const res); |
143 | extern VP8SetResidualCoeffsFunc VP8SetResidualCoeffs; |
144 | |
145 | // Cost calculation function. |
146 | typedef int (*VP8GetResidualCostFunc)(int ctx0, |
147 | const struct VP8Residual* const res); |
148 | extern VP8GetResidualCostFunc VP8GetResidualCost; |
149 | |
150 | // must be called before anything using the above |
151 | void VP8EncDspCostInit(void); |
152 | |
153 | //------------------------------------------------------------------------------ |
154 | // SSIM / PSNR utils |
155 | |
156 | // struct for accumulating statistical moments |
157 | typedef struct { |
158 | uint32_t w; // sum(w_i) : sum of weights |
159 | uint32_t xm, ym; // sum(w_i * x_i), sum(w_i * y_i) |
160 | uint32_t xxm, xym, yym; // sum(w_i * x_i * x_i), etc. |
161 | } VP8DistoStats; |
162 | |
163 | // Compute the final SSIM value |
164 | // The non-clipped version assumes stats->w = (2 * VP8_SSIM_KERNEL + 1)^2. |
165 | double VP8SSIMFromStats(const VP8DistoStats* const stats); |
166 | double VP8SSIMFromStatsClipped(const VP8DistoStats* const stats); |
167 | |
168 | #define VP8_SSIM_KERNEL 3 // total size of the kernel: 2 * VP8_SSIM_KERNEL + 1 |
169 | typedef double (*VP8SSIMGetClippedFunc)(const uint8_t* src1, int stride1, |
170 | const uint8_t* src2, int stride2, |
171 | int xo, int yo, // center position |
172 | int W, int H); // plane dimension |
173 | |
174 | #if !defined(WEBP_REDUCE_SIZE) |
175 | // This version is called with the guarantee that you can load 8 bytes and |
176 | // 8 rows at offset src1 and src2 |
177 | typedef double (*VP8SSIMGetFunc)(const uint8_t* src1, int stride1, |
178 | const uint8_t* src2, int stride2); |
179 | |
180 | extern VP8SSIMGetFunc VP8SSIMGet; // unclipped / unchecked |
181 | extern VP8SSIMGetClippedFunc VP8SSIMGetClipped; // with clipping |
182 | #endif |
183 | |
184 | #if !defined(WEBP_DISABLE_STATS) |
185 | typedef uint32_t (*VP8AccumulateSSEFunc)(const uint8_t* src1, |
186 | const uint8_t* src2, int len); |
187 | extern VP8AccumulateSSEFunc VP8AccumulateSSE; |
188 | #endif |
189 | |
190 | // must be called before using any of the above directly |
191 | void VP8SSIMDspInit(void); |
192 | |
193 | //------------------------------------------------------------------------------ |
194 | // Decoding |
195 | |
196 | typedef void (*VP8DecIdct)(const int16_t* coeffs, uint8_t* dst); |
197 | // when doing two transforms, coeffs is actually int16_t[2][16]. |
198 | typedef void (*VP8DecIdct2)(const int16_t* coeffs, uint8_t* dst, int do_two); |
199 | extern VP8DecIdct2 VP8Transform; |
200 | extern VP8DecIdct VP8TransformAC3; |
201 | extern VP8DecIdct VP8TransformUV; |
202 | extern VP8DecIdct VP8TransformDC; |
203 | extern VP8DecIdct VP8TransformDCUV; |
204 | extern VP8WHT VP8TransformWHT; |
205 | |
206 | #define WEBP_TRANSFORM_AC3_C1 20091 |
207 | #define WEBP_TRANSFORM_AC3_C2 35468 |
208 | #define WEBP_TRANSFORM_AC3_MUL1(a) ((((a) * WEBP_TRANSFORM_AC3_C1) >> 16) + (a)) |
209 | #define WEBP_TRANSFORM_AC3_MUL2(a) (((a) * WEBP_TRANSFORM_AC3_C2) >> 16) |
210 | |
211 | // *dst is the destination block, with stride BPS. Boundary samples are |
212 | // assumed accessible when needed. |
213 | typedef void (*VP8PredFunc)(uint8_t* dst); |
214 | extern VP8PredFunc VP8PredLuma16[/* NUM_B_DC_MODES */]; |
215 | extern VP8PredFunc VP8PredChroma8[/* NUM_B_DC_MODES */]; |
216 | extern VP8PredFunc VP8PredLuma4[/* NUM_BMODES */]; |
217 | |
218 | // clipping tables (for filtering) |
219 | extern const int8_t* const VP8ksclip1; // clips [-1020, 1020] to [-128, 127] |
220 | extern const int8_t* const VP8ksclip2; // clips [-112, 112] to [-16, 15] |
221 | extern const uint8_t* const VP8kclip1; // clips [-255,511] to [0,255] |
222 | extern const uint8_t* const VP8kabs0; // abs(x) for x in [-255,255] |
223 | // must be called first |
224 | void VP8InitClipTables(void); |
225 | |
226 | // simple filter (only for luma) |
227 | typedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh); |
228 | extern VP8SimpleFilterFunc VP8SimpleVFilter16; |
229 | extern VP8SimpleFilterFunc VP8SimpleHFilter16; |
230 | extern VP8SimpleFilterFunc VP8SimpleVFilter16i; // filter 3 inner edges |
231 | extern VP8SimpleFilterFunc VP8SimpleHFilter16i; |
232 | |
233 | // regular filter (on both macroblock edges and inner edges) |
234 | typedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride, |
235 | int thresh, int ithresh, int hev_t); |
236 | typedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride, |
237 | int thresh, int ithresh, int hev_t); |
238 | // on outer edge |
239 | extern VP8LumaFilterFunc VP8VFilter16; |
240 | extern VP8LumaFilterFunc VP8HFilter16; |
241 | extern VP8ChromaFilterFunc VP8VFilter8; |
242 | extern VP8ChromaFilterFunc VP8HFilter8; |
243 | |
244 | // on inner edge |
245 | extern VP8LumaFilterFunc VP8VFilter16i; // filtering 3 inner edges altogether |
246 | extern VP8LumaFilterFunc VP8HFilter16i; |
247 | extern VP8ChromaFilterFunc VP8VFilter8i; // filtering u and v altogether |
248 | extern VP8ChromaFilterFunc VP8HFilter8i; |
249 | |
250 | // Dithering. Combines dithering values (centered around 128) with dst[], |
251 | // according to: dst[] = clip(dst[] + (((dither[]-128) + 8) >> 4) |
252 | #define VP8_DITHER_DESCALE 4 |
253 | #define VP8_DITHER_DESCALE_ROUNDER (1 << (VP8_DITHER_DESCALE - 1)) |
254 | #define VP8_DITHER_AMP_BITS 7 |
255 | #define VP8_DITHER_AMP_CENTER (1 << VP8_DITHER_AMP_BITS) |
256 | extern void (*VP8DitherCombine8x8)(const uint8_t* dither, uint8_t* dst, |
257 | int dst_stride); |
258 | |
259 | // must be called before anything using the above |
260 | void VP8DspInit(void); |
261 | |
262 | //------------------------------------------------------------------------------ |
263 | // WebP I/O |
264 | |
265 | #define FANCY_UPSAMPLING // undefined to remove fancy upsampling support |
266 | |
267 | // Convert a pair of y/u/v lines together to the output rgb/a colorspace. |
268 | // bottom_y can be NULL if only one line of output is needed (at top/bottom). |
269 | typedef void (*WebPUpsampleLinePairFunc)( |
270 | const uint8_t* top_y, const uint8_t* bottom_y, |
271 | const uint8_t* top_u, const uint8_t* top_v, |
272 | const uint8_t* cur_u, const uint8_t* cur_v, |
273 | uint8_t* top_dst, uint8_t* bottom_dst, int len); |
274 | |
275 | #ifdef FANCY_UPSAMPLING |
276 | |
277 | // Fancy upsampling functions to convert YUV to RGB(A) modes |
278 | extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */]; |
279 | |
280 | #endif // FANCY_UPSAMPLING |
281 | |
282 | // Per-row point-sampling methods. |
283 | typedef void (*WebPSamplerRowFunc)(const uint8_t* y, |
284 | const uint8_t* u, const uint8_t* v, |
285 | uint8_t* dst, int len); |
286 | // Generic function to apply 'WebPSamplerRowFunc' to the whole plane: |
287 | void WebPSamplerProcessPlane(const uint8_t* y, int y_stride, |
288 | const uint8_t* u, const uint8_t* v, int uv_stride, |
289 | uint8_t* dst, int dst_stride, |
290 | int width, int height, WebPSamplerRowFunc func); |
291 | |
292 | // Sampling functions to convert rows of YUV to RGB(A) |
293 | extern WebPSamplerRowFunc WebPSamplers[/* MODE_LAST */]; |
294 | |
295 | // General function for converting two lines of ARGB or RGBA. |
296 | // 'alpha_is_last' should be true if 0xff000000 is stored in memory as |
297 | // as 0x00, 0x00, 0x00, 0xff (little endian). |
298 | WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last); |
299 | |
300 | // YUV444->RGB converters |
301 | typedef void (*WebPYUV444Converter)(const uint8_t* y, |
302 | const uint8_t* u, const uint8_t* v, |
303 | uint8_t* dst, int len); |
304 | |
305 | extern WebPYUV444Converter WebPYUV444Converters[/* MODE_LAST */]; |
306 | |
307 | // Must be called before using the WebPUpsamplers[] (and for premultiplied |
308 | // colorspaces like rgbA, rgbA4444, etc) |
309 | void WebPInitUpsamplers(void); |
310 | // Must be called before using WebPSamplers[] |
311 | void WebPInitSamplers(void); |
312 | // Must be called before using WebPYUV444Converters[] |
313 | void WebPInitYUV444Converters(void); |
314 | |
315 | //------------------------------------------------------------------------------ |
316 | // ARGB -> YUV converters |
317 | |
318 | // Convert ARGB samples to luma Y. |
319 | extern void (*WebPConvertARGBToY)(const uint32_t* argb, uint8_t* y, int width); |
320 | // Convert ARGB samples to U/V with downsampling. do_store should be '1' for |
321 | // even lines and '0' for odd ones. 'src_width' is the original width, not |
322 | // the U/V one. |
323 | extern void (*WebPConvertARGBToUV)(const uint32_t* argb, uint8_t* u, uint8_t* v, |
324 | int src_width, int do_store); |
325 | |
326 | // Convert a row of accumulated (four-values) of rgba32 toward U/V |
327 | extern void (*WebPConvertRGBA32ToUV)(const uint16_t* rgb, |
328 | uint8_t* u, uint8_t* v, int width); |
329 | |
330 | // Convert RGB or BGR to Y |
331 | extern void (*WebPConvertRGB24ToY)(const uint8_t* rgb, uint8_t* y, int width); |
332 | extern void (*WebPConvertBGR24ToY)(const uint8_t* bgr, uint8_t* y, int width); |
333 | |
334 | // used for plain-C fallback. |
335 | extern void WebPConvertARGBToUV_C(const uint32_t* argb, uint8_t* u, uint8_t* v, |
336 | int src_width, int do_store); |
337 | extern void WebPConvertRGBA32ToUV_C(const uint16_t* rgb, |
338 | uint8_t* u, uint8_t* v, int width); |
339 | |
340 | // Must be called before using the above. |
341 | void WebPInitConvertARGBToYUV(void); |
342 | |
343 | //------------------------------------------------------------------------------ |
344 | // Rescaler |
345 | |
346 | struct WebPRescaler; |
347 | |
348 | // Import a row of data and save its contribution in the rescaler. |
349 | // 'channel' denotes the channel number to be imported. 'Expand' corresponds to |
350 | // the wrk->x_expand case. Otherwise, 'Shrink' is to be used. |
351 | typedef void (*WebPRescalerImportRowFunc)(struct WebPRescaler* const wrk, |
352 | const uint8_t* src); |
353 | |
354 | extern WebPRescalerImportRowFunc WebPRescalerImportRowExpand; |
355 | extern WebPRescalerImportRowFunc WebPRescalerImportRowShrink; |
356 | |
357 | // Export one row (starting at x_out position) from rescaler. |
358 | // 'Expand' corresponds to the wrk->y_expand case. |
359 | // Otherwise 'Shrink' is to be used |
360 | typedef void (*WebPRescalerExportRowFunc)(struct WebPRescaler* const wrk); |
361 | extern WebPRescalerExportRowFunc WebPRescalerExportRowExpand; |
362 | extern WebPRescalerExportRowFunc WebPRescalerExportRowShrink; |
363 | |
364 | // Plain-C implementation, as fall-back. |
365 | extern void WebPRescalerImportRowExpand_C(struct WebPRescaler* const wrk, |
366 | const uint8_t* src); |
367 | extern void WebPRescalerImportRowShrink_C(struct WebPRescaler* const wrk, |
368 | const uint8_t* src); |
369 | extern void WebPRescalerExportRowExpand_C(struct WebPRescaler* const wrk); |
370 | extern void WebPRescalerExportRowShrink_C(struct WebPRescaler* const wrk); |
371 | |
372 | // Main entry calls: |
373 | extern void WebPRescalerImportRow(struct WebPRescaler* const wrk, |
374 | const uint8_t* src); |
375 | // Export one row (starting at x_out position) from rescaler. |
376 | extern void WebPRescalerExportRow(struct WebPRescaler* const wrk); |
377 | |
378 | // Must be called first before using the above. |
379 | void WebPRescalerDspInit(void); |
380 | |
381 | //------------------------------------------------------------------------------ |
382 | // Utilities for processing transparent channel. |
383 | |
384 | // Apply alpha pre-multiply on an rgba, bgra or argb plane of size w * h. |
385 | // alpha_first should be 0 for argb, 1 for rgba or bgra (where alpha is last). |
386 | extern void (*WebPApplyAlphaMultiply)( |
387 | uint8_t* rgba, int alpha_first, int w, int h, int stride); |
388 | |
389 | // Same, buf specifically for RGBA4444 format |
390 | extern void (*WebPApplyAlphaMultiply4444)( |
391 | uint8_t* rgba4444, int w, int h, int stride); |
392 | |
393 | // Dispatch the values from alpha[] plane to the ARGB destination 'dst'. |
394 | // Returns true if alpha[] plane has non-trivial values different from 0xff. |
395 | extern int (*WebPDispatchAlpha)(const uint8_t* WEBP_RESTRICT alpha, |
396 | int alpha_stride, int width, int height, |
397 | uint8_t* WEBP_RESTRICT dst, int dst_stride); |
398 | |
399 | // Transfer packed 8b alpha[] values to green channel in dst[], zero'ing the |
400 | // A/R/B values. 'dst_stride' is the stride for dst[] in uint32_t units. |
401 | extern void (*WebPDispatchAlphaToGreen)(const uint8_t* WEBP_RESTRICT alpha, |
402 | int alpha_stride, int width, int height, |
403 | uint32_t* WEBP_RESTRICT dst, |
404 | int dst_stride); |
405 | |
406 | // Extract the alpha values from 32b values in argb[] and pack them into alpha[] |
407 | // (this is the opposite of WebPDispatchAlpha). |
408 | // Returns true if there's only trivial 0xff alpha values. |
409 | extern int (*)(const uint8_t* WEBP_RESTRICT argb, |
410 | int argb_stride, int width, int height, |
411 | uint8_t* WEBP_RESTRICT alpha, |
412 | int alpha_stride); |
413 | |
414 | // Extract the green values from 32b values in argb[] and pack them into alpha[] |
415 | // (this is the opposite of WebPDispatchAlphaToGreen). |
416 | extern void (*)(const uint32_t* WEBP_RESTRICT argb, |
417 | uint8_t* WEBP_RESTRICT alpha, int size); |
418 | |
419 | // Pre-Multiply operation transforms x into x * A / 255 (where x=Y,R,G or B). |
420 | // Un-Multiply operation transforms x into x * 255 / A. |
421 | |
422 | // Pre-Multiply or Un-Multiply (if 'inverse' is true) argb values in a row. |
423 | extern void (*WebPMultARGBRow)(uint32_t* const ptr, int width, int inverse); |
424 | |
425 | // Same a WebPMultARGBRow(), but for several rows. |
426 | void WebPMultARGBRows(uint8_t* ptr, int stride, int width, int num_rows, |
427 | int inverse); |
428 | |
429 | // Same for a row of single values, with side alpha values. |
430 | extern void (*WebPMultRow)(uint8_t* WEBP_RESTRICT const ptr, |
431 | const uint8_t* WEBP_RESTRICT const alpha, |
432 | int width, int inverse); |
433 | |
434 | // Same a WebPMultRow(), but for several 'num_rows' rows. |
435 | void WebPMultRows(uint8_t* WEBP_RESTRICT ptr, int stride, |
436 | const uint8_t* WEBP_RESTRICT alpha, int alpha_stride, |
437 | int width, int num_rows, int inverse); |
438 | |
439 | // Plain-C versions, used as fallback by some implementations. |
440 | void WebPMultRow_C(uint8_t* WEBP_RESTRICT const ptr, |
441 | const uint8_t* WEBP_RESTRICT const alpha, |
442 | int width, int inverse); |
443 | void WebPMultARGBRow_C(uint32_t* const ptr, int width, int inverse); |
444 | |
445 | #ifdef WORDS_BIGENDIAN |
446 | // ARGB packing function: a/r/g/b input is rgba or bgra order. |
447 | extern void (*WebPPackARGB)(const uint8_t* WEBP_RESTRICT a, |
448 | const uint8_t* WEBP_RESTRICT r, |
449 | const uint8_t* WEBP_RESTRICT g, |
450 | const uint8_t* WEBP_RESTRICT b, |
451 | int len, uint32_t* WEBP_RESTRICT out); |
452 | #endif |
453 | |
454 | // RGB packing function. 'step' can be 3 or 4. r/g/b input is rgb or bgr order. |
455 | extern void (*WebPPackRGB)(const uint8_t* WEBP_RESTRICT r, |
456 | const uint8_t* WEBP_RESTRICT g, |
457 | const uint8_t* WEBP_RESTRICT b, |
458 | int len, int step, uint32_t* WEBP_RESTRICT out); |
459 | |
460 | // This function returns true if src[i] contains a value different from 0xff. |
461 | extern int (*WebPHasAlpha8b)(const uint8_t* src, int length); |
462 | // This function returns true if src[4*i] contains a value different from 0xff. |
463 | extern int (*WebPHasAlpha32b)(const uint8_t* src, int length); |
464 | // replaces transparent values in src[] by 'color'. |
465 | extern void (*WebPAlphaReplace)(uint32_t* src, int length, uint32_t color); |
466 | |
467 | // To be called first before using the above. |
468 | void WebPInitAlphaProcessing(void); |
469 | |
470 | //------------------------------------------------------------------------------ |
471 | // Filter functions |
472 | |
473 | typedef enum { // Filter types. |
474 | WEBP_FILTER_NONE = 0, |
475 | WEBP_FILTER_HORIZONTAL, |
476 | WEBP_FILTER_VERTICAL, |
477 | WEBP_FILTER_GRADIENT, |
478 | WEBP_FILTER_LAST = WEBP_FILTER_GRADIENT + 1, // end marker |
479 | WEBP_FILTER_BEST, // meta-types |
480 | WEBP_FILTER_FAST |
481 | } WEBP_FILTER_TYPE; |
482 | |
483 | typedef void (*WebPFilterFunc)(const uint8_t* in, int width, int height, |
484 | int stride, uint8_t* out); |
485 | // In-place un-filtering. |
486 | // Warning! 'prev_line' pointer can be equal to 'cur_line' or 'preds'. |
487 | typedef void (*WebPUnfilterFunc)(const uint8_t* prev_line, const uint8_t* preds, |
488 | uint8_t* cur_line, int width); |
489 | |
490 | // Filter the given data using the given predictor. |
491 | // 'in' corresponds to a 2-dimensional pixel array of size (stride * height) |
492 | // in raster order. |
493 | // 'stride' is number of bytes per scan line (with possible padding). |
494 | // 'out' should be pre-allocated. |
495 | extern WebPFilterFunc WebPFilters[WEBP_FILTER_LAST]; |
496 | |
497 | // In-place reconstruct the original data from the given filtered data. |
498 | // The reconstruction will be done for 'num_rows' rows starting from 'row' |
499 | // (assuming rows upto 'row - 1' are already reconstructed). |
500 | extern WebPUnfilterFunc WebPUnfilters[WEBP_FILTER_LAST]; |
501 | |
502 | // To be called first before using the above. |
503 | void VP8FiltersInit(void); |
504 | |
505 | #ifdef __cplusplus |
506 | } // extern "C" |
507 | #endif |
508 | |
509 | #endif // WEBP_DSP_DSP_H_ |
510 | |