/work/dav1d/src/lf_mask.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2018, VideoLAN and dav1d authors |
3 | | * Copyright © 2018, Two Orioles, LLC |
4 | | * All rights reserved. |
5 | | * |
6 | | * Redistribution and use in source and binary forms, with or without |
7 | | * modification, are permitted provided that the following conditions are met: |
8 | | * |
9 | | * 1. Redistributions of source code must retain the above copyright notice, this |
10 | | * list of conditions and the following disclaimer. |
11 | | * |
12 | | * 2. Redistributions in binary form must reproduce the above copyright notice, |
13 | | * this list of conditions and the following disclaimer in the documentation |
14 | | * and/or other materials provided with the distribution. |
15 | | * |
16 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
20 | | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | | */ |
27 | | |
28 | | #include "config.h" |
29 | | |
30 | | #include <string.h> |
31 | | |
32 | | #include "common/intops.h" |
33 | | |
34 | | #include "src/ctx.h" |
35 | | #include "src/internal.h" |
36 | | #include "src/levels.h" |
37 | | #include "src/lf_mask.h" |
38 | | #include "src/tables.h" |
39 | | |
40 | | #if HAVE_ASM |
41 | | #if ARCH_X86_64 |
42 | | #include "src/x86/lf_mask.h" |
43 | | #elif ARCH_AARCH64 |
44 | | #include "src/arm/lf_mask.h" |
45 | | #endif |
46 | | #endif |
47 | | |
48 | | static void decomp_tx(uint8_t (*const txa)[2 /* txsz, step */][32 /* y */][32 /* x */], |
49 | | const enum RectTxfmSize from, |
50 | | const int depth, |
51 | | const int y_off, const int x_off, |
52 | | const uint16_t *const tx_masks) |
53 | 1.91M | { |
54 | 1.91M | const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[from]; |
55 | 1.91M | const int is_split = (from == (int) TX_4X4 || depth > 1) ? 0 : |
56 | 1.91M | (tx_masks[depth] >> (y_off * 4 + x_off)) & 1; |
57 | | |
58 | 1.91M | if (is_split) { |
59 | 110k | const enum RectTxfmSize sub = t_dim->sub; |
60 | 110k | const int htw4 = t_dim->w >> 1, hth4 = t_dim->h >> 1; |
61 | | |
62 | 110k | decomp_tx(txa, sub, depth + 1, y_off * 2 + 0, x_off * 2 + 0, tx_masks); |
63 | 110k | if (t_dim->w >= t_dim->h) |
64 | 83.8k | decomp_tx((uint8_t(*)[2][32][32]) &txa[0][0][0][htw4], |
65 | 83.8k | sub, depth + 1, y_off * 2 + 0, x_off * 2 + 1, tx_masks); |
66 | 110k | if (t_dim->h >= t_dim->w) { |
67 | 81.7k | decomp_tx((uint8_t(*)[2][32][32]) &txa[0][0][hth4][0], |
68 | 81.7k | sub, depth + 1, y_off * 2 + 1, x_off * 2 + 0, tx_masks); |
69 | 81.7k | if (t_dim->w >= t_dim->h) |
70 | 55.5k | decomp_tx((uint8_t(*)[2][32][32]) &txa[0][0][hth4][htw4], |
71 | 55.5k | sub, depth + 1, y_off * 2 + 1, x_off * 2 + 1, tx_masks); |
72 | 81.7k | } |
73 | 1.80M | } else { |
74 | 1.80M | const int lw = imin(2, t_dim->lw), lh = imin(2, t_dim->lh); |
75 | | |
76 | 1.80M | #define set_ctx(rep_macro) \ |
77 | 7.68M | for (int y = 0; y < t_dim->h; y++) { \ |
78 | 5.87M | rep_macro(txa[0][0][y], 0, lw); \ |
79 | 5.87M | rep_macro(txa[1][0][y], 0, lh); \ |
80 | 5.87M | txa[0][1][y][0] = t_dim->w; \ |
81 | 5.87M | } \ |
82 | 1.80M | rep_macro(txa[1][1][0], 0, t_dim->h); |
83 | 1.80M | case_set_upto16(t_dim->lw); |
84 | 1.80M | #undef set_ctx |
85 | 1.80M | } |
86 | 1.91M | } |
87 | | |
88 | | static ALWAYS_INLINE |
89 | | void mask_edges_inter_inner(const int by4, const int bx4, |
90 | | const int w4, const int h4, |
91 | | uint16_t (*const masks)[32][3][2], |
92 | | const uint8_t txa[2][2][32][32]) |
93 | 656k | { |
94 | 656k | unsigned mask; |
95 | 656k | int x, y; |
96 | | // inner (tx) left|right edges |
97 | 3.20M | for (y = 0, mask = 1U << by4; y < h4; y++, mask <<= 1) { |
98 | 2.55M | const int sidx = mask >= 0x10000U; |
99 | 2.55M | const unsigned smask = mask >> (sidx << 4); |
100 | 2.55M | int ltx = txa[0][0][y][0]; |
101 | 2.55M | int step = txa[0][1][y][0]; |
102 | 3.04M | for (x = step; x < w4; x += step) { |
103 | 494k | const int rtx = txa[0][0][y][x]; |
104 | 494k | masks[0][bx4 + x][imin(rtx, ltx)][sidx] |= smask; |
105 | 494k | ltx = rtx; |
106 | 494k | step = txa[0][1][y][x]; |
107 | 494k | } |
108 | 2.55M | } |
109 | | |
110 | | // top |
111 | | // inner (tx) --- edges |
112 | | // bottom |
113 | 3.17M | for (x = 0, mask = 1U << bx4; x < w4; x++, mask <<= 1) { |
114 | 2.51M | const int sidx = mask >= 0x10000U; |
115 | 2.51M | const unsigned smask = mask >> (sidx << 4); |
116 | 2.51M | int ttx = txa[1][0][0][x]; |
117 | 2.51M | int step = txa[1][1][0][x]; |
118 | 2.98M | for (y = step; y < h4; y += step) { |
119 | 467k | const int btx = txa[1][0][y][x]; |
120 | 467k | masks[1][by4 + y][imin(ttx, btx)][sidx] |= smask; |
121 | 467k | ttx = btx; |
122 | 467k | step = txa[1][1][y][x]; |
123 | 467k | } |
124 | 2.51M | } |
125 | 656k | } |
126 | | |
127 | | static void mask_edges_inter_outer_c(uint8_t *const a, uint8_t *const l, |
128 | | const int by4, const int bx4, |
129 | | const int w4, const int h4, |
130 | | uint16_t (*const masks)[32][3][2], |
131 | | const uint8_t txa[2][2][32][32]) |
132 | 1.18M | { |
133 | 1.18M | int y, x; |
134 | 1.18M | unsigned mask = 1U << by4; |
135 | | // left block edge |
136 | 5.89M | for (y = 0; y < h4; y++, mask <<= 1) { |
137 | 4.70M | const int sidx = mask >= 0x10000; |
138 | 4.70M | const unsigned smask = mask >> (sidx << 4); |
139 | 4.70M | masks[0][bx4][imin(txa[0][0][y][0], l[y])][sidx] |= smask; |
140 | 4.70M | } |
141 | | |
142 | | // top block edge |
143 | 5.24M | for (x = 0, mask = 1U << bx4; x < w4; x++, mask <<= 1) { |
144 | 4.06M | const int sidx = mask >= 0x10000; |
145 | 4.06M | const unsigned smask = mask >> (sidx << 4); |
146 | 4.06M | masks[1][by4][imin(txa[1][0][0][x], a[x])][sidx] |= smask; |
147 | 4.06M | } |
148 | | |
149 | | // right block edge |
150 | 5.89M | for (y = 0; y < h4; y++) |
151 | 4.70M | l[y] = txa[0][0][y][w4 - 1]; |
152 | | // bottom block edge |
153 | 1.18M | memcpy(a, txa[1][0][h4 - 1], w4); |
154 | 1.18M | } |
155 | | |
156 | | static inline void mask_edges_intra(uint16_t (*const masks)[32][3][2], |
157 | | const int by4, const int bx4, |
158 | | const int w4, const int h4, |
159 | | const enum RectTxfmSize tx, |
160 | | uint8_t *const a, uint8_t *const l) |
161 | 3.55M | { |
162 | 3.55M | const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx]; |
163 | 3.55M | const int twl4 = t_dim->lw, thl4 = t_dim->lh; |
164 | 3.55M | const int twl4c = imin(2, twl4), thl4c = imin(2, thl4); |
165 | 3.55M | int y, x; |
166 | | |
167 | | // left block edge |
168 | 3.55M | unsigned mask = 1U << by4; |
169 | 19.7M | for (y = 0; y < h4; y++, mask <<= 1) { |
170 | 16.2M | const int sidx = mask >= 0x10000; |
171 | 16.2M | const unsigned smask = mask >> (sidx << 4); |
172 | 16.2M | masks[0][bx4][imin(twl4c, l[y])][sidx] |= smask; |
173 | 16.2M | } |
174 | | |
175 | | // top block edge |
176 | 17.7M | for (x = 0, mask = 1U << bx4; x < w4; x++, mask <<= 1) { |
177 | 14.2M | const int sidx = mask >= 0x10000; |
178 | 14.2M | const unsigned smask = mask >> (sidx << 4); |
179 | 14.2M | masks[1][by4][imin(thl4c, a[x])][sidx] |= smask; |
180 | 14.2M | } |
181 | | |
182 | | // inner (tx) left|right edges |
183 | 3.55M | const int hstep = t_dim->w; |
184 | 3.55M | unsigned t = 1U << by4; |
185 | 3.55M | unsigned inner = (unsigned) ((((uint64_t) t) << h4) - t); |
186 | 3.55M | unsigned inner1 = inner & 0xffff, inner2 = inner >> 16; |
187 | 4.35M | for (x = hstep; x < w4; x += hstep) { |
188 | 801k | if (inner1) masks[0][bx4 + x][twl4c][0] |= inner1; |
189 | 801k | if (inner2) masks[0][bx4 + x][twl4c][1] |= inner2; |
190 | 801k | } |
191 | | |
192 | | // top |
193 | | // inner (tx) --- edges |
194 | | // bottom |
195 | 3.55M | const int vstep = t_dim->h; |
196 | 3.55M | t = 1U << bx4; |
197 | 3.55M | inner = (unsigned) ((((uint64_t) t) << w4) - t); |
198 | 3.55M | inner1 = inner & 0xffff; |
199 | 3.55M | inner2 = inner >> 16; |
200 | 4.54M | for (y = vstep; y < h4; y += vstep) { |
201 | 991k | if (inner1) masks[1][by4 + y][thl4c][0] |= inner1; |
202 | 991k | if (inner2) masks[1][by4 + y][thl4c][1] |= inner2; |
203 | 991k | } |
204 | | |
205 | 3.55M | dav1d_memset_likely_pow2(a, thl4c, w4); |
206 | 3.55M | dav1d_memset_likely_pow2(l, twl4c, h4); |
207 | 3.55M | } |
208 | | |
209 | | static void mask_edges_chroma(uint16_t (*const masks)[32][2][2], |
210 | | const int cby4, const int cbx4, |
211 | | const int cw4, const int ch4, |
212 | | const int skip_inter, |
213 | | const enum RectTxfmSize tx, |
214 | | uint8_t *const a, uint8_t *const l, |
215 | | const int ss_hor, const int ss_ver) |
216 | 3.26M | { |
217 | 3.26M | const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[tx]; |
218 | 3.26M | const int twl4 = t_dim->lw, thl4 = t_dim->lh; |
219 | 3.26M | const int twl4c = !!twl4, thl4c = !!thl4; |
220 | 3.26M | int y, x; |
221 | 3.26M | const int vbits = 4 - ss_ver, hbits = 4 - ss_hor; |
222 | 3.26M | const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor; |
223 | 3.26M | const unsigned vmax = 1 << vmask, hmax = 1 << hmask; |
224 | | |
225 | | // left block edge |
226 | 3.26M | unsigned mask = 1U << cby4; |
227 | 13.6M | for (y = 0; y < ch4; y++, mask <<= 1) { |
228 | 10.3M | const int sidx = mask >= vmax; |
229 | 10.3M | const unsigned smask = mask >> (sidx << vbits); |
230 | 10.3M | masks[0][cbx4][imin(twl4c, l[y])][sidx] |= smask; |
231 | 10.3M | } |
232 | | |
233 | | // top block edge |
234 | 12.7M | for (x = 0, mask = 1U << cbx4; x < cw4; x++, mask <<= 1) { |
235 | 9.49M | const int sidx = mask >= hmax; |
236 | 9.49M | const unsigned smask = mask >> (sidx << hbits); |
237 | 9.49M | masks[1][cby4][imin(thl4c, a[x])][sidx] |= smask; |
238 | 9.49M | } |
239 | | |
240 | 3.26M | if (!skip_inter) { |
241 | | // inner (tx) left|right edges |
242 | 2.93M | const int hstep = t_dim->w; |
243 | 2.93M | unsigned t = 1U << cby4; |
244 | 2.93M | unsigned inner = (unsigned) ((((uint64_t) t) << ch4) - t); |
245 | 2.93M | unsigned inner1 = inner & ((1 << vmask) - 1), inner2 = inner >> vmask; |
246 | 3.17M | for (x = hstep; x < cw4; x += hstep) { |
247 | 238k | if (inner1) masks[0][cbx4 + x][twl4c][0] |= inner1; |
248 | 238k | if (inner2) masks[0][cbx4 + x][twl4c][1] |= inner2; |
249 | 238k | } |
250 | | |
251 | | // top |
252 | | // inner (tx) --- edges |
253 | | // bottom |
254 | 2.93M | const int vstep = t_dim->h; |
255 | 2.93M | t = 1U << cbx4; |
256 | 2.93M | inner = (unsigned) ((((uint64_t) t) << cw4) - t); |
257 | 2.93M | inner1 = inner & ((1 << hmask) - 1), inner2 = inner >> hmask; |
258 | 3.22M | for (y = vstep; y < ch4; y += vstep) { |
259 | 295k | if (inner1) masks[1][cby4 + y][thl4c][0] |= inner1; |
260 | 295k | if (inner2) masks[1][cby4 + y][thl4c][1] |= inner2; |
261 | 295k | } |
262 | 2.93M | } |
263 | | |
264 | 3.26M | dav1d_memset_likely_pow2(a, thl4c, cw4); |
265 | 3.26M | dav1d_memset_likely_pow2(l, twl4c, ch4); |
266 | 3.26M | } |
267 | | |
268 | | static void fill_levelcache_block_c(uint8_t (*level_cache_ptr)[2], |
269 | | const ptrdiff_t b_stride, |
270 | | const int bw, const int bh, |
271 | | const unsigned v0, |
272 | | const unsigned v1) |
273 | 7.98M | { |
274 | 7.98M | assert(bw > 0 && bw <= 32); |
275 | 7.98M | assert(((uintptr_t)level_cache_ptr & 1) == 0); |
276 | 7.98M | union alias16 v = (union alias16) { .u8 = { v0, v1 }}; |
277 | | |
278 | 39.2M | for (int y = 0; y < bh; y++) { |
279 | 226M | for (int x = 0; x < bw; x++) |
280 | 194M | ((union alias16 *) &level_cache_ptr[x][0])->u16 = v.u16; |
281 | 31.2M | level_cache_ptr += b_stride; |
282 | 31.2M | } |
283 | 7.98M | } |
284 | | |
285 | | void dav1d_create_lf_mask_intra(const Dav1dLfMaskDSPContext* dsp, |
286 | | Av1Filter *const lflvl, |
287 | | uint8_t (*const level_cache[2])[2], |
288 | | const ptrdiff_t b4_stride, |
289 | | const uint8_t (*filter_level)[8][2], |
290 | | const int bx, const int by, |
291 | | const int iw, const int ih, |
292 | | const enum BlockSize bs, |
293 | | const enum RectTxfmSize ytx, |
294 | | const enum RectTxfmSize uvtx, |
295 | | const enum Dav1dPixelLayout layout, |
296 | | uint8_t *const ay, uint8_t *const ly, |
297 | | uint8_t *const auv, uint8_t *const luv) |
298 | 3.92M | { |
299 | 3.92M | const uint8_t *const b_dim = dav1d_block_dimensions[bs]; |
300 | 3.92M | const int bw4 = imin(iw - bx, b_dim[0]); |
301 | 3.92M | const int bh4 = imin(ih - by, b_dim[1]); |
302 | 3.92M | const int bx4 = bx & 31; |
303 | 3.92M | const int by4 = by & 31; |
304 | 3.92M | assert(bw4 >= 0 && bh4 >= 0); |
305 | | |
306 | 3.92M | if (bw4 && bh4) { |
307 | 3.54M | uint8_t (*level_cache_ptr)[2] = level_cache[0] + by * b4_stride + bx; |
308 | | |
309 | 3.54M | dsp->fill_levelcache_block(level_cache_ptr, b4_stride, bw4, bh4, |
310 | 3.54M | filter_level[0][0][0], filter_level[1][0][0]); |
311 | 3.54M | mask_edges_intra(lflvl->filter_y, by4, bx4, bw4, bh4, ytx, ay, ly); |
312 | 3.54M | } |
313 | | |
314 | 3.92M | if (!auv) return; |
315 | | |
316 | 2.69M | const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420; |
317 | 2.69M | const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444; |
318 | 2.69M | const int cbw4 = imin(((iw + ss_hor) >> ss_hor) - (bx >> ss_hor), |
319 | 2.69M | (b_dim[0] + ss_hor) >> ss_hor); |
320 | 2.69M | const int cbh4 = imin(((ih + ss_ver) >> ss_ver) - (by >> ss_ver), |
321 | 2.69M | (b_dim[1] + ss_ver) >> ss_ver); |
322 | 2.69M | assert(cbw4 >= 0 && cbh4 >= 0); |
323 | | |
324 | 2.69M | if (!cbw4 || !cbh4) return; |
325 | | |
326 | 2.57M | const int cbx4 = bx4 >> ss_hor; |
327 | 2.57M | const int cby4 = by4 >> ss_ver; |
328 | | |
329 | 2.57M | uint8_t (*level_cache_ptr)[2] = |
330 | 2.57M | level_cache[1] + (by >> ss_ver) * b4_stride + (bx >> ss_hor); |
331 | | |
332 | 2.57M | dsp->fill_levelcache_block(level_cache_ptr, b4_stride, cbw4, cbh4, |
333 | 2.57M | filter_level[2][0][0], filter_level[3][0][0]); |
334 | 2.57M | mask_edges_chroma(lflvl->filter_uv, cby4, cbx4, cbw4, cbh4, 0, uvtx, |
335 | 2.57M | auv, luv, ss_hor, ss_ver); |
336 | 2.57M | } |
337 | | |
338 | | void dav1d_create_lf_mask_inter(Dav1dTaskContext *const t, |
339 | | uint8_t (*const level_cache[2])[2], |
340 | | const ptrdiff_t b4_stride, |
341 | | const uint8_t (*filter_level)[8][2], |
342 | | const int iw, const int ih, |
343 | | const int skip, const enum BlockSize bs, |
344 | | const enum RectTxfmSize max_ytx, |
345 | | const uint16_t *const tx_masks, |
346 | | const enum RectTxfmSize uvtx, |
347 | | const enum Dav1dPixelLayout layout, |
348 | | uint8_t *const ay, uint8_t *const ly, |
349 | | uint8_t *const auv, uint8_t *const luv) |
350 | 1.23M | { |
351 | 1.23M | const Dav1dLfMaskDSPContext *const dsp = &t->c->lf_mask_dsp; |
352 | 1.23M | Av1Filter *const lflvl = t->lf_mask; |
353 | 1.23M | const int bx = t->bx, by = t->by; |
354 | 1.23M | const uint8_t *const b_dim = dav1d_block_dimensions[bs]; |
355 | 1.23M | const int bw4 = imin(iw - bx, b_dim[0]); |
356 | 1.23M | const int bh4 = imin(ih - by, b_dim[1]); |
357 | 1.23M | const int bx4 = bx & 31; |
358 | 1.23M | const int by4 = by & 31; |
359 | 1.23M | assert(bw4 >= 0 && bh4 >= 0); |
360 | | |
361 | 1.23M | if (bw4 && bh4) { |
362 | 1.18M | uint8_t (*level_cache_ptr)[2] = level_cache[0] + by * b4_stride + bx; |
363 | | |
364 | 1.18M | dsp->fill_levelcache_block(level_cache_ptr, b4_stride, bw4, bh4, |
365 | 1.18M | filter_level[0][0][0], filter_level[1][0][0]); |
366 | | |
367 | 1.18M | const TxfmInfo *const t_dim = &dav1d_txfm_dimensions[max_ytx]; |
368 | 1.18M | uint8_t (*const txa)[2][32][32] = t->scratch.txa; |
369 | 2.43M | for (int y_off = 0, y = 0; y < bh4; y += t_dim->h, y_off++) |
370 | 2.84M | for (int x_off = 0, x = 0; x < bw4; x += t_dim->w, x_off++) |
371 | 1.58M | decomp_tx((uint8_t(*)[2][32][32]) &txa[0][0][y][x], |
372 | 1.58M | max_ytx, 0, y_off, x_off, tx_masks); |
373 | | |
374 | 1.18M | dsp->mask_edges_inter_outer(ay, ly, by4, bx4, bw4, bh4, lflvl->filter_y, txa); |
375 | 1.18M | if (!skip) |
376 | 656k | mask_edges_inter_inner(by4, bx4, bw4, bh4, lflvl->filter_y, txa); |
377 | 1.18M | } |
378 | | |
379 | 1.23M | if (!auv) return; |
380 | | |
381 | 699k | const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420; |
382 | 699k | const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444; |
383 | 699k | const int cbw4 = imin(((iw + ss_hor) >> ss_hor) - (bx >> ss_hor), |
384 | 699k | (b_dim[0] + ss_hor) >> ss_hor); |
385 | 699k | const int cbh4 = imin(((ih + ss_ver) >> ss_ver) - (by >> ss_ver), |
386 | 699k | (b_dim[1] + ss_ver) >> ss_ver); |
387 | 699k | assert(cbw4 >= 0 && cbh4 >= 0); |
388 | | |
389 | 699k | if (!cbw4 || !cbh4) return; |
390 | | |
391 | 692k | const int cbx4 = bx4 >> ss_hor; |
392 | 692k | const int cby4 = by4 >> ss_ver; |
393 | | |
394 | 692k | uint8_t (*level_cache_ptr)[2] = |
395 | 692k | level_cache[1] + (by >> ss_ver) * b4_stride + (bx >> ss_hor); |
396 | | |
397 | 692k | dsp->fill_levelcache_block(level_cache_ptr, b4_stride, cbw4, cbh4, |
398 | 692k | filter_level[2][0][0], filter_level[3][0][0]); |
399 | 692k | mask_edges_chroma(lflvl->filter_uv, cby4, cbx4, cbw4, cbh4, skip, uvtx, |
400 | 692k | auv, luv, ss_hor, ss_ver); |
401 | 692k | } |
402 | | |
403 | 154k | void dav1d_calc_eih(Av1FilterLUT *const lim_lut, const int filter_sharpness) { |
404 | | // set E/I/H values from loopfilter level |
405 | 154k | const int sharp = filter_sharpness; |
406 | 10.0M | for (int level = 0; level < 64; level++) { |
407 | 9.88M | int limit = level; |
408 | | |
409 | 9.88M | if (sharp > 0) { |
410 | 5.38M | limit >>= (sharp + 3) >> 2; |
411 | 5.38M | limit = imin(limit, 9 - sharp); |
412 | 5.38M | } |
413 | 9.88M | limit = imax(limit, 1); |
414 | | |
415 | 9.88M | lim_lut->i[level] = limit; |
416 | 9.88M | lim_lut->e[level] = 2 * (level + 2) + limit; |
417 | 9.88M | } |
418 | 154k | lim_lut->sharp[0] = (sharp + 3) >> 2; |
419 | 154k | lim_lut->sharp[1] = sharp ? 9 - sharp : 0xff; |
420 | 154k | } |
421 | | |
422 | | static void calc_lf_value(uint8_t (*const lflvl_values)[2], |
423 | | const int base_lvl, const int lf_delta, |
424 | | const int seg_delta, |
425 | | const Dav1dLoopfilterModeRefDeltas *const mr_delta) |
426 | 2.66M | { |
427 | 2.66M | const int base = iclip(iclip(base_lvl + lf_delta, 0, 63) + seg_delta, 0, 63); |
428 | | |
429 | 2.66M | if (!mr_delta) { |
430 | 1.33M | memset(lflvl_values, base, sizeof(*lflvl_values) * 8); |
431 | 1.33M | } else { |
432 | 1.33M | const int sh = base >= 32; |
433 | 1.33M | lflvl_values[0][0] = lflvl_values[0][1] = |
434 | 1.33M | iclip(base + (mr_delta->ref_delta[0] * (1 << sh)), 0, 63); |
435 | 10.6M | for (int r = 1; r < 8; r++) { |
436 | 27.9M | for (int m = 0; m < 2; m++) { |
437 | 18.6M | const int delta = |
438 | 18.6M | mr_delta->mode_delta[m] + mr_delta->ref_delta[r]; |
439 | 18.6M | lflvl_values[r][m] = iclip(base + (delta * (1 << sh)), 0, 63); |
440 | 18.6M | } |
441 | 9.33M | } |
442 | 1.33M | } |
443 | 2.66M | } |
444 | | |
445 | | static inline void calc_lf_value_chroma(uint8_t (*const lflvl_values)[2], |
446 | | const int base_lvl, const int lf_delta, |
447 | | const int seg_delta, |
448 | | const Dav1dLoopfilterModeRefDeltas *const mr_delta) |
449 | 1.53M | { |
450 | 1.53M | if (!base_lvl) |
451 | 393k | memset(lflvl_values, 0, sizeof(*lflvl_values) * 8); |
452 | 1.13M | else |
453 | 1.13M | calc_lf_value(lflvl_values, base_lvl, lf_delta, seg_delta, mr_delta); |
454 | 1.53M | } |
455 | | |
456 | | void dav1d_calc_lf_values(uint8_t (*const lflvl_values)[4][8][2], |
457 | | const Dav1dFrameHeader *const hdr, |
458 | | const int8_t lf_delta[4]) |
459 | 225k | { |
460 | 225k | const int n_seg = hdr->segmentation.enabled ? 8 : 1; |
461 | | |
462 | 225k | if (!hdr->loopfilter.level_y[0] && !hdr->loopfilter.level_y[1]) { |
463 | 46.9k | memset(lflvl_values, 0, sizeof(*lflvl_values) * n_seg); |
464 | 46.9k | return; |
465 | 46.9k | } |
466 | | |
467 | 178k | const Dav1dLoopfilterModeRefDeltas *const mr_deltas = |
468 | 178k | hdr->loopfilter.mode_ref_delta_enabled ? |
469 | 178k | &hdr->loopfilter.mode_ref_deltas : NULL; |
470 | 944k | for (int s = 0; s < n_seg; s++) { |
471 | 765k | const Dav1dSegmentationData *const segd = |
472 | 765k | hdr->segmentation.enabled ? &hdr->segmentation.seg_data.d[s] : NULL; |
473 | | |
474 | 765k | calc_lf_value(lflvl_values[s][0], hdr->loopfilter.level_y[0], |
475 | 765k | lf_delta[0], segd ? segd->delta_lf_y_v : 0, mr_deltas); |
476 | 765k | calc_lf_value(lflvl_values[s][1], hdr->loopfilter.level_y[1], |
477 | 765k | lf_delta[hdr->delta.lf.multi ? 1 : 0], |
478 | 765k | segd ? segd->delta_lf_y_h : 0, mr_deltas); |
479 | 765k | calc_lf_value_chroma(lflvl_values[s][2], hdr->loopfilter.level_u, |
480 | 765k | lf_delta[hdr->delta.lf.multi ? 2 : 0], |
481 | 765k | segd ? segd->delta_lf_u : 0, mr_deltas); |
482 | 765k | calc_lf_value_chroma(lflvl_values[s][3], hdr->loopfilter.level_v, |
483 | 765k | lf_delta[hdr->delta.lf.multi ? 3 : 0], |
484 | 765k | segd ? segd->delta_lf_v : 0, mr_deltas); |
485 | 765k | } |
486 | 178k | } |
487 | | |
488 | | COLD void dav1d_lf_mask_dsp_init(Dav1dLfMaskDSPContext *const c) |
489 | 100k | { |
490 | 100k | c->fill_levelcache_block = fill_levelcache_block_c; |
491 | 100k | c->mask_edges_inter_outer = mask_edges_inter_outer_c; |
492 | | #if HAVE_ASM |
493 | | #if ARCH_X86_64 |
494 | | lf_mask_dsp_init_x86(c); |
495 | | #elif ARCH_AARCH64 |
496 | | lf_mask_dsp_init_arm(c); |
497 | | #endif |
498 | | #endif |
499 | 100k | } |