Coverage Report

Created: 2026-08-31 06:22

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
851k
{
48
851k
    const int cdef_backup = !lr_backup;
49
851k
    const int dst_w = f->frame_hdr->super_res.enabled ?
50
517k
                      (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
851k
    int stripe_h = ((64 << (cdef_backup & sb128)) - 8 * !row) >> ss_ver;
54
851k
    src += (stripe_h - 2) * PXSTRIDE(src_stride);
55
56
851k
    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
851k
    if (lr_backup && (f->frame_hdr->width[0] != f->frame_hdr->width[1])) {
74
145k
        while (row + stripe_h <= row_h) {
75
64.0k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
76
64.0k
            f->dsp->mc.resize(dst, dst_stride, src, src_stride,
77
64.0k
                              dst_w, n_lines, src_w, f->resize_step[ss_hor],
78
64.0k
                              f->resize_start[ss_hor] HIGHBD_CALL_SUFFIX);
79
64.0k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
80
64.0k
            stripe_h = 64 >> ss_ver;
81
64.0k
            src += stripe_h * PXSTRIDE(src_stride);
82
64.0k
            dst += n_lines * PXSTRIDE(dst_stride);
83
64.0k
            if (n_lines == 3) {
84
1.03k
                pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], dst_w);
85
1.03k
                dst += PXSTRIDE(dst_stride);
86
1.03k
            }
87
64.0k
        }
88
769k
    } else {
89
1.29M
        while (row + stripe_h <= row_h) {
90
525k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
91
2.62M
            for (int i = 0; i < 4; i++) {
92
2.10M
                pixel_copy(dst, i == n_lines ? &dst[-PXSTRIDE(dst_stride)] :
93
2.10M
                                               src, src_w);
94
2.10M
                dst += PXSTRIDE(dst_stride);
95
2.10M
                src += PXSTRIDE(src_stride);
96
2.10M
            }
97
525k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
98
525k
            stripe_h = 64 >> ss_ver;
99
525k
            src += (stripe_h - 4) * PXSTRIDE(src_stride);
100
525k
        }
101
769k
    }
102
851k
}
103
104
void bytefn(dav1d_copy_lpf)(Dav1dFrameContext *const f,
105
                            /*const*/ pixel *const src[3], const int sby)
106
332k
{
107
332k
    const int have_tt = f->c->n_tc > 1;
108
332k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
332k
    const int offset = 8 * !!sby;
110
332k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
332k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
332k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
332k
    pixel *const dst[3] = {
114
332k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
332k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
332k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
332k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
332k
    const int restore_planes = f->lf.restore_planes;
121
122
332k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
321k
        const int h = f->cur.p.h;
124
321k
        const int w = f->bw << 2;
125
321k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
321k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
321k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
299k
            backup_lpf(f, dst[0], lr_stride[0],
129
299k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
299k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
321k
        if (have_tt && resize) {
132
54.6k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
54.6k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
54.6k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
54.6k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
54.6k
        }
137
321k
    }
138
332k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
297k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
246k
    {
141
246k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
246k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
246k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
246k
        const int w = f->bw << (2 - ss_hor);
145
246k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
246k
        const int offset_uv = offset >> ss_ver;
147
246k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
246k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
246k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
208k
            if (restore_planes & LR_RESTORE_U || !resize)
151
186k
                backup_lpf(f, dst[1], lr_stride[1],
152
186k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
186k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
186k
                           row_h, w, h, ss_hor, 1);
155
208k
            if (have_tt && resize)
156
41.2k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
41.2k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
41.2k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
41.2k
                           row_h, w, h, ss_hor, 0);
160
208k
        }
161
246k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
239k
            if (restore_planes & LR_RESTORE_V || !resize)
163
224k
                backup_lpf(f, dst[2], lr_stride[1],
164
224k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
224k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
224k
                           row_h, w, h, ss_hor, 1);
167
239k
            if (have_tt && resize)
168
45.9k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
45.9k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
45.9k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
45.9k
                           row_h, w, h, ss_hor, 0);
172
239k
        }
173
246k
    }
174
332k
}
dav1d_copy_lpf_8bpc
Line
Count
Source
106
162k
{
107
162k
    const int have_tt = f->c->n_tc > 1;
108
162k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
162k
    const int offset = 8 * !!sby;
110
162k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
162k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
162k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
162k
    pixel *const dst[3] = {
114
162k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
162k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
162k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
162k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
162k
    const int restore_planes = f->lf.restore_planes;
121
122
162k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
158k
        const int h = f->cur.p.h;
124
158k
        const int w = f->bw << 2;
125
158k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
158k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
158k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
149k
            backup_lpf(f, dst[0], lr_stride[0],
129
149k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
149k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
158k
        if (have_tt && resize) {
132
24.8k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
24.8k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
24.8k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
24.8k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
24.8k
        }
137
158k
    }
138
162k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
157k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
133k
    {
141
133k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
133k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
133k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
133k
        const int w = f->bw << (2 - ss_hor);
145
133k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
133k
        const int offset_uv = offset >> ss_ver;
147
133k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
133k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
133k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
113k
            if (restore_planes & LR_RESTORE_U || !resize)
151
102k
                backup_lpf(f, dst[1], lr_stride[1],
152
102k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
102k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
102k
                           row_h, w, h, ss_hor, 1);
155
113k
            if (have_tt && resize)
156
19.8k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
19.8k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
19.8k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
19.8k
                           row_h, w, h, ss_hor, 0);
160
113k
        }
161
133k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
130k
            if (restore_planes & LR_RESTORE_V || !resize)
163
124k
                backup_lpf(f, dst[2], lr_stride[1],
164
124k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
124k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
124k
                           row_h, w, h, ss_hor, 1);
167
130k
            if (have_tt && resize)
168
21.7k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
21.7k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
21.7k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
21.7k
                           row_h, w, h, ss_hor, 0);
172
130k
        }
173
133k
    }
174
162k
}
dav1d_copy_lpf_16bpc
Line
Count
Source
106
169k
{
107
169k
    const int have_tt = f->c->n_tc > 1;
108
169k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
169k
    const int offset = 8 * !!sby;
110
169k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
169k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
169k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
169k
    pixel *const dst[3] = {
114
169k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
169k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
169k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
169k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
169k
    const int restore_planes = f->lf.restore_planes;
121
122
169k
    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
149k
            backup_lpf(f, dst[0], lr_stride[0],
129
149k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
149k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
163k
        if (have_tt && resize) {
132
29.7k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
29.7k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
29.7k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
29.7k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
29.7k
        }
137
163k
    }
138
169k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
140k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
113k
    {
141
113k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
113k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
113k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
113k
        const int w = f->bw << (2 - ss_hor);
145
113k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
113k
        const int offset_uv = offset >> ss_ver;
147
113k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
113k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
113k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
95.7k
            if (restore_planes & LR_RESTORE_U || !resize)
151
83.2k
                backup_lpf(f, dst[1], lr_stride[1],
152
83.2k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
83.2k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
83.2k
                           row_h, w, h, ss_hor, 1);
155
95.7k
            if (have_tt && resize)
156
21.4k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
21.4k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
21.4k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
21.4k
                           row_h, w, h, ss_hor, 0);
160
95.7k
        }
161
113k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
109k
            if (restore_planes & LR_RESTORE_V || !resize)
163
100k
                backup_lpf(f, dst[2], lr_stride[1],
164
100k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
100k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
100k
                           row_h, w, h, ss_hor, 1);
167
109k
            if (have_tt && resize)
168
24.1k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
24.1k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
24.1k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
24.1k
                           row_h, w, h, ss_hor, 0);
172
109k
        }
173
113k
    }
174
169k
}
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
432k
{
185
432k
    const Dav1dDSPContext *const dsp = f->dsp;
186
187
    // filter edges between columns (e.g. block1 | block2)
188
4.92M
    for (int x = 0; x < w; x++) {
189
4.48M
        if (!have_left && !x) continue;
190
4.14M
        uint32_t hmask[4];
191
4.14M
        if (!starty4) {
192
3.31M
            hmask[0] = mask[x][0][0];
193
3.31M
            hmask[1] = mask[x][1][0];
194
3.31M
            hmask[2] = mask[x][2][0];
195
3.31M
            if (endy4 > 16) {
196
1.04M
                hmask[0] |= (unsigned) mask[x][0][1] << 16;
197
1.04M
                hmask[1] |= (unsigned) mask[x][1][1] << 16;
198
1.04M
                hmask[2] |= (unsigned) mask[x][2][1] << 16;
199
1.04M
            }
200
3.31M
        } else {
201
821k
            hmask[0] = mask[x][0][1];
202
821k
            hmask[1] = mask[x][1][1];
203
821k
            hmask[2] = mask[x][2][1];
204
821k
        }
205
4.14M
        hmask[3] = 0;
206
4.14M
        dsp->lf.loop_filter_sb[0][0](&dst[x * 4], ls, hmask,
207
4.14M
                                     (const uint8_t(*)[4]) &lvl[x][0], b4_stride,
208
4.14M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
209
4.14M
    }
210
432k
}
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
432k
{
221
432k
    const Dav1dDSPContext *const dsp = f->dsp;
222
223
    //                                 block1
224
    // filter edges between rows (e.g. ------)
225
    //                                 block2
226
5.82M
    for (int y = starty4; y < endy4;
227
5.38M
         y++, dst += 4 * PXSTRIDE(ls), lvl += b4_stride)
228
5.38M
    {
229
5.38M
        if (!have_top && !y) continue;
230
5.15M
        const uint32_t vmask[4] = {
231
5.15M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << 16),
232
5.15M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << 16),
233
5.15M
            mask[y][2][0] | ((unsigned) mask[y][2][1] << 16),
234
5.15M
            0,
235
5.15M
        };
236
5.15M
        dsp->lf.loop_filter_sb[0][1](dst, ls, vmask,
237
5.15M
                                     (const uint8_t(*)[4]) &lvl[0][1], b4_stride,
238
5.15M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
239
5.15M
    }
240
432k
}
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
312k
{
252
312k
    const Dav1dDSPContext *const dsp = f->dsp;
253
254
    // filter edges between columns (e.g. block1 | block2)
255
2.61M
    for (int x = 0; x < w; x++) {
256
2.30M
        if (!have_left && !x) continue;
257
2.05M
        uint32_t hmask[3];
258
2.05M
        if (!starty4) {
259
1.64M
            hmask[0] = mask[x][0][0];
260
1.64M
            hmask[1] = mask[x][1][0];
261
1.64M
            if (endy4 > (16 >> ss_ver)) {
262
491k
                hmask[0] |= (unsigned) mask[x][0][1] << (16 >> ss_ver);
263
491k
                hmask[1] |= (unsigned) mask[x][1][1] << (16 >> ss_ver);
264
491k
            }
265
1.64M
        } else {
266
405k
            hmask[0] = mask[x][0][1];
267
405k
            hmask[1] = mask[x][1][1];
268
405k
        }
269
2.05M
        hmask[2] = 0;
270
2.05M
        dsp->lf.loop_filter_sb[1][0](&u[x * 4], ls, hmask,
271
2.05M
                                     (const uint8_t(*)[4]) &lvl[x][2], b4_stride,
272
2.05M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
273
2.05M
        dsp->lf.loop_filter_sb[1][0](&v[x * 4], ls, hmask,
274
2.05M
                                     (const uint8_t(*)[4]) &lvl[x][3], b4_stride,
275
2.05M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
276
2.05M
    }
277
312k
}
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
311k
{
289
311k
    const Dav1dDSPContext *const dsp = f->dsp;
290
311k
    ptrdiff_t off_l = 0;
291
292
    //                                 block1
293
    // filter edges between rows (e.g. ------)
294
    //                                 block2
295
2.96M
    for (int y = starty4; y < endy4;
296
2.65M
         y++, off_l += 4 * PXSTRIDE(ls), lvl += b4_stride)
297
2.65M
    {
298
2.65M
        if (!have_top && !y) continue;
299
2.48M
        const uint32_t vmask[3] = {
300
2.48M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << (16 >> ss_hor)),
301
2.48M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << (16 >> ss_hor)),
302
2.48M
            0,
303
2.48M
        };
304
2.48M
        dsp->lf.loop_filter_sb[1][1](&u[off_l], ls, vmask,
305
2.48M
                                     (const uint8_t(*)[4]) &lvl[0][2], b4_stride,
306
2.48M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
307
2.48M
        dsp->lf.loop_filter_sb[1][1](&v[off_l], ls, vmask,
308
2.48M
                                     (const uint8_t(*)[4]) &lvl[0][3], b4_stride,
309
2.48M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
310
2.48M
    }
311
311k
}
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
347k
{
317
347k
    int x, have_left;
318
    // Don't filter outside the frame
319
347k
    const int is_sb64 = !f->seq_hdr->sb128;
320
347k
    const int starty4 = (sby & is_sb64) << 4;
321
347k
    const int sbsz = 32 >> is_sb64;
322
347k
    const int sbl2 = 5 - is_sb64;
323
347k
    const int halign = (f->bh + 31) & ~31;
324
347k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
347k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
347k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
347k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
347k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
347k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
347k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
347k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
350k
    for (int tile_col = 1;; tile_col++) {
335
350k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
350k
        if ((x << sbl2) >= f->bw) break;
337
2.74k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
2.74k
        x >>= is_sb64;
339
340
2.74k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
35.1k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
32.4k
            const int sidx = mask >= 0x10000U;
343
32.4k
            const unsigned smask = mask >> (sidx << 4);
344
32.4k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
32.4k
                                !!(y_hmask[1][sidx] & smask);
346
32.4k
            y_hmask[2][sidx] &= ~smask;
347
32.4k
            y_hmask[1][sidx] &= ~smask;
348
32.4k
            y_hmask[0][sidx] &= ~smask;
349
32.4k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
32.4k
        }
351
352
2.74k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
2.16k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
18.7k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
16.5k
                 y++, uv_mask <<= 1)
356
16.5k
            {
357
16.5k
                const int sidx = uv_mask >= vmax;
358
16.5k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
16.5k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
16.5k
                uv_hmask[1][sidx] &= ~smask;
361
16.5k
                uv_hmask[0][sidx] &= ~smask;
362
16.5k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
16.5k
            }
364
2.16k
        }
365
2.74k
        lpf_y  += halign;
366
2.74k
        lpf_uv += halign >> ss_ver;
367
2.74k
    }
368
369
    // fix lpf strength at tile row boundaries
370
347k
    if (start_of_tile_row) {
371
2.02k
        const BlockContext *a;
372
2.02k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
4.83k
             x < f->sb128w; x++, a++)
374
2.81k
        {
375
2.81k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
2.81k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
46.1k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
43.3k
                const int sidx = mask >= 0x10000U;
379
43.3k
                const unsigned smask = mask >> (sidx << 4);
380
43.3k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
43.3k
                                    !!(y_vmask[1][sidx] & smask);
382
43.3k
                y_vmask[2][sidx] &= ~smask;
383
43.3k
                y_vmask[1][sidx] &= ~smask;
384
43.3k
                y_vmask[0][sidx] &= ~smask;
385
43.3k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
43.3k
            }
387
388
2.81k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
2.15k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
2.15k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
29.0k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
26.9k
                    const int sidx = uv_mask >= hmax;
393
26.9k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
26.9k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
26.9k
                    uv_vmask[1][sidx] &= ~smask;
396
26.9k
                    uv_vmask[0][sidx] &= ~smask;
397
26.9k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
26.9k
                }
399
2.15k
            }
400
2.81k
        }
401
2.02k
    }
402
403
347k
    pixel *ptr;
404
347k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
780k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
432k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
432k
    {
408
432k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
432k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
432k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
432k
    }
412
413
347k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
94.6k
        return;
415
416
252k
    ptrdiff_t uv_off;
417
252k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
564k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
312k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
312k
    {
421
312k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
312k
                             lflvl[x].filter_uv[0],
423
312k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
312k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
312k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
312k
    }
427
252k
}
dav1d_loopfilter_sbrow_cols_8bpc
Line
Count
Source
316
170k
{
317
170k
    int x, have_left;
318
    // Don't filter outside the frame
319
170k
    const int is_sb64 = !f->seq_hdr->sb128;
320
170k
    const int starty4 = (sby & is_sb64) << 4;
321
170k
    const int sbsz = 32 >> is_sb64;
322
170k
    const int sbl2 = 5 - is_sb64;
323
170k
    const int halign = (f->bh + 31) & ~31;
324
170k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
170k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
170k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
170k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
170k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
170k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
170k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
170k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
171k
    for (int tile_col = 1;; tile_col++) {
335
171k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
171k
        if ((x << sbl2) >= f->bw) break;
337
1.15k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
1.15k
        x >>= is_sb64;
339
340
1.15k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
11.6k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
10.4k
            const int sidx = mask >= 0x10000U;
343
10.4k
            const unsigned smask = mask >> (sidx << 4);
344
10.4k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
10.4k
                                !!(y_hmask[1][sidx] & smask);
346
10.4k
            y_hmask[2][sidx] &= ~smask;
347
10.4k
            y_hmask[1][sidx] &= ~smask;
348
10.4k
            y_hmask[0][sidx] &= ~smask;
349
10.4k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
10.4k
        }
351
352
1.15k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
882
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
6.92k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
6.04k
                 y++, uv_mask <<= 1)
356
6.04k
            {
357
6.04k
                const int sidx = uv_mask >= vmax;
358
6.04k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
6.04k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
6.04k
                uv_hmask[1][sidx] &= ~smask;
361
6.04k
                uv_hmask[0][sidx] &= ~smask;
362
6.04k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
6.04k
            }
364
882
        }
365
1.15k
        lpf_y  += halign;
366
1.15k
        lpf_uv += halign >> ss_ver;
367
1.15k
    }
368
369
    // fix lpf strength at tile row boundaries
370
170k
    if (start_of_tile_row) {
371
1.14k
        const BlockContext *a;
372
1.14k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
2.62k
             x < f->sb128w; x++, a++)
374
1.48k
        {
375
1.48k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
1.48k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
21.9k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
20.5k
                const int sidx = mask >= 0x10000U;
379
20.5k
                const unsigned smask = mask >> (sidx << 4);
380
20.5k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
20.5k
                                    !!(y_vmask[1][sidx] & smask);
382
20.5k
                y_vmask[2][sidx] &= ~smask;
383
20.5k
                y_vmask[1][sidx] &= ~smask;
384
20.5k
                y_vmask[0][sidx] &= ~smask;
385
20.5k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
20.5k
            }
387
388
1.48k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
1.18k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
1.18k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
15.2k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
14.0k
                    const int sidx = uv_mask >= hmax;
393
14.0k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
14.0k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
14.0k
                    uv_vmask[1][sidx] &= ~smask;
396
14.0k
                    uv_vmask[0][sidx] &= ~smask;
397
14.0k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
14.0k
                }
399
1.18k
            }
400
1.48k
        }
401
1.14k
    }
402
403
170k
    pixel *ptr;
404
170k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
379k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
209k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
209k
    {
408
209k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
209k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
209k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
209k
    }
412
413
170k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
30.4k
        return;
415
416
139k
    ptrdiff_t uv_off;
417
139k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
308k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
168k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
168k
    {
421
168k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
168k
                             lflvl[x].filter_uv[0],
423
168k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
168k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
168k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
168k
    }
427
139k
}
dav1d_loopfilter_sbrow_cols_16bpc
Line
Count
Source
316
177k
{
317
177k
    int x, have_left;
318
    // Don't filter outside the frame
319
177k
    const int is_sb64 = !f->seq_hdr->sb128;
320
177k
    const int starty4 = (sby & is_sb64) << 4;
321
177k
    const int sbsz = 32 >> is_sb64;
322
177k
    const int sbl2 = 5 - is_sb64;
323
177k
    const int halign = (f->bh + 31) & ~31;
324
177k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
177k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
177k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
177k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
177k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
177k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
177k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
177k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
178k
    for (int tile_col = 1;; tile_col++) {
335
178k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
178k
        if ((x << sbl2) >= f->bw) break;
337
1.58k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
1.58k
        x >>= is_sb64;
339
340
1.58k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
23.5k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
21.9k
            const int sidx = mask >= 0x10000U;
343
21.9k
            const unsigned smask = mask >> (sidx << 4);
344
21.9k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
21.9k
                                !!(y_hmask[1][sidx] & smask);
346
21.9k
            y_hmask[2][sidx] &= ~smask;
347
21.9k
            y_hmask[1][sidx] &= ~smask;
348
21.9k
            y_hmask[0][sidx] &= ~smask;
349
21.9k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
21.9k
        }
351
352
1.58k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
1.27k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
11.8k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
10.5k
                 y++, uv_mask <<= 1)
356
10.5k
            {
357
10.5k
                const int sidx = uv_mask >= vmax;
358
10.5k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
10.5k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
10.5k
                uv_hmask[1][sidx] &= ~smask;
361
10.5k
                uv_hmask[0][sidx] &= ~smask;
362
10.5k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
10.5k
            }
364
1.27k
        }
365
1.58k
        lpf_y  += halign;
366
1.58k
        lpf_uv += halign >> ss_ver;
367
1.58k
    }
368
369
    // fix lpf strength at tile row boundaries
370
177k
    if (start_of_tile_row) {
371
878
        const BlockContext *a;
372
878
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
2.21k
             x < f->sb128w; x++, a++)
374
1.33k
        {
375
1.33k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
1.33k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
24.1k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
22.8k
                const int sidx = mask >= 0x10000U;
379
22.8k
                const unsigned smask = mask >> (sidx << 4);
380
22.8k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
22.8k
                                    !!(y_vmask[1][sidx] & smask);
382
22.8k
                y_vmask[2][sidx] &= ~smask;
383
22.8k
                y_vmask[1][sidx] &= ~smask;
384
22.8k
                y_vmask[0][sidx] &= ~smask;
385
22.8k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
22.8k
            }
387
388
1.33k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
976
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
976
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
13.8k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
12.9k
                    const int sidx = uv_mask >= hmax;
393
12.9k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
12.9k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
12.9k
                    uv_vmask[1][sidx] &= ~smask;
396
12.9k
                    uv_vmask[0][sidx] &= ~smask;
397
12.9k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
12.9k
                }
399
976
            }
400
1.33k
        }
401
878
    }
402
403
177k
    pixel *ptr;
404
177k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
400k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
223k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
223k
    {
408
223k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
223k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
223k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
223k
    }
412
413
177k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
64.1k
        return;
415
416
113k
    ptrdiff_t uv_off;
417
113k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
256k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
143k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
143k
    {
421
143k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
143k
                             lflvl[x].filter_uv[0],
423
143k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
143k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
143k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
143k
    }
427
113k
}
428
429
void bytefn(dav1d_loopfilter_sbrow_rows)(const Dav1dFrameContext *const f,
430
                                         pixel *const p[3], Av1Filter *const lflvl,
431
                                         int sby)
432
347k
{
433
347k
    int x;
434
    // Don't filter outside the frame
435
347k
    const int have_top = sby > 0;
436
347k
    const int is_sb64 = !f->seq_hdr->sb128;
437
347k
    const int starty4 = (sby & is_sb64) << 4;
438
347k
    const int sbsz = 32 >> is_sb64;
439
347k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
347k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
347k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
347k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
347k
    pixel *ptr;
445
347k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
780k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
432k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
432k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
432k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
432k
    }
451
452
347k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
94.6k
        return;
454
455
252k
    ptrdiff_t uv_off;
456
252k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
564k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
311k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
311k
    {
460
311k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
311k
                             lflvl[x].filter_uv[1],
462
311k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
311k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
311k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
311k
    }
466
252k
}
dav1d_loopfilter_sbrow_rows_8bpc
Line
Count
Source
432
170k
{
433
170k
    int x;
434
    // Don't filter outside the frame
435
170k
    const int have_top = sby > 0;
436
170k
    const int is_sb64 = !f->seq_hdr->sb128;
437
170k
    const int starty4 = (sby & is_sb64) << 4;
438
170k
    const int sbsz = 32 >> is_sb64;
439
170k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
170k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
170k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
170k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
170k
    pixel *ptr;
445
170k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
379k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
209k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
209k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
209k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
209k
    }
451
452
170k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
30.4k
        return;
454
455
139k
    ptrdiff_t uv_off;
456
139k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
308k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
168k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
168k
    {
460
168k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
168k
                             lflvl[x].filter_uv[1],
462
168k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
168k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
168k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
168k
    }
466
139k
}
dav1d_loopfilter_sbrow_rows_16bpc
Line
Count
Source
432
177k
{
433
177k
    int x;
434
    // Don't filter outside the frame
435
177k
    const int have_top = sby > 0;
436
177k
    const int is_sb64 = !f->seq_hdr->sb128;
437
177k
    const int starty4 = (sby & is_sb64) << 4;
438
177k
    const int sbsz = 32 >> is_sb64;
439
177k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
177k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
177k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
177k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
177k
    pixel *ptr;
445
177k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
400k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
223k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
223k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
223k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
223k
    }
451
452
177k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
64.1k
        return;
454
455
113k
    ptrdiff_t uv_off;
456
113k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
256k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
143k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
143k
    {
460
143k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
143k
                             lflvl[x].filter_uv[1],
462
143k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
143k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
143k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
143k
    }
466
113k
}