Coverage Report

Created: 2026-08-13 07:23

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
581k
{
48
581k
    const int cdef_backup = !lr_backup;
49
581k
    const int dst_w = f->frame_hdr->super_res.enabled ?
50
323k
                      (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
581k
    int stripe_h = ((64 << (cdef_backup & sb128)) - 8 * !row) >> ss_ver;
54
581k
    src += (stripe_h - 2) * PXSTRIDE(src_stride);
55
56
581k
    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
581k
    if (lr_backup && (f->frame_hdr->width[0] != f->frame_hdr->width[1])) {
74
100k
        while (row + stripe_h <= row_h) {
75
44.4k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
76
44.4k
            f->dsp->mc.resize(dst, dst_stride, src, src_stride,
77
44.4k
                              dst_w, n_lines, src_w, f->resize_step[ss_hor],
78
44.4k
                              f->resize_start[ss_hor] HIGHBD_CALL_SUFFIX);
79
44.4k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
80
44.4k
            stripe_h = 64 >> ss_ver;
81
44.4k
            src += stripe_h * PXSTRIDE(src_stride);
82
44.4k
            dst += n_lines * PXSTRIDE(dst_stride);
83
44.4k
            if (n_lines == 3) {
84
626
                pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], dst_w);
85
626
                dst += PXSTRIDE(dst_stride);
86
626
            }
87
44.4k
        }
88
524k
    } else {
89
840k
        while (row + stripe_h <= row_h) {
90
315k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
91
1.57M
            for (int i = 0; i < 4; i++) {
92
1.26M
                pixel_copy(dst, i == n_lines ? &dst[-PXSTRIDE(dst_stride)] :
93
1.26M
                                               src, src_w);
94
1.26M
                dst += PXSTRIDE(dst_stride);
95
1.26M
                src += PXSTRIDE(src_stride);
96
1.26M
            }
97
315k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
98
315k
            stripe_h = 64 >> ss_ver;
99
315k
            src += (stripe_h - 4) * PXSTRIDE(src_stride);
100
315k
        }
101
524k
    }
102
581k
}
103
104
void bytefn(dav1d_copy_lpf)(Dav1dFrameContext *const f,
105
                            /*const*/ pixel *const src[3], const int sby)
106
244k
{
107
244k
    const int have_tt = f->c->n_tc > 1;
108
244k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
244k
    const int offset = 8 * !!sby;
110
244k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
244k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
244k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
244k
    pixel *const dst[3] = {
114
244k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
244k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
244k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
244k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
244k
    const int restore_planes = f->lf.restore_planes;
121
122
244k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
237k
        const int h = f->cur.p.h;
124
237k
        const int w = f->bw << 2;
125
237k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
237k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
237k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
220k
            backup_lpf(f, dst[0], lr_stride[0],
129
220k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
220k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
237k
        if (have_tt && resize) {
132
41.8k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
41.8k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
41.8k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
41.8k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
41.8k
        }
137
237k
    }
138
244k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
211k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
165k
    {
141
165k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
165k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
165k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
165k
        const int w = f->bw << (2 - ss_hor);
145
165k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
165k
        const int offset_uv = offset >> ss_ver;
147
165k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
165k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
165k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
127k
            if (restore_planes & LR_RESTORE_U || !resize)
151
110k
                backup_lpf(f, dst[1], lr_stride[1],
152
110k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
110k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
110k
                           row_h, w, h, ss_hor, 1);
155
127k
            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
127k
        }
161
165k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
160k
            if (restore_planes & LR_RESTORE_V || !resize)
163
148k
                backup_lpf(f, dst[2], lr_stride[1],
164
148k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
148k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
148k
                           row_h, w, h, ss_hor, 1);
167
160k
            if (have_tt && resize)
168
31.2k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
31.2k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
31.2k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
31.2k
                           row_h, w, h, ss_hor, 0);
172
160k
        }
173
165k
    }
174
244k
}
dav1d_copy_lpf_8bpc
Line
Count
Source
106
105k
{
107
105k
    const int have_tt = f->c->n_tc > 1;
108
105k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
105k
    const int offset = 8 * !!sby;
110
105k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
105k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
105k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
105k
    pixel *const dst[3] = {
114
105k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
105k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
105k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
105k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
105k
    const int restore_planes = f->lf.restore_planes;
121
122
105k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
102k
        const int h = f->cur.p.h;
124
102k
        const int w = f->bw << 2;
125
102k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
102k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
102k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
95.4k
            backup_lpf(f, dst[0], lr_stride[0],
129
95.4k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
95.4k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
102k
        if (have_tt && resize) {
132
19.1k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
19.1k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
19.1k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
19.1k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
19.1k
        }
137
102k
    }
138
105k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
100k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
78.8k
    {
141
78.8k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
78.8k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
78.8k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
78.8k
        const int w = f->bw << (2 - ss_hor);
145
78.8k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
78.8k
        const int offset_uv = offset >> ss_ver;
147
78.8k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
78.8k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
78.8k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
62.0k
            if (restore_planes & LR_RESTORE_U || !resize)
151
55.1k
                backup_lpf(f, dst[1], lr_stride[1],
152
55.1k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
55.1k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
55.1k
                           row_h, w, h, ss_hor, 1);
155
62.0k
            if (have_tt && resize)
156
12.9k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
12.9k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
12.9k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
12.9k
                           row_h, w, h, ss_hor, 0);
160
62.0k
        }
161
78.8k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
76.1k
            if (restore_planes & LR_RESTORE_V || !resize)
163
71.3k
                backup_lpf(f, dst[2], lr_stride[1],
164
71.3k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
71.3k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
71.3k
                           row_h, w, h, ss_hor, 1);
167
76.1k
            if (have_tt && resize)
168
13.5k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
13.5k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
13.5k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
13.5k
                           row_h, w, h, ss_hor, 0);
172
76.1k
        }
173
78.8k
    }
174
105k
}
dav1d_copy_lpf_16bpc
Line
Count
Source
106
139k
{
107
139k
    const int have_tt = f->c->n_tc > 1;
108
139k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
139k
    const int offset = 8 * !!sby;
110
139k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
139k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
139k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
139k
    pixel *const dst[3] = {
114
139k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
139k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
139k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
139k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
139k
    const int restore_planes = f->lf.restore_planes;
121
122
139k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
134k
        const int h = f->cur.p.h;
124
134k
        const int w = f->bw << 2;
125
134k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
134k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
134k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
124k
            backup_lpf(f, dst[0], lr_stride[0],
129
124k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
124k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
134k
        if (have_tt && resize) {
132
22.7k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
22.7k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
22.7k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
22.7k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
22.7k
        }
137
134k
    }
138
139k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
110k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
86.6k
    {
141
86.6k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
86.6k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
86.6k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
86.6k
        const int w = f->bw << (2 - ss_hor);
145
86.6k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
86.6k
        const int offset_uv = offset >> ss_ver;
147
86.6k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
86.6k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
86.6k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
65.0k
            if (restore_planes & LR_RESTORE_U || !resize)
151
55.7k
                backup_lpf(f, dst[1], lr_stride[1],
152
55.7k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
55.7k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
55.7k
                           row_h, w, h, ss_hor, 1);
155
65.0k
            if (have_tt && resize)
156
15.2k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
15.2k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
15.2k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
15.2k
                           row_h, w, h, ss_hor, 0);
160
65.0k
        }
161
86.6k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
83.9k
            if (restore_planes & LR_RESTORE_V || !resize)
163
77.6k
                backup_lpf(f, dst[2], lr_stride[1],
164
77.6k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
77.6k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
77.6k
                           row_h, w, h, ss_hor, 1);
167
83.9k
            if (have_tt && resize)
168
17.7k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
17.7k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
17.7k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
17.7k
                           row_h, w, h, ss_hor, 0);
172
83.9k
        }
173
86.6k
    }
174
139k
}
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
349k
{
185
349k
    const Dav1dDSPContext *const dsp = f->dsp;
186
187
    // filter edges between columns (e.g. block1 | block2)
188
4.08M
    for (int x = 0; x < w; x++) {
189
3.73M
        if (!have_left && !x) continue;
190
3.46M
        uint32_t hmask[4];
191
3.46M
        if (!starty4) {
192
2.76M
            hmask[0] = mask[x][0][0];
193
2.76M
            hmask[1] = mask[x][1][0];
194
2.76M
            hmask[2] = mask[x][2][0];
195
2.76M
            if (endy4 > 16) {
196
1.05M
                hmask[0] |= (unsigned) mask[x][0][1] << 16;
197
1.05M
                hmask[1] |= (unsigned) mask[x][1][1] << 16;
198
1.05M
                hmask[2] |= (unsigned) mask[x][2][1] << 16;
199
1.05M
            }
200
2.76M
        } else {
201
703k
            hmask[0] = mask[x][0][1];
202
703k
            hmask[1] = mask[x][1][1];
203
703k
            hmask[2] = mask[x][2][1];
204
703k
        }
205
3.46M
        hmask[3] = 0;
206
3.46M
        dsp->lf.loop_filter_sb[0][0](&dst[x * 4], ls, hmask,
207
3.46M
                                     (const uint8_t(*)[4]) &lvl[x][0], b4_stride,
208
3.46M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
209
3.46M
    }
210
349k
}
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
348k
{
221
348k
    const Dav1dDSPContext *const dsp = f->dsp;
222
223
    //                                 block1
224
    // filter edges between rows (e.g. ------)
225
    //                                 block2
226
4.57M
    for (int y = starty4; y < endy4;
227
4.22M
         y++, dst += 4 * PXSTRIDE(ls), lvl += b4_stride)
228
4.22M
    {
229
4.22M
        if (!have_top && !y) continue;
230
4.02M
        const uint32_t vmask[4] = {
231
4.02M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << 16),
232
4.02M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << 16),
233
4.02M
            mask[y][2][0] | ((unsigned) mask[y][2][1] << 16),
234
4.02M
            0,
235
4.02M
        };
236
4.02M
        dsp->lf.loop_filter_sb[0][1](dst, ls, vmask,
237
4.02M
                                     (const uint8_t(*)[4]) &lvl[0][1], b4_stride,
238
4.02M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
239
4.02M
    }
240
348k
}
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
240k
{
252
240k
    const Dav1dDSPContext *const dsp = f->dsp;
253
254
    // filter edges between columns (e.g. block1 | block2)
255
2.09M
    for (int x = 0; x < w; x++) {
256
1.85M
        if (!have_left && !x) continue;
257
1.66M
        uint32_t hmask[3];
258
1.66M
        if (!starty4) {
259
1.29M
            hmask[0] = mask[x][0][0];
260
1.29M
            hmask[1] = mask[x][1][0];
261
1.29M
            if (endy4 > (16 >> ss_ver)) {
262
460k
                hmask[0] |= (unsigned) mask[x][0][1] << (16 >> ss_ver);
263
460k
                hmask[1] |= (unsigned) mask[x][1][1] << (16 >> ss_ver);
264
460k
            }
265
1.29M
        } else {
266
373k
            hmask[0] = mask[x][0][1];
267
373k
            hmask[1] = mask[x][1][1];
268
373k
        }
269
1.66M
        hmask[2] = 0;
270
1.66M
        dsp->lf.loop_filter_sb[1][0](&u[x * 4], ls, hmask,
271
1.66M
                                     (const uint8_t(*)[4]) &lvl[x][2], b4_stride,
272
1.66M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
273
1.66M
        dsp->lf.loop_filter_sb[1][0](&v[x * 4], ls, hmask,
274
1.66M
                                     (const uint8_t(*)[4]) &lvl[x][3], b4_stride,
275
1.66M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
276
1.66M
    }
277
240k
}
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
240k
{
289
240k
    const Dav1dDSPContext *const dsp = f->dsp;
290
240k
    ptrdiff_t off_l = 0;
291
292
    //                                 block1
293
    // filter edges between rows (e.g. ------)
294
    //                                 block2
295
2.26M
    for (int y = starty4; y < endy4;
296
2.02M
         y++, off_l += 4 * PXSTRIDE(ls), lvl += b4_stride)
297
2.02M
    {
298
2.02M
        if (!have_top && !y) continue;
299
1.87M
        const uint32_t vmask[3] = {
300
1.87M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << (16 >> ss_hor)),
301
1.87M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << (16 >> ss_hor)),
302
1.87M
            0,
303
1.87M
        };
304
1.87M
        dsp->lf.loop_filter_sb[1][1](&u[off_l], ls, vmask,
305
1.87M
                                     (const uint8_t(*)[4]) &lvl[0][2], b4_stride,
306
1.87M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
307
1.87M
        dsp->lf.loop_filter_sb[1][1](&v[off_l], ls, vmask,
308
1.87M
                                     (const uint8_t(*)[4]) &lvl[0][3], b4_stride,
309
1.87M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
310
1.87M
    }
311
240k
}
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
272k
{
317
272k
    int x, have_left;
318
    // Don't filter outside the frame
319
272k
    const int is_sb64 = !f->seq_hdr->sb128;
320
272k
    const int starty4 = (sby & is_sb64) << 4;
321
272k
    const int sbsz = 32 >> is_sb64;
322
272k
    const int sbl2 = 5 - is_sb64;
323
272k
    const int halign = (f->bh + 31) & ~31;
324
272k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
272k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
272k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
272k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
272k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
272k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
272k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
272k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
275k
    for (int tile_col = 1;; tile_col++) {
335
275k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
275k
        if ((x << sbl2) >= f->bw) break;
337
3.22k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
3.22k
        x >>= is_sb64;
339
340
3.22k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
48.3k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
45.1k
            const int sidx = mask >= 0x10000U;
343
45.1k
            const unsigned smask = mask >> (sidx << 4);
344
45.1k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
45.1k
                                !!(y_hmask[1][sidx] & smask);
346
45.1k
            y_hmask[2][sidx] &= ~smask;
347
45.1k
            y_hmask[1][sidx] &= ~smask;
348
45.1k
            y_hmask[0][sidx] &= ~smask;
349
45.1k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
45.1k
        }
351
352
3.22k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
2.79k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
30.8k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
28.0k
                 y++, uv_mask <<= 1)
356
28.0k
            {
357
28.0k
                const int sidx = uv_mask >= vmax;
358
28.0k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
28.0k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
28.0k
                uv_hmask[1][sidx] &= ~smask;
361
28.0k
                uv_hmask[0][sidx] &= ~smask;
362
28.0k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
28.0k
            }
364
2.79k
        }
365
3.22k
        lpf_y  += halign;
366
3.22k
        lpf_uv += halign >> ss_ver;
367
3.22k
    }
368
369
    // fix lpf strength at tile row boundaries
370
272k
    if (start_of_tile_row) {
371
1.59k
        const BlockContext *a;
372
1.59k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
4.03k
             x < f->sb128w; x++, a++)
374
2.43k
        {
375
2.43k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
2.43k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
42.6k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
40.2k
                const int sidx = mask >= 0x10000U;
379
40.2k
                const unsigned smask = mask >> (sidx << 4);
380
40.2k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
40.2k
                                    !!(y_vmask[1][sidx] & smask);
382
40.2k
                y_vmask[2][sidx] &= ~smask;
383
40.2k
                y_vmask[1][sidx] &= ~smask;
384
40.2k
                y_vmask[0][sidx] &= ~smask;
385
40.2k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
40.2k
            }
387
388
2.43k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
1.84k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
1.84k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
23.8k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
22.0k
                    const int sidx = uv_mask >= hmax;
393
22.0k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
22.0k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
22.0k
                    uv_vmask[1][sidx] &= ~smask;
396
22.0k
                    uv_vmask[0][sidx] &= ~smask;
397
22.0k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
22.0k
                }
399
1.84k
            }
400
2.43k
        }
401
1.59k
    }
402
403
272k
    pixel *ptr;
404
272k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
621k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
349k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
349k
    {
408
349k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
349k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
349k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
349k
    }
412
413
272k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
89.0k
        return;
415
416
183k
    ptrdiff_t uv_off;
417
183k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
424k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
240k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
240k
    {
421
240k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
240k
                             lflvl[x].filter_uv[0],
423
240k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
240k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
240k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
240k
    }
427
183k
}
dav1d_loopfilter_sbrow_cols_8bpc
Line
Count
Source
316
122k
{
317
122k
    int x, have_left;
318
    // Don't filter outside the frame
319
122k
    const int is_sb64 = !f->seq_hdr->sb128;
320
122k
    const int starty4 = (sby & is_sb64) << 4;
321
122k
    const int sbsz = 32 >> is_sb64;
322
122k
    const int sbl2 = 5 - is_sb64;
323
122k
    const int halign = (f->bh + 31) & ~31;
324
122k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
122k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
122k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
122k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
122k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
122k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
122k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
122k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
124k
    for (int tile_col = 1;; tile_col++) {
335
124k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
124k
        if ((x << sbl2) >= f->bw) break;
337
2.11k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
2.11k
        x >>= is_sb64;
339
340
2.11k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
32.0k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
29.9k
            const int sidx = mask >= 0x10000U;
343
29.9k
            const unsigned smask = mask >> (sidx << 4);
344
29.9k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
29.9k
                                !!(y_hmask[1][sidx] & smask);
346
29.9k
            y_hmask[2][sidx] &= ~smask;
347
29.9k
            y_hmask[1][sidx] &= ~smask;
348
29.9k
            y_hmask[0][sidx] &= ~smask;
349
29.9k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
29.9k
        }
351
352
2.11k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
1.85k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
21.3k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
19.4k
                 y++, uv_mask <<= 1)
356
19.4k
            {
357
19.4k
                const int sidx = uv_mask >= vmax;
358
19.4k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
19.4k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
19.4k
                uv_hmask[1][sidx] &= ~smask;
361
19.4k
                uv_hmask[0][sidx] &= ~smask;
362
19.4k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
19.4k
            }
364
1.85k
        }
365
2.11k
        lpf_y  += halign;
366
2.11k
        lpf_uv += halign >> ss_ver;
367
2.11k
    }
368
369
    // fix lpf strength at tile row boundaries
370
122k
    if (start_of_tile_row) {
371
919
        const BlockContext *a;
372
919
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
2.32k
             x < f->sb128w; x++, a++)
374
1.40k
        {
375
1.40k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
1.40k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
23.8k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
22.4k
                const int sidx = mask >= 0x10000U;
379
22.4k
                const unsigned smask = mask >> (sidx << 4);
380
22.4k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
22.4k
                                    !!(y_vmask[1][sidx] & smask);
382
22.4k
                y_vmask[2][sidx] &= ~smask;
383
22.4k
                y_vmask[1][sidx] &= ~smask;
384
22.4k
                y_vmask[0][sidx] &= ~smask;
385
22.4k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
22.4k
            }
387
388
1.40k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
1.05k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
1.05k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
12.5k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
11.5k
                    const int sidx = uv_mask >= hmax;
393
11.5k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
11.5k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
11.5k
                    uv_vmask[1][sidx] &= ~smask;
396
11.5k
                    uv_vmask[0][sidx] &= ~smask;
397
11.5k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
11.5k
                }
399
1.05k
            }
400
1.40k
        }
401
919
    }
402
403
122k
    pixel *ptr;
404
122k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
281k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
159k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
159k
    {
408
159k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
159k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
159k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
159k
    }
412
413
122k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
26.8k
        return;
415
416
95.1k
    ptrdiff_t uv_off;
417
95.1k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
220k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
125k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
125k
    {
421
125k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
125k
                             lflvl[x].filter_uv[0],
423
125k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
125k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
125k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
125k
    }
427
95.1k
}
dav1d_loopfilter_sbrow_cols_16bpc
Line
Count
Source
316
150k
{
317
150k
    int x, have_left;
318
    // Don't filter outside the frame
319
150k
    const int is_sb64 = !f->seq_hdr->sb128;
320
150k
    const int starty4 = (sby & is_sb64) << 4;
321
150k
    const int sbsz = 32 >> is_sb64;
322
150k
    const int sbl2 = 5 - is_sb64;
323
150k
    const int halign = (f->bh + 31) & ~31;
324
150k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
150k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
150k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
150k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
150k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
150k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
150k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
150k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
151k
    for (int tile_col = 1;; tile_col++) {
335
151k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
151k
        if ((x << sbl2) >= f->bw) break;
337
1.11k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
1.11k
        x >>= is_sb64;
339
340
1.11k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
16.3k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
15.2k
            const int sidx = mask >= 0x10000U;
343
15.2k
            const unsigned smask = mask >> (sidx << 4);
344
15.2k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
15.2k
                                !!(y_hmask[1][sidx] & smask);
346
15.2k
            y_hmask[2][sidx] &= ~smask;
347
15.2k
            y_hmask[1][sidx] &= ~smask;
348
15.2k
            y_hmask[0][sidx] &= ~smask;
349
15.2k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
15.2k
        }
351
352
1.11k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
947
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
9.52k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
8.57k
                 y++, uv_mask <<= 1)
356
8.57k
            {
357
8.57k
                const int sidx = uv_mask >= vmax;
358
8.57k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
8.57k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
8.57k
                uv_hmask[1][sidx] &= ~smask;
361
8.57k
                uv_hmask[0][sidx] &= ~smask;
362
8.57k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
8.57k
            }
364
947
        }
365
1.11k
        lpf_y  += halign;
366
1.11k
        lpf_uv += halign >> ss_ver;
367
1.11k
    }
368
369
    // fix lpf strength at tile row boundaries
370
150k
    if (start_of_tile_row) {
371
679
        const BlockContext *a;
372
679
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
1.70k
             x < f->sb128w; x++, a++)
374
1.02k
        {
375
1.02k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
1.02k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
18.8k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
17.8k
                const int sidx = mask >= 0x10000U;
379
17.8k
                const unsigned smask = mask >> (sidx << 4);
380
17.8k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
17.8k
                                    !!(y_vmask[1][sidx] & smask);
382
17.8k
                y_vmask[2][sidx] &= ~smask;
383
17.8k
                y_vmask[1][sidx] &= ~smask;
384
17.8k
                y_vmask[0][sidx] &= ~smask;
385
17.8k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
17.8k
            }
387
388
1.02k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
792
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
792
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
11.3k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
10.5k
                    const int sidx = uv_mask >= hmax;
393
10.5k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
10.5k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
10.5k
                    uv_vmask[1][sidx] &= ~smask;
396
10.5k
                    uv_vmask[0][sidx] &= ~smask;
397
10.5k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
10.5k
                }
399
792
            }
400
1.02k
        }
401
679
    }
402
403
150k
    pixel *ptr;
404
150k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
340k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
190k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
190k
    {
408
190k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
190k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
190k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
190k
    }
412
413
150k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
62.1k
        return;
415
416
88.2k
    ptrdiff_t uv_off;
417
88.2k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
203k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
115k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
115k
    {
421
115k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
115k
                             lflvl[x].filter_uv[0],
423
115k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
115k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
115k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
115k
    }
427
88.2k
}
428
429
void bytefn(dav1d_loopfilter_sbrow_rows)(const Dav1dFrameContext *const f,
430
                                         pixel *const p[3], Av1Filter *const lflvl,
431
                                         int sby)
432
272k
{
433
272k
    int x;
434
    // Don't filter outside the frame
435
272k
    const int have_top = sby > 0;
436
272k
    const int is_sb64 = !f->seq_hdr->sb128;
437
272k
    const int starty4 = (sby & is_sb64) << 4;
438
272k
    const int sbsz = 32 >> is_sb64;
439
272k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
272k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
272k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
272k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
272k
    pixel *ptr;
445
272k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
620k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
348k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
348k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
348k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
348k
    }
451
452
272k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
89.0k
        return;
454
455
183k
    ptrdiff_t uv_off;
456
183k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
423k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
240k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
240k
    {
460
240k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
240k
                             lflvl[x].filter_uv[1],
462
240k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
240k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
240k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
240k
    }
466
183k
}
dav1d_loopfilter_sbrow_rows_8bpc
Line
Count
Source
432
121k
{
433
121k
    int x;
434
    // Don't filter outside the frame
435
121k
    const int have_top = sby > 0;
436
121k
    const int is_sb64 = !f->seq_hdr->sb128;
437
121k
    const int starty4 = (sby & is_sb64) << 4;
438
121k
    const int sbsz = 32 >> is_sb64;
439
121k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
121k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
121k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
121k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
121k
    pixel *ptr;
445
121k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
280k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
158k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
158k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
158k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
158k
    }
451
452
121k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
26.8k
        return;
454
455
95.0k
    ptrdiff_t uv_off;
456
95.0k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
220k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
125k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
125k
    {
460
125k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
125k
                             lflvl[x].filter_uv[1],
462
125k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
125k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
125k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
125k
    }
466
95.0k
}
dav1d_loopfilter_sbrow_rows_16bpc
Line
Count
Source
432
150k
{
433
150k
    int x;
434
    // Don't filter outside the frame
435
150k
    const int have_top = sby > 0;
436
150k
    const int is_sb64 = !f->seq_hdr->sb128;
437
150k
    const int starty4 = (sby & is_sb64) << 4;
438
150k
    const int sbsz = 32 >> is_sb64;
439
150k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
150k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
150k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
150k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
150k
    pixel *ptr;
445
150k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
340k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
189k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
189k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
189k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
189k
    }
451
452
150k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
62.1k
        return;
454
455
88.2k
    ptrdiff_t uv_off;
456
88.2k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
203k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
115k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
115k
    {
460
115k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
115k
                             lflvl[x].filter_uv[1],
462
115k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
115k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
115k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
115k
    }
466
88.2k
}