Coverage Report

Created: 2026-09-01 06:57

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
882k
{
48
882k
    const int cdef_backup = !lr_backup;
49
882k
    const int dst_w = f->frame_hdr->super_res.enabled ?
50
521k
                      (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
882k
    int stripe_h = ((64 << (cdef_backup & sb128)) - 8 * !row) >> ss_ver;
54
882k
    src += (stripe_h - 2) * PXSTRIDE(src_stride);
55
56
882k
    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
882k
    if (lr_backup && (f->frame_hdr->width[0] != f->frame_hdr->width[1])) {
74
152k
        while (row + stripe_h <= row_h) {
75
66.7k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
76
66.7k
            f->dsp->mc.resize(dst, dst_stride, src, src_stride,
77
66.7k
                              dst_w, n_lines, src_w, f->resize_step[ss_hor],
78
66.7k
                              f->resize_start[ss_hor] HIGHBD_CALL_SUFFIX);
79
66.7k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
80
66.7k
            stripe_h = 64 >> ss_ver;
81
66.7k
            src += stripe_h * PXSTRIDE(src_stride);
82
66.7k
            dst += n_lines * PXSTRIDE(dst_stride);
83
66.7k
            if (n_lines == 3) {
84
1.02k
                pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], dst_w);
85
1.02k
                dst += PXSTRIDE(dst_stride);
86
1.02k
            }
87
66.7k
        }
88
797k
    } else {
89
1.34M
        while (row + stripe_h <= row_h) {
90
547k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
91
2.73M
            for (int i = 0; i < 4; i++) {
92
2.18M
                pixel_copy(dst, i == n_lines ? &dst[-PXSTRIDE(dst_stride)] :
93
2.18M
                                               src, src_w);
94
2.18M
                dst += PXSTRIDE(dst_stride);
95
2.18M
                src += PXSTRIDE(src_stride);
96
2.18M
            }
97
547k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
98
547k
            stripe_h = 64 >> ss_ver;
99
547k
            src += (stripe_h - 4) * PXSTRIDE(src_stride);
100
547k
        }
101
797k
    }
102
882k
}
103
104
void bytefn(dav1d_copy_lpf)(Dav1dFrameContext *const f,
105
                            /*const*/ pixel *const src[3], const int sby)
106
343k
{
107
343k
    const int have_tt = f->c->n_tc > 1;
108
343k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
343k
    const int offset = 8 * !!sby;
110
343k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
343k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
343k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
343k
    pixel *const dst[3] = {
114
343k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
343k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
343k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
343k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
343k
    const int restore_planes = f->lf.restore_planes;
121
122
343k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
333k
        const int h = f->cur.p.h;
124
333k
        const int w = f->bw << 2;
125
333k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
333k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
333k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
311k
            backup_lpf(f, dst[0], lr_stride[0],
129
311k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
311k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
333k
        if (have_tt && resize) {
132
56.0k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
56.0k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
56.0k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
56.0k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
56.0k
        }
137
333k
    }
138
343k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
309k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
255k
    {
141
255k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
255k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
255k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
255k
        const int w = f->bw << (2 - ss_hor);
145
255k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
255k
        const int offset_uv = offset >> ss_ver;
147
255k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
255k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
255k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
216k
            if (restore_planes & LR_RESTORE_U || !resize)
151
193k
                backup_lpf(f, dst[1], lr_stride[1],
152
193k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
193k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
193k
                           row_h, w, h, ss_hor, 1);
155
216k
            if (have_tt && resize)
156
42.3k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
42.3k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
42.3k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
42.3k
                           row_h, w, h, ss_hor, 0);
160
216k
        }
161
255k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
247k
            if (restore_planes & LR_RESTORE_V || !resize)
163
232k
                backup_lpf(f, dst[2], lr_stride[1],
164
232k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
232k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
232k
                           row_h, w, h, ss_hor, 1);
167
247k
            if (have_tt && resize)
168
47.4k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
47.4k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
47.4k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
47.4k
                           row_h, w, h, ss_hor, 0);
172
247k
        }
173
255k
    }
174
343k
}
dav1d_copy_lpf_8bpc
Line
Count
Source
106
166k
{
107
166k
    const int have_tt = f->c->n_tc > 1;
108
166k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
166k
    const int offset = 8 * !!sby;
110
166k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
166k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
166k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
166k
    pixel *const dst[3] = {
114
166k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
166k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
166k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
166k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
166k
    const int restore_planes = f->lf.restore_planes;
121
122
166k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
163k
        const int h = f->cur.p.h;
124
163k
        const int w = f->bw << 2;
125
163k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
163k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
163k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
154k
            backup_lpf(f, dst[0], lr_stride[0],
129
154k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
154k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
163k
        if (have_tt && resize) {
132
26.4k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
26.4k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
26.4k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
26.4k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
26.4k
        }
137
163k
    }
138
166k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
160k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
135k
    {
141
135k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
135k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
135k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
135k
        const int w = f->bw << (2 - ss_hor);
145
135k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
135k
        const int offset_uv = offset >> ss_ver;
147
135k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
135k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
135k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
115k
            if (restore_planes & LR_RESTORE_U || !resize)
151
105k
                backup_lpf(f, dst[1], lr_stride[1],
152
105k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
105k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
105k
                           row_h, w, h, ss_hor, 1);
155
115k
            if (have_tt && resize)
156
20.5k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
20.5k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
20.5k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
20.5k
                           row_h, w, h, ss_hor, 0);
160
115k
        }
161
135k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
133k
            if (restore_planes & LR_RESTORE_V || !resize)
163
126k
                backup_lpf(f, dst[2], lr_stride[1],
164
126k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
126k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
126k
                           row_h, w, h, ss_hor, 1);
167
133k
            if (have_tt && resize)
168
22.7k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
22.7k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
22.7k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
22.7k
                           row_h, w, h, ss_hor, 0);
172
133k
        }
173
135k
    }
174
166k
}
dav1d_copy_lpf_16bpc
Line
Count
Source
106
176k
{
107
176k
    const int have_tt = f->c->n_tc > 1;
108
176k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
176k
    const int offset = 8 * !!sby;
110
176k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
176k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
176k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
176k
    pixel *const dst[3] = {
114
176k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
176k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
176k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
176k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
176k
    const int restore_planes = f->lf.restore_planes;
121
122
176k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
169k
        const int h = f->cur.p.h;
124
169k
        const int w = f->bw << 2;
125
169k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
169k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
169k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
157k
            backup_lpf(f, dst[0], lr_stride[0],
129
157k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
157k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
169k
        if (have_tt && resize) {
132
29.6k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
29.6k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
29.6k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
29.6k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
29.6k
        }
137
169k
    }
138
176k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
148k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
119k
    {
141
119k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
119k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
119k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
119k
        const int w = f->bw << (2 - ss_hor);
145
119k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
119k
        const int offset_uv = offset >> ss_ver;
147
119k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
119k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
119k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
101k
            if (restore_planes & LR_RESTORE_U || !resize)
151
88.7k
                backup_lpf(f, dst[1], lr_stride[1],
152
88.7k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
88.7k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
88.7k
                           row_h, w, h, ss_hor, 1);
155
101k
            if (have_tt && resize)
156
21.8k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
21.8k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
21.8k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
21.8k
                           row_h, w, h, ss_hor, 0);
160
101k
        }
161
119k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
114k
            if (restore_planes & LR_RESTORE_V || !resize)
163
105k
                backup_lpf(f, dst[2], lr_stride[1],
164
105k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
105k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
105k
                           row_h, w, h, ss_hor, 1);
167
114k
            if (have_tt && resize)
168
24.6k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
24.6k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
24.6k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
24.6k
                           row_h, w, h, ss_hor, 0);
172
114k
        }
173
119k
    }
174
176k
}
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
447k
{
185
447k
    const Dav1dDSPContext *const dsp = f->dsp;
186
187
    // filter edges between columns (e.g. block1 | block2)
188
5.17M
    for (int x = 0; x < w; x++) {
189
4.72M
        if (!have_left && !x) continue;
190
4.36M
        uint32_t hmask[4];
191
4.36M
        if (!starty4) {
192
3.46M
            hmask[0] = mask[x][0][0];
193
3.46M
            hmask[1] = mask[x][1][0];
194
3.46M
            hmask[2] = mask[x][2][0];
195
3.46M
            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
3.46M
        } else {
201
900k
            hmask[0] = mask[x][0][1];
202
900k
            hmask[1] = mask[x][1][1];
203
900k
            hmask[2] = mask[x][2][1];
204
900k
        }
205
4.36M
        hmask[3] = 0;
206
4.36M
        dsp->lf.loop_filter_sb[0][0](&dst[x * 4], ls, hmask,
207
4.36M
                                     (const uint8_t(*)[4]) &lvl[x][0], b4_stride,
208
4.36M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
209
4.36M
    }
210
447k
}
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
446k
{
221
446k
    const Dav1dDSPContext *const dsp = f->dsp;
222
223
    //                                 block1
224
    // filter edges between rows (e.g. ------)
225
    //                                 block2
226
5.97M
    for (int y = starty4; y < endy4;
227
5.53M
         y++, dst += 4 * PXSTRIDE(ls), lvl += b4_stride)
228
5.53M
    {
229
5.53M
        if (!have_top && !y) continue;
230
5.28M
        const uint32_t vmask[4] = {
231
5.28M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << 16),
232
5.28M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << 16),
233
5.28M
            mask[y][2][0] | ((unsigned) mask[y][2][1] << 16),
234
5.28M
            0,
235
5.28M
        };
236
5.28M
        dsp->lf.loop_filter_sb[0][1](dst, ls, vmask,
237
5.28M
                                     (const uint8_t(*)[4]) &lvl[0][1], b4_stride,
238
5.28M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
239
5.28M
    }
240
446k
}
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
322k
{
252
322k
    const Dav1dDSPContext *const dsp = f->dsp;
253
254
    // filter edges between columns (e.g. block1 | block2)
255
2.73M
    for (int x = 0; x < w; x++) {
256
2.41M
        if (!have_left && !x) continue;
257
2.14M
        uint32_t hmask[3];
258
2.14M
        if (!starty4) {
259
1.72M
            hmask[0] = mask[x][0][0];
260
1.72M
            hmask[1] = mask[x][1][0];
261
1.72M
            if (endy4 > (16 >> ss_ver)) {
262
513k
                hmask[0] |= (unsigned) mask[x][0][1] << (16 >> ss_ver);
263
513k
                hmask[1] |= (unsigned) mask[x][1][1] << (16 >> ss_ver);
264
513k
            }
265
1.72M
        } else {
266
426k
            hmask[0] = mask[x][0][1];
267
426k
            hmask[1] = mask[x][1][1];
268
426k
        }
269
2.14M
        hmask[2] = 0;
270
2.14M
        dsp->lf.loop_filter_sb[1][0](&u[x * 4], ls, hmask,
271
2.14M
                                     (const uint8_t(*)[4]) &lvl[x][2], b4_stride,
272
2.14M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
273
2.14M
        dsp->lf.loop_filter_sb[1][0](&v[x * 4], ls, hmask,
274
2.14M
                                     (const uint8_t(*)[4]) &lvl[x][3], b4_stride,
275
2.14M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
276
2.14M
    }
277
322k
}
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
321k
{
289
321k
    const Dav1dDSPContext *const dsp = f->dsp;
290
321k
    ptrdiff_t off_l = 0;
291
292
    //                                 block1
293
    // filter edges between rows (e.g. ------)
294
    //                                 block2
295
3.08M
    for (int y = starty4; y < endy4;
296
2.75M
         y++, off_l += 4 * PXSTRIDE(ls), lvl += b4_stride)
297
2.75M
    {
298
2.75M
        if (!have_top && !y) continue;
299
2.58M
        const uint32_t vmask[3] = {
300
2.58M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << (16 >> ss_hor)),
301
2.58M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << (16 >> ss_hor)),
302
2.58M
            0,
303
2.58M
        };
304
2.58M
        dsp->lf.loop_filter_sb[1][1](&u[off_l], ls, vmask,
305
2.58M
                                     (const uint8_t(*)[4]) &lvl[0][2], b4_stride,
306
2.58M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
307
2.58M
        dsp->lf.loop_filter_sb[1][1](&v[off_l], ls, vmask,
308
2.58M
                                     (const uint8_t(*)[4]) &lvl[0][3], b4_stride,
309
2.58M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
310
2.58M
    }
311
321k
}
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
357k
{
317
357k
    int x, have_left;
318
    // Don't filter outside the frame
319
357k
    const int is_sb64 = !f->seq_hdr->sb128;
320
357k
    const int starty4 = (sby & is_sb64) << 4;
321
357k
    const int sbsz = 32 >> is_sb64;
322
357k
    const int sbl2 = 5 - is_sb64;
323
357k
    const int halign = (f->bh + 31) & ~31;
324
357k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
357k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
357k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
357k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
357k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
357k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
357k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
357k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
360k
    for (int tile_col = 1;; tile_col++) {
335
360k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
360k
        if ((x << sbl2) >= f->bw) break;
337
2.92k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
2.92k
        x >>= is_sb64;
339
340
2.92k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
36.0k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
33.1k
            const int sidx = mask >= 0x10000U;
343
33.1k
            const unsigned smask = mask >> (sidx << 4);
344
33.1k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
33.1k
                                !!(y_hmask[1][sidx] & smask);
346
33.1k
            y_hmask[2][sidx] &= ~smask;
347
33.1k
            y_hmask[1][sidx] &= ~smask;
348
33.1k
            y_hmask[0][sidx] &= ~smask;
349
33.1k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
33.1k
        }
351
352
2.92k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
2.37k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
19.9k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
17.6k
                 y++, uv_mask <<= 1)
356
17.6k
            {
357
17.6k
                const int sidx = uv_mask >= vmax;
358
17.6k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
17.6k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
17.6k
                uv_hmask[1][sidx] &= ~smask;
361
17.6k
                uv_hmask[0][sidx] &= ~smask;
362
17.6k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
17.6k
            }
364
2.37k
        }
365
2.92k
        lpf_y  += halign;
366
2.92k
        lpf_uv += halign >> ss_ver;
367
2.92k
    }
368
369
    // fix lpf strength at tile row boundaries
370
357k
    if (start_of_tile_row) {
371
2.17k
        const BlockContext *a;
372
2.17k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
5.17k
             x < f->sb128w; x++, a++)
374
2.99k
        {
375
2.99k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
2.99k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
48.0k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
45.0k
                const int sidx = mask >= 0x10000U;
379
45.0k
                const unsigned smask = mask >> (sidx << 4);
380
45.0k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
45.0k
                                    !!(y_vmask[1][sidx] & smask);
382
45.0k
                y_vmask[2][sidx] &= ~smask;
383
45.0k
                y_vmask[1][sidx] &= ~smask;
384
45.0k
                y_vmask[0][sidx] &= ~smask;
385
45.0k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
45.0k
            }
387
388
2.99k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
2.29k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
2.29k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
29.7k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
27.4k
                    const int sidx = uv_mask >= hmax;
393
27.4k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
27.4k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
27.4k
                    uv_vmask[1][sidx] &= ~smask;
396
27.4k
                    uv_vmask[0][sidx] &= ~smask;
397
27.4k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
27.4k
                }
399
2.29k
            }
400
2.99k
        }
401
2.17k
    }
402
403
357k
    pixel *ptr;
404
357k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
805k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
447k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
447k
    {
408
447k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
447k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
447k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
447k
    }
412
413
357k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
96.0k
        return;
415
416
261k
    ptrdiff_t uv_off;
417
261k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
583k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
322k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
322k
    {
421
322k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
322k
                             lflvl[x].filter_uv[0],
423
322k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
322k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
322k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
322k
    }
427
261k
}
dav1d_loopfilter_sbrow_cols_8bpc
Line
Count
Source
316
171k
{
317
171k
    int x, have_left;
318
    // Don't filter outside the frame
319
171k
    const int is_sb64 = !f->seq_hdr->sb128;
320
171k
    const int starty4 = (sby & is_sb64) << 4;
321
171k
    const int sbsz = 32 >> is_sb64;
322
171k
    const int sbl2 = 5 - is_sb64;
323
171k
    const int halign = (f->bh + 31) & ~31;
324
171k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
171k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
171k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
171k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
171k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
171k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
171k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
171k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
172k
    for (int tile_col = 1;; tile_col++) {
335
172k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
172k
        if ((x << sbl2) >= f->bw) break;
337
1.24k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
1.24k
        x >>= is_sb64;
339
340
1.24k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
12.8k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
11.5k
            const int sidx = mask >= 0x10000U;
343
11.5k
            const unsigned smask = mask >> (sidx << 4);
344
11.5k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
11.5k
                                !!(y_hmask[1][sidx] & smask);
346
11.5k
            y_hmask[2][sidx] &= ~smask;
347
11.5k
            y_hmask[1][sidx] &= ~smask;
348
11.5k
            y_hmask[0][sidx] &= ~smask;
349
11.5k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
11.5k
        }
351
352
1.24k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
981
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
7.56k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
6.58k
                 y++, uv_mask <<= 1)
356
6.58k
            {
357
6.58k
                const int sidx = uv_mask >= vmax;
358
6.58k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
6.58k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
6.58k
                uv_hmask[1][sidx] &= ~smask;
361
6.58k
                uv_hmask[0][sidx] &= ~smask;
362
6.58k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
6.58k
            }
364
981
        }
365
1.24k
        lpf_y  += halign;
366
1.24k
        lpf_uv += halign >> ss_ver;
367
1.24k
    }
368
369
    // fix lpf strength at tile row boundaries
370
171k
    if (start_of_tile_row) {
371
1.25k
        const BlockContext *a;
372
1.25k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
2.83k
             x < f->sb128w; x++, a++)
374
1.57k
        {
375
1.57k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
1.57k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
22.9k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
21.3k
                const int sidx = mask >= 0x10000U;
379
21.3k
                const unsigned smask = mask >> (sidx << 4);
380
21.3k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
21.3k
                                    !!(y_vmask[1][sidx] & smask);
382
21.3k
                y_vmask[2][sidx] &= ~smask;
383
21.3k
                y_vmask[1][sidx] &= ~smask;
384
21.3k
                y_vmask[0][sidx] &= ~smask;
385
21.3k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
21.3k
            }
387
388
1.57k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
1.29k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
1.29k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
15.7k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
14.4k
                    const int sidx = uv_mask >= hmax;
393
14.4k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
14.4k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
14.4k
                    uv_vmask[1][sidx] &= ~smask;
396
14.4k
                    uv_vmask[0][sidx] &= ~smask;
397
14.4k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
14.4k
                }
399
1.29k
            }
400
1.57k
        }
401
1.25k
    }
402
403
171k
    pixel *ptr;
404
171k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
384k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
212k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
212k
    {
408
212k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
212k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
212k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
212k
    }
412
413
171k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
30.4k
        return;
415
416
141k
    ptrdiff_t uv_off;
417
141k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
310k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
169k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
169k
    {
421
169k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
169k
                             lflvl[x].filter_uv[0],
423
169k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
169k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
169k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
169k
    }
427
141k
}
dav1d_loopfilter_sbrow_cols_16bpc
Line
Count
Source
316
186k
{
317
186k
    int x, have_left;
318
    // Don't filter outside the frame
319
186k
    const int is_sb64 = !f->seq_hdr->sb128;
320
186k
    const int starty4 = (sby & is_sb64) << 4;
321
186k
    const int sbsz = 32 >> is_sb64;
322
186k
    const int sbl2 = 5 - is_sb64;
323
186k
    const int halign = (f->bh + 31) & ~31;
324
186k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
186k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
186k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
186k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
186k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
186k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
186k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
186k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
187k
    for (int tile_col = 1;; tile_col++) {
335
187k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
187k
        if ((x << sbl2) >= f->bw) break;
337
1.68k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
1.68k
        x >>= is_sb64;
339
340
1.68k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
23.2k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
21.5k
            const int sidx = mask >= 0x10000U;
343
21.5k
            const unsigned smask = mask >> (sidx << 4);
344
21.5k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
21.5k
                                !!(y_hmask[1][sidx] & smask);
346
21.5k
            y_hmask[2][sidx] &= ~smask;
347
21.5k
            y_hmask[1][sidx] &= ~smask;
348
21.5k
            y_hmask[0][sidx] &= ~smask;
349
21.5k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
21.5k
        }
351
352
1.68k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
1.39k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
12.4k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
11.0k
                 y++, uv_mask <<= 1)
356
11.0k
            {
357
11.0k
                const int sidx = uv_mask >= vmax;
358
11.0k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
11.0k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
11.0k
                uv_hmask[1][sidx] &= ~smask;
361
11.0k
                uv_hmask[0][sidx] &= ~smask;
362
11.0k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
11.0k
            }
364
1.39k
        }
365
1.68k
        lpf_y  += halign;
366
1.68k
        lpf_uv += halign >> ss_ver;
367
1.68k
    }
368
369
    // fix lpf strength at tile row boundaries
370
186k
    if (start_of_tile_row) {
371
925
        const BlockContext *a;
372
925
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
2.33k
             x < f->sb128w; x++, a++)
374
1.41k
        {
375
1.41k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
1.41k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
25.1k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
23.7k
                const int sidx = mask >= 0x10000U;
379
23.7k
                const unsigned smask = mask >> (sidx << 4);
380
23.7k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
23.7k
                                    !!(y_vmask[1][sidx] & smask);
382
23.7k
                y_vmask[2][sidx] &= ~smask;
383
23.7k
                y_vmask[1][sidx] &= ~smask;
384
23.7k
                y_vmask[0][sidx] &= ~smask;
385
23.7k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
23.7k
            }
387
388
1.41k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
1.00k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
1.00k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
14.0k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
13.0k
                    const int sidx = uv_mask >= hmax;
393
13.0k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
13.0k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
13.0k
                    uv_vmask[1][sidx] &= ~smask;
396
13.0k
                    uv_vmask[0][sidx] &= ~smask;
397
13.0k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
13.0k
                }
399
1.00k
            }
400
1.41k
        }
401
925
    }
402
403
186k
    pixel *ptr;
404
186k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
420k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
234k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
234k
    {
408
234k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
234k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
234k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
234k
    }
412
413
186k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
65.5k
        return;
415
416
120k
    ptrdiff_t uv_off;
417
120k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
272k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
152k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
152k
    {
421
152k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
152k
                             lflvl[x].filter_uv[0],
423
152k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
152k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
152k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
152k
    }
427
120k
}
428
429
void bytefn(dav1d_loopfilter_sbrow_rows)(const Dav1dFrameContext *const f,
430
                                         pixel *const p[3], Av1Filter *const lflvl,
431
                                         int sby)
432
357k
{
433
357k
    int x;
434
    // Don't filter outside the frame
435
357k
    const int have_top = sby > 0;
436
357k
    const int is_sb64 = !f->seq_hdr->sb128;
437
357k
    const int starty4 = (sby & is_sb64) << 4;
438
357k
    const int sbsz = 32 >> is_sb64;
439
357k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
357k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
357k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
357k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
357k
    pixel *ptr;
445
357k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
804k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
446k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
446k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
446k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
446k
    }
451
452
357k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
95.9k
        return;
454
455
261k
    ptrdiff_t uv_off;
456
261k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
583k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
321k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
321k
    {
460
321k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
321k
                             lflvl[x].filter_uv[1],
462
321k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
321k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
321k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
321k
    }
466
261k
}
dav1d_loopfilter_sbrow_rows_8bpc
Line
Count
Source
432
171k
{
433
171k
    int x;
434
    // Don't filter outside the frame
435
171k
    const int have_top = sby > 0;
436
171k
    const int is_sb64 = !f->seq_hdr->sb128;
437
171k
    const int starty4 = (sby & is_sb64) << 4;
438
171k
    const int sbsz = 32 >> is_sb64;
439
171k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
171k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
171k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
171k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
171k
    pixel *ptr;
445
171k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
383k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
212k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
212k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
212k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
212k
    }
451
452
171k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
30.4k
        return;
454
455
141k
    ptrdiff_t uv_off;
456
141k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
310k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
169k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
169k
    {
460
169k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
169k
                             lflvl[x].filter_uv[1],
462
169k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
169k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
169k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
169k
    }
466
141k
}
dav1d_loopfilter_sbrow_rows_16bpc
Line
Count
Source
432
186k
{
433
186k
    int x;
434
    // Don't filter outside the frame
435
186k
    const int have_top = sby > 0;
436
186k
    const int is_sb64 = !f->seq_hdr->sb128;
437
186k
    const int starty4 = (sby & is_sb64) << 4;
438
186k
    const int sbsz = 32 >> is_sb64;
439
186k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
186k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
186k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
186k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
186k
    pixel *ptr;
445
186k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
420k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
234k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
234k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
234k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
234k
    }
451
452
186k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
65.5k
        return;
454
455
120k
    ptrdiff_t uv_off;
456
120k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
272k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
152k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
152k
    {
460
152k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
152k
                             lflvl[x].filter_uv[1],
462
152k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
152k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
152k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
152k
    }
466
120k
}