Coverage Report

Created: 2026-12-01 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/filmgrain_tmpl.c
Line
Count
Source
1
/*
2
 * Copyright © 2018, Niklas Haas
3
 * Copyright © 2018, VideoLAN and dav1d authors
4
 * Copyright © 2018, Two Orioles, LLC
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions are met:
9
 *
10
 * 1. Redistributions of source code must retain the above copyright notice, this
11
 *    list of conditions and the following disclaimer.
12
 *
13
 * 2. Redistributions in binary form must reproduce the above copyright notice,
14
 *    this list of conditions and the following disclaimer in the documentation
15
 *    and/or other materials provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
29
#include "common/attributes.h"
30
#include "common/intops.h"
31
32
#include "src/filmgrain.h"
33
#include "src/tables.h"
34
35
3.19k
#define SUB_GRAIN_WIDTH 44
36
1.93k
#define SUB_GRAIN_HEIGHT 38
37
38
31.1M
static inline int get_random_number(const int bits, unsigned *const state) {
39
31.1M
    const int r = *state;
40
31.1M
    unsigned bit = ((r >> 0) ^ (r >> 1) ^ (r >> 3) ^ (r >> 12)) & 1;
41
31.1M
    *state = (r >> 1) | (bit << 15);
42
43
31.1M
    return (*state >> (16 - bits)) & ((1 << bits) - 1);
44
31.1M
}
45
46
95.6M
static inline int round2(const int x, const uint64_t shift) {
47
95.6M
    return (x + ((1 << shift) >> 1)) >> shift;
48
95.6M
}
49
50
static void generate_grain_y_c(entry buf[][GRAIN_WIDTH],
51
                               const Dav1dFilmGrainData *const data
52
                               HIGHBD_DECL_SUFFIX)
53
3.08k
{
54
3.08k
    const int bitdepth_min_8 = bitdepth_from_max(bitdepth_max) - 8;
55
3.08k
    unsigned seed = data->seed;
56
3.08k
    const int shift = 4 - bitdepth_min_8 + data->grain_scale_shift;
57
3.08k
    const int grain_ctr = 128 << bitdepth_min_8;
58
3.08k
    const int grain_min = -grain_ctr, grain_max = grain_ctr - 1;
59
60
228k
    for (int y = 0; y < GRAIN_HEIGHT; y++) {
61
18.7M
        for (int x = 0; x < GRAIN_WIDTH; x++) {
62
18.4M
            const int value = get_random_number(11, &seed);
63
18.4M
            buf[y][x] = round2(dav1d_gaussian_sequence[ value ], shift);
64
18.4M
        }
65
225k
    }
66
67
3.08k
    const int ar_pad = 3;
68
3.08k
    const int ar_lag = data->ar_coeff_lag;
69
70
219k
    for (int y = ar_pad; y < GRAIN_HEIGHT; y++) {
71
16.6M
        for (int x = ar_pad; x < GRAIN_WIDTH - ar_pad; x++) {
72
16.4M
            const int8_t *coeff = data->ar_coeffs_y;
73
16.4M
            int sum = 0;
74
52.7M
            for (int dy = -ar_lag; dy <= 0; dy++) {
75
153M
                for (int dx = -ar_lag; dx <= ar_lag; dx++) {
76
133M
                    if (!dx && !dy)
77
16.4M
                        break;
78
117M
                    sum += *(coeff++) * buf[y + dy][x + dx];
79
117M
                }
80
36.2M
            }
81
82
16.4M
            const int grain = buf[y][x] + round2(sum, data->ar_coeff_shift);
83
16.4M
            buf[y][x] = iclip(grain, grain_min, grain_max);
84
16.4M
        }
85
216k
    }
86
3.08k
}
87
88
static NOINLINE void
89
generate_grain_uv_c(entry buf[][GRAIN_WIDTH],
90
                    const entry buf_y[][GRAIN_WIDTH],
91
                    const Dav1dFilmGrainData *const data, const intptr_t uv,
92
                    const int subx, const int suby HIGHBD_DECL_SUFFIX)
93
4.06k
{
94
4.06k
    const int bitdepth_min_8 = bitdepth_from_max(bitdepth_max) - 8;
95
4.06k
    unsigned seed = data->seed ^ (uv ? 0x49d8 : 0xb524);
96
4.06k
    const int shift = 4 - bitdepth_min_8 + data->grain_scale_shift;
97
4.06k
    const int grain_ctr = 128 << bitdepth_min_8;
98
4.06k
    const int grain_min = -grain_ctr, grain_max = grain_ctr - 1;
99
100
4.06k
    const int chromaW = subx ? SUB_GRAIN_WIDTH  : GRAIN_WIDTH;
101
4.06k
    const int chromaH = suby ? SUB_GRAIN_HEIGHT : GRAIN_HEIGHT;
102
103
232k
    for (int y = 0; y < chromaH; y++) {
104
12.6M
        for (int x = 0; x < chromaW; x++) {
105
12.4M
            const int value = get_random_number(11, &seed);
106
12.4M
            buf[y][x] = round2(dav1d_gaussian_sequence[ value ], shift);
107
12.4M
        }
108
228k
    }
109
110
4.06k
    const int ar_pad = 3;
111
4.06k
    const int ar_lag = data->ar_coeff_lag;
112
113
220k
    for (int y = ar_pad; y < chromaH; y++) {
114
10.7M
        for (int x = ar_pad; x < chromaW - ar_pad; x++) {
115
10.5M
            const int8_t *coeff = data->ar_coeffs_uv[uv];
116
10.5M
            int sum = 0;
117
34.7M
            for (int dy = -ar_lag; dy <= 0; dy++) {
118
108M
                for (int dx = -ar_lag; dx <= ar_lag; dx++) {
119
                    // For the final (current) pixel, we need to add in the
120
                    // contribution from the luma grain texture
121
94.7M
                    if (!dx && !dy) {
122
10.5M
                        if (!data->num_y_points)
123
4.76M
                            break;
124
5.75M
                        int luma = 0;
125
5.75M
                        const int lumaX = ((x - ar_pad) << subx) + ar_pad;
126
5.75M
                        const int lumaY = ((y - ar_pad) << suby) + ar_pad;
127
13.5M
                        for (int i = 0; i <= suby; i++) {
128
21.5M
                            for (int j = 0; j <= subx; j++) {
129
13.6M
                                luma += buf_y[lumaY + i][lumaX + j];
130
13.6M
                            }
131
7.83M
                        }
132
5.75M
                        luma = round2(luma, subx + suby);
133
5.75M
                        sum += luma * (*coeff);
134
5.75M
                        break;
135
10.5M
                    }
136
137
84.1M
                    sum += *(coeff++) * buf[y + dy][x + dx];
138
84.1M
                }
139
24.2M
            }
140
141
10.5M
            const int grain = buf[y][x] + round2(sum, data->ar_coeff_shift);
142
10.5M
            buf[y][x] = iclip(grain, grain_min, grain_max);
143
10.5M
        }
144
216k
    }
145
4.06k
}
146
147
#define gnuv_ss_fn(nm, ss_x, ss_y) \
148
4.06k
static decl_generate_grain_uv_fn(generate_grain_uv_##nm##_c) { \
149
4.06k
    generate_grain_uv_c(buf, buf_y, data, uv, ss_x, ss_y HIGHBD_TAIL_SUFFIX); \
150
4.06k
}
filmgrain_tmpl.c:generate_grain_uv_420_c
Line
Count
Source
148
1.93k
static decl_generate_grain_uv_fn(generate_grain_uv_##nm##_c) { \
149
1.93k
    generate_grain_uv_c(buf, buf_y, data, uv, ss_x, ss_y HIGHBD_TAIL_SUFFIX); \
150
1.93k
}
filmgrain_tmpl.c:generate_grain_uv_422_c
Line
Count
Source
148
1.26k
static decl_generate_grain_uv_fn(generate_grain_uv_##nm##_c) { \
149
1.26k
    generate_grain_uv_c(buf, buf_y, data, uv, ss_x, ss_y HIGHBD_TAIL_SUFFIX); \
150
1.26k
}
filmgrain_tmpl.c:generate_grain_uv_444_c
Line
Count
Source
148
863
static decl_generate_grain_uv_fn(generate_grain_uv_##nm##_c) { \
149
863
    generate_grain_uv_c(buf, buf_y, data, uv, ss_x, ss_y HIGHBD_TAIL_SUFFIX); \
150
863
}
151
152
gnuv_ss_fn(420, 1, 1);
153
gnuv_ss_fn(422, 1, 0);
154
gnuv_ss_fn(444, 0, 0);
155
156
// samples from the correct block of a grain LUT, while taking into account the
157
// offsets provided by the offsets cache
158
static inline entry sample_lut(const entry grain_lut[][GRAIN_WIDTH],
159
                               const int offsets[2][2], const int subx, const int suby,
160
                               const int bx, const int by, const int x, const int y)
161
32.6M
{
162
32.6M
    const int randval = offsets[bx][by];
163
32.6M
    const int offx = 3 + (2 >> subx) * (3 + (randval >> 4));
164
32.6M
    const int offy = 3 + (2 >> suby) * (3 + (randval & 0xF));
165
32.6M
    return grain_lut[offy + y + (FG_BLOCK_SIZE >> suby) * by]
166
32.6M
                    [offx + x + (FG_BLOCK_SIZE >> subx) * bx];
167
32.6M
}
168
169
static void fgy_32x32xn_c(pixel *const dst_row, const pixel *const src_row,
170
                          const ptrdiff_t stride,
171
                          const Dav1dFilmGrainData *const data, const size_t pw,
172
                          const uint8_t scaling[SCALING_SIZE],
173
                          const entry grain_lut[][GRAIN_WIDTH],
174
                          const int bh, const int row_num HIGHBD_DECL_SUFFIX)
175
10.3k
{
176
10.3k
    const int rows = 1 + (data->overlap_flag && row_num > 0);
177
10.3k
    const int bitdepth_min_8 = bitdepth_from_max(bitdepth_max) - 8;
178
10.3k
    const int grain_ctr = 128 << bitdepth_min_8;
179
10.3k
    const int grain_min = -grain_ctr, grain_max = grain_ctr - 1;
180
181
10.3k
    int min_value, max_value;
182
10.3k
    if (data->clip_to_restricted_range) {
183
4.53k
        min_value = 16 << bitdepth_min_8;
184
4.53k
        max_value = 235 << bitdepth_min_8;
185
5.85k
    } else {
186
5.85k
        min_value = 0;
187
5.85k
        max_value = BITDEPTH_MAX;
188
5.85k
    }
189
190
    // seed[0] contains the current row, seed[1] contains the previous
191
10.3k
    unsigned seed[2];
192
27.6k
    for (int i = 0; i < rows; i++) {
193
17.2k
        seed[i] = data->seed;
194
17.2k
        seed[i] ^= (((row_num - i) * 37  + 178) & 0xFF) << 8;
195
17.2k
        seed[i] ^= (((row_num - i) * 173 + 105) & 0xFF);
196
17.2k
    }
197
198
10.3k
    assert(stride % (FG_BLOCK_SIZE * sizeof(pixel)) == 0);
199
10.3k
    const ptrdiff_t pxstride = PXSTRIDE(stride);
200
201
10.3k
    int offsets[2 /* col offset */][2 /* row offset */];
202
203
    // process this row in FG_BLOCK_SIZE^2 blocks
204
49.3k
    for (unsigned bx = 0; bx < pw; bx += FG_BLOCK_SIZE) {
205
38.9k
        const int bw = imin(FG_BLOCK_SIZE, (int) pw - bx);
206
207
38.9k
        if (data->overlap_flag && bx) {
208
            // shift previous offsets left
209
58.1k
            for (int i = 0; i < rows; i++)
210
37.9k
                offsets[1][i] = offsets[0][i];
211
20.1k
        }
212
213
        // update current offsets
214
102k
        for (int i = 0; i < rows; i++)
215
63.2k
            offsets[0][i] = get_random_number(8, &seed[i]);
216
217
        // x/y block offsets to compensate for overlapped regions
218
38.9k
        const int ystart = data->overlap_flag && row_num ? imin(2, bh) : 0;
219
38.9k
        const int xstart = data->overlap_flag && bx      ? imin(2, bw) : 0;
220
221
38.9k
        static const int w[2][2] = { { 27, 17 }, { 17, 27 } };
222
223
38.9k
#define add_noise_y(x, grain)                                                     \
224
10.2M
        const int noise = round2(scaling[src[x]] * (grain), data->scaling_shift); \
225
10.2M
        dst[x] = iclip(src[x] + noise, min_value, max_value);
226
227
38.9k
        const pixel *src = src_row + bx;
228
38.9k
        pixel *dst = dst_row + bx;
229
230
86.6k
        for (int y = 0; y < ystart; y++, src += pxstride, dst += pxstride) {
231
            // Special case for doubly-overlapped corner
232
115k
            for (int x = 0; x < xstart; x++) {
233
                // Blend the top pixel with the top left block
234
67.6k
                int top = sample_lut(grain_lut, offsets, 0, 0, 0, 1, x, y);
235
67.6k
                int old = sample_lut(grain_lut, offsets, 0, 0, 1, 1, x, y);
236
67.6k
                top = round2(old * w[x][0] + top * w[x][1], 5);
237
67.6k
                top = iclip(top, grain_min, grain_max);
238
239
                // Blend the current pixel with the left block
240
67.6k
                int grain = sample_lut(grain_lut, offsets, 0, 0, 0, 0, x, y);
241
67.6k
                old = sample_lut(grain_lut, offsets, 0, 0, 1, 0, x, y);
242
67.6k
                grain = round2(old * w[x][0] + grain * w[x][1], 5);
243
67.6k
                grain = iclip(grain, grain_min, grain_max);
244
245
                // Mix the row rows together and apply grain
246
67.6k
                grain = round2(top * w[y][0] + grain * w[y][1], 5);
247
67.6k
                grain = iclip(grain, grain_min, grain_max);
248
67.6k
                add_noise_y(x, grain);
249
67.6k
            }
250
251
            // Special case for overlapped row (sans corner)
252
949k
            for (int x = xstart; x < bw; x++) {
253
902k
                int grain = sample_lut(grain_lut, offsets, 0, 0, 0, 0, x, y);
254
902k
                int old   = sample_lut(grain_lut, offsets, 0, 0, 0, 1, x, y);
255
902k
                grain = round2(old * w[y][0] + grain * w[y][1], 5);
256
902k
                grain = iclip(grain, grain_min, grain_max);
257
902k
                add_noise_y(x, grain);
258
902k
            }
259
47.7k
        }
260
261
951k
        for (int y = ystart; y < bh; y++, src += pxstride, dst += pxstride) {
262
            // Special case for overlapped column
263
1.76M
            for (int x = 0; x < xstart; x++) {
264
854k
                int grain = sample_lut(grain_lut, offsets, 0, 0, 0, 0, x, y);
265
854k
                int old   = sample_lut(grain_lut, offsets, 0, 0, 1, 0, x, y);
266
854k
                grain = round2(old * w[x][0] + grain * w[x][1], 5);
267
854k
                grain = iclip(grain, grain_min, grain_max);
268
854k
                add_noise_y(x, grain);
269
854k
            }
270
271
            // Non-overlapped image region (straightforward)
272
9.34M
            for (int x = xstart; x < bw; x++) {
273
8.43M
                int grain = sample_lut(grain_lut, offsets, 0, 0, 0, 0, x, y);
274
8.43M
                add_noise_y(x, grain);
275
8.43M
            }
276
913k
        }
277
38.9k
#undef add_noise_y
278
38.9k
    }
279
10.3k
}
280
281
static NOINLINE void
282
fguv_32x32xn_c(pixel *const dst_row, const pixel *const src_row,
283
               const ptrdiff_t stride, const Dav1dFilmGrainData *const data,
284
               const size_t pw, const uint8_t scaling[SCALING_SIZE],
285
               const entry grain_lut[][GRAIN_WIDTH], const int bh,
286
               const int row_num, const pixel *const luma_row,
287
               const ptrdiff_t luma_stride, const int uv, const int is_id,
288
               const int sx, const int sy HIGHBD_DECL_SUFFIX)
289
16.2k
{
290
16.2k
    const int rows = 1 + (data->overlap_flag && row_num > 0);
291
16.2k
    const int bitdepth_min_8 = bitdepth_from_max(bitdepth_max) - 8;
292
16.2k
    const int grain_ctr = 128 << bitdepth_min_8;
293
16.2k
    const int grain_min = -grain_ctr, grain_max = grain_ctr - 1;
294
295
16.2k
    int min_value, max_value;
296
16.2k
    if (data->clip_to_restricted_range) {
297
10.1k
        min_value = 16 << bitdepth_min_8;
298
10.1k
        max_value = (is_id ? 235 : 240) << bitdepth_min_8;
299
10.1k
    } else {
300
6.16k
        min_value = 0;
301
6.16k
        max_value = BITDEPTH_MAX;
302
6.16k
    }
303
304
    // seed[0] contains the current row, seed[1] contains the previous
305
16.2k
    unsigned seed[2];
306
40.5k
    for (int i = 0; i < rows; i++) {
307
24.2k
        seed[i] = data->seed;
308
24.2k
        seed[i] ^= (((row_num - i) * 37  + 178) & 0xFF) << 8;
309
24.2k
        seed[i] ^= (((row_num - i) * 173 + 105) & 0xFF);
310
24.2k
    }
311
312
16.2k
    assert(stride % (FG_BLOCK_SIZE * sizeof(pixel)) == 0);
313
16.2k
    const ptrdiff_t pxstride = PXSTRIDE(stride);
314
16.2k
    const ptrdiff_t luma_pxstride = PXSTRIDE(luma_stride) << sy;
315
316
16.2k
    int offsets[2 /* col offset */][2 /* row offset */];
317
318
    // process this row in FG_BLOCK_SIZE^2 blocks (subsampled)
319
145k
    for (unsigned bx = 0; bx < pw; bx += FG_BLOCK_SIZE >> sx) {
320
129k
        const int bw = imin(FG_BLOCK_SIZE >> sx, (int)(pw - bx));
321
129k
        if (data->overlap_flag && bx) {
322
            // shift previous offsets left
323
74.3k
            for (int i = 0; i < rows; i++)
324
48.1k
                offsets[1][i] = offsets[0][i];
325
26.2k
        }
326
327
        // update current offsets
328
287k
        for (int i = 0; i < rows; i++)
329
158k
            offsets[0][i] = get_random_number(8, &seed[i]);
330
331
        // x/y block offsets to compensate for overlapped regions
332
129k
        const int ystart = data->overlap_flag && row_num ? imin(2 >> sy, bh) : 0;
333
129k
        const int xstart = data->overlap_flag && bx      ? imin(2 >> sx, bw) : 0;
334
335
129k
        static const int w[2 /* sub */][2 /* off */][2] = {
336
129k
            { { 27, 17 }, { 17, 27 } },
337
129k
            { { 23, 22 } },
338
129k
        };
339
340
129k
#define add_noise_uv(x, grain)                                                       \
341
27.5M
            const pixel *const luma_src = luma + ((x) << sx);                        \
342
27.5M
            pixel avg = luma_src[0];                                                 \
343
27.5M
            if (sx)                                                                  \
344
27.5M
                avg = (avg + luma_src[1] + 1) >> 1;                                  \
345
27.5M
            int val = avg;                                                           \
346
27.5M
            if (!data->chroma_scaling_from_luma) {                                   \
347
5.06M
                const int combined = avg * data->uv_luma_mult[uv] +                  \
348
5.06M
                               src[x] * data->uv_mult[uv];                           \
349
5.06M
                val = iclip_pixel( (combined >> 6) +                                 \
350
5.06M
                                   (data->uv_offset[uv] * (1 << bitdepth_min_8)) );  \
351
5.06M
            }                                                                        \
352
27.5M
            const int noise = round2(scaling[ val ] * (grain), data->scaling_shift); \
353
27.5M
            dst[x] = iclip(src[x] + noise, min_value, max_value);
354
355
129k
        const pixel *src = src_row + bx;
356
129k
        pixel *dst = dst_row + bx;
357
129k
        const pixel *luma = luma_row + (bx << sx);
358
359
184k
        for (int y = 0; y < ystart; y++, src += pxstride, dst += pxstride, luma += luma_pxstride) {
360
            // Special case for doubly-overlapped corner
361
135k
            for (int x = 0; x < xstart; x++) {
362
                // Blend the top pixel with the top left block
363
80.1k
                int top = sample_lut(grain_lut, offsets, sx, sy, 0, 1, x, y);
364
80.1k
                int old = sample_lut(grain_lut, offsets, sx, sy, 1, 1, x, y);
365
80.1k
                top = round2(old * w[sx][x][0] + top * w[sx][x][1], 5);
366
80.1k
                top = iclip(top, grain_min, grain_max);
367
368
                // Blend the current pixel with the left block
369
80.1k
                int grain = sample_lut(grain_lut, offsets, sx, sy, 0, 0, x, y);
370
80.1k
                old = sample_lut(grain_lut, offsets, sx, sy, 1, 0, x, y);
371
80.1k
                grain = round2(old * w[sx][x][0] + grain * w[sx][x][1], 5);
372
80.1k
                grain = iclip(grain, grain_min, grain_max);
373
374
                // Mix the row rows together and apply to image
375
80.1k
                grain = round2(top * w[sy][y][0] + grain * w[sy][y][1], 5);
376
80.1k
                grain = iclip(grain, grain_min, grain_max);
377
80.1k
                add_noise_uv(x, grain);
378
80.1k
            }
379
380
            // Special case for overlapped row (sans corner)
381
1.25M
            for (int x = xstart; x < bw; x++) {
382
1.19M
                int grain = sample_lut(grain_lut, offsets, sx, sy, 0, 0, x, y);
383
1.19M
                int old   = sample_lut(grain_lut, offsets, sx, sy, 0, 1, x, y);
384
1.19M
                grain = round2(old * w[sy][y][0] + grain * w[sy][y][1], 5);
385
1.19M
                grain = iclip(grain, grain_min, grain_max);
386
1.19M
                add_noise_uv(x, grain);
387
1.19M
            }
388
55.2k
        }
389
390
2.46M
        for (int y = ystart; y < bh; y++, src += pxstride, dst += pxstride, luma += luma_pxstride) {
391
            // Special case for overlapped column
392
3.54M
            for (int x = 0; x < xstart; x++) {
393
1.21M
                int grain = sample_lut(grain_lut, offsets, sx, sy, 0, 0, x, y);
394
1.21M
                int old   = sample_lut(grain_lut, offsets, sx, sy, 1, 0, x, y);
395
1.21M
                grain = round2(old * w[sx][x][0] + grain * w[sx][x][1], 5);
396
1.21M
                grain = iclip(grain, grain_min, grain_max);
397
1.21M
                add_noise_uv(x, grain);
398
1.21M
            }
399
400
            // Non-overlapped image region (straightforward)
401
27.3M
            for (int x = xstart; x < bw; x++) {
402
25.0M
                int grain = sample_lut(grain_lut, offsets, sx, sy, 0, 0, x, y);
403
25.0M
                add_noise_uv(x, grain);
404
25.0M
            }
405
2.33M
        }
406
129k
#undef add_noise_uv
407
129k
    }
408
16.2k
}
409
410
#define fguv_ss_fn(nm, ss_x, ss_y) \
411
16.3k
static decl_fguv_32x32xn_fn(fguv_32x32xn_##nm##_c) { \
412
16.3k
    fguv_32x32xn_c(dst_row, src_row, stride, data, pw, scaling, grain_lut, bh, \
413
16.3k
                   row_num, luma_row, luma_stride, uv_pl, is_id, ss_x, ss_y \
414
16.3k
                   HIGHBD_TAIL_SUFFIX); \
415
16.3k
}
filmgrain_tmpl.c:fguv_32x32xn_420_c
Line
Count
Source
411
6.62k
static decl_fguv_32x32xn_fn(fguv_32x32xn_##nm##_c) { \
412
6.62k
    fguv_32x32xn_c(dst_row, src_row, stride, data, pw, scaling, grain_lut, bh, \
413
6.62k
                   row_num, luma_row, luma_stride, uv_pl, is_id, ss_x, ss_y \
414
6.62k
                   HIGHBD_TAIL_SUFFIX); \
415
6.62k
}
filmgrain_tmpl.c:fguv_32x32xn_422_c
Line
Count
Source
411
1.33k
static decl_fguv_32x32xn_fn(fguv_32x32xn_##nm##_c) { \
412
1.33k
    fguv_32x32xn_c(dst_row, src_row, stride, data, pw, scaling, grain_lut, bh, \
413
1.33k
                   row_num, luma_row, luma_stride, uv_pl, is_id, ss_x, ss_y \
414
1.33k
                   HIGHBD_TAIL_SUFFIX); \
415
1.33k
}
filmgrain_tmpl.c:fguv_32x32xn_444_c
Line
Count
Source
411
8.35k
static decl_fguv_32x32xn_fn(fguv_32x32xn_##nm##_c) { \
412
8.35k
    fguv_32x32xn_c(dst_row, src_row, stride, data, pw, scaling, grain_lut, bh, \
413
8.35k
                   row_num, luma_row, luma_stride, uv_pl, is_id, ss_x, ss_y \
414
8.35k
                   HIGHBD_TAIL_SUFFIX); \
415
8.35k
}
416
417
fguv_ss_fn(420, 1, 1);
418
fguv_ss_fn(422, 1, 0);
419
fguv_ss_fn(444, 0, 0);
420
421
#if HAVE_ASM
422
#if ARCH_AARCH64 || ARCH_ARM
423
#include "src/arm/filmgrain.h"
424
#elif ARCH_X86
425
#include "src/x86/filmgrain.h"
426
#elif ARCH_RISCV
427
#include "src/riscv/filmgrain.h"
428
#endif
429
#endif
430
431
9.19k
COLD void bitfn(dav1d_film_grain_dsp_init)(Dav1dFilmGrainDSPContext *const c) {
432
9.19k
    c->generate_grain_y = generate_grain_y_c;
433
9.19k
    c->generate_grain_uv[DAV1D_PIXEL_LAYOUT_I420 - 1] = generate_grain_uv_420_c;
434
9.19k
    c->generate_grain_uv[DAV1D_PIXEL_LAYOUT_I422 - 1] = generate_grain_uv_422_c;
435
9.19k
    c->generate_grain_uv[DAV1D_PIXEL_LAYOUT_I444 - 1] = generate_grain_uv_444_c;
436
437
9.19k
    c->fgy_32x32xn = fgy_32x32xn_c;
438
9.19k
    c->fguv_32x32xn[DAV1D_PIXEL_LAYOUT_I420 - 1] = fguv_32x32xn_420_c;
439
9.19k
    c->fguv_32x32xn[DAV1D_PIXEL_LAYOUT_I422 - 1] = fguv_32x32xn_422_c;
440
9.19k
    c->fguv_32x32xn[DAV1D_PIXEL_LAYOUT_I444 - 1] = fguv_32x32xn_444_c;
441
442
#if HAVE_ASM
443
#if ARCH_AARCH64 || ARCH_ARM
444
    film_grain_dsp_init_arm(c);
445
#elif ARCH_X86
446
    film_grain_dsp_init_x86(c);
447
#elif ARCH_RISCV
448
    film_grain_dsp_init_riscv(c);
449
#endif
450
#endif
451
9.19k
}
dav1d_film_grain_dsp_init_8bpc
Line
Count
Source
431
4.07k
COLD void bitfn(dav1d_film_grain_dsp_init)(Dav1dFilmGrainDSPContext *const c) {
432
4.07k
    c->generate_grain_y = generate_grain_y_c;
433
4.07k
    c->generate_grain_uv[DAV1D_PIXEL_LAYOUT_I420 - 1] = generate_grain_uv_420_c;
434
4.07k
    c->generate_grain_uv[DAV1D_PIXEL_LAYOUT_I422 - 1] = generate_grain_uv_422_c;
435
4.07k
    c->generate_grain_uv[DAV1D_PIXEL_LAYOUT_I444 - 1] = generate_grain_uv_444_c;
436
437
4.07k
    c->fgy_32x32xn = fgy_32x32xn_c;
438
4.07k
    c->fguv_32x32xn[DAV1D_PIXEL_LAYOUT_I420 - 1] = fguv_32x32xn_420_c;
439
4.07k
    c->fguv_32x32xn[DAV1D_PIXEL_LAYOUT_I422 - 1] = fguv_32x32xn_422_c;
440
4.07k
    c->fguv_32x32xn[DAV1D_PIXEL_LAYOUT_I444 - 1] = fguv_32x32xn_444_c;
441
442
#if HAVE_ASM
443
#if ARCH_AARCH64 || ARCH_ARM
444
    film_grain_dsp_init_arm(c);
445
#elif ARCH_X86
446
    film_grain_dsp_init_x86(c);
447
#elif ARCH_RISCV
448
    film_grain_dsp_init_riscv(c);
449
#endif
450
#endif
451
4.07k
}
dav1d_film_grain_dsp_init_16bpc
Line
Count
Source
431
5.11k
COLD void bitfn(dav1d_film_grain_dsp_init)(Dav1dFilmGrainDSPContext *const c) {
432
5.11k
    c->generate_grain_y = generate_grain_y_c;
433
5.11k
    c->generate_grain_uv[DAV1D_PIXEL_LAYOUT_I420 - 1] = generate_grain_uv_420_c;
434
5.11k
    c->generate_grain_uv[DAV1D_PIXEL_LAYOUT_I422 - 1] = generate_grain_uv_422_c;
435
5.11k
    c->generate_grain_uv[DAV1D_PIXEL_LAYOUT_I444 - 1] = generate_grain_uv_444_c;
436
437
5.11k
    c->fgy_32x32xn = fgy_32x32xn_c;
438
5.11k
    c->fguv_32x32xn[DAV1D_PIXEL_LAYOUT_I420 - 1] = fguv_32x32xn_420_c;
439
5.11k
    c->fguv_32x32xn[DAV1D_PIXEL_LAYOUT_I422 - 1] = fguv_32x32xn_422_c;
440
5.11k
    c->fguv_32x32xn[DAV1D_PIXEL_LAYOUT_I444 - 1] = fguv_32x32xn_444_c;
441
442
#if HAVE_ASM
443
#if ARCH_AARCH64 || ARCH_ARM
444
    film_grain_dsp_init_arm(c);
445
#elif ARCH_X86
446
    film_grain_dsp_init_x86(c);
447
#elif ARCH_RISCV
448
    film_grain_dsp_init_riscv(c);
449
#endif
450
#endif
451
5.11k
}