Coverage Report

Created: 2026-09-14 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/fg_apply_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 "config.h"
30
31
#include <stdint.h>
32
33
#include "dav1d/common.h"
34
#include "dav1d/picture.h"
35
36
#include "common/intops.h"
37
#include "common/bitdepth.h"
38
39
#include "src/fg_apply.h"
40
41
static void generate_scaling(const int bitdepth,
42
                             const uint8_t points[][2], const int num,
43
                             uint8_t scaling[SCALING_SIZE])
44
2.73k
{
45
2.73k
#if BITDEPTH == 8
46
2.73k
    const int shift_x = 0;
47
2.73k
    const int scaling_size = SCALING_SIZE;
48
#else
49
    assert(bitdepth > 8);
50
    const int shift_x = bitdepth - 8;
51
    const int scaling_size = 1 << bitdepth;
52
#endif
53
54
2.73k
    if (num == 0) {
55
205
        memset(scaling, 0, scaling_size);
56
205
        return;
57
205
    }
58
59
    // Fill up the preceding entries with the initial value
60
2.53k
    memset(scaling, points[0][1], points[0][0] << shift_x);
61
62
    // Linearly interpolate the values in the middle
63
3.59k
    for (int i = 0; i < num - 1; i++) {
64
1.06k
        const int bx = points[i][0];
65
1.06k
        const int by = points[i][1];
66
1.06k
        const int ex = points[i+1][0];
67
1.06k
        const int ey = points[i+1][1];
68
1.06k
        const int dx = ex - bx;
69
1.06k
        const int dy = ey - by;
70
1.06k
        assert(dx > 0);
71
1.06k
        const int delta = dy * ((0x10000 + (dx >> 1)) / dx);
72
86.8k
        for (int x = 0, d = 0x8000; x < dx; x++) {
73
85.7k
            scaling[(bx + x) << shift_x] = by + (d >> 16);
74
85.7k
            d += delta;
75
85.7k
        }
76
1.06k
    }
77
78
    // Fill up the remaining entries with the final value
79
2.53k
    const int n = points[num - 1][0] << shift_x;
80
2.53k
    memset(&scaling[n], points[num - 1][1], scaling_size - n);
81
82
#if BITDEPTH != 8
83
    const int pad = 1 << shift_x, rnd = pad >> 1;
84
    for (int i = 0; i < num - 1; i++) {
85
        const int bx = points[i][0] << shift_x;
86
        const int ex = points[i+1][0] << shift_x;
87
        const int dx = ex - bx;
88
        for (int x = 0; x < dx; x += pad) {
89
            const int range = scaling[bx + x + pad] - scaling[bx + x];
90
            for (int n = 1, r = rnd; n < pad; n++) {
91
                r += range;
92
                scaling[bx + x + n] = scaling[bx + x] + (r >> shift_x);
93
            }
94
        }
95
    }
96
#endif
97
2.53k
}
98
99
#ifndef UNIT_TEST
100
void bitfn(dav1d_prep_grain)(const Dav1dFilmGrainDSPContext *const dsp,
101
                             Dav1dPicture *const out,
102
                             const Dav1dPicture *const in,
103
                             uint8_t scaling[3][SCALING_SIZE],
104
                             entry grain_lut[3][GRAIN_HEIGHT+1][GRAIN_WIDTH])
105
5.26k
{
106
5.26k
    const Dav1dFilmGrainData *const data = &out->frame_hdr->film_grain.data;
107
#if BITDEPTH != 8
108
    const int bitdepth_max = (1 << out->p.bpc) - 1;
109
#endif
110
111
    // Generate grain LUTs as needed
112
5.26k
    dsp->generate_grain_y(grain_lut[0], data HIGHBD_TAIL_SUFFIX); // always needed
113
5.26k
    if (data->num_uv_points[0] || data->chroma_scaling_from_luma)
114
3.79k
        dsp->generate_grain_uv[in->p.layout - 1](grain_lut[1], grain_lut[0],
115
3.79k
                                                 data, 0 HIGHBD_TAIL_SUFFIX);
116
5.26k
    if (data->num_uv_points[1] || data->chroma_scaling_from_luma)
117
3.94k
        dsp->generate_grain_uv[in->p.layout - 1](grain_lut[2], grain_lut[0],
118
3.94k
                                                 data, 1 HIGHBD_TAIL_SUFFIX);
119
120
    // Generate scaling LUTs as needed
121
5.26k
    if (data->num_y_points || data->chroma_scaling_from_luma)
122
4.41k
        generate_scaling(in->p.bpc, data->y_points, data->num_y_points, scaling[0]);
123
5.26k
    if (data->num_uv_points[0])
124
819
        generate_scaling(in->p.bpc, data->uv_points[0], data->num_uv_points[0], scaling[1]);
125
5.26k
    if (data->num_uv_points[1])
126
967
        generate_scaling(in->p.bpc, data->uv_points[1], data->num_uv_points[1], scaling[2]);
127
128
    // Copy over the non-modified planes
129
5.26k
    assert(out->stride[0] == in->stride[0]);
130
5.26k
    if (!data->num_y_points) {
131
1.58k
        const ptrdiff_t stride = out->stride[0];
132
1.58k
        const ptrdiff_t sz = out->p.h * stride;
133
1.58k
        if (sz < 0)
134
0
            memcpy((uint8_t*) out->data[0] + sz - stride,
135
0
                   (uint8_t*) in->data[0] + sz - stride, -sz);
136
1.58k
        else
137
1.58k
            memcpy(out->data[0], in->data[0], sz);
138
1.58k
    }
139
140
5.26k
    if (in->p.layout != DAV1D_PIXEL_LAYOUT_I400 && !data->chroma_scaling_from_luma) {
141
1.76k
        assert(out->stride[1] == in->stride[1]);
142
1.76k
        const int ss_ver = in->p.layout == DAV1D_PIXEL_LAYOUT_I420;
143
1.76k
        const ptrdiff_t stride = out->stride[1];
144
1.76k
        const ptrdiff_t sz = ((out->p.h + ss_ver) >> ss_ver) * stride;
145
1.76k
        if (sz < 0) {
146
0
            if (!data->num_uv_points[0])
147
0
                memcpy((uint8_t*) out->data[1] + sz - stride,
148
0
                       (uint8_t*) in->data[1] + sz - stride, -sz);
149
0
            if (!data->num_uv_points[1])
150
0
                memcpy((uint8_t*) out->data[2] + sz - stride,
151
0
                       (uint8_t*) in->data[2] + sz - stride, -sz);
152
1.76k
        } else {
153
1.76k
            if (!data->num_uv_points[0])
154
944
                memcpy(out->data[1], in->data[1], sz);
155
1.76k
            if (!data->num_uv_points[1])
156
796
                memcpy(out->data[2], in->data[2], sz);
157
1.76k
        }
158
1.76k
    }
159
5.26k
}
dav1d_prep_grain_8bpc
Line
Count
Source
105
2.34k
{
106
2.34k
    const Dav1dFilmGrainData *const data = &out->frame_hdr->film_grain.data;
107
#if BITDEPTH != 8
108
    const int bitdepth_max = (1 << out->p.bpc) - 1;
109
#endif
110
111
    // Generate grain LUTs as needed
112
2.34k
    dsp->generate_grain_y(grain_lut[0], data HIGHBD_TAIL_SUFFIX); // always needed
113
2.34k
    if (data->num_uv_points[0] || data->chroma_scaling_from_luma)
114
1.68k
        dsp->generate_grain_uv[in->p.layout - 1](grain_lut[1], grain_lut[0],
115
1.68k
                                                 data, 0 HIGHBD_TAIL_SUFFIX);
116
2.34k
    if (data->num_uv_points[1] || data->chroma_scaling_from_luma)
117
1.72k
        dsp->generate_grain_uv[in->p.layout - 1](grain_lut[2], grain_lut[0],
118
1.72k
                                                 data, 1 HIGHBD_TAIL_SUFFIX);
119
120
    // Generate scaling LUTs as needed
121
2.34k
    if (data->num_y_points || data->chroma_scaling_from_luma)
122
1.88k
        generate_scaling(in->p.bpc, data->y_points, data->num_y_points, scaling[0]);
123
2.34k
    if (data->num_uv_points[0])
124
410
        generate_scaling(in->p.bpc, data->uv_points[0], data->num_uv_points[0], scaling[1]);
125
2.34k
    if (data->num_uv_points[1])
126
447
        generate_scaling(in->p.bpc, data->uv_points[1], data->num_uv_points[1], scaling[2]);
127
128
    // Copy over the non-modified planes
129
2.34k
    assert(out->stride[0] == in->stride[0]);
130
2.34k
    if (!data->num_y_points) {
131
668
        const ptrdiff_t stride = out->stride[0];
132
668
        const ptrdiff_t sz = out->p.h * stride;
133
668
        if (sz < 0)
134
0
            memcpy((uint8_t*) out->data[0] + sz - stride,
135
0
                   (uint8_t*) in->data[0] + sz - stride, -sz);
136
668
        else
137
668
            memcpy(out->data[0], in->data[0], sz);
138
668
    }
139
140
2.34k
    if (in->p.layout != DAV1D_PIXEL_LAYOUT_I400 && !data->chroma_scaling_from_luma) {
141
841
        assert(out->stride[1] == in->stride[1]);
142
841
        const int ss_ver = in->p.layout == DAV1D_PIXEL_LAYOUT_I420;
143
841
        const ptrdiff_t stride = out->stride[1];
144
841
        const ptrdiff_t sz = ((out->p.h + ss_ver) >> ss_ver) * stride;
145
841
        if (sz < 0) {
146
0
            if (!data->num_uv_points[0])
147
0
                memcpy((uint8_t*) out->data[1] + sz - stride,
148
0
                       (uint8_t*) in->data[1] + sz - stride, -sz);
149
0
            if (!data->num_uv_points[1])
150
0
                memcpy((uint8_t*) out->data[2] + sz - stride,
151
0
                       (uint8_t*) in->data[2] + sz - stride, -sz);
152
841
        } else {
153
841
            if (!data->num_uv_points[0])
154
431
                memcpy(out->data[1], in->data[1], sz);
155
841
            if (!data->num_uv_points[1])
156
394
                memcpy(out->data[2], in->data[2], sz);
157
841
        }
158
841
    }
159
2.34k
}
dav1d_prep_grain_16bpc
Line
Count
Source
105
2.92k
{
106
2.92k
    const Dav1dFilmGrainData *const data = &out->frame_hdr->film_grain.data;
107
2.92k
#if BITDEPTH != 8
108
2.92k
    const int bitdepth_max = (1 << out->p.bpc) - 1;
109
2.92k
#endif
110
111
    // Generate grain LUTs as needed
112
2.92k
    dsp->generate_grain_y(grain_lut[0], data HIGHBD_TAIL_SUFFIX); // always needed
113
2.92k
    if (data->num_uv_points[0] || data->chroma_scaling_from_luma)
114
2.11k
        dsp->generate_grain_uv[in->p.layout - 1](grain_lut[1], grain_lut[0],
115
2.11k
                                                 data, 0 HIGHBD_TAIL_SUFFIX);
116
2.92k
    if (data->num_uv_points[1] || data->chroma_scaling_from_luma)
117
2.22k
        dsp->generate_grain_uv[in->p.layout - 1](grain_lut[2], grain_lut[0],
118
2.22k
                                                 data, 1 HIGHBD_TAIL_SUFFIX);
119
120
    // Generate scaling LUTs as needed
121
2.92k
    if (data->num_y_points || data->chroma_scaling_from_luma)
122
2.52k
        generate_scaling(in->p.bpc, data->y_points, data->num_y_points, scaling[0]);
123
2.92k
    if (data->num_uv_points[0])
124
409
        generate_scaling(in->p.bpc, data->uv_points[0], data->num_uv_points[0], scaling[1]);
125
2.92k
    if (data->num_uv_points[1])
126
520
        generate_scaling(in->p.bpc, data->uv_points[1], data->num_uv_points[1], scaling[2]);
127
128
    // Copy over the non-modified planes
129
2.92k
    assert(out->stride[0] == in->stride[0]);
130
2.92k
    if (!data->num_y_points) {
131
914
        const ptrdiff_t stride = out->stride[0];
132
914
        const ptrdiff_t sz = out->p.h * stride;
133
914
        if (sz < 0)
134
0
            memcpy((uint8_t*) out->data[0] + sz - stride,
135
0
                   (uint8_t*) in->data[0] + sz - stride, -sz);
136
914
        else
137
914
            memcpy(out->data[0], in->data[0], sz);
138
914
    }
139
140
2.92k
    if (in->p.layout != DAV1D_PIXEL_LAYOUT_I400 && !data->chroma_scaling_from_luma) {
141
922
        assert(out->stride[1] == in->stride[1]);
142
922
        const int ss_ver = in->p.layout == DAV1D_PIXEL_LAYOUT_I420;
143
922
        const ptrdiff_t stride = out->stride[1];
144
922
        const ptrdiff_t sz = ((out->p.h + ss_ver) >> ss_ver) * stride;
145
922
        if (sz < 0) {
146
0
            if (!data->num_uv_points[0])
147
0
                memcpy((uint8_t*) out->data[1] + sz - stride,
148
0
                       (uint8_t*) in->data[1] + sz - stride, -sz);
149
0
            if (!data->num_uv_points[1])
150
0
                memcpy((uint8_t*) out->data[2] + sz - stride,
151
0
                       (uint8_t*) in->data[2] + sz - stride, -sz);
152
922
        } else {
153
922
            if (!data->num_uv_points[0])
154
513
                memcpy(out->data[1], in->data[1], sz);
155
922
            if (!data->num_uv_points[1])
156
402
                memcpy(out->data[2], in->data[2], sz);
157
922
        }
158
922
    }
159
2.92k
}
160
161
void bitfn(dav1d_apply_grain_row)(const Dav1dFilmGrainDSPContext *const dsp,
162
                                  Dav1dPicture *const out,
163
                                  const Dav1dPicture *const in,
164
                                  const uint8_t scaling[3][SCALING_SIZE],
165
                                  const entry grain_lut[3][GRAIN_HEIGHT+1][GRAIN_WIDTH],
166
                                  const int row)
167
59.9k
{
168
    // Synthesize grain for the affected planes
169
59.9k
    const Dav1dFilmGrainData *const data = &out->frame_hdr->film_grain.data;
170
59.9k
    const int ss_y = in->p.layout == DAV1D_PIXEL_LAYOUT_I420;
171
59.9k
    const int ss_x = in->p.layout != DAV1D_PIXEL_LAYOUT_I444;
172
59.9k
    const int cpw = (out->p.w + ss_x) >> ss_x;
173
59.9k
    const int is_id = out->seq_hdr->mtrx == DAV1D_MC_IDENTITY;
174
59.9k
    pixel *const luma_src =
175
59.9k
        ((pixel *) in->data[0]) + row * FG_BLOCK_SIZE * PXSTRIDE(in->stride[0]);
176
#if BITDEPTH != 8
177
    const int bitdepth_max = (1 << out->p.bpc) - 1;
178
#endif
179
180
59.9k
    if (data->num_y_points) {
181
47.0k
        const int bh = imin(out->p.h - row * FG_BLOCK_SIZE, FG_BLOCK_SIZE);
182
47.0k
        dsp->fgy_32x32xn(((pixel *) out->data[0]) + row * FG_BLOCK_SIZE * PXSTRIDE(out->stride[0]),
183
47.0k
                         luma_src, out->stride[0], data,
184
47.0k
                         out->p.w, scaling[0], grain_lut[0], bh, row HIGHBD_TAIL_SUFFIX);
185
47.0k
    }
186
187
59.9k
    if (!data->num_uv_points[0] && !data->num_uv_points[1] &&
188
40.7k
        !data->chroma_scaling_from_luma)
189
20.0k
    {
190
20.0k
        return;
191
20.0k
    }
192
193
39.9k
    const int bh = (imin(out->p.h - row * FG_BLOCK_SIZE, FG_BLOCK_SIZE) + ss_y) >> ss_y;
194
195
    // extend padding pixels
196
39.9k
    if (out->p.w & ss_x) {
197
4.07k
        pixel *ptr = luma_src;
198
70.4k
        for (int y = 0; y < bh; y++) {
199
66.4k
            ptr[out->p.w] = ptr[out->p.w - 1];
200
66.4k
            ptr += PXSTRIDE(in->stride[0]) << ss_y;
201
66.4k
        }
202
4.07k
    }
203
204
39.9k
    const ptrdiff_t uv_off = row * FG_BLOCK_SIZE * PXSTRIDE(out->stride[1]) >> ss_y;
205
39.9k
    if (data->chroma_scaling_from_luma) {
206
59.9k
        for (int pl = 0; pl < 2; pl++)
207
39.0k
            dsp->fguv_32x32xn[in->p.layout - 1](((pixel *) out->data[1 + pl]) + uv_off,
208
39.0k
                                                ((const pixel *) in->data[1 + pl]) + uv_off,
209
39.0k
                                                in->stride[1], data, cpw,
210
39.0k
                                                scaling[0], grain_lut[1 + pl],
211
39.0k
                                                bh, row, luma_src, in->stride[0],
212
39.0k
                                                pl, is_id HIGHBD_TAIL_SUFFIX);
213
20.9k
    } else {
214
43.9k
        for (int pl = 0; pl < 2; pl++)
215
24.9k
            if (data->num_uv_points[pl])
216
16.7k
                dsp->fguv_32x32xn[in->p.layout - 1](((pixel *) out->data[1 + pl]) + uv_off,
217
16.7k
                                                    ((const pixel *) in->data[1 + pl]) + uv_off,
218
16.7k
                                                    in->stride[1], data, cpw,
219
16.7k
                                                    scaling[1 + pl], grain_lut[1 + pl],
220
16.7k
                                                    bh, row, luma_src, in->stride[0],
221
16.7k
                                                    pl, is_id HIGHBD_TAIL_SUFFIX);
222
18.9k
    }
223
39.9k
}
dav1d_apply_grain_row_8bpc
Line
Count
Source
167
23.0k
{
168
    // Synthesize grain for the affected planes
169
23.0k
    const Dav1dFilmGrainData *const data = &out->frame_hdr->film_grain.data;
170
23.0k
    const int ss_y = in->p.layout == DAV1D_PIXEL_LAYOUT_I420;
171
23.0k
    const int ss_x = in->p.layout != DAV1D_PIXEL_LAYOUT_I444;
172
23.0k
    const int cpw = (out->p.w + ss_x) >> ss_x;
173
23.0k
    const int is_id = out->seq_hdr->mtrx == DAV1D_MC_IDENTITY;
174
23.0k
    pixel *const luma_src =
175
23.0k
        ((pixel *) in->data[0]) + row * FG_BLOCK_SIZE * PXSTRIDE(in->stride[0]);
176
#if BITDEPTH != 8
177
    const int bitdepth_max = (1 << out->p.bpc) - 1;
178
#endif
179
180
23.0k
    if (data->num_y_points) {
181
16.6k
        const int bh = imin(out->p.h - row * FG_BLOCK_SIZE, FG_BLOCK_SIZE);
182
16.6k
        dsp->fgy_32x32xn(((pixel *) out->data[0]) + row * FG_BLOCK_SIZE * PXSTRIDE(out->stride[0]),
183
16.6k
                         luma_src, out->stride[0], data,
184
16.6k
                         out->p.w, scaling[0], grain_lut[0], bh, row HIGHBD_TAIL_SUFFIX);
185
16.6k
    }
186
187
23.0k
    if (!data->num_uv_points[0] && !data->num_uv_points[1] &&
188
13.0k
        !data->chroma_scaling_from_luma)
189
3.18k
    {
190
3.18k
        return;
191
3.18k
    }
192
193
19.8k
    const int bh = (imin(out->p.h - row * FG_BLOCK_SIZE, FG_BLOCK_SIZE) + ss_y) >> ss_y;
194
195
    // extend padding pixels
196
19.8k
    if (out->p.w & ss_x) {
197
2.25k
        pixel *ptr = luma_src;
198
40.2k
        for (int y = 0; y < bh; y++) {
199
38.0k
            ptr[out->p.w] = ptr[out->p.w - 1];
200
38.0k
            ptr += PXSTRIDE(in->stride[0]) << ss_y;
201
38.0k
        }
202
2.25k
    }
203
204
19.8k
    const ptrdiff_t uv_off = row * FG_BLOCK_SIZE * PXSTRIDE(out->stride[1]) >> ss_y;
205
19.8k
    if (data->chroma_scaling_from_luma) {
206
28.4k
        for (int pl = 0; pl < 2; pl++)
207
18.4k
            dsp->fguv_32x32xn[in->p.layout - 1](((pixel *) out->data[1 + pl]) + uv_off,
208
18.4k
                                                ((const pixel *) in->data[1 + pl]) + uv_off,
209
18.4k
                                                in->stride[1], data, cpw,
210
18.4k
                                                scaling[0], grain_lut[1 + pl],
211
18.4k
                                                bh, row, luma_src, in->stride[0],
212
18.4k
                                                pl, is_id HIGHBD_TAIL_SUFFIX);
213
10.0k
    } else {
214
22.3k
        for (int pl = 0; pl < 2; pl++)
215
12.4k
            if (data->num_uv_points[pl])
216
8.49k
                dsp->fguv_32x32xn[in->p.layout - 1](((pixel *) out->data[1 + pl]) + uv_off,
217
8.49k
                                                    ((const pixel *) in->data[1 + pl]) + uv_off,
218
8.49k
                                                    in->stride[1], data, cpw,
219
8.49k
                                                    scaling[1 + pl], grain_lut[1 + pl],
220
8.49k
                                                    bh, row, luma_src, in->stride[0],
221
8.49k
                                                    pl, is_id HIGHBD_TAIL_SUFFIX);
222
9.82k
    }
223
19.8k
}
dav1d_apply_grain_row_16bpc
Line
Count
Source
167
36.9k
{
168
    // Synthesize grain for the affected planes
169
36.9k
    const Dav1dFilmGrainData *const data = &out->frame_hdr->film_grain.data;
170
36.9k
    const int ss_y = in->p.layout == DAV1D_PIXEL_LAYOUT_I420;
171
36.9k
    const int ss_x = in->p.layout != DAV1D_PIXEL_LAYOUT_I444;
172
36.9k
    const int cpw = (out->p.w + ss_x) >> ss_x;
173
36.9k
    const int is_id = out->seq_hdr->mtrx == DAV1D_MC_IDENTITY;
174
36.9k
    pixel *const luma_src =
175
36.9k
        ((pixel *) in->data[0]) + row * FG_BLOCK_SIZE * PXSTRIDE(in->stride[0]);
176
36.9k
#if BITDEPTH != 8
177
36.9k
    const int bitdepth_max = (1 << out->p.bpc) - 1;
178
36.9k
#endif
179
180
36.9k
    if (data->num_y_points) {
181
30.3k
        const int bh = imin(out->p.h - row * FG_BLOCK_SIZE, FG_BLOCK_SIZE);
182
30.3k
        dsp->fgy_32x32xn(((pixel *) out->data[0]) + row * FG_BLOCK_SIZE * PXSTRIDE(out->stride[0]),
183
30.3k
                         luma_src, out->stride[0], data,
184
30.3k
                         out->p.w, scaling[0], grain_lut[0], bh, row HIGHBD_TAIL_SUFFIX);
185
30.3k
    }
186
187
36.9k
    if (!data->num_uv_points[0] && !data->num_uv_points[1] &&
188
27.6k
        !data->chroma_scaling_from_luma)
189
16.8k
    {
190
16.8k
        return;
191
16.8k
    }
192
193
20.0k
    const int bh = (imin(out->p.h - row * FG_BLOCK_SIZE, FG_BLOCK_SIZE) + ss_y) >> ss_y;
194
195
    // extend padding pixels
196
20.0k
    if (out->p.w & ss_x) {
197
1.81k
        pixel *ptr = luma_src;
198
30.2k
        for (int y = 0; y < bh; y++) {
199
28.3k
            ptr[out->p.w] = ptr[out->p.w - 1];
200
28.3k
            ptr += PXSTRIDE(in->stride[0]) << ss_y;
201
28.3k
        }
202
1.81k
    }
203
204
20.0k
    const ptrdiff_t uv_off = row * FG_BLOCK_SIZE * PXSTRIDE(out->stride[1]) >> ss_y;
205
20.0k
    if (data->chroma_scaling_from_luma) {
206
31.5k
        for (int pl = 0; pl < 2; pl++)
207
20.5k
            dsp->fguv_32x32xn[in->p.layout - 1](((pixel *) out->data[1 + pl]) + uv_off,
208
20.5k
                                                ((const pixel *) in->data[1 + pl]) + uv_off,
209
20.5k
                                                in->stride[1], data, cpw,
210
20.5k
                                                scaling[0], grain_lut[1 + pl],
211
20.5k
                                                bh, row, luma_src, in->stride[0],
212
20.5k
                                                pl, is_id HIGHBD_TAIL_SUFFIX);
213
10.9k
    } else {
214
21.6k
        for (int pl = 0; pl < 2; pl++)
215
12.4k
            if (data->num_uv_points[pl])
216
8.24k
                dsp->fguv_32x32xn[in->p.layout - 1](((pixel *) out->data[1 + pl]) + uv_off,
217
8.24k
                                                    ((const pixel *) in->data[1 + pl]) + uv_off,
218
8.24k
                                                    in->stride[1], data, cpw,
219
8.24k
                                                    scaling[1 + pl], grain_lut[1 + pl],
220
8.24k
                                                    bh, row, luma_src, in->stride[0],
221
8.24k
                                                    pl, is_id HIGHBD_TAIL_SUFFIX);
222
9.13k
    }
223
20.0k
}
224
225
void bitfn(dav1d_apply_grain)(const Dav1dFilmGrainDSPContext *const dsp,
226
                              Dav1dPicture *const out,
227
                              const Dav1dPicture *const in)
228
0
{
229
0
    ALIGN_STK_16(entry, grain_lut, 3,[GRAIN_HEIGHT + 1][GRAIN_WIDTH]);
230
#if ARCH_X86_64 && BITDEPTH == 8
231
0
    ALIGN_STK_64(uint8_t, scaling, 3,[SCALING_SIZE]);
232
#else
233
    uint8_t scaling[3][SCALING_SIZE];
234
#endif
235
0
    const int rows = (out->p.h + FG_BLOCK_SIZE - 1) / FG_BLOCK_SIZE;
236
237
0
    bitfn(dav1d_prep_grain)(dsp, out, in, scaling, grain_lut);
238
0
    for (int row = 0; row < rows; row++)
239
0
        bitfn(dav1d_apply_grain_row)(dsp, out, in, scaling, grain_lut, row);
240
0
}
Unexecuted instantiation: dav1d_apply_grain_8bpc
Unexecuted instantiation: dav1d_apply_grain_16bpc
241
#endif