Coverage Report

Created: 2026-07-30 06:27

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
744k
{
48
744k
    const int cdef_backup = !lr_backup;
49
744k
    const int dst_w = f->frame_hdr->super_res.enabled ?
50
423k
                      (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
744k
    int stripe_h = ((64 << (cdef_backup & sb128)) - 8 * !row) >> ss_ver;
54
744k
    src += (stripe_h - 2) * PXSTRIDE(src_stride);
55
56
744k
    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
744k
    if (lr_backup && (f->frame_hdr->width[0] != f->frame_hdr->width[1])) {
74
178k
        while (row + stripe_h <= row_h) {
75
80.8k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
76
80.8k
            f->dsp->mc.resize(dst, dst_stride, src, src_stride,
77
80.8k
                              dst_w, n_lines, src_w, f->resize_step[ss_hor],
78
80.8k
                              f->resize_start[ss_hor] HIGHBD_CALL_SUFFIX);
79
80.8k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
80
80.8k
            stripe_h = 64 >> ss_ver;
81
80.8k
            src += stripe_h * PXSTRIDE(src_stride);
82
80.8k
            dst += n_lines * PXSTRIDE(dst_stride);
83
80.8k
            if (n_lines == 3) {
84
1.15k
                pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], dst_w);
85
1.15k
                dst += PXSTRIDE(dst_stride);
86
1.15k
            }
87
80.8k
        }
88
646k
    } else {
89
1.09M
        while (row + stripe_h <= row_h) {
90
447k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
91
2.23M
            for (int i = 0; i < 4; i++) {
92
1.79M
                pixel_copy(dst, i == n_lines ? &dst[-PXSTRIDE(dst_stride)] :
93
1.79M
                                               src, src_w);
94
1.79M
                dst += PXSTRIDE(dst_stride);
95
1.79M
                src += PXSTRIDE(src_stride);
96
1.79M
            }
97
447k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
98
447k
            stripe_h = 64 >> ss_ver;
99
447k
            src += (stripe_h - 4) * PXSTRIDE(src_stride);
100
447k
        }
101
646k
    }
102
744k
}
103
104
void bytefn(dav1d_copy_lpf)(Dav1dFrameContext *const f,
105
                            /*const*/ pixel *const src[3], const int sby)
106
294k
{
107
294k
    const int have_tt = f->c->n_tc > 1;
108
294k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
294k
    const int offset = 8 * !!sby;
110
294k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
294k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
294k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
294k
    pixel *const dst[3] = {
114
294k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
294k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
294k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
294k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
294k
    const int restore_planes = f->lf.restore_planes;
121
122
294k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
281k
        const int h = f->cur.p.h;
124
281k
        const int w = f->bw << 2;
125
281k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
281k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
281k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
251k
            backup_lpf(f, dst[0], lr_stride[0],
129
251k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
251k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
281k
        if (have_tt && resize) {
132
69.9k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
69.9k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
69.9k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
69.9k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
69.9k
        }
137
281k
    }
138
294k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
259k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
205k
    {
141
205k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
205k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
205k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
205k
        const int w = f->bw << (2 - ss_hor);
145
205k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
205k
        const int offset_uv = offset >> ss_ver;
147
205k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
205k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
205k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
167k
            if (restore_planes & LR_RESTORE_U || !resize)
151
138k
                backup_lpf(f, dst[1], lr_stride[1],
152
138k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
138k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
138k
                           row_h, w, h, ss_hor, 1);
155
167k
            if (have_tt && resize)
156
53.3k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
53.3k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
53.3k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
53.3k
                           row_h, w, h, ss_hor, 0);
160
167k
        }
161
205k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
197k
            if (restore_planes & LR_RESTORE_V || !resize)
163
174k
                backup_lpf(f, dst[2], lr_stride[1],
164
174k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
174k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
174k
                           row_h, w, h, ss_hor, 1);
167
197k
            if (have_tt && resize)
168
56.0k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
56.0k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
56.0k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
56.0k
                           row_h, w, h, ss_hor, 0);
172
197k
        }
173
205k
    }
174
294k
}
dav1d_copy_lpf_8bpc
Line
Count
Source
106
133k
{
107
133k
    const int have_tt = f->c->n_tc > 1;
108
133k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
133k
    const int offset = 8 * !!sby;
110
133k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
133k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
133k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
133k
    pixel *const dst[3] = {
114
133k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
133k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
133k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
133k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
133k
    const int restore_planes = f->lf.restore_planes;
121
122
133k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
127k
        const int h = f->cur.p.h;
124
127k
        const int w = f->bw << 2;
125
127k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
127k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
127k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
118k
            backup_lpf(f, dst[0], lr_stride[0],
129
118k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
118k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
127k
        if (have_tt && resize) {
132
30.6k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
30.6k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
30.6k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
30.6k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
30.6k
        }
137
127k
    }
138
133k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
125k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
100k
    {
141
100k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
100k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
100k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
100k
        const int w = f->bw << (2 - ss_hor);
145
100k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
100k
        const int offset_uv = offset >> ss_ver;
147
100k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
100k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
100k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
86.3k
            if (restore_planes & LR_RESTORE_U || !resize)
151
73.4k
                backup_lpf(f, dst[1], lr_stride[1],
152
73.4k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
73.4k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
73.4k
                           row_h, w, h, ss_hor, 1);
155
86.3k
            if (have_tt && resize)
156
23.6k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
23.6k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
23.6k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
23.6k
                           row_h, w, h, ss_hor, 0);
160
86.3k
        }
161
100k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
97.1k
            if (restore_planes & LR_RESTORE_V || !resize)
163
89.0k
                backup_lpf(f, dst[2], lr_stride[1],
164
89.0k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
89.0k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
89.0k
                           row_h, w, h, ss_hor, 1);
167
97.1k
            if (have_tt && resize)
168
24.2k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
24.2k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
24.2k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
24.2k
                           row_h, w, h, ss_hor, 0);
172
97.1k
        }
173
100k
    }
174
133k
}
dav1d_copy_lpf_16bpc
Line
Count
Source
106
160k
{
107
160k
    const int have_tt = f->c->n_tc > 1;
108
160k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
160k
    const int offset = 8 * !!sby;
110
160k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
160k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
160k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
160k
    pixel *const dst[3] = {
114
160k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
160k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
160k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
160k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
160k
    const int restore_planes = f->lf.restore_planes;
121
122
160k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
153k
        const int h = f->cur.p.h;
124
153k
        const int w = f->bw << 2;
125
153k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
153k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
153k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
133k
            backup_lpf(f, dst[0], lr_stride[0],
129
133k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
133k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
153k
        if (have_tt && resize) {
132
39.2k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
39.2k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
39.2k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
39.2k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
39.2k
        }
137
153k
    }
138
160k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
134k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
104k
    {
141
104k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
104k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
104k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
104k
        const int w = f->bw << (2 - ss_hor);
145
104k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
104k
        const int offset_uv = offset >> ss_ver;
147
104k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
104k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
104k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
81.4k
            if (restore_planes & LR_RESTORE_U || !resize)
151
65.1k
                backup_lpf(f, dst[1], lr_stride[1],
152
65.1k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
65.1k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
65.1k
                           row_h, w, h, ss_hor, 1);
155
81.4k
            if (have_tt && resize)
156
29.6k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
29.6k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
29.6k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
29.6k
                           row_h, w, h, ss_hor, 0);
160
81.4k
        }
161
104k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
100k
            if (restore_planes & LR_RESTORE_V || !resize)
163
85.6k
                backup_lpf(f, dst[2], lr_stride[1],
164
85.6k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
85.6k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
85.6k
                           row_h, w, h, ss_hor, 1);
167
100k
            if (have_tt && resize)
168
31.7k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
31.7k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
31.7k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
31.7k
                           row_h, w, h, ss_hor, 0);
172
100k
        }
173
104k
    }
174
160k
}
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
426k
{
185
426k
    const Dav1dDSPContext *const dsp = f->dsp;
186
187
    // filter edges between columns (e.g. block1 | block2)
188
5.74M
    for (int x = 0; x < w; x++) {
189
5.31M
        if (!have_left && !x) continue;
190
5.00M
        uint32_t hmask[4];
191
5.00M
        if (!starty4) {
192
4.11M
            hmask[0] = mask[x][0][0];
193
4.11M
            hmask[1] = mask[x][1][0];
194
4.11M
            hmask[2] = mask[x][2][0];
195
4.11M
            if (endy4 > 16) {
196
1.82M
                hmask[0] |= (unsigned) mask[x][0][1] << 16;
197
1.82M
                hmask[1] |= (unsigned) mask[x][1][1] << 16;
198
1.82M
                hmask[2] |= (unsigned) mask[x][2][1] << 16;
199
1.82M
            }
200
4.11M
        } else {
201
882k
            hmask[0] = mask[x][0][1];
202
882k
            hmask[1] = mask[x][1][1];
203
882k
            hmask[2] = mask[x][2][1];
204
882k
        }
205
5.00M
        hmask[3] = 0;
206
5.00M
        dsp->lf.loop_filter_sb[0][0](&dst[x * 4], ls, hmask,
207
5.00M
                                     (const uint8_t(*)[4]) &lvl[x][0], b4_stride,
208
5.00M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
209
5.00M
    }
210
426k
}
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
424k
{
221
424k
    const Dav1dDSPContext *const dsp = f->dsp;
222
223
    //                                 block1
224
    // filter edges between rows (e.g. ------)
225
    //                                 block2
226
6.06M
    for (int y = starty4; y < endy4;
227
5.64M
         y++, dst += 4 * PXSTRIDE(ls), lvl += b4_stride)
228
5.64M
    {
229
5.64M
        if (!have_top && !y) continue;
230
5.41M
        const uint32_t vmask[4] = {
231
5.41M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << 16),
232
5.41M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << 16),
233
5.41M
            mask[y][2][0] | ((unsigned) mask[y][2][1] << 16),
234
5.41M
            0,
235
5.41M
        };
236
5.41M
        dsp->lf.loop_filter_sb[0][1](dst, ls, vmask,
237
5.41M
                                     (const uint8_t(*)[4]) &lvl[0][1], b4_stride,
238
5.41M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
239
5.41M
    }
240
424k
}
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
299k
{
252
299k
    const Dav1dDSPContext *const dsp = f->dsp;
253
254
    // filter edges between columns (e.g. block1 | block2)
255
2.94M
    for (int x = 0; x < w; x++) {
256
2.64M
        if (!have_left && !x) continue;
257
2.42M
        uint32_t hmask[3];
258
2.42M
        if (!starty4) {
259
1.94M
            hmask[0] = mask[x][0][0];
260
1.94M
            hmask[1] = mask[x][1][0];
261
1.94M
            if (endy4 > (16 >> ss_ver)) {
262
826k
                hmask[0] |= (unsigned) mask[x][0][1] << (16 >> ss_ver);
263
826k
                hmask[1] |= (unsigned) mask[x][1][1] << (16 >> ss_ver);
264
826k
            }
265
1.94M
        } else {
266
480k
            hmask[0] = mask[x][0][1];
267
480k
            hmask[1] = mask[x][1][1];
268
480k
        }
269
2.42M
        hmask[2] = 0;
270
2.42M
        dsp->lf.loop_filter_sb[1][0](&u[x * 4], ls, hmask,
271
2.42M
                                     (const uint8_t(*)[4]) &lvl[x][2], b4_stride,
272
2.42M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
273
2.42M
        dsp->lf.loop_filter_sb[1][0](&v[x * 4], ls, hmask,
274
2.42M
                                     (const uint8_t(*)[4]) &lvl[x][3], b4_stride,
275
2.42M
                                     &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
276
2.42M
    }
277
299k
}
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
298k
{
289
298k
    const Dav1dDSPContext *const dsp = f->dsp;
290
298k
    ptrdiff_t off_l = 0;
291
292
    //                                 block1
293
    // filter edges between rows (e.g. ------)
294
    //                                 block2
295
2.99M
    for (int y = starty4; y < endy4;
296
2.69M
         y++, off_l += 4 * PXSTRIDE(ls), lvl += b4_stride)
297
2.69M
    {
298
2.69M
        if (!have_top && !y) continue;
299
2.53M
        const uint32_t vmask[3] = {
300
2.53M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << (16 >> ss_hor)),
301
2.53M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << (16 >> ss_hor)),
302
2.53M
            0,
303
2.53M
        };
304
2.53M
        dsp->lf.loop_filter_sb[1][1](&u[off_l], ls, vmask,
305
2.53M
                                     (const uint8_t(*)[4]) &lvl[0][2], b4_stride,
306
2.53M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
307
2.53M
        dsp->lf.loop_filter_sb[1][1](&v[off_l], ls, vmask,
308
2.53M
                                     (const uint8_t(*)[4]) &lvl[0][3], b4_stride,
309
2.53M
                                     &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
310
2.53M
    }
311
298k
}
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
315k
{
317
315k
    int x, have_left;
318
    // Don't filter outside the frame
319
315k
    const int is_sb64 = !f->seq_hdr->sb128;
320
315k
    const int starty4 = (sby & is_sb64) << 4;
321
315k
    const int sbsz = 32 >> is_sb64;
322
315k
    const int sbl2 = 5 - is_sb64;
323
315k
    const int halign = (f->bh + 31) & ~31;
324
315k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
315k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
315k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
315k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
315k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
315k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
315k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
315k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
319k
    for (int tile_col = 1;; tile_col++) {
335
319k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
319k
        if ((x << sbl2) >= f->bw) break;
337
4.05k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
4.05k
        x >>= is_sb64;
339
340
4.05k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
64.5k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
60.4k
            const int sidx = mask >= 0x10000U;
343
60.4k
            const unsigned smask = mask >> (sidx << 4);
344
60.4k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
60.4k
                                !!(y_hmask[1][sidx] & smask);
346
60.4k
            y_hmask[2][sidx] &= ~smask;
347
60.4k
            y_hmask[1][sidx] &= ~smask;
348
60.4k
            y_hmask[0][sidx] &= ~smask;
349
60.4k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
60.4k
        }
351
352
4.05k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
3.63k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
45.4k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
41.7k
                 y++, uv_mask <<= 1)
356
41.7k
            {
357
41.7k
                const int sidx = uv_mask >= vmax;
358
41.7k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
41.7k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
41.7k
                uv_hmask[1][sidx] &= ~smask;
361
41.7k
                uv_hmask[0][sidx] &= ~smask;
362
41.7k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
41.7k
            }
364
3.63k
        }
365
4.05k
        lpf_y  += halign;
366
4.05k
        lpf_uv += halign >> ss_ver;
367
4.05k
    }
368
369
    // fix lpf strength at tile row boundaries
370
315k
    if (start_of_tile_row) {
371
1.97k
        const BlockContext *a;
372
1.97k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
5.13k
             x < f->sb128w; x++, a++)
374
3.15k
        {
375
3.15k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
3.15k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
57.9k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
54.7k
                const int sidx = mask >= 0x10000U;
379
54.7k
                const unsigned smask = mask >> (sidx << 4);
380
54.7k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
54.7k
                                    !!(y_vmask[1][sidx] & smask);
382
54.7k
                y_vmask[2][sidx] &= ~smask;
383
54.7k
                y_vmask[1][sidx] &= ~smask;
384
54.7k
                y_vmask[0][sidx] &= ~smask;
385
54.7k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
54.7k
            }
387
388
3.15k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
2.50k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
2.50k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
35.9k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
33.4k
                    const int sidx = uv_mask >= hmax;
393
33.4k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
33.4k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
33.4k
                    uv_vmask[1][sidx] &= ~smask;
396
33.4k
                    uv_vmask[0][sidx] &= ~smask;
397
33.4k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
33.4k
                }
399
2.50k
            }
400
3.15k
        }
401
1.97k
    }
402
403
315k
    pixel *ptr;
404
315k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
742k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
426k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
426k
    {
408
426k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
426k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
426k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
426k
    }
412
413
315k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
98.1k
        return;
415
416
217k
    ptrdiff_t uv_off;
417
217k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
517k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
299k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
299k
    {
421
299k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
299k
                             lflvl[x].filter_uv[0],
423
299k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
299k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
299k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
299k
    }
427
217k
}
dav1d_loopfilter_sbrow_cols_8bpc
Line
Count
Source
316
155k
{
317
155k
    int x, have_left;
318
    // Don't filter outside the frame
319
155k
    const int is_sb64 = !f->seq_hdr->sb128;
320
155k
    const int starty4 = (sby & is_sb64) << 4;
321
155k
    const int sbsz = 32 >> is_sb64;
322
155k
    const int sbl2 = 5 - is_sb64;
323
155k
    const int halign = (f->bh + 31) & ~31;
324
155k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
155k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
155k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
155k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
155k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
155k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
155k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
155k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
157k
    for (int tile_col = 1;; tile_col++) {
335
157k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
157k
        if ((x << sbl2) >= f->bw) break;
337
2.05k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
2.05k
        x >>= is_sb64;
339
340
2.05k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
29.8k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
27.7k
            const int sidx = mask >= 0x10000U;
343
27.7k
            const unsigned smask = mask >> (sidx << 4);
344
27.7k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
27.7k
                                !!(y_hmask[1][sidx] & smask);
346
27.7k
            y_hmask[2][sidx] &= ~smask;
347
27.7k
            y_hmask[1][sidx] &= ~smask;
348
27.7k
            y_hmask[0][sidx] &= ~smask;
349
27.7k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
27.7k
        }
351
352
2.05k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
1.82k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
20.4k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
18.6k
                 y++, uv_mask <<= 1)
356
18.6k
            {
357
18.6k
                const int sidx = uv_mask >= vmax;
358
18.6k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
18.6k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
18.6k
                uv_hmask[1][sidx] &= ~smask;
361
18.6k
                uv_hmask[0][sidx] &= ~smask;
362
18.6k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
18.6k
            }
364
1.82k
        }
365
2.05k
        lpf_y  += halign;
366
2.05k
        lpf_uv += halign >> ss_ver;
367
2.05k
    }
368
369
    // fix lpf strength at tile row boundaries
370
155k
    if (start_of_tile_row) {
371
1.05k
        const BlockContext *a;
372
1.05k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
2.58k
             x < f->sb128w; x++, a++)
374
1.52k
        {
375
1.52k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
1.52k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
24.9k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
23.3k
                const int sidx = mask >= 0x10000U;
379
23.3k
                const unsigned smask = mask >> (sidx << 4);
380
23.3k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
23.3k
                                    !!(y_vmask[1][sidx] & smask);
382
23.3k
                y_vmask[2][sidx] &= ~smask;
383
23.3k
                y_vmask[1][sidx] &= ~smask;
384
23.3k
                y_vmask[0][sidx] &= ~smask;
385
23.3k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
23.3k
            }
387
388
1.52k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
1.23k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
1.23k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
14.2k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
13.0k
                    const int sidx = uv_mask >= hmax;
393
13.0k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
13.0k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
13.0k
                    uv_vmask[1][sidx] &= ~smask;
396
13.0k
                    uv_vmask[0][sidx] &= ~smask;
397
13.0k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
13.0k
                }
399
1.23k
            }
400
1.52k
        }
401
1.05k
    }
402
403
155k
    pixel *ptr;
404
155k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
372k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
217k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
217k
    {
408
217k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
217k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
217k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
217k
    }
412
413
155k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
34.3k
        return;
415
416
121k
    ptrdiff_t uv_off;
417
121k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
293k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
172k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
172k
    {
421
172k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
172k
                             lflvl[x].filter_uv[0],
423
172k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
172k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
172k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
172k
    }
427
121k
}
dav1d_loopfilter_sbrow_cols_16bpc
Line
Count
Source
316
160k
{
317
160k
    int x, have_left;
318
    // Don't filter outside the frame
319
160k
    const int is_sb64 = !f->seq_hdr->sb128;
320
160k
    const int starty4 = (sby & is_sb64) << 4;
321
160k
    const int sbsz = 32 >> is_sb64;
322
160k
    const int sbl2 = 5 - is_sb64;
323
160k
    const int halign = (f->bh + 31) & ~31;
324
160k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
325
160k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
326
160k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
327
160k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
328
160k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
329
160k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
330
331
    // fix lpf strength at tile col boundaries
332
160k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
333
160k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
334
162k
    for (int tile_col = 1;; tile_col++) {
335
162k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
336
162k
        if ((x << sbl2) >= f->bw) break;
337
1.99k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
338
1.99k
        x >>= is_sb64;
339
340
1.99k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
341
34.6k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
342
32.6k
            const int sidx = mask >= 0x10000U;
343
32.6k
            const unsigned smask = mask >> (sidx << 4);
344
32.6k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
345
32.6k
                                !!(y_hmask[1][sidx] & smask);
346
32.6k
            y_hmask[2][sidx] &= ~smask;
347
32.6k
            y_hmask[1][sidx] &= ~smask;
348
32.6k
            y_hmask[0][sidx] &= ~smask;
349
32.6k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
350
32.6k
        }
351
352
1.99k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
353
1.80k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
354
24.9k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
355
23.1k
                 y++, uv_mask <<= 1)
356
23.1k
            {
357
23.1k
                const int sidx = uv_mask >= vmax;
358
23.1k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
359
23.1k
                const int idx = !!(uv_hmask[1][sidx] & smask);
360
23.1k
                uv_hmask[1][sidx] &= ~smask;
361
23.1k
                uv_hmask[0][sidx] &= ~smask;
362
23.1k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
363
23.1k
            }
364
1.80k
        }
365
1.99k
        lpf_y  += halign;
366
1.99k
        lpf_uv += halign >> ss_ver;
367
1.99k
    }
368
369
    // fix lpf strength at tile row boundaries
370
160k
    if (start_of_tile_row) {
371
920
        const BlockContext *a;
372
920
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
373
2.54k
             x < f->sb128w; x++, a++)
374
1.62k
        {
375
1.62k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
376
1.62k
            const unsigned w = imin(32, f->w4 - (x << 5));
377
33.0k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
378
31.3k
                const int sidx = mask >= 0x10000U;
379
31.3k
                const unsigned smask = mask >> (sidx << 4);
380
31.3k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
381
31.3k
                                    !!(y_vmask[1][sidx] & smask);
382
31.3k
                y_vmask[2][sidx] &= ~smask;
383
31.3k
                y_vmask[1][sidx] &= ~smask;
384
31.3k
                y_vmask[0][sidx] &= ~smask;
385
31.3k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
386
31.3k
            }
387
388
1.62k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
389
1.26k
                const unsigned cw = (w + ss_hor) >> ss_hor;
390
1.26k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
391
21.7k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
392
20.4k
                    const int sidx = uv_mask >= hmax;
393
20.4k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
394
20.4k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
395
20.4k
                    uv_vmask[1][sidx] &= ~smask;
396
20.4k
                    uv_vmask[0][sidx] &= ~smask;
397
20.4k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
398
20.4k
                }
399
1.26k
            }
400
1.62k
        }
401
920
    }
402
403
160k
    pixel *ptr;
404
160k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
405
369k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
406
208k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
407
208k
    {
408
208k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
409
208k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
410
208k
                            imin(32, f->w4 - x * 32), starty4, endy4);
411
208k
    }
412
413
160k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
414
63.7k
        return;
415
416
96.6k
    ptrdiff_t uv_off;
417
96.6k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
418
223k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
419
126k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
420
126k
    {
421
126k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
422
126k
                             lflvl[x].filter_uv[0],
423
126k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
424
126k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
425
126k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
426
126k
    }
427
96.6k
}
428
429
void bytefn(dav1d_loopfilter_sbrow_rows)(const Dav1dFrameContext *const f,
430
                                         pixel *const p[3], Av1Filter *const lflvl,
431
                                         int sby)
432
315k
{
433
315k
    int x;
434
    // Don't filter outside the frame
435
315k
    const int have_top = sby > 0;
436
315k
    const int is_sb64 = !f->seq_hdr->sb128;
437
315k
    const int starty4 = (sby & is_sb64) << 4;
438
315k
    const int sbsz = 32 >> is_sb64;
439
315k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
315k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
315k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
315k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
315k
    pixel *ptr;
445
315k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
740k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
424k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
424k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
424k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
424k
    }
451
452
315k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
98.0k
        return;
454
455
217k
    ptrdiff_t uv_off;
456
217k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
515k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
298k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
298k
    {
460
298k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
298k
                             lflvl[x].filter_uv[1],
462
298k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
298k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
298k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
298k
    }
466
217k
}
dav1d_loopfilter_sbrow_rows_8bpc
Line
Count
Source
432
155k
{
433
155k
    int x;
434
    // Don't filter outside the frame
435
155k
    const int have_top = sby > 0;
436
155k
    const int is_sb64 = !f->seq_hdr->sb128;
437
155k
    const int starty4 = (sby & is_sb64) << 4;
438
155k
    const int sbsz = 32 >> is_sb64;
439
155k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
155k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
155k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
155k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
155k
    pixel *ptr;
445
155k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
371k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
216k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
216k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
216k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
216k
    }
451
452
155k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
34.3k
        return;
454
455
120k
    ptrdiff_t uv_off;
456
120k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
292k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
171k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
171k
    {
460
171k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
171k
                             lflvl[x].filter_uv[1],
462
171k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
171k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
171k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
171k
    }
466
120k
}
dav1d_loopfilter_sbrow_rows_16bpc
Line
Count
Source
432
160k
{
433
160k
    int x;
434
    // Don't filter outside the frame
435
160k
    const int have_top = sby > 0;
436
160k
    const int is_sb64 = !f->seq_hdr->sb128;
437
160k
    const int starty4 = (sby & is_sb64) << 4;
438
160k
    const int sbsz = 32 >> is_sb64;
439
160k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
440
160k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
441
160k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
442
160k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
443
444
160k
    pixel *ptr;
445
160k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
446
368k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
447
208k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
448
208k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
449
208k
                            imin(32, f->w4 - x * 32), starty4, endy4);
450
208k
    }
451
452
160k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
453
63.7k
        return;
454
455
96.5k
    ptrdiff_t uv_off;
456
96.5k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
457
222k
    for (uv_off = 0, x = 0; x < f->sb128w;
458
126k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
459
126k
    {
460
126k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
461
126k
                             lflvl[x].filter_uv[1],
462
126k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
463
126k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
464
126k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
465
126k
    }
466
96.5k
}