Coverage Report

Created: 2026-06-15 06:25

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
532k
{
48
532k
    const int cdef_backup = !lr_backup;
49
532k
    const int dst_w = f->frame_hdr->super_res.enabled ?
50
316k
                      (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
532k
    int stripe_h = ((64 << (cdef_backup & sb128)) - 8 * !row) >> ss_ver;
54
532k
    src += (stripe_h - 2) * PXSTRIDE(src_stride);
55
56
532k
    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
532k
    if (lr_backup && (f->frame_hdr->width[0] != f->frame_hdr->width[1])) {
74
98.9k
        while (row + stripe_h <= row_h) {
75
49.6k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
76
49.6k
            f->dsp->mc.resize(dst, dst_stride, src, src_stride,
77
49.6k
                              dst_w, n_lines, src_w, f->resize_step[ss_hor],
78
49.6k
                              f->resize_start[ss_hor] HIGHBD_CALL_SUFFIX);
79
49.6k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
80
49.6k
            stripe_h = 64 >> ss_ver;
81
49.6k
            src += stripe_h * PXSTRIDE(src_stride);
82
49.6k
            dst += n_lines * PXSTRIDE(dst_stride);
83
49.6k
            if (n_lines == 3) {
84
706
                pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], dst_w);
85
706
                dst += PXSTRIDE(dst_stride);
86
706
            }
87
49.6k
        }
88
483k
    } else {
89
882k
        while (row + stripe_h <= row_h) {
90
398k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
91
1.99M
            for (int i = 0; i < 4; i++) {
92
1.59M
                pixel_copy(dst, i == n_lines ? &dst[-PXSTRIDE(dst_stride)] :
93
1.59M
                                               src, src_w);
94
1.59M
                dst += PXSTRIDE(dst_stride);
95
1.59M
                src += PXSTRIDE(src_stride);
96
1.59M
            }
97
398k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
98
398k
            stripe_h = 64 >> ss_ver;
99
398k
            src += (stripe_h - 4) * PXSTRIDE(src_stride);
100
398k
        }
101
483k
    }
102
532k
}
103
104
void bytefn(dav1d_copy_lpf)(Dav1dFrameContext *const f,
105
                            /*const*/ pixel *const src[3], const int sby)
106
207k
{
107
207k
    const int have_tt = f->c->n_tc > 1;
108
207k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
207k
    const int offset = 8 * !!sby;
110
207k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
207k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
207k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
207k
    pixel *const dst[3] = {
114
207k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
207k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
207k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
207k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
207k
    const int restore_planes = f->lf.restore_planes;
121
122
207k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
200k
        const int h = f->cur.p.h;
124
200k
        const int w = f->bw << 2;
125
200k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
200k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
200k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
179k
            backup_lpf(f, dst[0], lr_stride[0],
129
179k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
179k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
200k
        if (have_tt && resize) {
132
42.2k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
42.2k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
42.2k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
42.2k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
42.2k
        }
137
200k
    }
138
207k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
201k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
156k
    {
141
156k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
156k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
156k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
156k
        const int w = f->bw << (2 - ss_hor);
145
156k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
156k
        const int offset_uv = offset >> ss_ver;
147
156k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
156k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
156k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
134k
            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
134k
            if (have_tt && resize)
156
28.4k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
28.4k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
28.4k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
28.4k
                           row_h, w, h, ss_hor, 0);
160
134k
        }
161
156k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
148k
            if (restore_planes & LR_RESTORE_V || !resize)
163
135k
                backup_lpf(f, dst[2], lr_stride[1],
164
135k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
135k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
135k
                           row_h, w, h, ss_hor, 1);
167
148k
            if (have_tt && resize)
168
28.5k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
28.5k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
28.5k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
28.5k
                           row_h, w, h, ss_hor, 0);
172
148k
        }
173
156k
    }
174
207k
}
dav1d_copy_lpf_8bpc
Line
Count
Source
106
98.7k
{
107
98.7k
    const int have_tt = f->c->n_tc > 1;
108
98.7k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
98.7k
    const int offset = 8 * !!sby;
110
98.7k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
98.7k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
98.7k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
98.7k
    pixel *const dst[3] = {
114
98.7k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
98.7k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
98.7k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
98.7k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
98.7k
    const int restore_planes = f->lf.restore_planes;
121
122
98.7k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
95.4k
        const int h = f->cur.p.h;
124
95.4k
        const int w = f->bw << 2;
125
95.4k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
95.4k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
95.4k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
86.2k
            backup_lpf(f, dst[0], lr_stride[0],
129
86.2k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
86.2k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
95.4k
        if (have_tt && resize) {
132
21.2k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
21.2k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
21.2k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
21.2k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
21.2k
        }
137
95.4k
    }
138
98.7k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
96.0k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
75.7k
    {
141
75.7k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
75.7k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
75.7k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
75.7k
        const int w = f->bw << (2 - ss_hor);
145
75.7k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
75.7k
        const int offset_uv = offset >> ss_ver;
147
75.7k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
75.7k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
75.7k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
64.8k
            if (restore_planes & LR_RESTORE_U || !resize)
151
54.8k
                backup_lpf(f, dst[1], lr_stride[1],
152
54.8k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
54.8k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
54.8k
                           row_h, w, h, ss_hor, 1);
155
64.8k
            if (have_tt && resize)
156
16.7k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
16.7k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
16.7k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
16.7k
                           row_h, w, h, ss_hor, 0);
160
64.8k
        }
161
75.7k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
72.0k
            if (restore_planes & LR_RESTORE_V || !resize)
163
64.9k
                backup_lpf(f, dst[2], lr_stride[1],
164
64.9k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
64.9k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
64.9k
                           row_h, w, h, ss_hor, 1);
167
72.0k
            if (have_tt && resize)
168
17.2k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
17.2k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
17.2k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
17.2k
                           row_h, w, h, ss_hor, 0);
172
72.0k
        }
173
75.7k
    }
174
98.7k
}
dav1d_copy_lpf_16bpc
Line
Count
Source
106
108k
{
107
108k
    const int have_tt = f->c->n_tc > 1;
108
108k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
108k
    const int offset = 8 * !!sby;
110
108k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
108k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
108k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
108k
    pixel *const dst[3] = {
114
108k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
108k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
108k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
108k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
108k
    const int restore_planes = f->lf.restore_planes;
121
122
108k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
104k
        const int h = f->cur.p.h;
124
104k
        const int w = f->bw << 2;
125
104k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
104k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
104k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
93.3k
            backup_lpf(f, dst[0], lr_stride[0],
129
93.3k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
93.3k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
104k
        if (have_tt && resize) {
132
21.0k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
21.0k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
21.0k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
21.0k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
21.0k
        }
137
104k
    }
138
108k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
105k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
80.2k
    {
141
80.2k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
80.2k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
80.2k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
80.2k
        const int w = f->bw << (2 - ss_hor);
145
80.2k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
80.2k
        const int offset_uv = offset >> ss_ver;
147
80.2k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
80.2k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
80.2k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
69.3k
            if (restore_planes & LR_RESTORE_U || !resize)
151
63.1k
                backup_lpf(f, dst[1], lr_stride[1],
152
63.1k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
63.1k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
63.1k
                           row_h, w, h, ss_hor, 1);
155
69.3k
            if (have_tt && resize)
156
11.6k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
11.6k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
11.6k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
11.6k
                           row_h, w, h, ss_hor, 0);
160
69.3k
        }
161
80.2k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
76.8k
            if (restore_planes & LR_RESTORE_V || !resize)
163
70.9k
                backup_lpf(f, dst[2], lr_stride[1],
164
70.9k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
70.9k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
70.9k
                           row_h, w, h, ss_hor, 1);
167
76.8k
            if (have_tt && resize)
168
11.2k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
11.2k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
11.2k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
11.2k
                           row_h, w, h, ss_hor, 0);
172
76.8k
        }
173
80.2k
    }
174
108k
}
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
285k
{
185
285k
    const Dav1dDSPContext *const dsp = f->dsp;
186
187
    // filter edges between columns (e.g. block1 | block2)
188
4.75M
    for (int x = 0; x < w; x++) {
189
4.46M
        if (!have_left && !x) continue;
190
4.28M
        uint32_t hmask[4];
191
4.28M
        if (!starty4) {
192
3.59M
            hmask[0] = mask[x][0][0];
193
3.59M
            hmask[1] = mask[x][1][0];
194
3.59M
            hmask[2] = mask[x][2][0];
195
3.59M
            if (endy4 > 16) {
196
1.75M
                hmask[0] |= (unsigned) mask[x][0][1] << 16;
197
1.75M
                hmask[1] |= (unsigned) mask[x][1][1] << 16;
198
1.75M
                hmask[2] |= (unsigned) mask[x][2][1] << 16;
199
1.75M
            }
200
3.59M
        } else {
201
683k
            hmask[0] = mask[x][0][1];
202
683k
            hmask[1] = mask[x][1][1];
203
683k
            hmask[2] = mask[x][2][1];
204
683k
        }
205
4.28M
        hmask[3] = 0;
206
4.28M
        dsp->lf.loop_filter_sb[0][0](&dst[x * 4], ls, hmask,
207
4.28M
                                     (const uint8_t(*)[4]) &lvl[x][0], b4_stride,
208
4.28M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
209
4.28M
    }
210
285k
}
211
212
static inline void filter_plane_rows_y(const Dav1dFrameContext *const f,
213
                                       const int have_top,
214
                                       const uint8_t (*lvl)[4],
215
                                       const ptrdiff_t b4_stride,
216
                                       const uint16_t (*const mask)[3][2],
217
                                       pixel *dst, const ptrdiff_t ls,
218
                                       const int w,
219
                                       const int starty4, const int endy4)
220
284k
{
221
284k
    const Dav1dDSPContext *const dsp = f->dsp;
222
223
    //                                 block1
224
    // filter edges between rows (e.g. ------)
225
    //                                 block2
226
4.72M
    for (int y = starty4; y < endy4;
227
4.44M
         y++, dst += 4 * PXSTRIDE(ls), lvl += b4_stride)
228
4.44M
    {
229
4.44M
        if (!have_top && !y) continue;
230
4.31M
        const uint32_t vmask[4] = {
231
4.31M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << 16),
232
4.31M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << 16),
233
4.31M
            mask[y][2][0] | ((unsigned) mask[y][2][1] << 16),
234
4.31M
            0,
235
4.31M
        };
236
4.31M
        dsp->lf.loop_filter_sb[0][1](dst, ls, vmask,
237
4.31M
                                     (const uint8_t(*)[4]) &lvl[0][1], b4_stride,
238
4.31M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
239
4.31M
    }
240
284k
}
241
242
static inline void filter_plane_cols_uv(const Dav1dFrameContext *const f,
243
                                        const int have_left,
244
                                        const uint8_t (*lvl)[4],
245
                                        const ptrdiff_t b4_stride,
246
                                        const uint16_t (*const mask)[2][2],
247
                                        pixel *const u, pixel *const v,
248
                                        const ptrdiff_t ls, const int w,
249
                                        const int starty4, const int endy4,
250
                                        const int ss_ver)
251
198k
{
252
198k
    const Dav1dDSPContext *const dsp = f->dsp;
253
254
    // filter edges between columns (e.g. block1 | block2)
255
2.33M
    for (int x = 0; x < w; x++) {
256
2.13M
        if (!have_left && !x) continue;
257
2.01M
        uint32_t hmask[3];
258
2.01M
        if (!starty4) {
259
1.71M
            hmask[0] = mask[x][0][0];
260
1.71M
            hmask[1] = mask[x][1][0];
261
1.71M
            if (endy4 > (16 >> ss_ver)) {
262
835k
                hmask[0] |= (unsigned) mask[x][0][1] << (16 >> ss_ver);
263
835k
                hmask[1] |= (unsigned) mask[x][1][1] << (16 >> ss_ver);
264
835k
            }
265
1.71M
        } else {
266
300k
            hmask[0] = mask[x][0][1];
267
300k
            hmask[1] = mask[x][1][1];
268
300k
        }
269
2.01M
        hmask[2] = 0;
270
2.01M
        dsp->lf.loop_filter_sb[1][0](&u[x * 4], ls, hmask,
271
2.01M
                                     (const uint8_t(*)[4]) &lvl[x][2], b4_stride,
272
2.01M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
273
2.01M
        dsp->lf.loop_filter_sb[1][0](&v[x * 4], ls, hmask,
274
2.01M
                                     (const uint8_t(*)[4]) &lvl[x][3], b4_stride,
275
2.01M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
276
2.01M
    }
277
198k
}
278
279
static inline void filter_plane_rows_uv(const Dav1dFrameContext *const f,
280
                                        const int have_top,
281
                                        const uint8_t (*lvl)[4],
282
                                        const ptrdiff_t b4_stride,
283
                                        const uint16_t (*const mask)[2][2],
284
                                        pixel *const u, pixel *const v,
285
                                        const ptrdiff_t ls, const int w,
286
                                        const int starty4, const int endy4,
287
                                        const int ss_hor)
288
197k
{
289
197k
    const Dav1dDSPContext *const dsp = f->dsp;
290
197k
    ptrdiff_t off_l = 0;
291
292
    //                                 block1
293
    // filter edges between rows (e.g. ------)
294
    //                                 block2
295
2.42M
    for (int y = starty4; y < endy4;
296
2.22M
         y++, off_l += 4 * PXSTRIDE(ls), lvl += b4_stride)
297
2.22M
    {
298
2.22M
        if (!have_top && !y) continue;
299
2.13M
        const uint32_t vmask[3] = {
300
2.13M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << (16 >> ss_hor)),
301
2.13M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << (16 >> ss_hor)),
302
2.13M
            0,
303
2.13M
        };
304
2.13M
        dsp->lf.loop_filter_sb[1][1](&u[off_l], ls, vmask,
305
2.13M
                                     (const uint8_t(*)[4]) &lvl[0][2], b4_stride,
306
2.13M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
307
2.13M
        dsp->lf.loop_filter_sb[1][1](&v[off_l], ls, vmask,
308
2.13M
                                     (const uint8_t(*)[4]) &lvl[0][3], b4_stride,
309
2.13M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
310
2.13M
    }
311
197k
}
312
313
void bytefn(dav1d_loopfilter_sbrow_cols)(const Dav1dFrameContext *const f,
314
                                         pixel *const p[3], Av1Filter *const lflvl,
315
                                         int sby, const int start_of_tile_row)
316
185k
{
317
185k
    int x, have_left;
318
    // Don't filter outside the frame
319
185k
    const int is_sb64 = !f->seq_hdr->sb128;
320
185k
    const int starty4 = (sby & is_sb64) << 4;
321
185k
    const int sbsz = 32 >> is_sb64;
322
185k
    const int sbl2 = 5 - is_sb64;
323
185k
    const int halign = (f->bh + 31) & ~31;
324
185k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
185k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
185k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
185k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
185k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
185k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
185k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
185k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
189k
    for (int tile_col = 1;; tile_col++) {
335
189k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
189k
        if ((x << sbl2) >= f->bw) break;
337
3.11k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
3.11k
        x >>= is_sb64;
339
340
3.11k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
43.2k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
40.1k
            const int sidx = mask >= 0x10000U;
343
40.1k
            const unsigned smask = mask >> (sidx << 4);
344
40.1k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
40.1k
                                !!(y_hmask[1][sidx] & smask);
346
40.1k
            y_hmask[2][sidx] &= ~smask;
347
40.1k
            y_hmask[1][sidx] &= ~smask;
348
40.1k
            y_hmask[0][sidx] &= ~smask;
349
40.1k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
40.1k
        }
351
352
3.11k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
2.78k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
29.9k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
27.1k
                 y++, uv_mask <<= 1)
356
27.1k
            {
357
27.1k
                const int sidx = uv_mask >= vmax;
358
27.1k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
27.1k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
27.1k
                uv_hmask[1][sidx] &= ~smask;
361
27.1k
                uv_hmask[0][sidx] &= ~smask;
362
27.1k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
27.1k
            }
364
2.78k
        }
365
3.11k
        lpf_y  += halign;
366
3.11k
        lpf_uv += halign >> ss_ver;
367
3.11k
    }
368
369
    // fix lpf strength at tile row boundaries
370
185k
    if (start_of_tile_row) {
371
1.88k
        const BlockContext *a;
372
1.88k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
4.70k
             x < f->sb128w; x++, a++)
374
2.81k
        {
375
2.81k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
2.81k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
46.3k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
43.5k
                const int sidx = mask >= 0x10000U;
379
43.5k
                const unsigned smask = mask >> (sidx << 4);
380
43.5k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
43.5k
                                    !!(y_vmask[1][sidx] & smask);
382
43.5k
                y_vmask[2][sidx] &= ~smask;
383
43.5k
                y_vmask[1][sidx] &= ~smask;
384
43.5k
                y_vmask[0][sidx] &= ~smask;
385
43.5k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
43.5k
            }
387
388
2.81k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
2.37k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
2.37k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
31.9k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
29.5k
                    const int sidx = uv_mask >= hmax;
393
29.5k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
29.5k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
29.5k
                    uv_vmask[1][sidx] &= ~smask;
396
29.5k
                    uv_vmask[0][sidx] &= ~smask;
397
29.5k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
29.5k
                }
399
2.37k
            }
400
2.81k
        }
401
1.88k
    }
402
403
185k
    pixel *ptr;
404
185k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
471k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
285k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
285k
    {
408
285k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
285k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
285k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
285k
    }
412
413
185k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
59.6k
        return;
415
416
126k
    ptrdiff_t uv_off;
417
126k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
325k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
198k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
198k
    {
421
198k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
198k
                             lflvl[x].filter_uv[0],
423
198k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
198k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
198k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
198k
    }
427
126k
}
dav1d_loopfilter_sbrow_cols_8bpc
Line
Count
Source
316
93.4k
{
317
93.4k
    int x, have_left;
318
    // Don't filter outside the frame
319
93.4k
    const int is_sb64 = !f->seq_hdr->sb128;
320
93.4k
    const int starty4 = (sby & is_sb64) << 4;
321
93.4k
    const int sbsz = 32 >> is_sb64;
322
93.4k
    const int sbl2 = 5 - is_sb64;
323
93.4k
    const int halign = (f->bh + 31) & ~31;
324
93.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
93.4k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
93.4k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
93.4k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
93.4k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
93.4k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
93.4k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
93.4k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
94.8k
    for (int tile_col = 1;; tile_col++) {
335
94.8k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
94.8k
        if ((x << sbl2) >= f->bw) break;
337
1.48k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
1.48k
        x >>= is_sb64;
339
340
1.48k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
18.3k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
16.8k
            const int sidx = mask >= 0x10000U;
343
16.8k
            const unsigned smask = mask >> (sidx << 4);
344
16.8k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
16.8k
                                !!(y_hmask[1][sidx] & smask);
346
16.8k
            y_hmask[2][sidx] &= ~smask;
347
16.8k
            y_hmask[1][sidx] &= ~smask;
348
16.8k
            y_hmask[0][sidx] &= ~smask;
349
16.8k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
16.8k
        }
351
352
1.48k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
1.36k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
12.2k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
10.8k
                 y++, uv_mask <<= 1)
356
10.8k
            {
357
10.8k
                const int sidx = uv_mask >= vmax;
358
10.8k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
10.8k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
10.8k
                uv_hmask[1][sidx] &= ~smask;
361
10.8k
                uv_hmask[0][sidx] &= ~smask;
362
10.8k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
10.8k
            }
364
1.36k
        }
365
1.48k
        lpf_y  += halign;
366
1.48k
        lpf_uv += halign >> ss_ver;
367
1.48k
    }
368
369
    // fix lpf strength at tile row boundaries
370
93.4k
    if (start_of_tile_row) {
371
963
        const BlockContext *a;
372
963
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
2.18k
             x < f->sb128w; x++, a++)
374
1.21k
        {
375
1.21k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
1.21k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
15.4k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
14.2k
                const int sidx = mask >= 0x10000U;
379
14.2k
                const unsigned smask = mask >> (sidx << 4);
380
14.2k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
14.2k
                                    !!(y_vmask[1][sidx] & smask);
382
14.2k
                y_vmask[2][sidx] &= ~smask;
383
14.2k
                y_vmask[1][sidx] &= ~smask;
384
14.2k
                y_vmask[0][sidx] &= ~smask;
385
14.2k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
14.2k
            }
387
388
1.21k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
976
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
976
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
9.05k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
8.07k
                    const int sidx = uv_mask >= hmax;
393
8.07k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
8.07k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
8.07k
                    uv_vmask[1][sidx] &= ~smask;
396
8.07k
                    uv_vmask[0][sidx] &= ~smask;
397
8.07k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
8.07k
                }
399
976
            }
400
1.21k
        }
401
963
    }
402
403
93.4k
    pixel *ptr;
404
93.4k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
235k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
141k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
141k
    {
408
141k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
141k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
141k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
141k
    }
412
413
93.4k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
25.6k
        return;
415
416
67.7k
    ptrdiff_t uv_off;
417
67.7k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
171k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
103k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
103k
    {
421
103k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
103k
                             lflvl[x].filter_uv[0],
423
103k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
103k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
103k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
103k
    }
427
67.7k
}
dav1d_loopfilter_sbrow_cols_16bpc
Line
Count
Source
316
92.5k
{
317
92.5k
    int x, have_left;
318
    // Don't filter outside the frame
319
92.5k
    const int is_sb64 = !f->seq_hdr->sb128;
320
92.5k
    const int starty4 = (sby & is_sb64) << 4;
321
92.5k
    const int sbsz = 32 >> is_sb64;
322
92.5k
    const int sbl2 = 5 - is_sb64;
323
92.5k
    const int halign = (f->bh + 31) & ~31;
324
92.5k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
92.5k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
92.5k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
92.5k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
92.5k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
92.5k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
92.5k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
92.5k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
94.1k
    for (int tile_col = 1;; tile_col++) {
335
94.1k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
94.1k
        if ((x << sbl2) >= f->bw) break;
337
1.62k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
1.62k
        x >>= is_sb64;
339
340
1.62k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
24.9k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
23.2k
            const int sidx = mask >= 0x10000U;
343
23.2k
            const unsigned smask = mask >> (sidx << 4);
344
23.2k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
23.2k
                                !!(y_hmask[1][sidx] & smask);
346
23.2k
            y_hmask[2][sidx] &= ~smask;
347
23.2k
            y_hmask[1][sidx] &= ~smask;
348
23.2k
            y_hmask[0][sidx] &= ~smask;
349
23.2k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
23.2k
        }
351
352
1.62k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
1.42k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
17.7k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
16.3k
                 y++, uv_mask <<= 1)
356
16.3k
            {
357
16.3k
                const int sidx = uv_mask >= vmax;
358
16.3k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
16.3k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
16.3k
                uv_hmask[1][sidx] &= ~smask;
361
16.3k
                uv_hmask[0][sidx] &= ~smask;
362
16.3k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
16.3k
            }
364
1.42k
        }
365
1.62k
        lpf_y  += halign;
366
1.62k
        lpf_uv += halign >> ss_ver;
367
1.62k
    }
368
369
    // fix lpf strength at tile row boundaries
370
92.5k
    if (start_of_tile_row) {
371
923
        const BlockContext *a;
372
923
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
2.52k
             x < f->sb128w; x++, a++)
374
1.59k
        {
375
1.59k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
1.59k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
30.9k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
29.3k
                const int sidx = mask >= 0x10000U;
379
29.3k
                const unsigned smask = mask >> (sidx << 4);
380
29.3k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
29.3k
                                    !!(y_vmask[1][sidx] & smask);
382
29.3k
                y_vmask[2][sidx] &= ~smask;
383
29.3k
                y_vmask[1][sidx] &= ~smask;
384
29.3k
                y_vmask[0][sidx] &= ~smask;
385
29.3k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
29.3k
            }
387
388
1.59k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
1.39k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
1.39k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
22.9k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
21.5k
                    const int sidx = uv_mask >= hmax;
393
21.5k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
21.5k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
21.5k
                    uv_vmask[1][sidx] &= ~smask;
396
21.5k
                    uv_vmask[0][sidx] &= ~smask;
397
21.5k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
21.5k
                }
399
1.39k
            }
400
1.59k
        }
401
923
    }
402
403
92.5k
    pixel *ptr;
404
92.5k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
236k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
143k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
143k
    {
408
143k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
143k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
143k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
143k
    }
412
413
92.5k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
34.0k
        return;
415
416
58.5k
    ptrdiff_t uv_off;
417
58.5k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
153k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
94.8k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
94.8k
    {
421
94.8k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
94.8k
                             lflvl[x].filter_uv[0],
423
94.8k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
94.8k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
94.8k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
94.8k
    }
427
58.5k
}
428
429
void bytefn(dav1d_loopfilter_sbrow_rows)(const Dav1dFrameContext *const f,
430
                                         pixel *const p[3], Av1Filter *const lflvl,
431
                                         int sby)
432
185k
{
433
185k
    int x;
434
    // Don't filter outside the frame
435
185k
    const int have_top = sby > 0;
436
185k
    const int is_sb64 = !f->seq_hdr->sb128;
437
185k
    const int starty4 = (sby & is_sb64) << 4;
438
185k
    const int sbsz = 32 >> is_sb64;
439
185k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
185k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
185k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
185k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
185k
    pixel *ptr;
445
185k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
470k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
284k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
284k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
284k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
284k
    }
451
452
185k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
59.5k
        return;
454
455
126k
    ptrdiff_t uv_off;
456
126k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
323k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
197k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
197k
    {
460
197k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
197k
                             lflvl[x].filter_uv[1],
462
197k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
197k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
197k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
197k
    }
466
126k
}
dav1d_loopfilter_sbrow_rows_8bpc
Line
Count
Source
432
93.2k
{
433
93.2k
    int x;
434
    // Don't filter outside the frame
435
93.2k
    const int have_top = sby > 0;
436
93.2k
    const int is_sb64 = !f->seq_hdr->sb128;
437
93.2k
    const int starty4 = (sby & is_sb64) << 4;
438
93.2k
    const int sbsz = 32 >> is_sb64;
439
93.2k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
93.2k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
93.2k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
93.2k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
93.2k
    pixel *ptr;
445
93.2k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
234k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
141k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
141k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
141k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
141k
    }
451
452
93.2k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
25.5k
        return;
454
455
67.6k
    ptrdiff_t uv_off;
456
67.6k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
170k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
103k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
103k
    {
460
103k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
103k
                             lflvl[x].filter_uv[1],
462
103k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
103k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
103k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
103k
    }
466
67.6k
}
dav1d_loopfilter_sbrow_rows_16bpc
Line
Count
Source
432
92.4k
{
433
92.4k
    int x;
434
    // Don't filter outside the frame
435
92.4k
    const int have_top = sby > 0;
436
92.4k
    const int is_sb64 = !f->seq_hdr->sb128;
437
92.4k
    const int starty4 = (sby & is_sb64) << 4;
438
92.4k
    const int sbsz = 32 >> is_sb64;
439
92.4k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
92.4k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
92.4k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
92.4k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
92.4k
    pixel *ptr;
445
92.4k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
236k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
143k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
143k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
143k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
143k
    }
451
452
92.4k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
33.9k
        return;
454
455
58.5k
    ptrdiff_t uv_off;
456
58.5k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
153k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
94.6k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
94.6k
    {
460
94.6k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
94.6k
                             lflvl[x].filter_uv[1],
462
94.6k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
94.6k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
94.6k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
94.6k
    }
466
58.5k
}