• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "../webp/config.h"
19 #endif
20 
21 #include "../webp/types.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define BPS 32   // this is the common stride for enc/dec
28 
29 //------------------------------------------------------------------------------
30 // CPU detection
31 
32 #if defined(__GNUC__)
33 # define LOCAL_GCC_VERSION ((__GNUC__ << 8) | __GNUC_MINOR__)
34 # define LOCAL_GCC_PREREQ(maj, min) \
35     (LOCAL_GCC_VERSION >= (((maj) << 8) | (min)))
36 #else
37 # define LOCAL_GCC_VERSION 0
38 # define LOCAL_GCC_PREREQ(maj, min) 0
39 #endif
40 
41 #ifndef __has_builtin
42 # define __has_builtin(x) 0
43 #endif
44 
45 #if defined(_MSC_VER) && _MSC_VER > 1310 && \
46     (defined(_M_X64) || defined(_M_IX86))
47 #define WEBP_MSC_SSE2  // Visual C++ SSE2 targets
48 #endif
49 
50 #if defined(_MSC_VER) && _MSC_VER >= 1500 && \
51     (defined(_M_X64) || defined(_M_IX86))
52 #define WEBP_MSC_SSE41  // Visual C++ SSE4.1 targets
53 #endif
54 
55 // WEBP_HAVE_* are used to indicate the presence of the instruction set in dsp
56 // files without intrinsics, allowing the corresponding Init() to be called.
57 // Files containing intrinsics will need to be built targeting the instruction
58 // set so should succeed on one of the earlier tests.
59 #if defined(__SSE2__) || defined(WEBP_MSC_SSE2) || defined(WEBP_HAVE_SSE2)
60 #define WEBP_USE_SSE2
61 #endif
62 
63 #if defined(__SSE4_1__) || defined(WEBP_MSC_SSE41) || defined(WEBP_HAVE_SSE41)
64 #define WEBP_USE_SSE41
65 #endif
66 
67 #if defined(__AVX2__) || defined(WEBP_HAVE_AVX2)
68 #define WEBP_USE_AVX2
69 #endif
70 
71 // The intrinsics currently cause compiler errors with arm-nacl-gcc and the
72 // inline assembly would need to be modified for use with Native Client.
73 #if (defined(__ARM_NEON__) || \
74      defined(__aarch64__) || defined(WEBP_HAVE_NEON)) && \
75     !defined(__native_client__)
76 #define WEBP_USE_NEON
77 #endif
78 
79 #if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_M_ARM)
80 #define WEBP_USE_NEON
81 #define WEBP_USE_INTRINSICS
82 #endif
83 
84 #if defined(__mips__) && !defined(__mips64) && \
85     defined(__mips_isa_rev) && (__mips_isa_rev >= 1) && (__mips_isa_rev < 6)
86 #define WEBP_USE_MIPS32
87 #if (__mips_isa_rev >= 2)
88 #define WEBP_USE_MIPS32_R2
89 #if defined(__mips_dspr2) || (__mips_dsp_rev >= 2)
90 #define WEBP_USE_MIPS_DSP_R2
91 #endif
92 #endif
93 #endif
94 
95 #if defined(__mips_msa) && defined(__mips_isa_rev) && (__mips_isa_rev >= 5)
96 #define WEBP_USE_MSA
97 #endif
98 
99 // This macro prevents thread_sanitizer from reporting known concurrent writes.
100 #define WEBP_TSAN_IGNORE_FUNCTION
101 #if defined(__has_feature)
102 #if __has_feature(thread_sanitizer)
103 #undef WEBP_TSAN_IGNORE_FUNCTION
104 #define WEBP_TSAN_IGNORE_FUNCTION __attribute__((no_sanitize_thread))
105 #endif
106 #endif
107 
108 #define WEBP_UBSAN_IGNORE_UNDEF
109 #define WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW
110 #if defined(__clang__) && defined(__has_attribute)
111 #if __has_attribute(no_sanitize)
112 // This macro prevents the undefined behavior sanitizer from reporting
113 // failures. This is only meant to silence unaligned loads on platforms that
114 // are known to support them.
115 #undef WEBP_UBSAN_IGNORE_UNDEF
116 #define WEBP_UBSAN_IGNORE_UNDEF \
117   __attribute__((no_sanitize("undefined")))
118 
119 // This macro prevents the undefined behavior sanitizer from reporting
120 // failures related to unsigned integer overflows. This is only meant to
121 // silence cases where this well defined behavior is expected.
122 #undef WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW
123 #define WEBP_UBSAN_IGNORE_UNSIGNED_OVERFLOW \
124   __attribute__((no_sanitize("unsigned-integer-overflow")))
125 #endif
126 #endif
127 
128 typedef enum {
129   kSSE2,
130   kSSE3,
131   kSlowSSSE3,  // special feature for slow SSSE3 architectures
132   kSSE4_1,
133   kAVX,
134   kAVX2,
135   kNEON,
136   kMIPS32,
137   kMIPSdspR2,
138   kMSA
139 } CPUFeature;
140 // returns true if the CPU supports the feature.
141 typedef int (*VP8CPUInfo)(CPUFeature feature);
142 WEBP_EXTERN(VP8CPUInfo) VP8GetCPUInfo;
143 
144 //------------------------------------------------------------------------------
145 // Init stub generator
146 
147 // Defines an init function stub to ensure each module exposes a symbol,
148 // avoiding a compiler warning.
149 #define WEBP_DSP_INIT_STUB(func) \
150   extern void func(void); \
151   WEBP_TSAN_IGNORE_FUNCTION void func(void) {}
152 
153 //------------------------------------------------------------------------------
154 // Encoding
155 
156 // Transforms
157 // VP8Idct: Does one of two inverse transforms. If do_two is set, the transforms
158 //          will be done for (ref, in, dst) and (ref + 4, in + 16, dst + 4).
159 typedef void (*VP8Idct)(const uint8_t* ref, const int16_t* in, uint8_t* dst,
160                         int do_two);
161 typedef void (*VP8Fdct)(const uint8_t* src, const uint8_t* ref, int16_t* out);
162 typedef void (*VP8WHT)(const int16_t* in, int16_t* out);
163 extern VP8Idct VP8ITransform;
164 extern VP8Fdct VP8FTransform;
165 extern VP8Fdct VP8FTransform2;   // performs two transforms at a time
166 extern VP8WHT VP8FTransformWHT;
167 // Predictions
168 // *dst is the destination block. *top and *left can be NULL.
169 typedef void (*VP8IntraPreds)(uint8_t *dst, const uint8_t* left,
170                               const uint8_t* top);
171 typedef void (*VP8Intra4Preds)(uint8_t *dst, const uint8_t* top);
172 extern VP8Intra4Preds VP8EncPredLuma4;
173 extern VP8IntraPreds VP8EncPredLuma16;
174 extern VP8IntraPreds VP8EncPredChroma8;
175 
176 typedef int (*VP8Metric)(const uint8_t* pix, const uint8_t* ref);
177 extern VP8Metric VP8SSE16x16, VP8SSE16x8, VP8SSE8x8, VP8SSE4x4;
178 typedef int (*VP8WMetric)(const uint8_t* pix, const uint8_t* ref,
179                           const uint16_t* const weights);
180 // The weights for VP8TDisto4x4 and VP8TDisto16x16 contain a row-major
181 // 4 by 4 symmetric matrix.
182 extern VP8WMetric VP8TDisto4x4, VP8TDisto16x16;
183 
184 // Compute the average (DC) of four 4x4 blocks.
185 // Each sub-4x4 block #i sum is stored in dc[i].
186 typedef void (*VP8MeanMetric)(const uint8_t* ref, uint32_t dc[4]);
187 extern VP8MeanMetric VP8Mean16x4;
188 
189 typedef void (*VP8BlockCopy)(const uint8_t* src, uint8_t* dst);
190 extern VP8BlockCopy VP8Copy4x4;
191 extern VP8BlockCopy VP8Copy16x8;
192 // Quantization
193 struct VP8Matrix;   // forward declaration
194 typedef int (*VP8QuantizeBlock)(int16_t in[16], int16_t out[16],
195                                 const struct VP8Matrix* const mtx);
196 // Same as VP8QuantizeBlock, but quantizes two consecutive blocks.
197 typedef int (*VP8Quantize2Blocks)(int16_t in[32], int16_t out[32],
198                                   const struct VP8Matrix* const mtx);
199 
200 extern VP8QuantizeBlock VP8EncQuantizeBlock;
201 extern VP8Quantize2Blocks VP8EncQuantize2Blocks;
202 
203 // specific to 2nd transform:
204 typedef int (*VP8QuantizeBlockWHT)(int16_t in[16], int16_t out[16],
205                                    const struct VP8Matrix* const mtx);
206 extern VP8QuantizeBlockWHT VP8EncQuantizeBlockWHT;
207 
208 extern const int VP8DspScan[16 + 4 + 4];
209 
210 // Collect histogram for susceptibility calculation.
211 #define MAX_COEFF_THRESH   31   // size of histogram used by CollectHistogram.
212 typedef struct {
213   // We only need to store max_value and last_non_zero, not the distribution.
214   int max_value;
215   int last_non_zero;
216 } VP8Histogram;
217 typedef void (*VP8CHisto)(const uint8_t* ref, const uint8_t* pred,
218                           int start_block, int end_block,
219                           VP8Histogram* const histo);
220 extern VP8CHisto VP8CollectHistogram;
221 // General-purpose util function to help VP8CollectHistogram().
222 void VP8SetHistogramData(const int distribution[MAX_COEFF_THRESH + 1],
223                          VP8Histogram* const histo);
224 
225 // must be called before using any of the above
226 void VP8EncDspInit(void);
227 
228 //------------------------------------------------------------------------------
229 // cost functions (encoding)
230 
231 extern const uint16_t VP8EntropyCost[256];        // 8bit fixed-point log(p)
232 // approximate cost per level:
233 extern const uint16_t VP8LevelFixedCosts[2047 /*MAX_LEVEL*/ + 1];
234 extern const uint8_t VP8EncBands[16 + 1];
235 
236 struct VP8Residual;
237 typedef void (*VP8SetResidualCoeffsFunc)(const int16_t* const coeffs,
238                                          struct VP8Residual* const res);
239 extern VP8SetResidualCoeffsFunc VP8SetResidualCoeffs;
240 
241 // Cost calculation function.
242 typedef int (*VP8GetResidualCostFunc)(int ctx0,
243                                       const struct VP8Residual* const res);
244 extern VP8GetResidualCostFunc VP8GetResidualCost;
245 
246 // must be called before anything using the above
247 void VP8EncDspCostInit(void);
248 
249 //------------------------------------------------------------------------------
250 // SSIM / PSNR utils
251 
252 // struct for accumulating statistical moments
253 typedef struct {
254   uint32_t w;              // sum(w_i) : sum of weights
255   uint32_t xm, ym;         // sum(w_i * x_i), sum(w_i * y_i)
256   uint32_t xxm, xym, yym;  // sum(w_i * x_i * x_i), etc.
257 } VP8DistoStats;
258 
259 // Compute the final SSIM value
260 // The non-clipped version assumes stats->w = (2 * VP8_SSIM_KERNEL + 1)^2.
261 double VP8SSIMFromStats(const VP8DistoStats* const stats);
262 double VP8SSIMFromStatsClipped(const VP8DistoStats* const stats);
263 
264 #define VP8_SSIM_KERNEL 3   // total size of the kernel: 2 * VP8_SSIM_KERNEL + 1
265 typedef double (*VP8SSIMGetClippedFunc)(const uint8_t* src1, int stride1,
266                                         const uint8_t* src2, int stride2,
267                                         int xo, int yo,  // center position
268                                         int W, int H);   // plane dimension
269 
270 // This version is called with the guarantee that you can load 8 bytes and
271 // 8 rows at offset src1 and src2
272 typedef double (*VP8SSIMGetFunc)(const uint8_t* src1, int stride1,
273                                  const uint8_t* src2, int stride2);
274 
275 extern VP8SSIMGetFunc VP8SSIMGet;         // unclipped / unchecked
276 extern VP8SSIMGetClippedFunc VP8SSIMGetClipped;   // with clipping
277 
278 typedef uint32_t (*VP8AccumulateSSEFunc)(const uint8_t* src1,
279                                          const uint8_t* src2, int len);
280 extern VP8AccumulateSSEFunc VP8AccumulateSSE;
281 
282 // must be called before using any of the above directly
283 void VP8SSIMDspInit(void);
284 
285 //------------------------------------------------------------------------------
286 // Decoding
287 
288 typedef void (*VP8DecIdct)(const int16_t* coeffs, uint8_t* dst);
289 // when doing two transforms, coeffs is actually int16_t[2][16].
290 typedef void (*VP8DecIdct2)(const int16_t* coeffs, uint8_t* dst, int do_two);
291 extern VP8DecIdct2 VP8Transform;
292 extern VP8DecIdct VP8TransformAC3;
293 extern VP8DecIdct VP8TransformUV;
294 extern VP8DecIdct VP8TransformDC;
295 extern VP8DecIdct VP8TransformDCUV;
296 extern VP8WHT VP8TransformWHT;
297 
298 // *dst is the destination block, with stride BPS. Boundary samples are
299 // assumed accessible when needed.
300 typedef void (*VP8PredFunc)(uint8_t* dst);
301 extern VP8PredFunc VP8PredLuma16[/* NUM_B_DC_MODES */];
302 extern VP8PredFunc VP8PredChroma8[/* NUM_B_DC_MODES */];
303 extern VP8PredFunc VP8PredLuma4[/* NUM_BMODES */];
304 
305 // clipping tables (for filtering)
306 extern const int8_t* const VP8ksclip1;  // clips [-1020, 1020] to [-128, 127]
307 extern const int8_t* const VP8ksclip2;  // clips [-112, 112] to [-16, 15]
308 extern const uint8_t* const VP8kclip1;  // clips [-255,511] to [0,255]
309 extern const uint8_t* const VP8kabs0;   // abs(x) for x in [-255,255]
310 // must be called first
311 void VP8InitClipTables(void);
312 
313 // simple filter (only for luma)
314 typedef void (*VP8SimpleFilterFunc)(uint8_t* p, int stride, int thresh);
315 extern VP8SimpleFilterFunc VP8SimpleVFilter16;
316 extern VP8SimpleFilterFunc VP8SimpleHFilter16;
317 extern VP8SimpleFilterFunc VP8SimpleVFilter16i;  // filter 3 inner edges
318 extern VP8SimpleFilterFunc VP8SimpleHFilter16i;
319 
320 // regular filter (on both macroblock edges and inner edges)
321 typedef void (*VP8LumaFilterFunc)(uint8_t* luma, int stride,
322                                   int thresh, int ithresh, int hev_t);
323 typedef void (*VP8ChromaFilterFunc)(uint8_t* u, uint8_t* v, int stride,
324                                     int thresh, int ithresh, int hev_t);
325 // on outer edge
326 extern VP8LumaFilterFunc VP8VFilter16;
327 extern VP8LumaFilterFunc VP8HFilter16;
328 extern VP8ChromaFilterFunc VP8VFilter8;
329 extern VP8ChromaFilterFunc VP8HFilter8;
330 
331 // on inner edge
332 extern VP8LumaFilterFunc VP8VFilter16i;   // filtering 3 inner edges altogether
333 extern VP8LumaFilterFunc VP8HFilter16i;
334 extern VP8ChromaFilterFunc VP8VFilter8i;  // filtering u and v altogether
335 extern VP8ChromaFilterFunc VP8HFilter8i;
336 
337 // Dithering. Combines dithering values (centered around 128) with dst[],
338 // according to: dst[] = clip(dst[] + (((dither[]-128) + 8) >> 4)
339 #define VP8_DITHER_DESCALE 4
340 #define VP8_DITHER_DESCALE_ROUNDER (1 << (VP8_DITHER_DESCALE - 1))
341 #define VP8_DITHER_AMP_BITS 7
342 #define VP8_DITHER_AMP_CENTER (1 << VP8_DITHER_AMP_BITS)
343 extern void (*VP8DitherCombine8x8)(const uint8_t* dither, uint8_t* dst,
344                                    int dst_stride);
345 
346 // must be called before anything using the above
347 void VP8DspInit(void);
348 
349 //------------------------------------------------------------------------------
350 // WebP I/O
351 
352 #define FANCY_UPSAMPLING   // undefined to remove fancy upsampling support
353 
354 // Convert a pair of y/u/v lines together to the output rgb/a colorspace.
355 // bottom_y can be NULL if only one line of output is needed (at top/bottom).
356 typedef void (*WebPUpsampleLinePairFunc)(
357     const uint8_t* top_y, const uint8_t* bottom_y,
358     const uint8_t* top_u, const uint8_t* top_v,
359     const uint8_t* cur_u, const uint8_t* cur_v,
360     uint8_t* top_dst, uint8_t* bottom_dst, int len);
361 
362 #ifdef FANCY_UPSAMPLING
363 
364 // Fancy upsampling functions to convert YUV to RGB(A) modes
365 extern WebPUpsampleLinePairFunc WebPUpsamplers[/* MODE_LAST */];
366 
367 #endif    // FANCY_UPSAMPLING
368 
369 // Per-row point-sampling methods.
370 typedef void (*WebPSamplerRowFunc)(const uint8_t* y,
371                                    const uint8_t* u, const uint8_t* v,
372                                    uint8_t* dst, int len);
373 // Generic function to apply 'WebPSamplerRowFunc' to the whole plane:
374 void WebPSamplerProcessPlane(const uint8_t* y, int y_stride,
375                              const uint8_t* u, const uint8_t* v, int uv_stride,
376                              uint8_t* dst, int dst_stride,
377                              int width, int height, WebPSamplerRowFunc func);
378 
379 // Sampling functions to convert rows of YUV to RGB(A)
380 extern WebPSamplerRowFunc WebPSamplers[/* MODE_LAST */];
381 
382 // General function for converting two lines of ARGB or RGBA.
383 // 'alpha_is_last' should be true if 0xff000000 is stored in memory as
384 // as 0x00, 0x00, 0x00, 0xff (little endian).
385 WebPUpsampleLinePairFunc WebPGetLinePairConverter(int alpha_is_last);
386 
387 // YUV444->RGB converters
388 typedef void (*WebPYUV444Converter)(const uint8_t* y,
389                                     const uint8_t* u, const uint8_t* v,
390                                     uint8_t* dst, int len);
391 
392 extern WebPYUV444Converter WebPYUV444Converters[/* MODE_LAST */];
393 
394 // Must be called before using the WebPUpsamplers[] (and for premultiplied
395 // colorspaces like rgbA, rgbA4444, etc)
396 void WebPInitUpsamplers(void);
397 // Must be called before using WebPSamplers[]
398 void WebPInitSamplers(void);
399 // Must be called before using WebPYUV444Converters[]
400 void WebPInitYUV444Converters(void);
401 
402 //------------------------------------------------------------------------------
403 // ARGB -> YUV converters
404 
405 // Convert ARGB samples to luma Y.
406 extern void (*WebPConvertARGBToY)(const uint32_t* argb, uint8_t* y, int width);
407 // Convert ARGB samples to U/V with downsampling. do_store should be '1' for
408 // even lines and '0' for odd ones. 'src_width' is the original width, not
409 // the U/V one.
410 extern void (*WebPConvertARGBToUV)(const uint32_t* argb, uint8_t* u, uint8_t* v,
411                                    int src_width, int do_store);
412 
413 // Convert a row of accumulated (four-values) of rgba32 toward U/V
414 extern void (*WebPConvertRGBA32ToUV)(const uint16_t* rgb,
415                                      uint8_t* u, uint8_t* v, int width);
416 
417 // Convert RGB or BGR to Y
418 extern void (*WebPConvertRGB24ToY)(const uint8_t* rgb, uint8_t* y, int width);
419 extern void (*WebPConvertBGR24ToY)(const uint8_t* bgr, uint8_t* y, int width);
420 
421 // used for plain-C fallback.
422 extern void WebPConvertARGBToUV_C(const uint32_t* argb, uint8_t* u, uint8_t* v,
423                                   int src_width, int do_store);
424 extern void WebPConvertRGBA32ToUV_C(const uint16_t* rgb,
425                                     uint8_t* u, uint8_t* v, int width);
426 
427 // utilities for accurate RGB->YUV conversion
428 extern uint64_t (*WebPSharpYUVUpdateY)(const uint16_t* src, const uint16_t* ref,
429                                        uint16_t* dst, int len);
430 extern void (*WebPSharpYUVUpdateRGB)(const int16_t* src, const int16_t* ref,
431                                      int16_t* dst, int len);
432 extern void (*WebPSharpYUVFilterRow)(const int16_t* A, const int16_t* B,
433                                      int len,
434                                      const uint16_t* best_y, uint16_t* out);
435 
436 // Must be called before using the above.
437 void WebPInitConvertARGBToYUV(void);
438 
439 //------------------------------------------------------------------------------
440 // Rescaler
441 
442 struct WebPRescaler;
443 
444 // Import a row of data and save its contribution in the rescaler.
445 // 'channel' denotes the channel number to be imported. 'Expand' corresponds to
446 // the wrk->x_expand case. Otherwise, 'Shrink' is to be used.
447 typedef void (*WebPRescalerImportRowFunc)(struct WebPRescaler* const wrk,
448                                           const uint8_t* src);
449 
450 extern WebPRescalerImportRowFunc WebPRescalerImportRowExpand;
451 extern WebPRescalerImportRowFunc WebPRescalerImportRowShrink;
452 
453 // Export one row (starting at x_out position) from rescaler.
454 // 'Expand' corresponds to the wrk->y_expand case.
455 // Otherwise 'Shrink' is to be used
456 typedef void (*WebPRescalerExportRowFunc)(struct WebPRescaler* const wrk);
457 extern WebPRescalerExportRowFunc WebPRescalerExportRowExpand;
458 extern WebPRescalerExportRowFunc WebPRescalerExportRowShrink;
459 
460 // Plain-C implementation, as fall-back.
461 extern void WebPRescalerImportRowExpandC(struct WebPRescaler* const wrk,
462                                          const uint8_t* src);
463 extern void WebPRescalerImportRowShrinkC(struct WebPRescaler* const wrk,
464                                          const uint8_t* src);
465 extern void WebPRescalerExportRowExpandC(struct WebPRescaler* const wrk);
466 extern void WebPRescalerExportRowShrinkC(struct WebPRescaler* const wrk);
467 
468 // Main entry calls:
469 extern void WebPRescalerImportRow(struct WebPRescaler* const wrk,
470                                   const uint8_t* src);
471 // Export one row (starting at x_out position) from rescaler.
472 extern void WebPRescalerExportRow(struct WebPRescaler* const wrk);
473 
474 // Must be called first before using the above.
475 void WebPRescalerDspInit(void);
476 
477 //------------------------------------------------------------------------------
478 // Utilities for processing transparent channel.
479 
480 // Apply alpha pre-multiply on an rgba, bgra or argb plane of size w * h.
481 // alpha_first should be 0 for argb, 1 for rgba or bgra (where alpha is last).
482 extern void (*WebPApplyAlphaMultiply)(
483     uint8_t* rgba, int alpha_first, int w, int h, int stride);
484 
485 // Same, buf specifically for RGBA4444 format
486 extern void (*WebPApplyAlphaMultiply4444)(
487     uint8_t* rgba4444, int w, int h, int stride);
488 
489 // Dispatch the values from alpha[] plane to the ARGB destination 'dst'.
490 // Returns true if alpha[] plane has non-trivial values different from 0xff.
491 extern int (*WebPDispatchAlpha)(const uint8_t* alpha, int alpha_stride,
492                                 int width, int height,
493                                 uint8_t* dst, int dst_stride);
494 
495 // Transfer packed 8b alpha[] values to green channel in dst[], zero'ing the
496 // A/R/B values. 'dst_stride' is the stride for dst[] in uint32_t units.
497 extern void (*WebPDispatchAlphaToGreen)(const uint8_t* alpha, int alpha_stride,
498                                         int width, int height,
499                                         uint32_t* dst, int dst_stride);
500 
501 // Extract the alpha values from 32b values in argb[] and pack them into alpha[]
502 // (this is the opposite of WebPDispatchAlpha).
503 // Returns true if there's only trivial 0xff alpha values.
504 extern int (*WebPExtractAlpha)(const uint8_t* argb, int argb_stride,
505                                int width, int height,
506                                uint8_t* alpha, int alpha_stride);
507 
508 // Extract the green values from 32b values in argb[] and pack them into alpha[]
509 // (this is the opposite of WebPDispatchAlphaToGreen).
510 extern void (*WebPExtractGreen)(const uint32_t* argb, uint8_t* alpha, int size);
511 
512 // Pre-Multiply operation transforms x into x * A / 255  (where x=Y,R,G or B).
513 // Un-Multiply operation transforms x into x * 255 / A.
514 
515 // Pre-Multiply or Un-Multiply (if 'inverse' is true) argb values in a row.
516 extern void (*WebPMultARGBRow)(uint32_t* const ptr, int width, int inverse);
517 
518 // Same a WebPMultARGBRow(), but for several rows.
519 void WebPMultARGBRows(uint8_t* ptr, int stride, int width, int num_rows,
520                       int inverse);
521 
522 // Same for a row of single values, with side alpha values.
523 extern void (*WebPMultRow)(uint8_t* const ptr, const uint8_t* const alpha,
524                            int width, int inverse);
525 
526 // Same a WebPMultRow(), but for several 'num_rows' rows.
527 void WebPMultRows(uint8_t* ptr, int stride,
528                   const uint8_t* alpha, int alpha_stride,
529                   int width, int num_rows, int inverse);
530 
531 // Plain-C versions, used as fallback by some implementations.
532 void WebPMultRowC(uint8_t* const ptr, const uint8_t* const alpha,
533                   int width, int inverse);
534 void WebPMultARGBRowC(uint32_t* const ptr, int width, int inverse);
535 
536 // To be called first before using the above.
537 void WebPInitAlphaProcessing(void);
538 
539 // ARGB packing function: a/r/g/b input is rgba or bgra order.
540 extern void (*VP8PackARGB)(const uint8_t* a, const uint8_t* r,
541                            const uint8_t* g, const uint8_t* b, int len,
542                            uint32_t* out);
543 
544 // RGB packing function. 'step' can be 3 or 4. r/g/b input is rgb or bgr order.
545 extern void (*VP8PackRGB)(const uint8_t* r, const uint8_t* g, const uint8_t* b,
546                           int len, int step, uint32_t* out);
547 
548 // To be called first before using the above.
549 void VP8EncDspARGBInit(void);
550 
551 //------------------------------------------------------------------------------
552 // Filter functions
553 
554 typedef enum {     // Filter types.
555   WEBP_FILTER_NONE = 0,
556   WEBP_FILTER_HORIZONTAL,
557   WEBP_FILTER_VERTICAL,
558   WEBP_FILTER_GRADIENT,
559   WEBP_FILTER_LAST = WEBP_FILTER_GRADIENT + 1,  // end marker
560   WEBP_FILTER_BEST,    // meta-types
561   WEBP_FILTER_FAST
562 } WEBP_FILTER_TYPE;
563 
564 typedef void (*WebPFilterFunc)(const uint8_t* in, int width, int height,
565                                int stride, uint8_t* out);
566 // In-place un-filtering.
567 // Warning! 'prev_line' pointer can be equal to 'cur_line' or 'preds'.
568 typedef void (*WebPUnfilterFunc)(const uint8_t* prev_line, const uint8_t* preds,
569                                  uint8_t* cur_line, int width);
570 
571 // Filter the given data using the given predictor.
572 // 'in' corresponds to a 2-dimensional pixel array of size (stride * height)
573 // in raster order.
574 // 'stride' is number of bytes per scan line (with possible padding).
575 // 'out' should be pre-allocated.
576 extern WebPFilterFunc WebPFilters[WEBP_FILTER_LAST];
577 
578 // In-place reconstruct the original data from the given filtered data.
579 // The reconstruction will be done for 'num_rows' rows starting from 'row'
580 // (assuming rows upto 'row - 1' are already reconstructed).
581 extern WebPUnfilterFunc WebPUnfilters[WEBP_FILTER_LAST];
582 
583 // To be called first before using the above.
584 void VP8FiltersInit(void);
585 
586 #ifdef __cplusplus
587 }    // extern "C"
588 #endif
589 
590 #endif  /* WEBP_DSP_DSP_H_ */
591