Coverage Report

Created: 2026-10-28 06:18

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
898k
{
48
898k
    const int cdef_backup = !lr_backup;
49
898k
    const int dst_w = f->frame_hdr->super_res.enabled ?
50
546k
                      (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
898k
    int stripe_h = ((64 << (cdef_backup & sb128)) - 8 * !row) >> ss_ver;
54
898k
    src += (stripe_h - 2) * PXSTRIDE(src_stride);
55
56
898k
    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
898k
    if (lr_backup && (f->frame_hdr->width[0] != f->frame_hdr->width[1])) {
74
255k
        while (row + stripe_h <= row_h) {
75
145k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
76
145k
            f->dsp->mc.resize(dst, dst_stride, src, src_stride,
77
145k
                              dst_w, n_lines, src_w, f->resize_step[ss_hor],
78
145k
                              f->resize_start[ss_hor] HIGHBD_CALL_SUFFIX);
79
145k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
80
145k
            stripe_h = 64 >> ss_ver;
81
145k
            src += stripe_h * PXSTRIDE(src_stride);
82
145k
            dst += n_lines * PXSTRIDE(dst_stride);
83
145k
            if (n_lines == 3) {
84
1.61k
                pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], dst_w);
85
1.61k
                dst += PXSTRIDE(dst_stride);
86
1.61k
            }
87
145k
        }
88
788k
    } else {
89
1.62M
        while (row + stripe_h <= row_h) {
90
833k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
91
4.16M
            for (int i = 0; i < 4; i++) {
92
3.33M
                pixel_copy(dst, i == n_lines ? &dst[-PXSTRIDE(dst_stride)] :
93
3.33M
                                               src, src_w);
94
3.33M
                dst += PXSTRIDE(dst_stride);
95
3.33M
                src += PXSTRIDE(src_stride);
96
3.33M
            }
97
833k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
98
833k
            stripe_h = 64 >> ss_ver;
99
833k
            src += (stripe_h - 4) * PXSTRIDE(src_stride);
100
833k
        }
101
788k
    }
102
898k
}
103
104
void bytefn(dav1d_copy_lpf)(Dav1dFrameContext *const f,
105
                            /*const*/ pixel *const src[3], const int sby)
106
331k
{
107
331k
    const int have_tt = f->c->n_tc > 1;
108
331k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
331k
    const int offset = 8 * !!sby;
110
331k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
331k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
331k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
331k
    pixel *const dst[3] = {
114
331k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
331k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
331k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
331k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
331k
    const int restore_planes = f->lf.restore_planes;
121
122
331k
    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
297k
            backup_lpf(f, dst[0], lr_stride[0],
129
297k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
297k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
321k
        if (have_tt && resize) {
132
66.0k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
66.0k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
66.0k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
66.0k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
66.0k
        }
137
321k
    }
138
331k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
323k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
249k
    {
141
249k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
249k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
249k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
249k
        const int w = f->bw << (2 - ss_hor);
145
249k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
249k
        const int offset_uv = offset >> ss_ver;
147
249k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
249k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
249k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
226k
            if (restore_planes & LR_RESTORE_U || !resize)
151
205k
                backup_lpf(f, dst[1], lr_stride[1],
152
205k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
205k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
205k
                           row_h, w, h, ss_hor, 1);
155
226k
            if (have_tt && resize)
156
51.1k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
51.1k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
51.1k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
51.1k
                           row_h, w, h, ss_hor, 0);
160
226k
        }
161
249k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
241k
            if (restore_planes & LR_RESTORE_V || !resize)
163
226k
                backup_lpf(f, dst[2], lr_stride[1],
164
226k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
226k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
226k
                           row_h, w, h, ss_hor, 1);
167
241k
            if (have_tt && resize)
168
52.3k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
52.3k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
52.3k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
52.3k
                           row_h, w, h, ss_hor, 0);
172
241k
        }
173
249k
    }
174
331k
}
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
160k
        const int h = f->cur.p.h;
124
160k
        const int w = f->bw << 2;
125
160k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
160k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
160k
        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
160k
        if (have_tt && resize) {
132
27.4k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
27.4k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
27.4k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
27.4k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
27.4k
        }
137
160k
    }
138
166k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
162k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
118k
    {
141
118k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
118k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
118k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
118k
        const int w = f->bw << (2 - ss_hor);
145
118k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
118k
        const int offset_uv = offset >> ss_ver;
147
118k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
118k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
118k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
110k
            if (restore_planes & LR_RESTORE_U || !resize)
151
101k
                backup_lpf(f, dst[1], lr_stride[1],
152
101k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
101k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
101k
                           row_h, w, h, ss_hor, 1);
155
110k
            if (have_tt && resize)
156
23.9k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
23.9k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
23.9k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
23.9k
                           row_h, w, h, ss_hor, 0);
160
110k
        }
161
118k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
115k
            if (restore_planes & LR_RESTORE_V || !resize)
163
107k
                backup_lpf(f, dst[2], lr_stride[1],
164
107k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
107k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
107k
                           row_h, w, h, ss_hor, 1);
167
115k
            if (have_tt && resize)
168
24.0k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
24.0k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
24.0k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
24.0k
                           row_h, w, h, ss_hor, 0);
172
115k
        }
173
118k
    }
174
166k
}
dav1d_copy_lpf_16bpc
Line
Count
Source
106
165k
{
107
165k
    const int have_tt = f->c->n_tc > 1;
108
165k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
165k
    const int offset = 8 * !!sby;
110
165k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
165k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
165k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
165k
    pixel *const dst[3] = {
114
165k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
165k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
165k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
165k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
165k
    const int restore_planes = f->lf.restore_planes;
121
122
165k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
160k
        const int h = f->cur.p.h;
124
160k
        const int w = f->bw << 2;
125
160k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
160k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
160k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
147k
            backup_lpf(f, dst[0], lr_stride[0],
129
147k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
147k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
160k
        if (have_tt && resize) {
132
38.6k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
38.6k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
38.6k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
38.6k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
38.6k
        }
137
160k
    }
138
165k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
160k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
131k
    {
141
131k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
131k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
131k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
131k
        const int w = f->bw << (2 - ss_hor);
145
131k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
131k
        const int offset_uv = offset >> ss_ver;
147
131k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
131k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
131k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
115k
            if (restore_planes & LR_RESTORE_U || !resize)
151
104k
                backup_lpf(f, dst[1], lr_stride[1],
152
104k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
104k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
104k
                           row_h, w, h, ss_hor, 1);
155
115k
            if (have_tt && resize)
156
27.1k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
27.1k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
27.1k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
27.1k
                           row_h, w, h, ss_hor, 0);
160
115k
        }
161
131k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
126k
            if (restore_planes & LR_RESTORE_V || !resize)
163
118k
                backup_lpf(f, dst[2], lr_stride[1],
164
118k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
118k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
118k
                           row_h, w, h, ss_hor, 1);
167
126k
            if (have_tt && resize)
168
28.2k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
28.2k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
28.2k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
28.2k
                           row_h, w, h, ss_hor, 0);
172
126k
        }
173
131k
    }
174
165k
}
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
441k
{
185
441k
    const Dav1dDSPContext *const dsp = f->dsp;
186
441k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[0][0];
187
188
    // filter edges between columns (e.g. block1 | block2)
189
6.47M
    for (int x = 0; x < w; x++) {
190
6.03M
        if (!have_left && !x) continue;
191
5.70M
        uint32_t hmask[4];
192
5.70M
        if (!starty4) {
193
4.52M
            hmask[0] = mask[x][0][0];
194
4.52M
            hmask[1] = mask[x][1][0];
195
4.52M
            hmask[2] = mask[x][2][0];
196
4.52M
            if (endy4 > 16) {
197
1.68M
                hmask[0] |= (unsigned) mask[x][0][1] << 16;
198
1.68M
                hmask[1] |= (unsigned) mask[x][1][1] << 16;
199
1.68M
                hmask[2] |= (unsigned) mask[x][2][1] << 16;
200
1.68M
            }
201
4.52M
        } else {
202
1.18M
            hmask[0] = mask[x][0][1];
203
1.18M
            hmask[1] = mask[x][1][1];
204
1.18M
            hmask[2] = mask[x][2][1];
205
1.18M
        }
206
5.70M
        hmask[3] = 0;
207
5.70M
        loop_filter_sb(&dst[x * 4], ls, hmask,
208
5.70M
                       (const uint8_t(*)[4]) &lvl[x][0], b4_stride,
209
5.70M
                       &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
210
5.70M
    }
211
441k
}
212
213
static inline void filter_plane_rows_y(const Dav1dFrameContext *const f,
214
                                       const int have_top,
215
                                       const uint8_t (*lvl)[4],
216
                                       const ptrdiff_t b4_stride,
217
                                       const uint16_t (*const mask)[3][2],
218
                                       pixel *dst, const ptrdiff_t ls,
219
                                       const int w,
220
                                       const int starty4, const int endy4)
221
440k
{
222
440k
    const Dav1dDSPContext *const dsp = f->dsp;
223
440k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[0][1];
224
225
    //                                 block1
226
    // filter edges between rows (e.g. ------)
227
    //                                 block2
228
8.41M
    for (int y = starty4; y < endy4;
229
7.97M
         y++, dst += 4 * PXSTRIDE(ls), lvl += b4_stride)
230
7.97M
    {
231
7.97M
        if (!have_top && !y) continue;
232
7.84M
        const uint32_t vmask[4] = {
233
7.84M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << 16),
234
7.84M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << 16),
235
7.84M
            mask[y][2][0] | ((unsigned) mask[y][2][1] << 16),
236
7.84M
            0,
237
7.84M
        };
238
7.84M
        loop_filter_sb(dst, ls, vmask,
239
7.84M
                       (const uint8_t(*)[4]) &lvl[0][1], b4_stride,
240
7.84M
                       &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
241
7.84M
    }
242
440k
}
243
244
static inline void filter_plane_cols_uv(const Dav1dFrameContext *const f,
245
                                        const int have_left,
246
                                        const uint8_t (*lvl)[4],
247
                                        const ptrdiff_t b4_stride,
248
                                        const uint16_t (*const mask)[2][2],
249
                                        pixel *const u, pixel *const v,
250
                                        const ptrdiff_t ls, const int w,
251
                                        const int starty4, const int endy4,
252
                                        const int ss_ver)
253
319k
{
254
319k
    const Dav1dDSPContext *const dsp = f->dsp;
255
319k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[1][0];
256
257
    // filter edges between columns (e.g. block1 | block2)
258
2.97M
    for (int x = 0; x < w; x++) {
259
2.65M
        if (!have_left && !x) continue;
260
2.41M
        uint32_t hmask[3];
261
2.41M
        if (!starty4) {
262
1.94M
            hmask[0] = mask[x][0][0];
263
1.94M
            hmask[1] = mask[x][1][0];
264
1.94M
            if (endy4 > (16 >> ss_ver)) {
265
747k
                hmask[0] |= (unsigned) mask[x][0][1] << (16 >> ss_ver);
266
747k
                hmask[1] |= (unsigned) mask[x][1][1] << (16 >> ss_ver);
267
747k
            }
268
1.94M
        } else {
269
465k
            hmask[0] = mask[x][0][1];
270
465k
            hmask[1] = mask[x][1][1];
271
465k
        }
272
2.41M
        hmask[2] = 0;
273
2.41M
        loop_filter_sb(&u[x * 4], ls, hmask,
274
2.41M
                       (const uint8_t(*)[4]) &lvl[x][2], b4_stride,
275
2.41M
                       &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
276
2.41M
        loop_filter_sb(&v[x * 4], ls, hmask,
277
2.41M
                       (const uint8_t(*)[4]) &lvl[x][3], b4_stride,
278
2.41M
                       &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
279
2.41M
    }
280
319k
}
281
282
static inline void filter_plane_rows_uv(const Dav1dFrameContext *const f,
283
                                        const int have_top,
284
                                        const uint8_t (*lvl)[4],
285
                                        const ptrdiff_t b4_stride,
286
                                        const uint16_t (*const mask)[2][2],
287
                                        pixel *const u, pixel *const v,
288
                                        const ptrdiff_t ls, const int w,
289
                                        const int starty4, const int endy4,
290
                                        const int ss_hor)
291
318k
{
292
318k
    const Dav1dDSPContext *const dsp = f->dsp;
293
318k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[1][1];
294
318k
    ptrdiff_t off_l = 0;
295
296
    //                                 block1
297
    // filter edges between rows (e.g. ------)
298
    //                                 block2
299
3.81M
    for (int y = starty4; y < endy4;
300
3.49M
         y++, off_l += 4 * PXSTRIDE(ls), lvl += b4_stride)
301
3.49M
    {
302
3.49M
        if (!have_top && !y) continue;
303
3.40M
        const uint32_t vmask[3] = {
304
3.40M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << (16 >> ss_hor)),
305
3.40M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << (16 >> ss_hor)),
306
3.40M
            0,
307
3.40M
        };
308
3.40M
        loop_filter_sb(&u[off_l], ls, vmask,
309
3.40M
                       (const uint8_t(*)[4]) &lvl[0][2], b4_stride,
310
3.40M
                       &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
311
3.40M
        loop_filter_sb(&v[off_l], ls, vmask,
312
3.40M
                       (const uint8_t(*)[4]) &lvl[0][3], b4_stride,
313
3.40M
                       &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
314
3.40M
    }
315
318k
}
316
317
void bytefn(dav1d_loopfilter_sbrow_cols)(const Dav1dFrameContext *const f,
318
                                         pixel *const p[3], Av1Filter *const lflvl,
319
                                         int sby, const int start_of_tile_row)
320
332k
{
321
332k
    int x, have_left;
322
    // Don't filter outside the frame
323
332k
    const int is_sb64 = !f->seq_hdr->sb128;
324
332k
    const int starty4 = (sby & is_sb64) << 4;
325
332k
    const int sbsz = 32 >> is_sb64;
326
332k
    const int sbl2 = 5 - is_sb64;
327
332k
    const int halign = (f->bh + 31) & ~31;
328
332k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
329
332k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
330
332k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
331
332k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
332
332k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
333
332k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
334
335
    // fix lpf strength at tile col boundaries
336
332k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
337
332k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
338
340k
    for (int tile_col = 1;; tile_col++) {
339
340k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
340
340k
        if ((x << sbl2) >= f->bw) break;
341
7.90k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
342
7.90k
        x >>= is_sb64;
343
344
7.90k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
345
175k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
346
167k
            const int sidx = mask >= 0x10000U;
347
167k
            const unsigned smask = mask >> (sidx << 4);
348
167k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
349
167k
                                !!(y_hmask[1][sidx] & smask);
350
167k
            y_hmask[2][sidx] &= ~smask;
351
167k
            y_hmask[1][sidx] &= ~smask;
352
167k
            y_hmask[0][sidx] &= ~smask;
353
167k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
354
167k
        }
355
356
7.90k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
357
6.61k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
358
84.8k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
359
78.1k
                 y++, uv_mask <<= 1)
360
78.1k
            {
361
78.1k
                const int sidx = uv_mask >= vmax;
362
78.1k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
363
78.1k
                const int idx = !!(uv_hmask[1][sidx] & smask);
364
78.1k
                uv_hmask[1][sidx] &= ~smask;
365
78.1k
                uv_hmask[0][sidx] &= ~smask;
366
78.1k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
367
78.1k
            }
368
6.61k
        }
369
7.90k
        lpf_y  += halign;
370
7.90k
        lpf_uv += halign >> ss_ver;
371
7.90k
    }
372
373
    // fix lpf strength at tile row boundaries
374
332k
    if (start_of_tile_row) {
375
3.01k
        const BlockContext *a;
376
3.01k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
377
8.40k
             x < f->sb128w; x++, a++)
378
5.38k
        {
379
5.38k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
380
5.38k
            const unsigned w = imin(32, f->w4 - (x << 5));
381
112k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
382
106k
                const int sidx = mask >= 0x10000U;
383
106k
                const unsigned smask = mask >> (sidx << 4);
384
106k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
385
106k
                                    !!(y_vmask[1][sidx] & smask);
386
106k
                y_vmask[2][sidx] &= ~smask;
387
106k
                y_vmask[1][sidx] &= ~smask;
388
106k
                y_vmask[0][sidx] &= ~smask;
389
106k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
390
106k
            }
391
392
5.38k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
393
4.06k
                const unsigned cw = (w + ss_hor) >> ss_hor;
394
4.06k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
395
53.8k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
396
49.7k
                    const int sidx = uv_mask >= hmax;
397
49.7k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
398
49.7k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
399
49.7k
                    uv_vmask[1][sidx] &= ~smask;
400
49.7k
                    uv_vmask[0][sidx] &= ~smask;
401
49.7k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
402
49.7k
                }
403
4.06k
            }
404
5.38k
        }
405
3.01k
    }
406
407
332k
    pixel *ptr;
408
332k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
409
773k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
410
441k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
411
441k
    {
412
441k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
413
441k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
414
441k
                            imin(32, f->w4 - x * 32), starty4, endy4);
415
441k
    }
416
417
332k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
418
82.9k
        return;
419
420
249k
    ptrdiff_t uv_off;
421
249k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
422
568k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
423
319k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
424
319k
    {
425
319k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
426
319k
                             lflvl[x].filter_uv[0],
427
319k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
428
319k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
429
319k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
430
319k
    }
431
249k
}
dav1d_loopfilter_sbrow_cols_8bpc
Line
Count
Source
320
173k
{
321
173k
    int x, have_left;
322
    // Don't filter outside the frame
323
173k
    const int is_sb64 = !f->seq_hdr->sb128;
324
173k
    const int starty4 = (sby & is_sb64) << 4;
325
173k
    const int sbsz = 32 >> is_sb64;
326
173k
    const int sbl2 = 5 - is_sb64;
327
173k
    const int halign = (f->bh + 31) & ~31;
328
173k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
329
173k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
330
173k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
331
173k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
332
173k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
333
173k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
334
335
    // fix lpf strength at tile col boundaries
336
173k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
337
173k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
338
177k
    for (int tile_col = 1;; tile_col++) {
339
177k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
340
177k
        if ((x << sbl2) >= f->bw) break;
341
4.01k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
342
4.01k
        x >>= is_sb64;
343
344
4.01k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
345
89.4k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
346
85.4k
            const int sidx = mask >= 0x10000U;
347
85.4k
            const unsigned smask = mask >> (sidx << 4);
348
85.4k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
349
85.4k
                                !!(y_hmask[1][sidx] & smask);
350
85.4k
            y_hmask[2][sidx] &= ~smask;
351
85.4k
            y_hmask[1][sidx] &= ~smask;
352
85.4k
            y_hmask[0][sidx] &= ~smask;
353
85.4k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
354
85.4k
        }
355
356
4.01k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
357
3.33k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
358
43.5k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
359
40.2k
                 y++, uv_mask <<= 1)
360
40.2k
            {
361
40.2k
                const int sidx = uv_mask >= vmax;
362
40.2k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
363
40.2k
                const int idx = !!(uv_hmask[1][sidx] & smask);
364
40.2k
                uv_hmask[1][sidx] &= ~smask;
365
40.2k
                uv_hmask[0][sidx] &= ~smask;
366
40.2k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
367
40.2k
            }
368
3.33k
        }
369
4.01k
        lpf_y  += halign;
370
4.01k
        lpf_uv += halign >> ss_ver;
371
4.01k
    }
372
373
    // fix lpf strength at tile row boundaries
374
173k
    if (start_of_tile_row) {
375
1.07k
        const BlockContext *a;
376
1.07k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
377
3.53k
             x < f->sb128w; x++, a++)
378
2.45k
        {
379
2.45k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
380
2.45k
            const unsigned w = imin(32, f->w4 - (x << 5));
381
57.7k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
382
55.2k
                const int sidx = mask >= 0x10000U;
383
55.2k
                const unsigned smask = mask >> (sidx << 4);
384
55.2k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
385
55.2k
                                    !!(y_vmask[1][sidx] & smask);
386
55.2k
                y_vmask[2][sidx] &= ~smask;
387
55.2k
                y_vmask[1][sidx] &= ~smask;
388
55.2k
                y_vmask[0][sidx] &= ~smask;
389
55.2k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
390
55.2k
            }
391
392
2.45k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
393
2.04k
                const unsigned cw = (w + ss_hor) >> ss_hor;
394
2.04k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
395
29.8k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
396
27.7k
                    const int sidx = uv_mask >= hmax;
397
27.7k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
398
27.7k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
399
27.7k
                    uv_vmask[1][sidx] &= ~smask;
400
27.7k
                    uv_vmask[0][sidx] &= ~smask;
401
27.7k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
402
27.7k
                }
403
2.04k
            }
404
2.45k
        }
405
1.07k
    }
406
407
173k
    pixel *ptr;
408
173k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
409
407k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
410
234k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
411
234k
    {
412
234k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
413
234k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
414
234k
                            imin(32, f->w4 - x * 32), starty4, endy4);
415
234k
    }
416
417
173k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
418
47.5k
        return;
419
420
125k
    ptrdiff_t uv_off;
421
125k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
422
283k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
423
157k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
424
157k
    {
425
157k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
426
157k
                             lflvl[x].filter_uv[0],
427
157k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
428
157k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
429
157k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
430
157k
    }
431
125k
}
dav1d_loopfilter_sbrow_cols_16bpc
Line
Count
Source
320
159k
{
321
159k
    int x, have_left;
322
    // Don't filter outside the frame
323
159k
    const int is_sb64 = !f->seq_hdr->sb128;
324
159k
    const int starty4 = (sby & is_sb64) << 4;
325
159k
    const int sbsz = 32 >> is_sb64;
326
159k
    const int sbl2 = 5 - is_sb64;
327
159k
    const int halign = (f->bh + 31) & ~31;
328
159k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
329
159k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
330
159k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
331
159k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
332
159k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
333
159k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
334
335
    // fix lpf strength at tile col boundaries
336
159k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
337
159k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
338
163k
    for (int tile_col = 1;; tile_col++) {
339
163k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
340
163k
        if ((x << sbl2) >= f->bw) break;
341
3.89k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
342
3.89k
        x >>= is_sb64;
343
344
3.89k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
345
85.9k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
346
82.0k
            const int sidx = mask >= 0x10000U;
347
82.0k
            const unsigned smask = mask >> (sidx << 4);
348
82.0k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
349
82.0k
                                !!(y_hmask[1][sidx] & smask);
350
82.0k
            y_hmask[2][sidx] &= ~smask;
351
82.0k
            y_hmask[1][sidx] &= ~smask;
352
82.0k
            y_hmask[0][sidx] &= ~smask;
353
82.0k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
354
82.0k
        }
355
356
3.89k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
357
3.28k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
358
41.2k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
359
37.9k
                 y++, uv_mask <<= 1)
360
37.9k
            {
361
37.9k
                const int sidx = uv_mask >= vmax;
362
37.9k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
363
37.9k
                const int idx = !!(uv_hmask[1][sidx] & smask);
364
37.9k
                uv_hmask[1][sidx] &= ~smask;
365
37.9k
                uv_hmask[0][sidx] &= ~smask;
366
37.9k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
367
37.9k
            }
368
3.28k
        }
369
3.89k
        lpf_y  += halign;
370
3.89k
        lpf_uv += halign >> ss_ver;
371
3.89k
    }
372
373
    // fix lpf strength at tile row boundaries
374
159k
    if (start_of_tile_row) {
375
1.94k
        const BlockContext *a;
376
1.94k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
377
4.87k
             x < f->sb128w; x++, a++)
378
2.92k
        {
379
2.92k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
380
2.92k
            const unsigned w = imin(32, f->w4 - (x << 5));
381
54.6k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
382
51.6k
                const int sidx = mask >= 0x10000U;
383
51.6k
                const unsigned smask = mask >> (sidx << 4);
384
51.6k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
385
51.6k
                                    !!(y_vmask[1][sidx] & smask);
386
51.6k
                y_vmask[2][sidx] &= ~smask;
387
51.6k
                y_vmask[1][sidx] &= ~smask;
388
51.6k
                y_vmask[0][sidx] &= ~smask;
389
51.6k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
390
51.6k
            }
391
392
2.92k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
393
2.02k
                const unsigned cw = (w + ss_hor) >> ss_hor;
394
2.02k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
395
23.9k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
396
21.9k
                    const int sidx = uv_mask >= hmax;
397
21.9k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
398
21.9k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
399
21.9k
                    uv_vmask[1][sidx] &= ~smask;
400
21.9k
                    uv_vmask[0][sidx] &= ~smask;
401
21.9k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
402
21.9k
                }
403
2.02k
            }
404
2.92k
        }
405
1.94k
    }
406
407
159k
    pixel *ptr;
408
159k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
409
366k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
410
207k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
411
207k
    {
412
207k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
413
207k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
414
207k
                            imin(32, f->w4 - x * 32), starty4, endy4);
415
207k
    }
416
417
159k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
418
35.3k
        return;
419
420
123k
    ptrdiff_t uv_off;
421
123k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
422
285k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
423
161k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
424
161k
    {
425
161k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
426
161k
                             lflvl[x].filter_uv[0],
427
161k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
428
161k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
429
161k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
430
161k
    }
431
123k
}
432
433
void bytefn(dav1d_loopfilter_sbrow_rows)(const Dav1dFrameContext *const f,
434
                                         pixel *const p[3], Av1Filter *const lflvl,
435
                                         int sby)
436
331k
{
437
331k
    int x;
438
    // Don't filter outside the frame
439
331k
    const int have_top = sby > 0;
440
331k
    const int is_sb64 = !f->seq_hdr->sb128;
441
331k
    const int starty4 = (sby & is_sb64) << 4;
442
331k
    const int sbsz = 32 >> is_sb64;
443
331k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
444
331k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
445
331k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
446
331k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
447
448
331k
    pixel *ptr;
449
331k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
450
771k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
451
440k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
452
440k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
453
440k
                            imin(32, f->w4 - x * 32), starty4, endy4);
454
440k
    }
455
456
331k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
457
82.7k
        return;
458
459
248k
    ptrdiff_t uv_off;
460
248k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
461
567k
    for (uv_off = 0, x = 0; x < f->sb128w;
462
318k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
463
318k
    {
464
318k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
465
318k
                             lflvl[x].filter_uv[1],
466
318k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
467
318k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
468
318k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
469
318k
    }
470
248k
}
dav1d_loopfilter_sbrow_rows_8bpc
Line
Count
Source
436
172k
{
437
172k
    int x;
438
    // Don't filter outside the frame
439
172k
    const int have_top = sby > 0;
440
172k
    const int is_sb64 = !f->seq_hdr->sb128;
441
172k
    const int starty4 = (sby & is_sb64) << 4;
442
172k
    const int sbsz = 32 >> is_sb64;
443
172k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
444
172k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
445
172k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
446
172k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
447
448
172k
    pixel *ptr;
449
172k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
450
406k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
451
233k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
452
233k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
453
233k
                            imin(32, f->w4 - x * 32), starty4, endy4);
454
233k
    }
455
456
172k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
457
47.4k
        return;
458
459
125k
    ptrdiff_t uv_off;
460
125k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
461
282k
    for (uv_off = 0, x = 0; x < f->sb128w;
462
157k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
463
157k
    {
464
157k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
465
157k
                             lflvl[x].filter_uv[1],
466
157k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
467
157k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
468
157k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
469
157k
    }
470
125k
}
dav1d_loopfilter_sbrow_rows_16bpc
Line
Count
Source
436
158k
{
437
158k
    int x;
438
    // Don't filter outside the frame
439
158k
    const int have_top = sby > 0;
440
158k
    const int is_sb64 = !f->seq_hdr->sb128;
441
158k
    const int starty4 = (sby & is_sb64) << 4;
442
158k
    const int sbsz = 32 >> is_sb64;
443
158k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
444
158k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
445
158k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
446
158k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
447
448
158k
    pixel *ptr;
449
158k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
450
365k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
451
206k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
452
206k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
453
206k
                            imin(32, f->w4 - x * 32), starty4, endy4);
454
206k
    }
455
456
158k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
457
35.2k
        return;
458
459
123k
    ptrdiff_t uv_off;
460
123k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
461
284k
    for (uv_off = 0, x = 0; x < f->sb128w;
462
160k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
463
160k
    {
464
160k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
465
160k
                             lflvl[x].filter_uv[1],
466
160k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
467
160k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
468
160k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
469
160k
    }
470
123k
}