Coverage Report

Created: 2026-07-16 06:32

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
559k
{
48
559k
    const int cdef_backup = !lr_backup;
49
559k
    const int dst_w = f->frame_hdr->super_res.enabled ?
50
281k
                      (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
559k
    int stripe_h = ((64 << (cdef_backup & sb128)) - 8 * !row) >> ss_ver;
54
559k
    src += (stripe_h - 2) * PXSTRIDE(src_stride);
55
56
559k
    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
559k
    if (lr_backup && (f->frame_hdr->width[0] != f->frame_hdr->width[1])) {
74
129k
        while (row + stripe_h <= row_h) {
75
64.4k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
76
64.4k
            f->dsp->mc.resize(dst, dst_stride, src, src_stride,
77
64.4k
                              dst_w, n_lines, src_w, f->resize_step[ss_hor],
78
64.4k
                              f->resize_start[ss_hor] HIGHBD_CALL_SUFFIX);
79
64.4k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
80
64.4k
            stripe_h = 64 >> ss_ver;
81
64.4k
            src += stripe_h * PXSTRIDE(src_stride);
82
64.4k
            dst += n_lines * PXSTRIDE(dst_stride);
83
64.4k
            if (n_lines == 3) {
84
826
                pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], dst_w);
85
826
                dst += PXSTRIDE(dst_stride);
86
826
            }
87
64.4k
        }
88
494k
    } else {
89
866k
        while (row + stripe_h <= row_h) {
90
371k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
91
1.85M
            for (int i = 0; i < 4; i++) {
92
1.48M
                pixel_copy(dst, i == n_lines ? &dst[-PXSTRIDE(dst_stride)] :
93
1.48M
                                               src, src_w);
94
1.48M
                dst += PXSTRIDE(dst_stride);
95
1.48M
                src += PXSTRIDE(src_stride);
96
1.48M
            }
97
371k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
98
371k
            stripe_h = 64 >> ss_ver;
99
371k
            src += (stripe_h - 4) * PXSTRIDE(src_stride);
100
371k
        }
101
494k
    }
102
559k
}
103
104
void bytefn(dav1d_copy_lpf)(Dav1dFrameContext *const f,
105
                            /*const*/ pixel *const src[3], const int sby)
106
215k
{
107
215k
    const int have_tt = f->c->n_tc > 1;
108
215k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
215k
    const int offset = 8 * !!sby;
110
215k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
215k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
215k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
215k
    pixel *const dst[3] = {
114
215k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
215k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
215k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
215k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
215k
    const int restore_planes = f->lf.restore_planes;
121
122
215k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
206k
        const int h = f->cur.p.h;
124
206k
        const int w = f->bw << 2;
125
206k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
206k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
206k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
185k
            backup_lpf(f, dst[0], lr_stride[0],
129
185k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
185k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
206k
        if (have_tt && resize) {
132
48.5k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
48.5k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
48.5k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
48.5k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
48.5k
        }
137
206k
    }
138
215k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
207k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
161k
    {
141
161k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
161k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
161k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
161k
        const int w = f->bw << (2 - ss_hor);
145
161k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
161k
        const int offset_uv = offset >> ss_ver;
147
161k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
161k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
161k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
133k
            if (restore_planes & LR_RESTORE_U || !resize)
151
114k
                backup_lpf(f, dst[1], lr_stride[1],
152
114k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
114k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
114k
                           row_h, w, h, ss_hor, 1);
155
133k
            if (have_tt && resize)
156
35.0k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
35.0k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
35.0k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
35.0k
                           row_h, w, h, ss_hor, 0);
160
133k
        }
161
161k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
153k
            if (restore_planes & LR_RESTORE_V || !resize)
163
140k
                backup_lpf(f, dst[2], lr_stride[1],
164
140k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
140k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
140k
                           row_h, w, h, ss_hor, 1);
167
153k
            if (have_tt && resize)
168
35.5k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
35.5k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
35.5k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
35.5k
                           row_h, w, h, ss_hor, 0);
172
153k
        }
173
161k
    }
174
215k
}
dav1d_copy_lpf_8bpc
Line
Count
Source
106
107k
{
107
107k
    const int have_tt = f->c->n_tc > 1;
108
107k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
107k
    const int offset = 8 * !!sby;
110
107k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
107k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
107k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
107k
    pixel *const dst[3] = {
114
107k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
107k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
107k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
107k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
107k
    const int restore_planes = f->lf.restore_planes;
121
122
107k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
103k
        const int h = f->cur.p.h;
124
103k
        const int w = f->bw << 2;
125
103k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
103k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
103k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
94.9k
            backup_lpf(f, dst[0], lr_stride[0],
129
94.9k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
94.9k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
103k
        if (have_tt && resize) {
132
23.0k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
23.0k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
23.0k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
23.0k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
23.0k
        }
137
103k
    }
138
107k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
103k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
81.4k
    {
141
81.4k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
81.4k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
81.4k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
81.4k
        const int w = f->bw << (2 - ss_hor);
145
81.4k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
81.4k
        const int offset_uv = offset >> ss_ver;
147
81.4k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
81.4k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
81.4k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
70.4k
            if (restore_planes & LR_RESTORE_U || !resize)
151
59.8k
                backup_lpf(f, dst[1], lr_stride[1],
152
59.8k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
59.8k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
59.8k
                           row_h, w, h, ss_hor, 1);
155
70.4k
            if (have_tt && resize)
156
17.8k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
17.8k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
17.8k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
17.8k
                           row_h, w, h, ss_hor, 0);
160
70.4k
        }
161
81.4k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
77.4k
            if (restore_planes & LR_RESTORE_V || !resize)
163
71.0k
                backup_lpf(f, dst[2], lr_stride[1],
164
71.0k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
71.0k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
71.0k
                           row_h, w, h, ss_hor, 1);
167
77.4k
            if (have_tt && resize)
168
18.3k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
18.3k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
18.3k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
18.3k
                           row_h, w, h, ss_hor, 0);
172
77.4k
        }
173
81.4k
    }
174
107k
}
dav1d_copy_lpf_16bpc
Line
Count
Source
106
108k
{
107
108k
    const int have_tt = f->c->n_tc > 1;
108
108k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
108k
    const int offset = 8 * !!sby;
110
108k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
108k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
108k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
108k
    pixel *const dst[3] = {
114
108k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
108k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
108k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
108k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
108k
    const int restore_planes = f->lf.restore_planes;
121
122
108k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
102k
        const int h = f->cur.p.h;
124
102k
        const int w = f->bw << 2;
125
102k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
102k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
102k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
90.8k
            backup_lpf(f, dst[0], lr_stride[0],
129
90.8k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
90.8k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
102k
        if (have_tt && resize) {
132
25.4k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
25.4k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
25.4k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
25.4k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
25.4k
        }
137
102k
    }
138
108k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
104k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
79.6k
    {
141
79.6k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
79.6k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
79.6k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
79.6k
        const int w = f->bw << (2 - ss_hor);
145
79.6k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
79.6k
        const int offset_uv = offset >> ss_ver;
147
79.6k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
79.6k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
79.6k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
63.4k
            if (restore_planes & LR_RESTORE_U || !resize)
151
54.2k
                backup_lpf(f, dst[1], lr_stride[1],
152
54.2k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
54.2k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
54.2k
                           row_h, w, h, ss_hor, 1);
155
63.4k
            if (have_tt && resize)
156
17.2k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
17.2k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
17.2k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
17.2k
                           row_h, w, h, ss_hor, 0);
160
63.4k
        }
161
79.6k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
76.4k
            if (restore_planes & LR_RESTORE_V || !resize)
163
69.7k
                backup_lpf(f, dst[2], lr_stride[1],
164
69.7k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
69.7k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
69.7k
                           row_h, w, h, ss_hor, 1);
167
76.4k
            if (have_tt && resize)
168
17.1k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
17.1k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
17.1k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
17.1k
                           row_h, w, h, ss_hor, 0);
172
76.4k
        }
173
79.6k
    }
174
108k
}
175
176
static inline void filter_plane_cols_y(const Dav1dFrameContext *const f,
177
                                       const int have_left,
178
                                       const uint8_t (*lvl)[4],
179
                                       const ptrdiff_t b4_stride,
180
                                       const uint16_t (*const mask)[3][2],
181
                                       pixel *dst, const ptrdiff_t ls,
182
                                       const int w,
183
                                       const int starty4, const int endy4)
184
303k
{
185
303k
    const Dav1dDSPContext *const dsp = f->dsp;
186
187
    // filter edges between columns (e.g. block1 | block2)
188
4.71M
    for (int x = 0; x < w; x++) {
189
4.41M
        if (!have_left && !x) continue;
190
4.20M
        uint32_t hmask[4];
191
4.20M
        if (!starty4) {
192
3.53M
            hmask[0] = mask[x][0][0];
193
3.53M
            hmask[1] = mask[x][1][0];
194
3.53M
            hmask[2] = mask[x][2][0];
195
3.53M
            if (endy4 > 16) {
196
1.73M
                hmask[0] |= (unsigned) mask[x][0][1] << 16;
197
1.73M
                hmask[1] |= (unsigned) mask[x][1][1] << 16;
198
1.73M
                hmask[2] |= (unsigned) mask[x][2][1] << 16;
199
1.73M
            }
200
3.53M
        } else {
201
673k
            hmask[0] = mask[x][0][1];
202
673k
            hmask[1] = mask[x][1][1];
203
673k
            hmask[2] = mask[x][2][1];
204
673k
        }
205
4.20M
        hmask[3] = 0;
206
4.20M
        dsp->lf.loop_filter_sb[0][0](&dst[x * 4], ls, hmask,
207
4.20M
                                     (const uint8_t(*)[4]) &lvl[x][0], b4_stride,
208
4.20M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
209
4.20M
    }
210
303k
}
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
302k
{
221
302k
    const Dav1dDSPContext *const dsp = f->dsp;
222
223
    //                                 block1
224
    // filter edges between rows (e.g. ------)
225
    //                                 block2
226
4.87M
    for (int y = starty4; y < endy4;
227
4.56M
         y++, dst += 4 * PXSTRIDE(ls), lvl += b4_stride)
228
4.56M
    {
229
4.56M
        if (!have_top && !y) continue;
230
4.41M
        const uint32_t vmask[4] = {
231
4.41M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << 16),
232
4.41M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << 16),
233
4.41M
            mask[y][2][0] | ((unsigned) mask[y][2][1] << 16),
234
4.41M
            0,
235
4.41M
        };
236
4.41M
        dsp->lf.loop_filter_sb[0][1](dst, ls, vmask,
237
4.41M
                                     (const uint8_t(*)[4]) &lvl[0][1], b4_stride,
238
4.41M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
239
4.41M
    }
240
302k
}
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
221k
{
252
221k
    const Dav1dDSPContext *const dsp = f->dsp;
253
254
    // filter edges between columns (e.g. block1 | block2)
255
2.47M
    for (int x = 0; x < w; x++) {
256
2.24M
        if (!have_left && !x) continue;
257
2.09M
        uint32_t hmask[3];
258
2.09M
        if (!starty4) {
259
1.76M
            hmask[0] = mask[x][0][0];
260
1.76M
            hmask[1] = mask[x][1][0];
261
1.76M
            if (endy4 > (16 >> ss_ver)) {
262
873k
                hmask[0] |= (unsigned) mask[x][0][1] << (16 >> ss_ver);
263
873k
                hmask[1] |= (unsigned) mask[x][1][1] << (16 >> ss_ver);
264
873k
            }
265
1.76M
        } else {
266
337k
            hmask[0] = mask[x][0][1];
267
337k
            hmask[1] = mask[x][1][1];
268
337k
        }
269
2.09M
        hmask[2] = 0;
270
2.09M
        dsp->lf.loop_filter_sb[1][0](&u[x * 4], ls, hmask,
271
2.09M
                                     (const uint8_t(*)[4]) &lvl[x][2], b4_stride,
272
2.09M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
273
2.09M
        dsp->lf.loop_filter_sb[1][0](&v[x * 4], ls, hmask,
274
2.09M
                                     (const uint8_t(*)[4]) &lvl[x][3], b4_stride,
275
2.09M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
276
2.09M
    }
277
221k
}
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
220k
{
289
220k
    const Dav1dDSPContext *const dsp = f->dsp;
290
220k
    ptrdiff_t off_l = 0;
291
292
    //                                 block1
293
    // filter edges between rows (e.g. ------)
294
    //                                 block2
295
2.67M
    for (int y = starty4; y < endy4;
296
2.44M
         y++, off_l += 4 * PXSTRIDE(ls), lvl += b4_stride)
297
2.44M
    {
298
2.44M
        if (!have_top && !y) continue;
299
2.33M
        const uint32_t vmask[3] = {
300
2.33M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << (16 >> ss_hor)),
301
2.33M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << (16 >> ss_hor)),
302
2.33M
            0,
303
2.33M
        };
304
2.33M
        dsp->lf.loop_filter_sb[1][1](&u[off_l], ls, vmask,
305
2.33M
                                     (const uint8_t(*)[4]) &lvl[0][2], b4_stride,
306
2.33M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
307
2.33M
        dsp->lf.loop_filter_sb[1][1](&v[off_l], ls, vmask,
308
2.33M
                                     (const uint8_t(*)[4]) &lvl[0][3], b4_stride,
309
2.33M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
310
2.33M
    }
311
220k
}
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
205k
{
317
205k
    int x, have_left;
318
    // Don't filter outside the frame
319
205k
    const int is_sb64 = !f->seq_hdr->sb128;
320
205k
    const int starty4 = (sby & is_sb64) << 4;
321
205k
    const int sbsz = 32 >> is_sb64;
322
205k
    const int sbl2 = 5 - is_sb64;
323
205k
    const int halign = (f->bh + 31) & ~31;
324
205k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
205k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
205k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
205k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
205k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
205k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
205k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
205k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
208k
    for (int tile_col = 1;; tile_col++) {
335
208k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
208k
        if ((x << sbl2) >= f->bw) break;
337
3.19k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
3.19k
        x >>= is_sb64;
339
340
3.19k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
49.2k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
46.0k
            const int sidx = mask >= 0x10000U;
343
46.0k
            const unsigned smask = mask >> (sidx << 4);
344
46.0k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
46.0k
                                !!(y_hmask[1][sidx] & smask);
346
46.0k
            y_hmask[2][sidx] &= ~smask;
347
46.0k
            y_hmask[1][sidx] &= ~smask;
348
46.0k
            y_hmask[0][sidx] &= ~smask;
349
46.0k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
46.0k
        }
351
352
3.19k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
2.83k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
34.4k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
31.6k
                 y++, uv_mask <<= 1)
356
31.6k
            {
357
31.6k
                const int sidx = uv_mask >= vmax;
358
31.6k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
31.6k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
31.6k
                uv_hmask[1][sidx] &= ~smask;
361
31.6k
                uv_hmask[0][sidx] &= ~smask;
362
31.6k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
31.6k
            }
364
2.83k
        }
365
3.19k
        lpf_y  += halign;
366
3.19k
        lpf_uv += halign >> ss_ver;
367
3.19k
    }
368
369
    // fix lpf strength at tile row boundaries
370
205k
    if (start_of_tile_row) {
371
1.56k
        const BlockContext *a;
372
1.56k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
4.01k
             x < f->sb128w; x++, a++)
374
2.45k
        {
375
2.45k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
2.45k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
43.9k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
41.5k
                const int sidx = mask >= 0x10000U;
379
41.5k
                const unsigned smask = mask >> (sidx << 4);
380
41.5k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
41.5k
                                    !!(y_vmask[1][sidx] & smask);
382
41.5k
                y_vmask[2][sidx] &= ~smask;
383
41.5k
                y_vmask[1][sidx] &= ~smask;
384
41.5k
                y_vmask[0][sidx] &= ~smask;
385
41.5k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
41.5k
            }
387
388
2.45k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
2.10k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
2.10k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
29.2k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
27.1k
                    const int sidx = uv_mask >= hmax;
393
27.1k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
27.1k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
27.1k
                    uv_vmask[1][sidx] &= ~smask;
396
27.1k
                    uv_vmask[0][sidx] &= ~smask;
397
27.1k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
27.1k
                }
399
2.10k
            }
400
2.45k
        }
401
1.56k
    }
402
403
205k
    pixel *ptr;
404
205k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
509k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
303k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
303k
    {
408
303k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
303k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
303k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
303k
    }
412
413
205k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
57.2k
        return;
415
416
148k
    ptrdiff_t uv_off;
417
148k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
370k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
221k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
221k
    {
421
221k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
221k
                             lflvl[x].filter_uv[0],
423
221k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
221k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
221k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
221k
    }
427
148k
}
dav1d_loopfilter_sbrow_cols_8bpc
Line
Count
Source
316
107k
{
317
107k
    int x, have_left;
318
    // Don't filter outside the frame
319
107k
    const int is_sb64 = !f->seq_hdr->sb128;
320
107k
    const int starty4 = (sby & is_sb64) << 4;
321
107k
    const int sbsz = 32 >> is_sb64;
322
107k
    const int sbl2 = 5 - is_sb64;
323
107k
    const int halign = (f->bh + 31) & ~31;
324
107k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
107k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
107k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
107k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
107k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
107k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
107k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
107k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
109k
    for (int tile_col = 1;; tile_col++) {
335
109k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
109k
        if ((x << sbl2) >= f->bw) break;
337
1.55k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
1.55k
        x >>= is_sb64;
339
340
1.55k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
22.8k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
21.3k
            const int sidx = mask >= 0x10000U;
343
21.3k
            const unsigned smask = mask >> (sidx << 4);
344
21.3k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
21.3k
                                !!(y_hmask[1][sidx] & smask);
346
21.3k
            y_hmask[2][sidx] &= ~smask;
347
21.3k
            y_hmask[1][sidx] &= ~smask;
348
21.3k
            y_hmask[0][sidx] &= ~smask;
349
21.3k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
21.3k
        }
351
352
1.55k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
1.33k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
15.3k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
14.0k
                 y++, uv_mask <<= 1)
356
14.0k
            {
357
14.0k
                const int sidx = uv_mask >= vmax;
358
14.0k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
14.0k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
14.0k
                uv_hmask[1][sidx] &= ~smask;
361
14.0k
                uv_hmask[0][sidx] &= ~smask;
362
14.0k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
14.0k
            }
364
1.33k
        }
365
1.55k
        lpf_y  += halign;
366
1.55k
        lpf_uv += halign >> ss_ver;
367
1.55k
    }
368
369
    // fix lpf strength at tile row boundaries
370
107k
    if (start_of_tile_row) {
371
807
        const BlockContext *a;
372
807
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
1.94k
             x < f->sb128w; x++, a++)
374
1.13k
        {
375
1.13k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
1.13k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
17.5k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
16.3k
                const int sidx = mask >= 0x10000U;
379
16.3k
                const unsigned smask = mask >> (sidx << 4);
380
16.3k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
16.3k
                                    !!(y_vmask[1][sidx] & smask);
382
16.3k
                y_vmask[2][sidx] &= ~smask;
383
16.3k
                y_vmask[1][sidx] &= ~smask;
384
16.3k
                y_vmask[0][sidx] &= ~smask;
385
16.3k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
16.3k
            }
387
388
1.13k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
973
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
973
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
11.1k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
10.1k
                    const int sidx = uv_mask >= hmax;
393
10.1k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
10.1k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
10.1k
                    uv_vmask[1][sidx] &= ~smask;
396
10.1k
                    uv_vmask[0][sidx] &= ~smask;
397
10.1k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
10.1k
                }
399
973
            }
400
1.13k
        }
401
807
    }
402
403
107k
    pixel *ptr;
404
107k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
266k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
158k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
158k
    {
408
158k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
158k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
158k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
158k
    }
412
413
107k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
27.3k
        return;
415
416
80.6k
    ptrdiff_t uv_off;
417
80.6k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
199k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
118k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
118k
    {
421
118k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
118k
                             lflvl[x].filter_uv[0],
423
118k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
118k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
118k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
118k
    }
427
80.6k
}
dav1d_loopfilter_sbrow_cols_16bpc
Line
Count
Source
316
97.7k
{
317
97.7k
    int x, have_left;
318
    // Don't filter outside the frame
319
97.7k
    const int is_sb64 = !f->seq_hdr->sb128;
320
97.7k
    const int starty4 = (sby & is_sb64) << 4;
321
97.7k
    const int sbsz = 32 >> is_sb64;
322
97.7k
    const int sbl2 = 5 - is_sb64;
323
97.7k
    const int halign = (f->bh + 31) & ~31;
324
97.7k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
97.7k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
97.7k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
97.7k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
97.7k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
97.7k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
97.7k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
97.7k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
99.3k
    for (int tile_col = 1;; tile_col++) {
335
99.3k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
99.3k
        if ((x << sbl2) >= f->bw) break;
337
1.64k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
1.64k
        x >>= is_sb64;
339
340
1.64k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
26.3k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
24.7k
            const int sidx = mask >= 0x10000U;
343
24.7k
            const unsigned smask = mask >> (sidx << 4);
344
24.7k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
24.7k
                                !!(y_hmask[1][sidx] & smask);
346
24.7k
            y_hmask[2][sidx] &= ~smask;
347
24.7k
            y_hmask[1][sidx] &= ~smask;
348
24.7k
            y_hmask[0][sidx] &= ~smask;
349
24.7k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
24.7k
        }
351
352
1.64k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
1.50k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
19.0k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
17.5k
                 y++, uv_mask <<= 1)
356
17.5k
            {
357
17.5k
                const int sidx = uv_mask >= vmax;
358
17.5k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
17.5k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
17.5k
                uv_hmask[1][sidx] &= ~smask;
361
17.5k
                uv_hmask[0][sidx] &= ~smask;
362
17.5k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
17.5k
            }
364
1.50k
        }
365
1.64k
        lpf_y  += halign;
366
1.64k
        lpf_uv += halign >> ss_ver;
367
1.64k
    }
368
369
    // fix lpf strength at tile row boundaries
370
97.7k
    if (start_of_tile_row) {
371
753
        const BlockContext *a;
372
753
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
2.07k
             x < f->sb128w; x++, a++)
374
1.31k
        {
375
1.31k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
1.31k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
26.4k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
25.1k
                const int sidx = mask >= 0x10000U;
379
25.1k
                const unsigned smask = mask >> (sidx << 4);
380
25.1k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
25.1k
                                    !!(y_vmask[1][sidx] & smask);
382
25.1k
                y_vmask[2][sidx] &= ~smask;
383
25.1k
                y_vmask[1][sidx] &= ~smask;
384
25.1k
                y_vmask[0][sidx] &= ~smask;
385
25.1k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
25.1k
            }
387
388
1.31k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
1.12k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
1.12k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
18.0k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
16.9k
                    const int sidx = uv_mask >= hmax;
393
16.9k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
16.9k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
16.9k
                    uv_vmask[1][sidx] &= ~smask;
396
16.9k
                    uv_vmask[0][sidx] &= ~smask;
397
16.9k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
16.9k
                }
399
1.12k
            }
400
1.31k
        }
401
753
    }
402
403
97.7k
    pixel *ptr;
404
97.7k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
243k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
145k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
145k
    {
408
145k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
145k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
145k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
145k
    }
412
413
97.7k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
29.9k
        return;
415
416
67.7k
    ptrdiff_t uv_off;
417
67.7k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
171k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
103k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
103k
    {
421
103k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
103k
                             lflvl[x].filter_uv[0],
423
103k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
103k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
103k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
103k
    }
427
67.7k
}
428
429
void bytefn(dav1d_loopfilter_sbrow_rows)(const Dav1dFrameContext *const f,
430
                                         pixel *const p[3], Av1Filter *const lflvl,
431
                                         int sby)
432
205k
{
433
205k
    int x;
434
    // Don't filter outside the frame
435
205k
    const int have_top = sby > 0;
436
205k
    const int is_sb64 = !f->seq_hdr->sb128;
437
205k
    const int starty4 = (sby & is_sb64) << 4;
438
205k
    const int sbsz = 32 >> is_sb64;
439
205k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
205k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
205k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
205k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
205k
    pixel *ptr;
445
205k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
507k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
302k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
302k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
302k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
302k
    }
451
452
205k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
57.1k
        return;
454
455
148k
    ptrdiff_t uv_off;
456
148k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
368k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
220k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
220k
    {
460
220k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
220k
                             lflvl[x].filter_uv[1],
462
220k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
220k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
220k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
220k
    }
466
148k
}
dav1d_loopfilter_sbrow_rows_8bpc
Line
Count
Source
432
107k
{
433
107k
    int x;
434
    // Don't filter outside the frame
435
107k
    const int have_top = sby > 0;
436
107k
    const int is_sb64 = !f->seq_hdr->sb128;
437
107k
    const int starty4 = (sby & is_sb64) << 4;
438
107k
    const int sbsz = 32 >> is_sb64;
439
107k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
107k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
107k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
107k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
107k
    pixel *ptr;
445
107k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
264k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
157k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
157k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
157k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
157k
    }
451
452
107k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
27.3k
        return;
454
455
80.4k
    ptrdiff_t uv_off;
456
80.4k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
197k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
117k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
117k
    {
460
117k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
117k
                             lflvl[x].filter_uv[1],
462
117k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
117k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
117k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
117k
    }
466
80.4k
}
dav1d_loopfilter_sbrow_rows_16bpc
Line
Count
Source
432
97.6k
{
433
97.6k
    int x;
434
    // Don't filter outside the frame
435
97.6k
    const int have_top = sby > 0;
436
97.6k
    const int is_sb64 = !f->seq_hdr->sb128;
437
97.6k
    const int starty4 = (sby & is_sb64) << 4;
438
97.6k
    const int sbsz = 32 >> is_sb64;
439
97.6k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
97.6k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
97.6k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
97.6k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
97.6k
    pixel *ptr;
445
97.6k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
242k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
145k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
145k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
145k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
145k
    }
451
452
97.6k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
29.8k
        return;
454
455
67.7k
    ptrdiff_t uv_off;
456
67.7k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
171k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
103k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
103k
    {
460
103k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
103k
                             lflvl[x].filter_uv[1],
462
103k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
103k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
103k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
103k
    }
466
67.7k
}