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