Coverage Report

Created: 2026-09-14 06:44

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
988k
{
48
988k
    const int cdef_backup = !lr_backup;
49
988k
    const int dst_w = f->frame_hdr->super_res.enabled ?
50
605k
                      (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
988k
    int stripe_h = ((64 << (cdef_backup & sb128)) - 8 * !row) >> ss_ver;
54
988k
    src += (stripe_h - 2) * PXSTRIDE(src_stride);
55
56
988k
    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
988k
    if (lr_backup && (f->frame_hdr->width[0] != f->frame_hdr->width[1])) {
74
190k
        while (row + stripe_h <= row_h) {
75
87.5k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
76
87.5k
            f->dsp->mc.resize(dst, dst_stride, src, src_stride,
77
87.5k
                              dst_w, n_lines, src_w, f->resize_step[ss_hor],
78
87.5k
                              f->resize_start[ss_hor] HIGHBD_CALL_SUFFIX);
79
87.5k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
80
87.5k
            stripe_h = 64 >> ss_ver;
81
87.5k
            src += stripe_h * PXSTRIDE(src_stride);
82
87.5k
            dst += n_lines * PXSTRIDE(dst_stride);
83
87.5k
            if (n_lines == 3) {
84
1.21k
                pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], dst_w);
85
1.21k
                dst += PXSTRIDE(dst_stride);
86
1.21k
            }
87
87.5k
        }
88
886k
    } else {
89
1.49M
        while (row + stripe_h <= row_h) {
90
612k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
91
3.06M
            for (int i = 0; i < 4; i++) {
92
2.45M
                pixel_copy(dst, i == n_lines ? &dst[-PXSTRIDE(dst_stride)] :
93
2.45M
                                               src, src_w);
94
2.45M
                dst += PXSTRIDE(dst_stride);
95
2.45M
                src += PXSTRIDE(src_stride);
96
2.45M
            }
97
612k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
98
612k
            stripe_h = 64 >> ss_ver;
99
612k
            src += (stripe_h - 4) * PXSTRIDE(src_stride);
100
612k
        }
101
886k
    }
102
988k
}
103
104
void bytefn(dav1d_copy_lpf)(Dav1dFrameContext *const f,
105
                            /*const*/ pixel *const src[3], const int sby)
106
378k
{
107
378k
    const int have_tt = f->c->n_tc > 1;
108
378k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
378k
    const int offset = 8 * !!sby;
110
378k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
378k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
378k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
378k
    pixel *const dst[3] = {
114
378k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
378k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
378k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
378k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
378k
    const int restore_planes = f->lf.restore_planes;
121
122
378k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
367k
        const int h = f->cur.p.h;
124
367k
        const int w = f->bw << 2;
125
367k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
367k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
367k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
340k
            backup_lpf(f, dst[0], lr_stride[0],
129
340k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
340k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
367k
        if (have_tt && resize) {
132
66.3k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
66.3k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
66.3k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
66.3k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
66.3k
        }
137
367k
    }
138
378k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
348k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
289k
    {
141
289k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
289k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
289k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
289k
        const int w = f->bw << (2 - ss_hor);
145
289k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
289k
        const int offset_uv = offset >> ss_ver;
147
289k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
289k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
289k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
236k
            if (restore_planes & LR_RESTORE_U || !resize)
151
210k
                backup_lpf(f, dst[1], lr_stride[1],
152
210k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
210k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
210k
                           row_h, w, h, ss_hor, 1);
155
236k
            if (have_tt && resize)
156
51.7k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
51.7k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
51.7k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
51.7k
                           row_h, w, h, ss_hor, 0);
160
236k
        }
161
289k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
283k
            if (restore_planes & LR_RESTORE_V || !resize)
163
265k
                backup_lpf(f, dst[2], lr_stride[1],
164
265k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
265k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
265k
                           row_h, w, h, ss_hor, 1);
167
283k
            if (have_tt && resize)
168
55.3k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
55.3k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
55.3k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
55.3k
                           row_h, w, h, ss_hor, 0);
172
283k
        }
173
289k
    }
174
378k
}
dav1d_copy_lpf_8bpc
Line
Count
Source
106
185k
{
107
185k
    const int have_tt = f->c->n_tc > 1;
108
185k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
185k
    const int offset = 8 * !!sby;
110
185k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
185k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
185k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
185k
    pixel *const dst[3] = {
114
185k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
185k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
185k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
185k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
185k
    const int restore_planes = f->lf.restore_planes;
121
122
185k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
181k
        const int h = f->cur.p.h;
124
181k
        const int w = f->bw << 2;
125
181k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
181k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
181k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
169k
            backup_lpf(f, dst[0], lr_stride[0],
129
169k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
169k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
181k
        if (have_tt && resize) {
132
31.0k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
31.0k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
31.0k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
31.0k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
31.0k
        }
137
181k
    }
138
185k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
176k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
149k
    {
141
149k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
149k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
149k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
149k
        const int w = f->bw << (2 - ss_hor);
145
149k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
149k
        const int offset_uv = offset >> ss_ver;
147
149k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
149k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
149k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
125k
            if (restore_planes & LR_RESTORE_U || !resize)
151
111k
                backup_lpf(f, dst[1], lr_stride[1],
152
111k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
111k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
111k
                           row_h, w, h, ss_hor, 1);
155
125k
            if (have_tt && resize)
156
24.8k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
24.8k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
24.8k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
24.8k
                           row_h, w, h, ss_hor, 0);
160
125k
        }
161
149k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
146k
            if (restore_planes & LR_RESTORE_V || !resize)
163
137k
                backup_lpf(f, dst[2], lr_stride[1],
164
137k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
137k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
137k
                           row_h, w, h, ss_hor, 1);
167
146k
            if (have_tt && resize)
168
26.6k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
26.6k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
26.6k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
26.6k
                           row_h, w, h, ss_hor, 0);
172
146k
        }
173
149k
    }
174
185k
}
dav1d_copy_lpf_16bpc
Line
Count
Source
106
192k
{
107
192k
    const int have_tt = f->c->n_tc > 1;
108
192k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
192k
    const int offset = 8 * !!sby;
110
192k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
192k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
192k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
192k
    pixel *const dst[3] = {
114
192k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
192k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
192k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
192k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
192k
    const int restore_planes = f->lf.restore_planes;
121
122
192k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
185k
        const int h = f->cur.p.h;
124
185k
        const int w = f->bw << 2;
125
185k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
185k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
185k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
170k
            backup_lpf(f, dst[0], lr_stride[0],
129
170k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
170k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
185k
        if (have_tt && resize) {
132
35.2k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
35.2k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
35.2k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
35.2k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
35.2k
        }
137
185k
    }
138
192k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
171k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
140k
    {
141
140k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
140k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
140k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
140k
        const int w = f->bw << (2 - ss_hor);
145
140k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
140k
        const int offset_uv = offset >> ss_ver;
147
140k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
140k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
140k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
111k
            if (restore_planes & LR_RESTORE_U || !resize)
151
98.6k
                backup_lpf(f, dst[1], lr_stride[1],
152
98.6k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
98.6k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
98.6k
                           row_h, w, h, ss_hor, 1);
155
111k
            if (have_tt && resize)
156
26.8k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
26.8k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
26.8k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
26.8k
                           row_h, w, h, ss_hor, 0);
160
111k
        }
161
140k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
136k
            if (restore_planes & LR_RESTORE_V || !resize)
163
127k
                backup_lpf(f, dst[2], lr_stride[1],
164
127k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
127k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
127k
                           row_h, w, h, ss_hor, 1);
167
136k
            if (have_tt && resize)
168
28.7k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
28.7k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
28.7k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
28.7k
                           row_h, w, h, ss_hor, 0);
172
136k
        }
173
140k
    }
174
192k
}
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
472k
{
185
472k
    const Dav1dDSPContext *const dsp = f->dsp;
186
472k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[0][0];
187
188
    // filter edges between columns (e.g. block1 | block2)
189
4.93M
    for (int x = 0; x < w; x++) {
190
4.46M
        if (!have_left && !x) continue;
191
4.06M
        uint32_t hmask[4];
192
4.06M
        if (!starty4) {
193
3.34M
            hmask[0] = mask[x][0][0];
194
3.34M
            hmask[1] = mask[x][1][0];
195
3.34M
            hmask[2] = mask[x][2][0];
196
3.34M
            if (endy4 > 16) {
197
1.07M
                hmask[0] |= (unsigned) mask[x][0][1] << 16;
198
1.07M
                hmask[1] |= (unsigned) mask[x][1][1] << 16;
199
1.07M
                hmask[2] |= (unsigned) mask[x][2][1] << 16;
200
1.07M
            }
201
3.34M
        } else {
202
724k
            hmask[0] = mask[x][0][1];
203
724k
            hmask[1] = mask[x][1][1];
204
724k
            hmask[2] = mask[x][2][1];
205
724k
        }
206
4.06M
        hmask[3] = 0;
207
4.06M
        loop_filter_sb(&dst[x * 4], ls, hmask,
208
4.06M
                       (const uint8_t(*)[4]) &lvl[x][0], b4_stride,
209
4.06M
                       &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
210
4.06M
    }
211
472k
}
212
213
static inline void filter_plane_rows_y(const Dav1dFrameContext *const f,
214
                                       const int have_top,
215
                                       const uint8_t (*lvl)[4],
216
                                       const ptrdiff_t b4_stride,
217
                                       const uint16_t (*const mask)[3][2],
218
                                       pixel *dst, const ptrdiff_t ls,
219
                                       const int w,
220
                                       const int starty4, const int endy4)
221
472k
{
222
472k
    const Dav1dDSPContext *const dsp = f->dsp;
223
472k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[0][1];
224
225
    //                                 block1
226
    // filter edges between rows (e.g. ------)
227
    //                                 block2
228
6.55M
    for (int y = starty4; y < endy4;
229
6.08M
         y++, dst += 4 * PXSTRIDE(ls), lvl += b4_stride)
230
6.08M
    {
231
6.08M
        if (!have_top && !y) continue;
232
5.82M
        const uint32_t vmask[4] = {
233
5.82M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << 16),
234
5.82M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << 16),
235
5.82M
            mask[y][2][0] | ((unsigned) mask[y][2][1] << 16),
236
5.82M
            0,
237
5.82M
        };
238
5.82M
        loop_filter_sb(dst, ls, vmask,
239
5.82M
                       (const uint8_t(*)[4]) &lvl[0][1], b4_stride,
240
5.82M
                       &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
241
5.82M
    }
242
472k
}
243
244
static inline void filter_plane_cols_uv(const Dav1dFrameContext *const f,
245
                                        const int have_left,
246
                                        const uint8_t (*lvl)[4],
247
                                        const ptrdiff_t b4_stride,
248
                                        const uint16_t (*const mask)[2][2],
249
                                        pixel *const u, pixel *const v,
250
                                        const ptrdiff_t ls, const int w,
251
                                        const int starty4, const int endy4,
252
                                        const int ss_ver)
253
358k
{
254
358k
    const Dav1dDSPContext *const dsp = f->dsp;
255
358k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[1][0];
256
257
    // filter edges between columns (e.g. block1 | block2)
258
2.78M
    for (int x = 0; x < w; x++) {
259
2.42M
        if (!have_left && !x) continue;
260
2.12M
        uint32_t hmask[3];
261
2.12M
        if (!starty4) {
262
1.77M
            hmask[0] = mask[x][0][0];
263
1.77M
            hmask[1] = mask[x][1][0];
264
1.77M
            if (endy4 > (16 >> ss_ver)) {
265
626k
                hmask[0] |= (unsigned) mask[x][0][1] << (16 >> ss_ver);
266
626k
                hmask[1] |= (unsigned) mask[x][1][1] << (16 >> ss_ver);
267
626k
            }
268
1.77M
        } else {
269
350k
            hmask[0] = mask[x][0][1];
270
350k
            hmask[1] = mask[x][1][1];
271
350k
        }
272
2.12M
        hmask[2] = 0;
273
2.12M
        loop_filter_sb(&u[x * 4], ls, hmask,
274
2.12M
                       (const uint8_t(*)[4]) &lvl[x][2], b4_stride,
275
2.12M
                       &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
276
2.12M
        loop_filter_sb(&v[x * 4], ls, hmask,
277
2.12M
                       (const uint8_t(*)[4]) &lvl[x][3], b4_stride,
278
2.12M
                       &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
279
2.12M
    }
280
358k
}
281
282
static inline void filter_plane_rows_uv(const Dav1dFrameContext *const f,
283
                                        const int have_top,
284
                                        const uint8_t (*lvl)[4],
285
                                        const ptrdiff_t b4_stride,
286
                                        const uint16_t (*const mask)[2][2],
287
                                        pixel *const u, pixel *const v,
288
                                        const ptrdiff_t ls, const int w,
289
                                        const int starty4, const int endy4,
290
                                        const int ss_hor)
291
358k
{
292
358k
    const Dav1dDSPContext *const dsp = f->dsp;
293
358k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[1][1];
294
358k
    ptrdiff_t off_l = 0;
295
296
    //                                 block1
297
    // filter edges between rows (e.g. ------)
298
    //                                 block2
299
3.56M
    for (int y = starty4; y < endy4;
300
3.20M
         y++, off_l += 4 * PXSTRIDE(ls), lvl += b4_stride)
301
3.20M
    {
302
3.20M
        if (!have_top && !y) continue;
303
3.00M
        const uint32_t vmask[3] = {
304
3.00M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << (16 >> ss_hor)),
305
3.00M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << (16 >> ss_hor)),
306
3.00M
            0,
307
3.00M
        };
308
3.00M
        loop_filter_sb(&u[off_l], ls, vmask,
309
3.00M
                       (const uint8_t(*)[4]) &lvl[0][2], b4_stride,
310
3.00M
                       &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
311
3.00M
        loop_filter_sb(&v[off_l], ls, vmask,
312
3.00M
                       (const uint8_t(*)[4]) &lvl[0][3], b4_stride,
313
3.00M
                       &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
314
3.00M
    }
315
358k
}
316
317
void bytefn(dav1d_loopfilter_sbrow_cols)(const Dav1dFrameContext *const f,
318
                                         pixel *const p[3], Av1Filter *const lflvl,
319
                                         int sby, const int start_of_tile_row)
320
396k
{
321
396k
    int x, have_left;
322
    // Don't filter outside the frame
323
396k
    const int is_sb64 = !f->seq_hdr->sb128;
324
396k
    const int starty4 = (sby & is_sb64) << 4;
325
396k
    const int sbsz = 32 >> is_sb64;
326
396k
    const int sbl2 = 5 - is_sb64;
327
396k
    const int halign = (f->bh + 31) & ~31;
328
396k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
329
396k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
330
396k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
331
396k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
332
396k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
333
396k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
334
335
    // fix lpf strength at tile col boundaries
336
396k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
337
396k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
338
400k
    for (int tile_col = 1;; tile_col++) {
339
400k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
340
400k
        if ((x << sbl2) >= f->bw) break;
341
3.10k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
342
3.10k
        x >>= is_sb64;
343
344
3.10k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
345
34.8k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
346
31.7k
            const int sidx = mask >= 0x10000U;
347
31.7k
            const unsigned smask = mask >> (sidx << 4);
348
31.7k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
349
31.7k
                                !!(y_hmask[1][sidx] & smask);
350
31.7k
            y_hmask[2][sidx] &= ~smask;
351
31.7k
            y_hmask[1][sidx] &= ~smask;
352
31.7k
            y_hmask[0][sidx] &= ~smask;
353
31.7k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
354
31.7k
        }
355
356
3.10k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
357
2.52k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
358
20.7k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
359
18.1k
                 y++, uv_mask <<= 1)
360
18.1k
            {
361
18.1k
                const int sidx = uv_mask >= vmax;
362
18.1k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
363
18.1k
                const int idx = !!(uv_hmask[1][sidx] & smask);
364
18.1k
                uv_hmask[1][sidx] &= ~smask;
365
18.1k
                uv_hmask[0][sidx] &= ~smask;
366
18.1k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
367
18.1k
            }
368
2.52k
        }
369
3.10k
        lpf_y  += halign;
370
3.10k
        lpf_uv += halign >> ss_ver;
371
3.10k
    }
372
373
    // fix lpf strength at tile row boundaries
374
396k
    if (start_of_tile_row) {
375
2.31k
        const BlockContext *a;
376
2.31k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
377
5.36k
             x < f->sb128w; x++, a++)
378
3.05k
        {
379
3.05k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
380
3.05k
            const unsigned w = imin(32, f->w4 - (x << 5));
381
48.8k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
382
45.7k
                const int sidx = mask >= 0x10000U;
383
45.7k
                const unsigned smask = mask >> (sidx << 4);
384
45.7k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
385
45.7k
                                    !!(y_vmask[1][sidx] & smask);
386
45.7k
                y_vmask[2][sidx] &= ~smask;
387
45.7k
                y_vmask[1][sidx] &= ~smask;
388
45.7k
                y_vmask[0][sidx] &= ~smask;
389
45.7k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
390
45.7k
            }
391
392
3.05k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
393
2.52k
                const unsigned cw = (w + ss_hor) >> ss_hor;
394
2.52k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
395
33.4k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
396
30.9k
                    const int sidx = uv_mask >= hmax;
397
30.9k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
398
30.9k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
399
30.9k
                    uv_vmask[1][sidx] &= ~smask;
400
30.9k
                    uv_vmask[0][sidx] &= ~smask;
401
30.9k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
402
30.9k
                }
403
2.52k
            }
404
3.05k
        }
405
2.31k
    }
406
407
396k
    pixel *ptr;
408
396k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
409
869k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
410
472k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
411
472k
    {
412
472k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
413
472k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
414
472k
                            imin(32, f->w4 - x * 32), starty4, endy4);
415
472k
    }
416
417
396k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
418
95.9k
        return;
419
420
300k
    ptrdiff_t uv_off;
421
300k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
422
659k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
423
358k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
424
358k
    {
425
358k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
426
358k
                             lflvl[x].filter_uv[0],
427
358k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
428
358k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
429
358k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
430
358k
    }
431
300k
}
dav1d_loopfilter_sbrow_cols_8bpc
Line
Count
Source
320
199k
{
321
199k
    int x, have_left;
322
    // Don't filter outside the frame
323
199k
    const int is_sb64 = !f->seq_hdr->sb128;
324
199k
    const int starty4 = (sby & is_sb64) << 4;
325
199k
    const int sbsz = 32 >> is_sb64;
326
199k
    const int sbl2 = 5 - is_sb64;
327
199k
    const int halign = (f->bh + 31) & ~31;
328
199k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
329
199k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
330
199k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
331
199k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
332
199k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
333
199k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
334
335
    // fix lpf strength at tile col boundaries
336
199k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
337
199k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
338
201k
    for (int tile_col = 1;; tile_col++) {
339
201k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
340
201k
        if ((x << sbl2) >= f->bw) break;
341
1.39k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
342
1.39k
        x >>= is_sb64;
343
344
1.39k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
345
15.4k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
346
14.0k
            const int sidx = mask >= 0x10000U;
347
14.0k
            const unsigned smask = mask >> (sidx << 4);
348
14.0k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
349
14.0k
                                !!(y_hmask[1][sidx] & smask);
350
14.0k
            y_hmask[2][sidx] &= ~smask;
351
14.0k
            y_hmask[1][sidx] &= ~smask;
352
14.0k
            y_hmask[0][sidx] &= ~smask;
353
14.0k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
354
14.0k
        }
355
356
1.39k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
357
1.15k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
358
9.70k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
359
8.55k
                 y++, uv_mask <<= 1)
360
8.55k
            {
361
8.55k
                const int sidx = uv_mask >= vmax;
362
8.55k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
363
8.55k
                const int idx = !!(uv_hmask[1][sidx] & smask);
364
8.55k
                uv_hmask[1][sidx] &= ~smask;
365
8.55k
                uv_hmask[0][sidx] &= ~smask;
366
8.55k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
367
8.55k
            }
368
1.15k
        }
369
1.39k
        lpf_y  += halign;
370
1.39k
        lpf_uv += halign >> ss_ver;
371
1.39k
    }
372
373
    // fix lpf strength at tile row boundaries
374
199k
    if (start_of_tile_row) {
375
1.45k
        const BlockContext *a;
376
1.45k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
377
3.29k
             x < f->sb128w; x++, a++)
378
1.84k
        {
379
1.84k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
380
1.84k
            const unsigned w = imin(32, f->w4 - (x << 5));
381
27.3k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
382
25.5k
                const int sidx = mask >= 0x10000U;
383
25.5k
                const unsigned smask = mask >> (sidx << 4);
384
25.5k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
385
25.5k
                                    !!(y_vmask[1][sidx] & smask);
386
25.5k
                y_vmask[2][sidx] &= ~smask;
387
25.5k
                y_vmask[1][sidx] &= ~smask;
388
25.5k
                y_vmask[0][sidx] &= ~smask;
389
25.5k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
390
25.5k
            }
391
392
1.84k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
393
1.52k
                const unsigned cw = (w + ss_hor) >> ss_hor;
394
1.52k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
395
19.2k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
396
17.7k
                    const int sidx = uv_mask >= hmax;
397
17.7k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
398
17.7k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
399
17.7k
                    uv_vmask[1][sidx] &= ~smask;
400
17.7k
                    uv_vmask[0][sidx] &= ~smask;
401
17.7k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
402
17.7k
                }
403
1.52k
            }
404
1.84k
        }
405
1.45k
    }
406
407
199k
    pixel *ptr;
408
199k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
409
440k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
410
240k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
411
240k
    {
412
240k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
413
240k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
414
240k
                            imin(32, f->w4 - x * 32), starty4, endy4);
415
240k
    }
416
417
199k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
418
36.2k
        return;
419
420
163k
    ptrdiff_t uv_off;
421
163k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
422
358k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
423
195k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
424
195k
    {
425
195k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
426
195k
                             lflvl[x].filter_uv[0],
427
195k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
428
195k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
429
195k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
430
195k
    }
431
163k
}
dav1d_loopfilter_sbrow_cols_16bpc
Line
Count
Source
320
197k
{
321
197k
    int x, have_left;
322
    // Don't filter outside the frame
323
197k
    const int is_sb64 = !f->seq_hdr->sb128;
324
197k
    const int starty4 = (sby & is_sb64) << 4;
325
197k
    const int sbsz = 32 >> is_sb64;
326
197k
    const int sbl2 = 5 - is_sb64;
327
197k
    const int halign = (f->bh + 31) & ~31;
328
197k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
329
197k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
330
197k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
331
197k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
332
197k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
333
197k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
334
335
    // fix lpf strength at tile col boundaries
336
197k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
337
197k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
338
198k
    for (int tile_col = 1;; tile_col++) {
339
198k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
340
198k
        if ((x << sbl2) >= f->bw) break;
341
1.70k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
342
1.70k
        x >>= is_sb64;
343
344
1.70k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
345
19.3k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
346
17.6k
            const int sidx = mask >= 0x10000U;
347
17.6k
            const unsigned smask = mask >> (sidx << 4);
348
17.6k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
349
17.6k
                                !!(y_hmask[1][sidx] & smask);
350
17.6k
            y_hmask[2][sidx] &= ~smask;
351
17.6k
            y_hmask[1][sidx] &= ~smask;
352
17.6k
            y_hmask[0][sidx] &= ~smask;
353
17.6k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
354
17.6k
        }
355
356
1.70k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
357
1.36k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
358
10.9k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
359
9.62k
                 y++, uv_mask <<= 1)
360
9.62k
            {
361
9.62k
                const int sidx = uv_mask >= vmax;
362
9.62k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
363
9.62k
                const int idx = !!(uv_hmask[1][sidx] & smask);
364
9.62k
                uv_hmask[1][sidx] &= ~smask;
365
9.62k
                uv_hmask[0][sidx] &= ~smask;
366
9.62k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
367
9.62k
            }
368
1.36k
        }
369
1.70k
        lpf_y  += halign;
370
1.70k
        lpf_uv += halign >> ss_ver;
371
1.70k
    }
372
373
    // fix lpf strength at tile row boundaries
374
197k
    if (start_of_tile_row) {
375
862
        const BlockContext *a;
376
862
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
377
2.07k
             x < f->sb128w; x++, a++)
378
1.21k
        {
379
1.21k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
380
1.21k
            const unsigned w = imin(32, f->w4 - (x << 5));
381
21.4k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
382
20.2k
                const int sidx = mask >= 0x10000U;
383
20.2k
                const unsigned smask = mask >> (sidx << 4);
384
20.2k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
385
20.2k
                                    !!(y_vmask[1][sidx] & smask);
386
20.2k
                y_vmask[2][sidx] &= ~smask;
387
20.2k
                y_vmask[1][sidx] &= ~smask;
388
20.2k
                y_vmask[0][sidx] &= ~smask;
389
20.2k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
390
20.2k
            }
391
392
1.21k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
393
1.00k
                const unsigned cw = (w + ss_hor) >> ss_hor;
394
1.00k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
395
14.1k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
396
13.1k
                    const int sidx = uv_mask >= hmax;
397
13.1k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
398
13.1k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
399
13.1k
                    uv_vmask[1][sidx] &= ~smask;
400
13.1k
                    uv_vmask[0][sidx] &= ~smask;
401
13.1k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
402
13.1k
                }
403
1.00k
            }
404
1.21k
        }
405
862
    }
406
407
197k
    pixel *ptr;
408
197k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
409
429k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
410
232k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
411
232k
    {
412
232k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
413
232k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
414
232k
                            imin(32, f->w4 - x * 32), starty4, endy4);
415
232k
    }
416
417
197k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
418
59.7k
        return;
419
420
137k
    ptrdiff_t uv_off;
421
137k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
422
300k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
423
163k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
424
163k
    {
425
163k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
426
163k
                             lflvl[x].filter_uv[0],
427
163k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
428
163k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
429
163k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
430
163k
    }
431
137k
}
432
433
void bytefn(dav1d_loopfilter_sbrow_rows)(const Dav1dFrameContext *const f,
434
                                         pixel *const p[3], Av1Filter *const lflvl,
435
                                         int sby)
436
396k
{
437
396k
    int x;
438
    // Don't filter outside the frame
439
396k
    const int have_top = sby > 0;
440
396k
    const int is_sb64 = !f->seq_hdr->sb128;
441
396k
    const int starty4 = (sby & is_sb64) << 4;
442
396k
    const int sbsz = 32 >> is_sb64;
443
396k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
444
396k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
445
396k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
446
396k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
447
448
396k
    pixel *ptr;
449
396k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
450
868k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
451
472k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
452
472k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
453
472k
                            imin(32, f->w4 - x * 32), starty4, endy4);
454
472k
    }
455
456
396k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
457
95.8k
        return;
458
459
300k
    ptrdiff_t uv_off;
460
300k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
461
658k
    for (uv_off = 0, x = 0; x < f->sb128w;
462
358k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
463
358k
    {
464
358k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
465
358k
                             lflvl[x].filter_uv[1],
466
358k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
467
358k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
468
358k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
469
358k
    }
470
300k
}
dav1d_loopfilter_sbrow_rows_8bpc
Line
Count
Source
436
199k
{
437
199k
    int x;
438
    // Don't filter outside the frame
439
199k
    const int have_top = sby > 0;
440
199k
    const int is_sb64 = !f->seq_hdr->sb128;
441
199k
    const int starty4 = (sby & is_sb64) << 4;
442
199k
    const int sbsz = 32 >> is_sb64;
443
199k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
444
199k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
445
199k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
446
199k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
447
448
199k
    pixel *ptr;
449
199k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
450
439k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
451
240k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
452
240k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
453
240k
                            imin(32, f->w4 - x * 32), starty4, endy4);
454
240k
    }
455
456
199k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
457
36.1k
        return;
458
459
163k
    ptrdiff_t uv_off;
460
163k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
461
358k
    for (uv_off = 0, x = 0; x < f->sb128w;
462
194k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
463
194k
    {
464
194k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
465
194k
                             lflvl[x].filter_uv[1],
466
194k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
467
194k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
468
194k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
469
194k
    }
470
163k
}
dav1d_loopfilter_sbrow_rows_16bpc
Line
Count
Source
436
197k
{
437
197k
    int x;
438
    // Don't filter outside the frame
439
197k
    const int have_top = sby > 0;
440
197k
    const int is_sb64 = !f->seq_hdr->sb128;
441
197k
    const int starty4 = (sby & is_sb64) << 4;
442
197k
    const int sbsz = 32 >> is_sb64;
443
197k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
444
197k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
445
197k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
446
197k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
447
448
197k
    pixel *ptr;
449
197k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
450
429k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
451
232k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
452
232k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
453
232k
                            imin(32, f->w4 - x * 32), starty4, endy4);
454
232k
    }
455
456
197k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
457
59.6k
        return;
458
459
137k
    ptrdiff_t uv_off;
460
137k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
461
300k
    for (uv_off = 0, x = 0; x < f->sb128w;
462
163k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
463
163k
    {
464
163k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
465
163k
                             lflvl[x].filter_uv[1],
466
163k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
467
163k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
468
163k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
469
163k
    }
470
137k
}