Coverage Report

Created: 2026-09-13 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/lf_apply_tmpl.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/lf_apply.h"
35
#include "src/lr_apply.h"
36
37
// The loop filter buffer stores 12 rows of pixels. A superblock block will
38
// contain at most 2 stripes. Each stripe requires 4 rows pixels (2 above
39
// and 2 below) the final 4 rows are used to swap the bottom of the last
40
// stripe with the top of the next super block row.
41
static void backup_lpf(const Dav1dFrameContext *const f,
42
                       pixel *dst, const ptrdiff_t dst_stride,
43
                       const pixel *src, const ptrdiff_t src_stride,
44
                       const int ss_ver, const int sb128,
45
                       int row, const int row_h, const int src_w,
46
                       const int h, const int ss_hor, const int lr_backup)
47
1.04M
{
48
1.04M
    const int cdef_backup = !lr_backup;
49
1.04M
    const int dst_w = f->frame_hdr->super_res.enabled ?
50
651k
                      (f->frame_hdr->width[1] + ss_hor) >> ss_hor : src_w;
51
52
    // The first stripe of the frame is shorter by 8 luma pixel rows.
53
1.04M
    int stripe_h = ((64 << (cdef_backup & sb128)) - 8 * !row) >> ss_ver;
54
1.04M
    src += (stripe_h - 2) * PXSTRIDE(src_stride);
55
56
1.04M
    if (f->c->n_tc == 1) {
57
0
        if (row) {
58
0
            const int top = 4 << sb128;
59
            // Copy the top part of the stored loop filtered pixels from the
60
            // previous sb row needed above the first stripe of this sb row.
61
0
            pixel_copy(&dst[PXSTRIDE(dst_stride) *  0],
62
0
                       &dst[PXSTRIDE(dst_stride) *  top],      dst_w);
63
0
            pixel_copy(&dst[PXSTRIDE(dst_stride) *  1],
64
0
                       &dst[PXSTRIDE(dst_stride) * (top + 1)], dst_w);
65
0
            pixel_copy(&dst[PXSTRIDE(dst_stride) *  2],
66
0
                       &dst[PXSTRIDE(dst_stride) * (top + 2)], dst_w);
67
0
            pixel_copy(&dst[PXSTRIDE(dst_stride) *  3],
68
0
                       &dst[PXSTRIDE(dst_stride) * (top + 3)], dst_w);
69
0
        }
70
0
        dst += 4 * PXSTRIDE(dst_stride);
71
0
    }
72
73
1.04M
    if (lr_backup && (f->frame_hdr->width[0] != f->frame_hdr->width[1])) {
74
195k
        while (row + stripe_h <= row_h) {
75
88.2k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
76
88.2k
            f->dsp->mc.resize(dst, dst_stride, src, src_stride,
77
88.2k
                              dst_w, n_lines, src_w, f->resize_step[ss_hor],
78
88.2k
                              f->resize_start[ss_hor] HIGHBD_CALL_SUFFIX);
79
88.2k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
80
88.2k
            stripe_h = 64 >> ss_ver;
81
88.2k
            src += stripe_h * PXSTRIDE(src_stride);
82
88.2k
            dst += n_lines * PXSTRIDE(dst_stride);
83
88.2k
            if (n_lines == 3) {
84
1.21k
                pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], dst_w);
85
1.21k
                dst += PXSTRIDE(dst_stride);
86
1.21k
            }
87
88.2k
        }
88
939k
    } else {
89
1.57M
        while (row + stripe_h <= row_h) {
90
638k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
91
3.19M
            for (int i = 0; i < 4; i++) {
92
2.55M
                pixel_copy(dst, i == n_lines ? &dst[-PXSTRIDE(dst_stride)] :
93
2.55M
                                               src, src_w);
94
2.55M
                dst += PXSTRIDE(dst_stride);
95
2.55M
                src += PXSTRIDE(src_stride);
96
2.55M
            }
97
638k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
98
638k
            stripe_h = 64 >> ss_ver;
99
638k
            src += (stripe_h - 4) * PXSTRIDE(src_stride);
100
638k
        }
101
939k
    }
102
1.04M
}
103
104
void bytefn(dav1d_copy_lpf)(Dav1dFrameContext *const f,
105
                            /*const*/ pixel *const src[3], const int sby)
106
398k
{
107
398k
    const int have_tt = f->c->n_tc > 1;
108
398k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
398k
    const int offset = 8 * !!sby;
110
398k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
398k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
398k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
398k
    pixel *const dst[3] = {
114
398k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
398k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
398k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
398k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
398k
    const int restore_planes = f->lf.restore_planes;
121
122
398k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
387k
        const int h = f->cur.p.h;
124
387k
        const int w = f->bw << 2;
125
387k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
387k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
387k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
359k
            backup_lpf(f, dst[0], lr_stride[0],
129
359k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
359k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
387k
        if (have_tt && resize) {
132
70.6k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
70.6k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
70.6k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
70.6k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
70.6k
        }
137
387k
    }
138
398k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
367k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
306k
    {
141
306k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
306k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
306k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
306k
        const int w = f->bw << (2 - ss_hor);
145
306k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
306k
        const int offset_uv = offset >> ss_ver;
147
306k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
306k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
306k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
251k
            if (restore_planes & LR_RESTORE_U || !resize)
151
223k
                backup_lpf(f, dst[1], lr_stride[1],
152
223k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
223k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
223k
                           row_h, w, h, ss_hor, 1);
155
251k
            if (have_tt && resize)
156
53.5k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
53.5k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
53.5k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
53.5k
                           row_h, w, h, ss_hor, 0);
160
251k
        }
161
306k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
300k
            if (restore_planes & LR_RESTORE_V || !resize)
163
282k
                backup_lpf(f, dst[2], lr_stride[1],
164
282k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
282k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
282k
                           row_h, w, h, ss_hor, 1);
167
300k
            if (have_tt && resize)
168
57.7k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
57.7k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
57.7k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
57.7k
                           row_h, w, h, ss_hor, 0);
172
300k
        }
173
306k
    }
174
398k
}
dav1d_copy_lpf_8bpc
Line
Count
Source
106
194k
{
107
194k
    const int have_tt = f->c->n_tc > 1;
108
194k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
194k
    const int offset = 8 * !!sby;
110
194k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
194k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
194k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
194k
    pixel *const dst[3] = {
114
194k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
194k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
194k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
194k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
194k
    const int restore_planes = f->lf.restore_planes;
121
122
194k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
190k
        const int h = f->cur.p.h;
124
190k
        const int w = f->bw << 2;
125
190k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
190k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
190k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
178k
            backup_lpf(f, dst[0], lr_stride[0],
129
178k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
178k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
190k
        if (have_tt && resize) {
132
32.2k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
32.2k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
32.2k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
32.2k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
32.2k
        }
137
190k
    }
138
194k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
184k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
157k
    {
141
157k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
157k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
157k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
157k
        const int w = f->bw << (2 - ss_hor);
145
157k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
157k
        const int offset_uv = offset >> ss_ver;
147
157k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
157k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
157k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
132k
            if (restore_planes & LR_RESTORE_U || !resize)
151
118k
                backup_lpf(f, dst[1], lr_stride[1],
152
118k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
118k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
118k
                           row_h, w, h, ss_hor, 1);
155
132k
            if (have_tt && resize)
156
25.4k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
25.4k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
25.4k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
25.4k
                           row_h, w, h, ss_hor, 0);
160
132k
        }
161
157k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
155k
            if (restore_planes & LR_RESTORE_V || !resize)
163
145k
                backup_lpf(f, dst[2], lr_stride[1],
164
145k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
145k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
145k
                           row_h, w, h, ss_hor, 1);
167
155k
            if (have_tt && resize)
168
27.3k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
27.3k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
27.3k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
27.3k
                           row_h, w, h, ss_hor, 0);
172
155k
        }
173
157k
    }
174
194k
}
dav1d_copy_lpf_16bpc
Line
Count
Source
106
204k
{
107
204k
    const int have_tt = f->c->n_tc > 1;
108
204k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
204k
    const int offset = 8 * !!sby;
110
204k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
204k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
204k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
204k
    pixel *const dst[3] = {
114
204k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
204k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
204k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
204k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
204k
    const int restore_planes = f->lf.restore_planes;
121
122
204k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
197k
        const int h = f->cur.p.h;
124
197k
        const int w = f->bw << 2;
125
197k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
197k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
197k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
180k
            backup_lpf(f, dst[0], lr_stride[0],
129
180k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
180k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
197k
        if (have_tt && resize) {
132
38.4k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
38.4k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
38.4k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
38.4k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
38.4k
        }
137
197k
    }
138
204k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
182k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
149k
    {
141
149k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
149k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
149k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
149k
        const int w = f->bw << (2 - ss_hor);
145
149k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
149k
        const int offset_uv = offset >> ss_ver;
147
149k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
149k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
149k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
118k
            if (restore_planes & LR_RESTORE_U || !resize)
151
105k
                backup_lpf(f, dst[1], lr_stride[1],
152
105k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
105k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
105k
                           row_h, w, h, ss_hor, 1);
155
118k
            if (have_tt && resize)
156
28.1k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
28.1k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
28.1k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
28.1k
                           row_h, w, h, ss_hor, 0);
160
118k
        }
161
149k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
145k
            if (restore_planes & LR_RESTORE_V || !resize)
163
136k
                backup_lpf(f, dst[2], lr_stride[1],
164
136k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
136k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
136k
                           row_h, w, h, ss_hor, 1);
167
145k
            if (have_tt && resize)
168
30.3k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
30.3k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
30.3k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
30.3k
                           row_h, w, h, ss_hor, 0);
172
145k
        }
173
149k
    }
174
204k
}
175
176
static inline void filter_plane_cols_y(const Dav1dFrameContext *const f,
177
                                       const int have_left,
178
                                       const uint8_t (*lvl)[4],
179
                                       const ptrdiff_t b4_stride,
180
                                       const uint16_t (*const mask)[3][2],
181
                                       pixel *dst, const ptrdiff_t ls,
182
                                       const int w,
183
                                       const int starty4, const int endy4)
184
495k
{
185
495k
    const Dav1dDSPContext *const dsp = f->dsp;
186
495k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[0][0];
187
188
    // filter edges between columns (e.g. block1 | block2)
189
5.15M
    for (int x = 0; x < w; x++) {
190
4.66M
        if (!have_left && !x) continue;
191
4.24M
        uint32_t hmask[4];
192
4.24M
        if (!starty4) {
193
3.49M
            hmask[0] = mask[x][0][0];
194
3.49M
            hmask[1] = mask[x][1][0];
195
3.49M
            hmask[2] = mask[x][2][0];
196
3.49M
            if (endy4 > 16) {
197
1.13M
                hmask[0] |= (unsigned) mask[x][0][1] << 16;
198
1.13M
                hmask[1] |= (unsigned) mask[x][1][1] << 16;
199
1.13M
                hmask[2] |= (unsigned) mask[x][2][1] << 16;
200
1.13M
            }
201
3.49M
        } else {
202
748k
            hmask[0] = mask[x][0][1];
203
748k
            hmask[1] = mask[x][1][1];
204
748k
            hmask[2] = mask[x][2][1];
205
748k
        }
206
4.24M
        hmask[3] = 0;
207
4.24M
        loop_filter_sb(&dst[x * 4], ls, hmask,
208
4.24M
                       (const uint8_t(*)[4]) &lvl[x][0], b4_stride,
209
4.24M
                       &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
210
4.24M
    }
211
495k
}
212
213
static inline void filter_plane_rows_y(const Dav1dFrameContext *const f,
214
                                       const int have_top,
215
                                       const uint8_t (*lvl)[4],
216
                                       const ptrdiff_t b4_stride,
217
                                       const uint16_t (*const mask)[3][2],
218
                                       pixel *dst, const ptrdiff_t ls,
219
                                       const int w,
220
                                       const int starty4, const int endy4)
221
495k
{
222
495k
    const Dav1dDSPContext *const dsp = f->dsp;
223
495k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[0][1];
224
225
    //                                 block1
226
    // filter edges between rows (e.g. ------)
227
    //                                 block2
228
6.83M
    for (int y = starty4; y < endy4;
229
6.34M
         y++, dst += 4 * PXSTRIDE(ls), lvl += b4_stride)
230
6.34M
    {
231
6.34M
        if (!have_top && !y) continue;
232
6.06M
        const uint32_t vmask[4] = {
233
6.06M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << 16),
234
6.06M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << 16),
235
6.06M
            mask[y][2][0] | ((unsigned) mask[y][2][1] << 16),
236
6.06M
            0,
237
6.06M
        };
238
6.06M
        loop_filter_sb(dst, ls, vmask,
239
6.06M
                       (const uint8_t(*)[4]) &lvl[0][1], b4_stride,
240
6.06M
                       &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
241
6.06M
    }
242
495k
}
243
244
static inline void filter_plane_cols_uv(const Dav1dFrameContext *const f,
245
                                        const int have_left,
246
                                        const uint8_t (*lvl)[4],
247
                                        const ptrdiff_t b4_stride,
248
                                        const uint16_t (*const mask)[2][2],
249
                                        pixel *const u, pixel *const v,
250
                                        const ptrdiff_t ls, const int w,
251
                                        const int starty4, const int endy4,
252
                                        const int ss_ver)
253
377k
{
254
377k
    const Dav1dDSPContext *const dsp = f->dsp;
255
377k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[1][0];
256
257
    // filter edges between columns (e.g. block1 | block2)
258
2.88M
    for (int x = 0; x < w; x++) {
259
2.50M
        if (!have_left && !x) continue;
260
2.18M
        uint32_t hmask[3];
261
2.18M
        if (!starty4) {
262
1.82M
            hmask[0] = mask[x][0][0];
263
1.82M
            hmask[1] = mask[x][1][0];
264
1.82M
            if (endy4 > (16 >> ss_ver)) {
265
628k
                hmask[0] |= (unsigned) mask[x][0][1] << (16 >> ss_ver);
266
628k
                hmask[1] |= (unsigned) mask[x][1][1] << (16 >> ss_ver);
267
628k
            }
268
1.82M
        } else {
269
358k
            hmask[0] = mask[x][0][1];
270
358k
            hmask[1] = mask[x][1][1];
271
358k
        }
272
2.18M
        hmask[2] = 0;
273
2.18M
        loop_filter_sb(&u[x * 4], ls, hmask,
274
2.18M
                       (const uint8_t(*)[4]) &lvl[x][2], b4_stride,
275
2.18M
                       &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
276
2.18M
        loop_filter_sb(&v[x * 4], ls, hmask,
277
2.18M
                       (const uint8_t(*)[4]) &lvl[x][3], b4_stride,
278
2.18M
                       &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
279
2.18M
    }
280
377k
}
281
282
static inline void filter_plane_rows_uv(const Dav1dFrameContext *const f,
283
                                        const int have_top,
284
                                        const uint8_t (*lvl)[4],
285
                                        const ptrdiff_t b4_stride,
286
                                        const uint16_t (*const mask)[2][2],
287
                                        pixel *const u, pixel *const v,
288
                                        const ptrdiff_t ls, const int w,
289
                                        const int starty4, const int endy4,
290
                                        const int ss_hor)
291
377k
{
292
377k
    const Dav1dDSPContext *const dsp = f->dsp;
293
377k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[1][1];
294
377k
    ptrdiff_t off_l = 0;
295
296
    //                                 block1
297
    // filter edges between rows (e.g. ------)
298
    //                                 block2
299
3.66M
    for (int y = starty4; y < endy4;
300
3.29M
         y++, off_l += 4 * PXSTRIDE(ls), lvl += b4_stride)
301
3.29M
    {
302
3.29M
        if (!have_top && !y) continue;
303
3.07M
        const uint32_t vmask[3] = {
304
3.07M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << (16 >> ss_hor)),
305
3.07M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << (16 >> ss_hor)),
306
3.07M
            0,
307
3.07M
        };
308
3.07M
        loop_filter_sb(&u[off_l], ls, vmask,
309
3.07M
                       (const uint8_t(*)[4]) &lvl[0][2], b4_stride,
310
3.07M
                       &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
311
3.07M
        loop_filter_sb(&v[off_l], ls, vmask,
312
3.07M
                       (const uint8_t(*)[4]) &lvl[0][3], b4_stride,
313
3.07M
                       &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
314
3.07M
    }
315
377k
}
316
317
void bytefn(dav1d_loopfilter_sbrow_cols)(const Dav1dFrameContext *const f,
318
                                         pixel *const p[3], Av1Filter *const lflvl,
319
                                         int sby, const int start_of_tile_row)
320
417k
{
321
417k
    int x, have_left;
322
    // Don't filter outside the frame
323
417k
    const int is_sb64 = !f->seq_hdr->sb128;
324
417k
    const int starty4 = (sby & is_sb64) << 4;
325
417k
    const int sbsz = 32 >> is_sb64;
326
417k
    const int sbl2 = 5 - is_sb64;
327
417k
    const int halign = (f->bh + 31) & ~31;
328
417k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
329
417k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
330
417k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
331
417k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
332
417k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
333
417k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
334
335
    // fix lpf strength at tile col boundaries
336
417k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
337
417k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
338
420k
    for (int tile_col = 1;; tile_col++) {
339
420k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
340
420k
        if ((x << sbl2) >= f->bw) break;
341
3.28k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
342
3.28k
        x >>= is_sb64;
343
344
3.28k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
345
38.4k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
346
35.1k
            const int sidx = mask >= 0x10000U;
347
35.1k
            const unsigned smask = mask >> (sidx << 4);
348
35.1k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
349
35.1k
                                !!(y_hmask[1][sidx] & smask);
350
35.1k
            y_hmask[2][sidx] &= ~smask;
351
35.1k
            y_hmask[1][sidx] &= ~smask;
352
35.1k
            y_hmask[0][sidx] &= ~smask;
353
35.1k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
354
35.1k
        }
355
356
3.28k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
357
2.71k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
358
22.9k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
359
20.2k
                 y++, uv_mask <<= 1)
360
20.2k
            {
361
20.2k
                const int sidx = uv_mask >= vmax;
362
20.2k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
363
20.2k
                const int idx = !!(uv_hmask[1][sidx] & smask);
364
20.2k
                uv_hmask[1][sidx] &= ~smask;
365
20.2k
                uv_hmask[0][sidx] &= ~smask;
366
20.2k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
367
20.2k
            }
368
2.71k
        }
369
3.28k
        lpf_y  += halign;
370
3.28k
        lpf_uv += halign >> ss_ver;
371
3.28k
    }
372
373
    // fix lpf strength at tile row boundaries
374
417k
    if (start_of_tile_row) {
375
2.44k
        const BlockContext *a;
376
2.44k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
377
5.70k
             x < f->sb128w; x++, a++)
378
3.25k
        {
379
3.25k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
380
3.25k
            const unsigned w = imin(32, f->w4 - (x << 5));
381
52.9k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
382
49.6k
                const int sidx = mask >= 0x10000U;
383
49.6k
                const unsigned smask = mask >> (sidx << 4);
384
49.6k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
385
49.6k
                                    !!(y_vmask[1][sidx] & smask);
386
49.6k
                y_vmask[2][sidx] &= ~smask;
387
49.6k
                y_vmask[1][sidx] &= ~smask;
388
49.6k
                y_vmask[0][sidx] &= ~smask;
389
49.6k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
390
49.6k
            }
391
392
3.25k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
393
2.70k
                const unsigned cw = (w + ss_hor) >> ss_hor;
394
2.70k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
395
34.9k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
396
32.2k
                    const int sidx = uv_mask >= hmax;
397
32.2k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
398
32.2k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
399
32.2k
                    uv_vmask[1][sidx] &= ~smask;
400
32.2k
                    uv_vmask[0][sidx] &= ~smask;
401
32.2k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
402
32.2k
                }
403
2.70k
            }
404
3.25k
        }
405
2.44k
    }
406
407
417k
    pixel *ptr;
408
417k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
409
913k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
410
495k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
411
495k
    {
412
495k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
413
495k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
414
495k
                            imin(32, f->w4 - x * 32), starty4, endy4);
415
495k
    }
416
417
417k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
418
98.9k
        return;
419
420
318k
    ptrdiff_t uv_off;
421
318k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
422
696k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
423
377k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
424
377k
    {
425
377k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
426
377k
                             lflvl[x].filter_uv[0],
427
377k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
428
377k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
429
377k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
430
377k
    }
431
318k
}
dav1d_loopfilter_sbrow_cols_8bpc
Line
Count
Source
320
209k
{
321
209k
    int x, have_left;
322
    // Don't filter outside the frame
323
209k
    const int is_sb64 = !f->seq_hdr->sb128;
324
209k
    const int starty4 = (sby & is_sb64) << 4;
325
209k
    const int sbsz = 32 >> is_sb64;
326
209k
    const int sbl2 = 5 - is_sb64;
327
209k
    const int halign = (f->bh + 31) & ~31;
328
209k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
329
209k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
330
209k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
331
209k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
332
209k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
333
209k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
334
335
    // fix lpf strength at tile col boundaries
336
209k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
337
209k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
338
210k
    for (int tile_col = 1;; tile_col++) {
339
210k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
340
210k
        if ((x << sbl2) >= f->bw) break;
341
1.44k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
342
1.44k
        x >>= is_sb64;
343
344
1.44k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
345
16.0k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
346
14.5k
            const int sidx = mask >= 0x10000U;
347
14.5k
            const unsigned smask = mask >> (sidx << 4);
348
14.5k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
349
14.5k
                                !!(y_hmask[1][sidx] & smask);
350
14.5k
            y_hmask[2][sidx] &= ~smask;
351
14.5k
            y_hmask[1][sidx] &= ~smask;
352
14.5k
            y_hmask[0][sidx] &= ~smask;
353
14.5k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
354
14.5k
        }
355
356
1.44k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
357
1.20k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
358
10.0k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
359
8.80k
                 y++, uv_mask <<= 1)
360
8.80k
            {
361
8.80k
                const int sidx = uv_mask >= vmax;
362
8.80k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
363
8.80k
                const int idx = !!(uv_hmask[1][sidx] & smask);
364
8.80k
                uv_hmask[1][sidx] &= ~smask;
365
8.80k
                uv_hmask[0][sidx] &= ~smask;
366
8.80k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
367
8.80k
            }
368
1.20k
        }
369
1.44k
        lpf_y  += halign;
370
1.44k
        lpf_uv += halign >> ss_ver;
371
1.44k
    }
372
373
    // fix lpf strength at tile row boundaries
374
209k
    if (start_of_tile_row) {
375
1.47k
        const BlockContext *a;
376
1.47k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
377
3.27k
             x < f->sb128w; x++, a++)
378
1.80k
        {
379
1.80k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
380
1.80k
            const unsigned w = imin(32, f->w4 - (x << 5));
381
26.0k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
382
24.2k
                const int sidx = mask >= 0x10000U;
383
24.2k
                const unsigned smask = mask >> (sidx << 4);
384
24.2k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
385
24.2k
                                    !!(y_vmask[1][sidx] & smask);
386
24.2k
                y_vmask[2][sidx] &= ~smask;
387
24.2k
                y_vmask[1][sidx] &= ~smask;
388
24.2k
                y_vmask[0][sidx] &= ~smask;
389
24.2k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
390
24.2k
            }
391
392
1.80k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
393
1.47k
                const unsigned cw = (w + ss_hor) >> ss_hor;
394
1.47k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
395
17.4k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
396
16.0k
                    const int sidx = uv_mask >= hmax;
397
16.0k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
398
16.0k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
399
16.0k
                    uv_vmask[1][sidx] &= ~smask;
400
16.0k
                    uv_vmask[0][sidx] &= ~smask;
401
16.0k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
402
16.0k
                }
403
1.47k
            }
404
1.80k
        }
405
1.47k
    }
406
407
209k
    pixel *ptr;
408
209k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
409
460k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
410
251k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
411
251k
    {
412
251k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
413
251k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
414
251k
                            imin(32, f->w4 - x * 32), starty4, endy4);
415
251k
    }
416
417
209k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
418
37.2k
        return;
419
420
172k
    ptrdiff_t uv_off;
421
172k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
422
376k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
423
204k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
424
204k
    {
425
204k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
426
204k
                             lflvl[x].filter_uv[0],
427
204k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
428
204k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
429
204k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
430
204k
    }
431
172k
}
dav1d_loopfilter_sbrow_cols_16bpc
Line
Count
Source
320
208k
{
321
208k
    int x, have_left;
322
    // Don't filter outside the frame
323
208k
    const int is_sb64 = !f->seq_hdr->sb128;
324
208k
    const int starty4 = (sby & is_sb64) << 4;
325
208k
    const int sbsz = 32 >> is_sb64;
326
208k
    const int sbl2 = 5 - is_sb64;
327
208k
    const int halign = (f->bh + 31) & ~31;
328
208k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
329
208k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
330
208k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
331
208k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
332
208k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
333
208k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
334
335
    // fix lpf strength at tile col boundaries
336
208k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
337
208k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
338
210k
    for (int tile_col = 1;; tile_col++) {
339
210k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
340
210k
        if ((x << sbl2) >= f->bw) break;
341
1.84k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
342
1.84k
        x >>= is_sb64;
343
344
1.84k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
345
22.4k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
346
20.6k
            const int sidx = mask >= 0x10000U;
347
20.6k
            const unsigned smask = mask >> (sidx << 4);
348
20.6k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
349
20.6k
                                !!(y_hmask[1][sidx] & smask);
350
20.6k
            y_hmask[2][sidx] &= ~smask;
351
20.6k
            y_hmask[1][sidx] &= ~smask;
352
20.6k
            y_hmask[0][sidx] &= ~smask;
353
20.6k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
354
20.6k
        }
355
356
1.84k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
357
1.50k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
358
12.9k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
359
11.4k
                 y++, uv_mask <<= 1)
360
11.4k
            {
361
11.4k
                const int sidx = uv_mask >= vmax;
362
11.4k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
363
11.4k
                const int idx = !!(uv_hmask[1][sidx] & smask);
364
11.4k
                uv_hmask[1][sidx] &= ~smask;
365
11.4k
                uv_hmask[0][sidx] &= ~smask;
366
11.4k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
367
11.4k
            }
368
1.50k
        }
369
1.84k
        lpf_y  += halign;
370
1.84k
        lpf_uv += halign >> ss_ver;
371
1.84k
    }
372
373
    // fix lpf strength at tile row boundaries
374
208k
    if (start_of_tile_row) {
375
970
        const BlockContext *a;
376
970
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
377
2.42k
             x < f->sb128w; x++, a++)
378
1.45k
        {
379
1.45k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
380
1.45k
            const unsigned w = imin(32, f->w4 - (x << 5));
381
26.9k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
382
25.4k
                const int sidx = mask >= 0x10000U;
383
25.4k
                const unsigned smask = mask >> (sidx << 4);
384
25.4k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
385
25.4k
                                    !!(y_vmask[1][sidx] & smask);
386
25.4k
                y_vmask[2][sidx] &= ~smask;
387
25.4k
                y_vmask[1][sidx] &= ~smask;
388
25.4k
                y_vmask[0][sidx] &= ~smask;
389
25.4k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
390
25.4k
            }
391
392
1.45k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
393
1.22k
                const unsigned cw = (w + ss_hor) >> ss_hor;
394
1.22k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
395
17.4k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
396
16.2k
                    const int sidx = uv_mask >= hmax;
397
16.2k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
398
16.2k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
399
16.2k
                    uv_vmask[1][sidx] &= ~smask;
400
16.2k
                    uv_vmask[0][sidx] &= ~smask;
401
16.2k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
402
16.2k
                }
403
1.22k
            }
404
1.45k
        }
405
970
    }
406
407
208k
    pixel *ptr;
408
208k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
409
452k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
410
244k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
411
244k
    {
412
244k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
413
244k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
414
244k
                            imin(32, f->w4 - x * 32), starty4, endy4);
415
244k
    }
416
417
208k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
418
61.7k
        return;
419
420
146k
    ptrdiff_t uv_off;
421
146k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
422
319k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
423
173k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
424
173k
    {
425
173k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
426
173k
                             lflvl[x].filter_uv[0],
427
173k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
428
173k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
429
173k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
430
173k
    }
431
146k
}
432
433
void bytefn(dav1d_loopfilter_sbrow_rows)(const Dav1dFrameContext *const f,
434
                                         pixel *const p[3], Av1Filter *const lflvl,
435
                                         int sby)
436
417k
{
437
417k
    int x;
438
    // Don't filter outside the frame
439
417k
    const int have_top = sby > 0;
440
417k
    const int is_sb64 = !f->seq_hdr->sb128;
441
417k
    const int starty4 = (sby & is_sb64) << 4;
442
417k
    const int sbsz = 32 >> is_sb64;
443
417k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
444
417k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
445
417k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
446
417k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
447
448
417k
    pixel *ptr;
449
417k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
450
912k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
451
495k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
452
495k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
453
495k
                            imin(32, f->w4 - x * 32), starty4, endy4);
454
495k
    }
455
456
417k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
457
98.9k
        return;
458
459
318k
    ptrdiff_t uv_off;
460
318k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
461
695k
    for (uv_off = 0, x = 0; x < f->sb128w;
462
377k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
463
377k
    {
464
377k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
465
377k
                             lflvl[x].filter_uv[1],
466
377k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
467
377k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
468
377k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
469
377k
    }
470
318k
}
dav1d_loopfilter_sbrow_rows_8bpc
Line
Count
Source
436
209k
{
437
209k
    int x;
438
    // Don't filter outside the frame
439
209k
    const int have_top = sby > 0;
440
209k
    const int is_sb64 = !f->seq_hdr->sb128;
441
209k
    const int starty4 = (sby & is_sb64) << 4;
442
209k
    const int sbsz = 32 >> is_sb64;
443
209k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
444
209k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
445
209k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
446
209k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
447
448
209k
    pixel *ptr;
449
209k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
450
460k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
451
250k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
452
250k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
453
250k
                            imin(32, f->w4 - x * 32), starty4, endy4);
454
250k
    }
455
456
209k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
457
37.1k
        return;
458
459
172k
    ptrdiff_t uv_off;
460
172k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
461
376k
    for (uv_off = 0, x = 0; x < f->sb128w;
462
204k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
463
204k
    {
464
204k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
465
204k
                             lflvl[x].filter_uv[1],
466
204k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
467
204k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
468
204k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
469
204k
    }
470
172k
}
dav1d_loopfilter_sbrow_rows_16bpc
Line
Count
Source
436
208k
{
437
208k
    int x;
438
    // Don't filter outside the frame
439
208k
    const int have_top = sby > 0;
440
208k
    const int is_sb64 = !f->seq_hdr->sb128;
441
208k
    const int starty4 = (sby & is_sb64) << 4;
442
208k
    const int sbsz = 32 >> is_sb64;
443
208k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
444
208k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
445
208k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
446
208k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
447
448
208k
    pixel *ptr;
449
208k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
450
452k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
451
244k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
452
244k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
453
244k
                            imin(32, f->w4 - x * 32), starty4, endy4);
454
244k
    }
455
456
208k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
457
61.7k
        return;
458
459
146k
    ptrdiff_t uv_off;
460
146k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
461
319k
    for (uv_off = 0, x = 0; x < f->sb128w;
462
173k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
463
173k
    {
464
173k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
465
173k
                             lflvl[x].filter_uv[1],
466
173k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
467
173k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
468
173k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
469
173k
    }
470
146k
}