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