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