1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// libwebp v1.6.0, src/dsp/dsp.h:
//
// Copyright 2011 Google Inc. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the COPYING file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
// -----------------------------------------------------------------------------
//
// Speed-critical functions.
//
// Author: Skal (pascal.massimino@gmail.com)
//! Translation of `src/dsp/dsp.h` from libwebp v1.6.0.
//!
//! Work package: WP4 (pixel ops).
//!
//! # Deviations from upstream
//!
//! Changes of representation that the ADRs allow, or behavior that the Rust
//! side cannot reproduce exactly. Each records the reason.
//!
//! 1. **Function-pointer typedefs.** The typedefs of `dsp.h` for the dispatch
//! pointers have no Rust type of their own. Each dispatch pointer is a plain
//! function with the snake-case name of the pointer, and its signature is
//! the one of the module that implements it (ADR 0003). The aliases
//! `WebPSamplerRowFunc`, `WebPUpsampleLinePairFunc`, `WebPYUV444Converter`,
//! `WebPFilterFunc` and `WebPUnfilterFunc` are kept where a parameter or a
//! table has the type.
//! 2. **Pointers and strides.** A pointer into a buffer is a slice and an
//! offset; an `int` stride is kept as `i32` in the signature and converted
//! to `usize` with a checked conversion. A row outside its buffer panics
//! where C would read or write outside it, which is undefined.
//! 3. **Assertions and overflow.** `assert` is `debug_assert!`, which is active
//! in the dev and `checked` profiles like upstream's debug build. Wrapping
//! is spelled out where the C unsigned arithmetic wraps (the `uint32_t` and
//! `uint64_t` products of the filters, the rescaler and the SSIM), and plain
//! arithmetic is used where the C code cannot overflow.
//!
//! # Checks not applicable
//!
//! These checks do not apply, or cannot be made, with the reason:
//!
//! 1. **SIMD variants.** The SSE2, SSE41 and NEON variants and their wrappers
//! (`VP8YuvToRgba32_SSE2` and the others, `alpha_processing_sse2.c` and the
//! like) belong to the SIMD modules (ADR 0008). The `WEBP_HAVE_*` guards
//! around the `Init` calls are false in the reference configuration.
//! 2. **Compile-time switches off in the reference configuration.**
//! `WEBP_SWAP_16BIT_CSP` (the swapped RGB-565 and RGBA-4444 byte order,
//! `YUV_*` writers under `WEBP_SWAP_16BIT_CSP == 1`, and
//! `ApplyAlphaMultiply_16b_C` with 1) is 0, so the standard byte order is
//! translated only. `WEBP_REDUCE_CSP` is unset, so `EmptyUpsampleFunc` and
//! `EmptyYuv444Func` are not translated. `USE_DITHERING` is undefined, so
//! the ordered dither table and its branches are not translated.
//! `USE_TABLES_FOR_ALPHA_MULT` is 0, so `kMultTables` is not translated.
//! `FANCY_UPSAMPLING` is defined by `dsp.h`, so the `DUAL_SAMPLE` functions
//! are not compiled.
//! 3. **`Init` functions.** `VP8FiltersInit`, `VP8SSIMDspInit`,
//! `WebPInitAlphaProcessing`, `WebPInitConvertARGBToYUV`,
//! `WebPInitSamplers`, `WebPInitUpsamplers`, `WebPInitYUV444Converters` and
//! `WebPRescalerDspInit` only assign portable pointers, and ADR 0003 omits
//! them. Their SIMD branches belong to the SIMD modules (ADR 0008).
// upstream: src/dsp/dsp.h BPS
/// The common stride of the encoder and decoder blocks.
pub const BPS: i32 = 32;
// upstream: src/dsp/dsp.h MAX_COEFF_THRESH
/// Size of the histogram that `VP8CollectHistogram` uses.
pub const MAX_COEFF_THRESH: i32 = 31;
// upstream: src/dsp/dsp.h VP8Histogram
/// The statistics of one block that `VP8CollectHistogram` gathers. Only the
/// maximum value and the last non-zero position are kept.
// upstream: src/dsp/dsp.h VP8DistoStats
/// Accumulated statistical moments of a window, for the SSIM computation.
// upstream: src/dsp/dsp.h VP8_SSIM_KERNEL
/// Half the size of the SSIM kernel: the kernel is `2 * VP8_SSIM_KERNEL + 1` wide.
pub const VP8_SSIM_KERNEL: i32 = 3;
// upstream: src/dsp/dsp.h VP8_DITHER_DESCALE
/// Descaling of the dithering values.
pub const VP8_DITHER_DESCALE: i32 = 4;
// upstream: src/dsp/dsp.h VP8_DITHER_DESCALE_ROUNDER
/// Rounding term of the dithering descaling.
pub const VP8_DITHER_DESCALE_ROUNDER: i32 = 1 << ;
// upstream: src/dsp/dsp.h VP8_DITHER_AMP_BITS
/// Bits of the dithering amplitude.
pub const VP8_DITHER_AMP_BITS: i32 = 7;
// upstream: src/dsp/dsp.h VP8_DITHER_AMP_CENTER
/// Center of the dithering amplitude.
pub const VP8_DITHER_AMP_CENTER: i32 = 1 << VP8_DITHER_AMP_BITS;
// upstream: src/dsp/dsp.h WEBP_TRANSFORM_AC3_C1
/// Fixed-point constant of the AC3 inverse transform (`sqrt(2) * cos(pi/8)`).
pub const WEBP_TRANSFORM_AC3_C1: i32 = 20091;
// upstream: src/dsp/dsp.h WEBP_TRANSFORM_AC3_C2
/// Fixed-point constant of the AC3 inverse transform (`sqrt(2) * sin(pi/8)`).
pub const WEBP_TRANSFORM_AC3_C2: i32 = 35468;
// upstream: src/dsp/dsp.h WEBP_TRANSFORM_AC3_MUL1
/// `a * C1 >> 16` plus `a`, as the AC3 transform computes it.
// upstream: src/dsp/dsp.h WEBP_TRANSFORM_AC3_MUL2
/// `a * C2 >> 16`, as the AC3 transform computes it.
// upstream: src/dsp/dsp.h WEBP_FILTER_TYPE
/// A filter type of the lossless and alpha coders. The C enumeration has no
/// negative values, so it wraps `u32` (ADR 0003).
;