1*09537850SAkhilesh Sanikop // Copyright 2019 The libgav1 Authors
2*09537850SAkhilesh Sanikop //
3*09537850SAkhilesh Sanikop // Licensed under the Apache License, Version 2.0 (the "License");
4*09537850SAkhilesh Sanikop // you may not use this file except in compliance with the License.
5*09537850SAkhilesh Sanikop // You may obtain a copy of the License at
6*09537850SAkhilesh Sanikop //
7*09537850SAkhilesh Sanikop // http://www.apache.org/licenses/LICENSE-2.0
8*09537850SAkhilesh Sanikop //
9*09537850SAkhilesh Sanikop // Unless required by applicable law or agreed to in writing, software
10*09537850SAkhilesh Sanikop // distributed under the License is distributed on an "AS IS" BASIS,
11*09537850SAkhilesh Sanikop // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*09537850SAkhilesh Sanikop // See the License for the specific language governing permissions and
13*09537850SAkhilesh Sanikop // limitations under the License.
14*09537850SAkhilesh Sanikop
15*09537850SAkhilesh Sanikop #include "src/dsp/cdef.h"
16*09537850SAkhilesh Sanikop
17*09537850SAkhilesh Sanikop #include <algorithm>
18*09537850SAkhilesh Sanikop #include <cassert>
19*09537850SAkhilesh Sanikop #include <cstddef>
20*09537850SAkhilesh Sanikop #include <cstdint>
21*09537850SAkhilesh Sanikop #include <cstring>
22*09537850SAkhilesh Sanikop
23*09537850SAkhilesh Sanikop #include "src/dsp/constants.h"
24*09537850SAkhilesh Sanikop #include "src/dsp/dsp.h"
25*09537850SAkhilesh Sanikop #include "src/utils/common.h"
26*09537850SAkhilesh Sanikop #include "src/utils/constants.h"
27*09537850SAkhilesh Sanikop
28*09537850SAkhilesh Sanikop namespace libgav1 {
29*09537850SAkhilesh Sanikop namespace dsp {
30*09537850SAkhilesh Sanikop namespace {
31*09537850SAkhilesh Sanikop
32*09537850SAkhilesh Sanikop #include "src/dsp/cdef.inc"
33*09537850SAkhilesh Sanikop
34*09537850SAkhilesh Sanikop // Silence unused function warnings when CdefDirection_C is obviated.
35*09537850SAkhilesh Sanikop #if LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS || \
36*09537850SAkhilesh Sanikop !defined(LIBGAV1_Dsp8bpp_CdefDirection) || \
37*09537850SAkhilesh Sanikop (LIBGAV1_MAX_BITDEPTH >= 10 && \
38*09537850SAkhilesh Sanikop !defined(LIBGAV1_Dsp10bpp_CdefDirection)) || \
39*09537850SAkhilesh Sanikop (LIBGAV1_MAX_BITDEPTH == 12 && !defined(LIBGAV1_Dsp12bpp_CdefDirection))
40*09537850SAkhilesh Sanikop constexpr int16_t kDivisionTable[] = {840, 420, 280, 210, 168, 140, 120, 105};
41*09537850SAkhilesh Sanikop
Square(int32_t x)42*09537850SAkhilesh Sanikop int32_t Square(int32_t x) { return x * x; }
43*09537850SAkhilesh Sanikop
44*09537850SAkhilesh Sanikop template <int bitdepth, typename Pixel>
CdefDirection_C(const void * LIBGAV1_RESTRICT const source,ptrdiff_t stride,uint8_t * LIBGAV1_RESTRICT const direction,int * LIBGAV1_RESTRICT const variance)45*09537850SAkhilesh Sanikop void CdefDirection_C(const void* LIBGAV1_RESTRICT const source,
46*09537850SAkhilesh Sanikop ptrdiff_t stride,
47*09537850SAkhilesh Sanikop uint8_t* LIBGAV1_RESTRICT const direction,
48*09537850SAkhilesh Sanikop int* LIBGAV1_RESTRICT const variance) {
49*09537850SAkhilesh Sanikop assert(direction != nullptr);
50*09537850SAkhilesh Sanikop assert(variance != nullptr);
51*09537850SAkhilesh Sanikop const auto* src = static_cast<const Pixel*>(source);
52*09537850SAkhilesh Sanikop stride /= sizeof(Pixel);
53*09537850SAkhilesh Sanikop int32_t cost[8] = {};
54*09537850SAkhilesh Sanikop // |partial| does not have to be int32_t for 8bpp. int16_t will suffice. We
55*09537850SAkhilesh Sanikop // use int32_t to keep it simple since |cost| will have to be int32_t.
56*09537850SAkhilesh Sanikop int32_t partial[8][15] = {};
57*09537850SAkhilesh Sanikop for (int i = 0; i < 8; ++i) {
58*09537850SAkhilesh Sanikop for (int j = 0; j < 8; ++j) {
59*09537850SAkhilesh Sanikop const int x = (src[j] >> (bitdepth - 8)) - 128;
60*09537850SAkhilesh Sanikop partial[0][i + j] += x;
61*09537850SAkhilesh Sanikop partial[1][i + j / 2] += x;
62*09537850SAkhilesh Sanikop partial[2][i] += x;
63*09537850SAkhilesh Sanikop partial[3][3 + i - j / 2] += x;
64*09537850SAkhilesh Sanikop partial[4][7 + i - j] += x;
65*09537850SAkhilesh Sanikop partial[5][3 - i / 2 + j] += x;
66*09537850SAkhilesh Sanikop partial[6][j] += x;
67*09537850SAkhilesh Sanikop partial[7][i / 2 + j] += x;
68*09537850SAkhilesh Sanikop }
69*09537850SAkhilesh Sanikop src += stride;
70*09537850SAkhilesh Sanikop }
71*09537850SAkhilesh Sanikop for (int i = 0; i < 8; ++i) {
72*09537850SAkhilesh Sanikop cost[2] += Square(partial[2][i]);
73*09537850SAkhilesh Sanikop cost[6] += Square(partial[6][i]);
74*09537850SAkhilesh Sanikop }
75*09537850SAkhilesh Sanikop cost[2] *= kDivisionTable[7];
76*09537850SAkhilesh Sanikop cost[6] *= kDivisionTable[7];
77*09537850SAkhilesh Sanikop for (int i = 0; i < 7; ++i) {
78*09537850SAkhilesh Sanikop cost[0] += (Square(partial[0][i]) + Square(partial[0][14 - i])) *
79*09537850SAkhilesh Sanikop kDivisionTable[i];
80*09537850SAkhilesh Sanikop cost[4] += (Square(partial[4][i]) + Square(partial[4][14 - i])) *
81*09537850SAkhilesh Sanikop kDivisionTable[i];
82*09537850SAkhilesh Sanikop }
83*09537850SAkhilesh Sanikop cost[0] += Square(partial[0][7]) * kDivisionTable[7];
84*09537850SAkhilesh Sanikop cost[4] += Square(partial[4][7]) * kDivisionTable[7];
85*09537850SAkhilesh Sanikop for (int i = 1; i < 8; i += 2) {
86*09537850SAkhilesh Sanikop for (int j = 0; j < 5; ++j) {
87*09537850SAkhilesh Sanikop cost[i] += Square(partial[i][3 + j]);
88*09537850SAkhilesh Sanikop }
89*09537850SAkhilesh Sanikop cost[i] *= kDivisionTable[7];
90*09537850SAkhilesh Sanikop for (int j = 0; j < 3; ++j) {
91*09537850SAkhilesh Sanikop cost[i] += (Square(partial[i][j]) + Square(partial[i][10 - j])) *
92*09537850SAkhilesh Sanikop kDivisionTable[2 * j + 1];
93*09537850SAkhilesh Sanikop }
94*09537850SAkhilesh Sanikop }
95*09537850SAkhilesh Sanikop int32_t best_cost = 0;
96*09537850SAkhilesh Sanikop *direction = 0;
97*09537850SAkhilesh Sanikop for (int i = 0; i < 8; ++i) {
98*09537850SAkhilesh Sanikop if (cost[i] > best_cost) {
99*09537850SAkhilesh Sanikop best_cost = cost[i];
100*09537850SAkhilesh Sanikop *direction = i;
101*09537850SAkhilesh Sanikop }
102*09537850SAkhilesh Sanikop }
103*09537850SAkhilesh Sanikop *variance = (best_cost - cost[(*direction + 4) & 7]) >> 10;
104*09537850SAkhilesh Sanikop }
105*09537850SAkhilesh Sanikop #endif // LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS ||
106*09537850SAkhilesh Sanikop // !defined(LIBGAV1_Dsp8bpp_CdefDirection) ||
107*09537850SAkhilesh Sanikop // (LIBGAV1_MAX_BITDEPTH >= 10 &&
108*09537850SAkhilesh Sanikop // !defined(LIBGAV1_Dsp10bpp_CdefDirection))
109*09537850SAkhilesh Sanikop // (LIBGAV1_MAX_BITDEPTH == 12 &&
110*09537850SAkhilesh Sanikop // !defined(LIBGAV1_Dsp12bpp_CdefDirection))
111*09537850SAkhilesh Sanikop
112*09537850SAkhilesh Sanikop // Silence unused function warnings when CdefFilter_C is obviated.
113*09537850SAkhilesh Sanikop #if LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS || \
114*09537850SAkhilesh Sanikop !defined(LIBGAV1_Dsp8bpp_CdefFilters) || \
115*09537850SAkhilesh Sanikop (LIBGAV1_MAX_BITDEPTH >= 10 && !defined(LIBGAV1_Dsp10bpp_CdefFilters)) || \
116*09537850SAkhilesh Sanikop (LIBGAV1_MAX_BITDEPTH == 12 && !defined(LIBGAV1_Dsp12bpp_CdefFilters))
117*09537850SAkhilesh Sanikop
Constrain(int diff,int threshold,int damping)118*09537850SAkhilesh Sanikop int Constrain(int diff, int threshold, int damping) {
119*09537850SAkhilesh Sanikop assert(threshold != 0);
120*09537850SAkhilesh Sanikop damping = std::max(0, damping - FloorLog2(threshold));
121*09537850SAkhilesh Sanikop const int sign = (diff < 0) ? -1 : 1;
122*09537850SAkhilesh Sanikop return sign *
123*09537850SAkhilesh Sanikop Clip3(threshold - (std::abs(diff) >> damping), 0, std::abs(diff));
124*09537850SAkhilesh Sanikop }
125*09537850SAkhilesh Sanikop
126*09537850SAkhilesh Sanikop // Filters the source block. It doesn't check whether the candidate pixel is
127*09537850SAkhilesh Sanikop // inside the frame. However it requires the source input to be padded with a
128*09537850SAkhilesh Sanikop // constant large value (kCdefLargeValue) if at the boundary.
129*09537850SAkhilesh Sanikop template <int block_width, int bitdepth, typename Pixel,
130*09537850SAkhilesh Sanikop bool enable_primary = true, bool enable_secondary = true>
CdefFilter_C(const uint16_t * LIBGAV1_RESTRICT src,const ptrdiff_t src_stride,const int block_height,const int primary_strength,const int secondary_strength,const int damping,const int direction,void * LIBGAV1_RESTRICT const dest,const ptrdiff_t dest_stride)131*09537850SAkhilesh Sanikop void CdefFilter_C(const uint16_t* LIBGAV1_RESTRICT src,
132*09537850SAkhilesh Sanikop const ptrdiff_t src_stride, const int block_height,
133*09537850SAkhilesh Sanikop const int primary_strength, const int secondary_strength,
134*09537850SAkhilesh Sanikop const int damping, const int direction,
135*09537850SAkhilesh Sanikop void* LIBGAV1_RESTRICT const dest,
136*09537850SAkhilesh Sanikop const ptrdiff_t dest_stride) {
137*09537850SAkhilesh Sanikop static_assert(block_width == 4 || block_width == 8, "Invalid CDEF width.");
138*09537850SAkhilesh Sanikop static_assert(enable_primary || enable_secondary, "");
139*09537850SAkhilesh Sanikop assert(block_height == 4 || block_height == 8);
140*09537850SAkhilesh Sanikop assert(direction >= 0 && direction <= 7);
141*09537850SAkhilesh Sanikop constexpr int coeff_shift = bitdepth - 8;
142*09537850SAkhilesh Sanikop // Section 5.9.19. CDEF params syntax.
143*09537850SAkhilesh Sanikop assert(primary_strength >= 0 && primary_strength <= 15 << coeff_shift);
144*09537850SAkhilesh Sanikop assert(secondary_strength >= 0 && secondary_strength <= 4 << coeff_shift &&
145*09537850SAkhilesh Sanikop secondary_strength != 3 << coeff_shift);
146*09537850SAkhilesh Sanikop assert(primary_strength != 0 || secondary_strength != 0);
147*09537850SAkhilesh Sanikop // damping is decreased by 1 for chroma.
148*09537850SAkhilesh Sanikop assert((damping >= 3 && damping <= 6 + coeff_shift) ||
149*09537850SAkhilesh Sanikop (damping >= 2 && damping <= 5 + coeff_shift));
150*09537850SAkhilesh Sanikop // When only primary_strength or secondary_strength are non-zero the number
151*09537850SAkhilesh Sanikop // of pixels inspected (4 for primary_strength, 8 for secondary_strength) and
152*09537850SAkhilesh Sanikop // the taps used don't exceed the amount the sum is
153*09537850SAkhilesh Sanikop // descaled by (16) so we can skip tracking and clipping to the minimum and
154*09537850SAkhilesh Sanikop // maximum value observed.
155*09537850SAkhilesh Sanikop constexpr bool clipping_required = enable_primary && enable_secondary;
156*09537850SAkhilesh Sanikop static constexpr int kCdefSecondaryTaps[2] = {kCdefSecondaryTap0,
157*09537850SAkhilesh Sanikop kCdefSecondaryTap1};
158*09537850SAkhilesh Sanikop auto* dst = static_cast<Pixel*>(dest);
159*09537850SAkhilesh Sanikop const ptrdiff_t dst_stride = dest_stride / sizeof(Pixel);
160*09537850SAkhilesh Sanikop int y = block_height;
161*09537850SAkhilesh Sanikop do {
162*09537850SAkhilesh Sanikop int x = 0;
163*09537850SAkhilesh Sanikop do {
164*09537850SAkhilesh Sanikop int16_t sum = 0;
165*09537850SAkhilesh Sanikop const uint16_t pixel_value = src[x];
166*09537850SAkhilesh Sanikop uint16_t max_value = pixel_value;
167*09537850SAkhilesh Sanikop uint16_t min_value = pixel_value;
168*09537850SAkhilesh Sanikop for (int k = 0; k < 2; ++k) {
169*09537850SAkhilesh Sanikop static constexpr int signs[] = {-1, 1};
170*09537850SAkhilesh Sanikop for (const int& sign : signs) {
171*09537850SAkhilesh Sanikop if (enable_primary) {
172*09537850SAkhilesh Sanikop const int dy = sign * kCdefDirections[direction][k][0];
173*09537850SAkhilesh Sanikop const int dx = sign * kCdefDirections[direction][k][1];
174*09537850SAkhilesh Sanikop const uint16_t value = src[dy * src_stride + dx + x];
175*09537850SAkhilesh Sanikop // Note: the summation can ignore the condition check in SIMD
176*09537850SAkhilesh Sanikop // implementation, because Constrain() will return 0 when
177*09537850SAkhilesh Sanikop // value == kCdefLargeValue.
178*09537850SAkhilesh Sanikop if (value != kCdefLargeValue) {
179*09537850SAkhilesh Sanikop sum += Constrain(value - pixel_value, primary_strength, damping) *
180*09537850SAkhilesh Sanikop kCdefPrimaryTaps[(primary_strength >> coeff_shift) & 1][k];
181*09537850SAkhilesh Sanikop if (clipping_required) {
182*09537850SAkhilesh Sanikop max_value = std::max(value, max_value);
183*09537850SAkhilesh Sanikop min_value = std::min(value, min_value);
184*09537850SAkhilesh Sanikop }
185*09537850SAkhilesh Sanikop }
186*09537850SAkhilesh Sanikop }
187*09537850SAkhilesh Sanikop
188*09537850SAkhilesh Sanikop if (enable_secondary) {
189*09537850SAkhilesh Sanikop static constexpr int offsets[] = {-2, 2};
190*09537850SAkhilesh Sanikop for (const int& offset : offsets) {
191*09537850SAkhilesh Sanikop const int dy = sign * kCdefDirections[direction + offset][k][0];
192*09537850SAkhilesh Sanikop const int dx = sign * kCdefDirections[direction + offset][k][1];
193*09537850SAkhilesh Sanikop const uint16_t value = src[dy * src_stride + dx + x];
194*09537850SAkhilesh Sanikop // Note: the summation can ignore the condition check in SIMD
195*09537850SAkhilesh Sanikop // implementation.
196*09537850SAkhilesh Sanikop if (value != kCdefLargeValue) {
197*09537850SAkhilesh Sanikop sum += Constrain(value - pixel_value, secondary_strength,
198*09537850SAkhilesh Sanikop damping) *
199*09537850SAkhilesh Sanikop kCdefSecondaryTaps[k];
200*09537850SAkhilesh Sanikop if (clipping_required) {
201*09537850SAkhilesh Sanikop max_value = std::max(value, max_value);
202*09537850SAkhilesh Sanikop min_value = std::min(value, min_value);
203*09537850SAkhilesh Sanikop }
204*09537850SAkhilesh Sanikop }
205*09537850SAkhilesh Sanikop }
206*09537850SAkhilesh Sanikop }
207*09537850SAkhilesh Sanikop }
208*09537850SAkhilesh Sanikop }
209*09537850SAkhilesh Sanikop
210*09537850SAkhilesh Sanikop const int offset = (8 + sum - (sum < 0)) >> 4;
211*09537850SAkhilesh Sanikop if (clipping_required) {
212*09537850SAkhilesh Sanikop dst[x] = static_cast<Pixel>(
213*09537850SAkhilesh Sanikop Clip3(pixel_value + offset, min_value, max_value));
214*09537850SAkhilesh Sanikop } else {
215*09537850SAkhilesh Sanikop dst[x] = static_cast<Pixel>(pixel_value + offset);
216*09537850SAkhilesh Sanikop }
217*09537850SAkhilesh Sanikop } while (++x < block_width);
218*09537850SAkhilesh Sanikop
219*09537850SAkhilesh Sanikop src += src_stride;
220*09537850SAkhilesh Sanikop dst += dst_stride;
221*09537850SAkhilesh Sanikop } while (--y != 0);
222*09537850SAkhilesh Sanikop }
223*09537850SAkhilesh Sanikop #endif // LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS ||
224*09537850SAkhilesh Sanikop // !defined(LIBGAV1_Dsp8bpp_CdefFilters) ||
225*09537850SAkhilesh Sanikop // (LIBGAV1_MAX_BITDEPTH >= 10 &&
226*09537850SAkhilesh Sanikop // !defined(LIBGAV1_Dsp10bpp_CdefFilters))
227*09537850SAkhilesh Sanikop // (LIBGAV1_MAX_BITDEPTH == 12 &&
228*09537850SAkhilesh Sanikop // !defined(LIBGAV1_Dsp12bpp_CdefFilters))
229*09537850SAkhilesh Sanikop
Init8bpp()230*09537850SAkhilesh Sanikop void Init8bpp() {
231*09537850SAkhilesh Sanikop Dsp* const dsp = dsp_internal::GetWritableDspTable(8);
232*09537850SAkhilesh Sanikop assert(dsp != nullptr);
233*09537850SAkhilesh Sanikop #if LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
234*09537850SAkhilesh Sanikop dsp->cdef_direction = CdefDirection_C<8, uint8_t>;
235*09537850SAkhilesh Sanikop dsp->cdef_filters[0][0] = CdefFilter_C<4, 8, uint8_t>;
236*09537850SAkhilesh Sanikop dsp->cdef_filters[0][1] = CdefFilter_C<4, 8, uint8_t, /*enable_primary=*/true,
237*09537850SAkhilesh Sanikop /*enable_secondary=*/false>;
238*09537850SAkhilesh Sanikop dsp->cdef_filters[0][2] =
239*09537850SAkhilesh Sanikop CdefFilter_C<4, 8, uint8_t, /*enable_primary=*/false>;
240*09537850SAkhilesh Sanikop dsp->cdef_filters[1][0] = CdefFilter_C<8, 8, uint8_t>;
241*09537850SAkhilesh Sanikop dsp->cdef_filters[1][1] = CdefFilter_C<8, 8, uint8_t, /*enable_primary=*/true,
242*09537850SAkhilesh Sanikop /*enable_secondary=*/false>;
243*09537850SAkhilesh Sanikop dsp->cdef_filters[1][2] =
244*09537850SAkhilesh Sanikop CdefFilter_C<8, 8, uint8_t, /*enable_primary=*/false>;
245*09537850SAkhilesh Sanikop #else // !LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
246*09537850SAkhilesh Sanikop static_cast<void>(dsp);
247*09537850SAkhilesh Sanikop #ifndef LIBGAV1_Dsp8bpp_CdefDirection
248*09537850SAkhilesh Sanikop dsp->cdef_direction = CdefDirection_C<8, uint8_t>;
249*09537850SAkhilesh Sanikop #endif
250*09537850SAkhilesh Sanikop #ifndef LIBGAV1_Dsp8bpp_CdefFilters
251*09537850SAkhilesh Sanikop dsp->cdef_filters[0][0] = CdefFilter_C<4, 8, uint8_t>;
252*09537850SAkhilesh Sanikop dsp->cdef_filters[0][1] = CdefFilter_C<4, 8, uint8_t, /*enable_primary=*/true,
253*09537850SAkhilesh Sanikop /*enable_secondary=*/false>;
254*09537850SAkhilesh Sanikop dsp->cdef_filters[0][2] =
255*09537850SAkhilesh Sanikop CdefFilter_C<4, 8, uint8_t, /*enable_primary=*/false>;
256*09537850SAkhilesh Sanikop dsp->cdef_filters[1][0] = CdefFilter_C<8, 8, uint8_t>;
257*09537850SAkhilesh Sanikop dsp->cdef_filters[1][1] = CdefFilter_C<8, 8, uint8_t, /*enable_primary=*/true,
258*09537850SAkhilesh Sanikop /*enable_secondary=*/false>;
259*09537850SAkhilesh Sanikop dsp->cdef_filters[1][2] =
260*09537850SAkhilesh Sanikop CdefFilter_C<8, 8, uint8_t, /*enable_primary=*/false>;
261*09537850SAkhilesh Sanikop #endif
262*09537850SAkhilesh Sanikop #endif // LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
263*09537850SAkhilesh Sanikop }
264*09537850SAkhilesh Sanikop
265*09537850SAkhilesh Sanikop #if LIBGAV1_MAX_BITDEPTH >= 10
Init10bpp()266*09537850SAkhilesh Sanikop void Init10bpp() {
267*09537850SAkhilesh Sanikop Dsp* const dsp = dsp_internal::GetWritableDspTable(10);
268*09537850SAkhilesh Sanikop assert(dsp != nullptr);
269*09537850SAkhilesh Sanikop #if LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
270*09537850SAkhilesh Sanikop dsp->cdef_direction = CdefDirection_C<10, uint16_t>;
271*09537850SAkhilesh Sanikop dsp->cdef_filters[0][0] = CdefFilter_C<4, 10, uint16_t>;
272*09537850SAkhilesh Sanikop dsp->cdef_filters[0][1] =
273*09537850SAkhilesh Sanikop CdefFilter_C<4, 10, uint16_t, /*enable_primary=*/true,
274*09537850SAkhilesh Sanikop /*enable_secondary=*/false>;
275*09537850SAkhilesh Sanikop dsp->cdef_filters[0][2] =
276*09537850SAkhilesh Sanikop CdefFilter_C<4, 10, uint16_t, /*enable_primary=*/false>;
277*09537850SAkhilesh Sanikop dsp->cdef_filters[1][0] = CdefFilter_C<8, 10, uint16_t>;
278*09537850SAkhilesh Sanikop dsp->cdef_filters[1][1] =
279*09537850SAkhilesh Sanikop CdefFilter_C<8, 10, uint16_t, /*enable_primary=*/true,
280*09537850SAkhilesh Sanikop /*enable_secondary=*/false>;
281*09537850SAkhilesh Sanikop dsp->cdef_filters[1][2] =
282*09537850SAkhilesh Sanikop CdefFilter_C<8, 10, uint16_t, /*enable_primary=*/false>;
283*09537850SAkhilesh Sanikop #else // !LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
284*09537850SAkhilesh Sanikop static_cast<void>(dsp);
285*09537850SAkhilesh Sanikop #ifndef LIBGAV1_Dsp10bpp_CdefDirection
286*09537850SAkhilesh Sanikop dsp->cdef_direction = CdefDirection_C<10, uint16_t>;
287*09537850SAkhilesh Sanikop #endif
288*09537850SAkhilesh Sanikop #ifndef LIBGAV1_Dsp10bpp_CdefFilters
289*09537850SAkhilesh Sanikop dsp->cdef_filters[0][0] = CdefFilter_C<4, 10, uint16_t>;
290*09537850SAkhilesh Sanikop dsp->cdef_filters[0][1] =
291*09537850SAkhilesh Sanikop CdefFilter_C<4, 10, uint16_t, /*enable_primary=*/true,
292*09537850SAkhilesh Sanikop /*enable_secondary=*/false>;
293*09537850SAkhilesh Sanikop dsp->cdef_filters[0][2] =
294*09537850SAkhilesh Sanikop CdefFilter_C<4, 10, uint16_t, /*enable_primary=*/false>;
295*09537850SAkhilesh Sanikop dsp->cdef_filters[1][0] = CdefFilter_C<8, 10, uint16_t>;
296*09537850SAkhilesh Sanikop dsp->cdef_filters[1][1] =
297*09537850SAkhilesh Sanikop CdefFilter_C<8, 10, uint16_t, /*enable_primary=*/true,
298*09537850SAkhilesh Sanikop /*enable_secondary=*/false>;
299*09537850SAkhilesh Sanikop dsp->cdef_filters[1][2] =
300*09537850SAkhilesh Sanikop CdefFilter_C<8, 10, uint16_t, /*enable_primary=*/false>;
301*09537850SAkhilesh Sanikop #endif
302*09537850SAkhilesh Sanikop #endif // LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
303*09537850SAkhilesh Sanikop }
304*09537850SAkhilesh Sanikop #endif // LIBGAV1_MAX_BITDEPTH >= 10
305*09537850SAkhilesh Sanikop
306*09537850SAkhilesh Sanikop #if LIBGAV1_MAX_BITDEPTH == 12
Init12bpp()307*09537850SAkhilesh Sanikop void Init12bpp() {
308*09537850SAkhilesh Sanikop Dsp* const dsp = dsp_internal::GetWritableDspTable(12);
309*09537850SAkhilesh Sanikop assert(dsp != nullptr);
310*09537850SAkhilesh Sanikop #if LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
311*09537850SAkhilesh Sanikop dsp->cdef_direction = CdefDirection_C<12, uint16_t>;
312*09537850SAkhilesh Sanikop dsp->cdef_filters[0][0] = CdefFilter_C<4, 12, uint16_t>;
313*09537850SAkhilesh Sanikop dsp->cdef_filters[0][1] =
314*09537850SAkhilesh Sanikop CdefFilter_C<4, 12, uint16_t, /*enable_primary=*/true,
315*09537850SAkhilesh Sanikop /*enable_secondary=*/false>;
316*09537850SAkhilesh Sanikop dsp->cdef_filters[0][2] =
317*09537850SAkhilesh Sanikop CdefFilter_C<4, 12, uint16_t, /*enable_primary=*/false>;
318*09537850SAkhilesh Sanikop dsp->cdef_filters[1][0] = CdefFilter_C<8, 12, uint16_t>;
319*09537850SAkhilesh Sanikop dsp->cdef_filters[1][1] =
320*09537850SAkhilesh Sanikop CdefFilter_C<8, 12, uint16_t, /*enable_primary=*/true,
321*09537850SAkhilesh Sanikop /*enable_secondary=*/false>;
322*09537850SAkhilesh Sanikop dsp->cdef_filters[1][2] =
323*09537850SAkhilesh Sanikop CdefFilter_C<8, 12, uint16_t, /*enable_primary=*/false>;
324*09537850SAkhilesh Sanikop #else // !LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
325*09537850SAkhilesh Sanikop static_cast<void>(dsp);
326*09537850SAkhilesh Sanikop #ifndef LIBGAV1_Dsp12bpp_CdefDirection
327*09537850SAkhilesh Sanikop dsp->cdef_direction = CdefDirection_C<12, uint16_t>;
328*09537850SAkhilesh Sanikop #endif
329*09537850SAkhilesh Sanikop #ifndef LIBGAV1_Dsp12bpp_CdefFilters
330*09537850SAkhilesh Sanikop dsp->cdef_filters[0][0] = CdefFilter_C<4, 12, uint16_t>;
331*09537850SAkhilesh Sanikop dsp->cdef_filters[0][1] =
332*09537850SAkhilesh Sanikop CdefFilter_C<4, 12, uint16_t, /*enable_primary=*/true,
333*09537850SAkhilesh Sanikop /*enable_secondary=*/false>;
334*09537850SAkhilesh Sanikop dsp->cdef_filters[0][2] =
335*09537850SAkhilesh Sanikop CdefFilter_C<4, 12, uint16_t, /*enable_primary=*/false>;
336*09537850SAkhilesh Sanikop dsp->cdef_filters[1][0] = CdefFilter_C<8, 12, uint16_t>;
337*09537850SAkhilesh Sanikop dsp->cdef_filters[1][1] =
338*09537850SAkhilesh Sanikop CdefFilter_C<8, 12, uint16_t, /*enable_primary=*/true,
339*09537850SAkhilesh Sanikop /*enable_secondary=*/false>;
340*09537850SAkhilesh Sanikop dsp->cdef_filters[1][2] =
341*09537850SAkhilesh Sanikop CdefFilter_C<8, 12, uint16_t, /*enable_primary=*/false>;
342*09537850SAkhilesh Sanikop #endif
343*09537850SAkhilesh Sanikop #endif // LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
344*09537850SAkhilesh Sanikop }
345*09537850SAkhilesh Sanikop #endif // LIBGAV1_MAX_BITDEPTH == 12
346*09537850SAkhilesh Sanikop
347*09537850SAkhilesh Sanikop } // namespace
348*09537850SAkhilesh Sanikop
CdefInit_C()349*09537850SAkhilesh Sanikop void CdefInit_C() {
350*09537850SAkhilesh Sanikop Init8bpp();
351*09537850SAkhilesh Sanikop #if LIBGAV1_MAX_BITDEPTH >= 10
352*09537850SAkhilesh Sanikop Init10bpp();
353*09537850SAkhilesh Sanikop #endif
354*09537850SAkhilesh Sanikop #if LIBGAV1_MAX_BITDEPTH == 12
355*09537850SAkhilesh Sanikop Init12bpp();
356*09537850SAkhilesh Sanikop #endif
357*09537850SAkhilesh Sanikop }
358*09537850SAkhilesh Sanikop
359*09537850SAkhilesh Sanikop } // namespace dsp
360*09537850SAkhilesh Sanikop } // namespace libgav1
361