Coverage Report

Created: 2026-10-17 06:56

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
1.31M
{
48
1.31M
    const int cdef_backup = !lr_backup;
49
1.31M
    const int dst_w = f->frame_hdr->super_res.enabled ?
50
683k
                      (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
1.31M
    int stripe_h = ((64 << (cdef_backup & sb128)) - 8 * !row) >> ss_ver;
54
1.31M
    src += (stripe_h - 2) * PXSTRIDE(src_stride);
55
56
1.31M
    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
1.31M
    if (lr_backup && (f->frame_hdr->width[0] != f->frame_hdr->width[1])) {
74
181k
        while (row + stripe_h <= row_h) {
75
84.4k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
76
84.4k
            f->dsp->mc.resize(dst, dst_stride, src, src_stride,
77
84.4k
                              dst_w, n_lines, src_w, f->resize_step[ss_hor],
78
84.4k
                              f->resize_start[ss_hor] HIGHBD_CALL_SUFFIX);
79
84.4k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
80
84.4k
            stripe_h = 64 >> ss_ver;
81
84.4k
            src += stripe_h * PXSTRIDE(src_stride);
82
84.4k
            dst += n_lines * PXSTRIDE(dst_stride);
83
84.4k
            if (n_lines == 3) {
84
1.27k
                pixel_copy(dst, &dst[-PXSTRIDE(dst_stride)], dst_w);
85
1.27k
                dst += PXSTRIDE(dst_stride);
86
1.27k
            }
87
84.4k
        }
88
1.21M
    } else {
89
2.19M
        while (row + stripe_h <= row_h) {
90
976k
            const int n_lines = 4 - (row + stripe_h + 1 == h);
91
4.86M
            for (int i = 0; i < 4; i++) {
92
3.89M
                pixel_copy(dst, i == n_lines ? &dst[-PXSTRIDE(dst_stride)] :
93
3.89M
                                               src, src_w);
94
3.89M
                dst += PXSTRIDE(dst_stride);
95
3.89M
                src += PXSTRIDE(src_stride);
96
3.89M
            }
97
976k
            row += stripe_h; // unmodified stripe_h for the 1st stripe
98
976k
            stripe_h = 64 >> ss_ver;
99
976k
            src += (stripe_h - 4) * PXSTRIDE(src_stride);
100
976k
        }
101
1.21M
    }
102
1.31M
}
103
104
void bytefn(dav1d_copy_lpf)(Dav1dFrameContext *const f,
105
                            /*const*/ pixel *const src[3], const int sby)
106
496k
{
107
496k
    const int have_tt = f->c->n_tc > 1;
108
496k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
496k
    const int offset = 8 * !!sby;
110
496k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
496k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
496k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
496k
    pixel *const dst[3] = {
114
496k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
496k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
496k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
496k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
496k
    const int restore_planes = f->lf.restore_planes;
121
122
496k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
483k
        const int h = f->cur.p.h;
124
483k
        const int w = f->bw << 2;
125
483k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
483k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
483k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
449k
            backup_lpf(f, dst[0], lr_stride[0],
129
449k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
449k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
483k
        if (have_tt && resize) {
132
70.4k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
70.4k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
70.4k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
70.4k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
70.4k
        }
137
483k
    }
138
496k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
473k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
396k
    {
141
396k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
396k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
396k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
396k
        const int w = f->bw << (2 - ss_hor);
145
396k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
396k
        const int offset_uv = offset >> ss_ver;
147
396k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
396k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
396k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
343k
            if (restore_planes & LR_RESTORE_U || !resize)
151
311k
                backup_lpf(f, dst[1], lr_stride[1],
152
311k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
311k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
311k
                           row_h, w, h, ss_hor, 1);
155
343k
            if (have_tt && resize)
156
56.7k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
56.7k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
56.7k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
56.7k
                           row_h, w, h, ss_hor, 0);
160
343k
        }
161
396k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
389k
            if (restore_planes & LR_RESTORE_V || !resize)
163
366k
                backup_lpf(f, dst[2], lr_stride[1],
164
366k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
366k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
366k
                           row_h, w, h, ss_hor, 1);
167
389k
            if (have_tt && resize)
168
59.0k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
59.0k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
59.0k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
59.0k
                           row_h, w, h, ss_hor, 0);
172
389k
        }
173
396k
    }
174
496k
}
dav1d_copy_lpf_8bpc
Line
Count
Source
106
241k
{
107
241k
    const int have_tt = f->c->n_tc > 1;
108
241k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
241k
    const int offset = 8 * !!sby;
110
241k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
241k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
241k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
241k
    pixel *const dst[3] = {
114
241k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
241k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
241k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
241k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
241k
    const int restore_planes = f->lf.restore_planes;
121
122
241k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
237k
        const int h = f->cur.p.h;
124
237k
        const int w = f->bw << 2;
125
237k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
237k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
237k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
222k
            backup_lpf(f, dst[0], lr_stride[0],
129
222k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
222k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
237k
        if (have_tt && resize) {
132
28.1k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
28.1k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
28.1k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
28.1k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
28.1k
        }
137
237k
    }
138
241k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
232k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
197k
    {
141
197k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
197k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
197k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
197k
        const int w = f->bw << (2 - ss_hor);
145
197k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
197k
        const int offset_uv = offset >> ss_ver;
147
197k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
197k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
197k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
173k
            if (restore_planes & LR_RESTORE_U || !resize)
151
159k
                backup_lpf(f, dst[1], lr_stride[1],
152
159k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
159k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
159k
                           row_h, w, h, ss_hor, 1);
155
173k
            if (have_tt && resize)
156
22.3k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
22.3k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
22.3k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
22.3k
                           row_h, w, h, ss_hor, 0);
160
173k
        }
161
197k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
194k
            if (restore_planes & LR_RESTORE_V || !resize)
163
183k
                backup_lpf(f, dst[2], lr_stride[1],
164
183k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
183k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
183k
                           row_h, w, h, ss_hor, 1);
167
194k
            if (have_tt && resize)
168
23.5k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
23.5k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
23.5k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
23.5k
                           row_h, w, h, ss_hor, 0);
172
194k
        }
173
197k
    }
174
241k
}
dav1d_copy_lpf_16bpc
Line
Count
Source
106
255k
{
107
255k
    const int have_tt = f->c->n_tc > 1;
108
255k
    const int resize = f->frame_hdr->width[0] != f->frame_hdr->width[1];
109
255k
    const int offset = 8 * !!sby;
110
255k
    const ptrdiff_t *const src_stride = f->cur.stride;
111
255k
    const ptrdiff_t *const lr_stride = f->sr_cur.p.stride;
112
255k
    const int tt_off = have_tt * sby * (4 << f->seq_hdr->sb128);
113
255k
    pixel *const dst[3] = {
114
255k
        f->lf.lr_lpf_line[0] + tt_off * PXSTRIDE(lr_stride[0]),
115
255k
        f->lf.lr_lpf_line[1] + tt_off * PXSTRIDE(lr_stride[1]),
116
255k
        f->lf.lr_lpf_line[2] + tt_off * PXSTRIDE(lr_stride[1])
117
255k
    };
118
119
    // TODO Also check block level restore type to reduce copying.
120
255k
    const int restore_planes = f->lf.restore_planes;
121
122
255k
    if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_Y) {
123
246k
        const int h = f->cur.p.h;
124
246k
        const int w = f->bw << 2;
125
246k
        const int row_h = imin((sby + 1) << (6 + f->seq_hdr->sb128), h - 1);
126
246k
        const int y_stripe = (sby << (6 + f->seq_hdr->sb128)) - offset;
127
246k
        if (restore_planes & LR_RESTORE_Y || !resize)
128
227k
            backup_lpf(f, dst[0], lr_stride[0],
129
227k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
130
227k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 1);
131
246k
        if (have_tt && resize) {
132
42.3k
            const ptrdiff_t cdef_off_y = sby * 4 * PXSTRIDE(src_stride[0]);
133
42.3k
            backup_lpf(f, f->lf.cdef_lpf_line[0] + cdef_off_y, src_stride[0],
134
42.3k
                       src[0] - offset * PXSTRIDE(src_stride[0]), src_stride[0],
135
42.3k
                       0, f->seq_hdr->sb128, y_stripe, row_h, w, h, 0, 0);
136
42.3k
        }
137
246k
    }
138
255k
    if ((f->seq_hdr->cdef || restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) &&
139
240k
        f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400)
140
199k
    {
141
199k
        const int ss_ver = f->sr_cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
142
199k
        const int ss_hor = f->sr_cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
143
199k
        const int h = (f->cur.p.h + ss_ver) >> ss_ver;
144
199k
        const int w = f->bw << (2 - ss_hor);
145
199k
        const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr->sb128), h - 1);
146
199k
        const int offset_uv = offset >> ss_ver;
147
199k
        const int y_stripe = (sby << ((6 - ss_ver) + f->seq_hdr->sb128)) - offset_uv;
148
199k
        const ptrdiff_t cdef_off_uv = sby * 4 * PXSTRIDE(src_stride[1]);
149
199k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_U) {
150
170k
            if (restore_planes & LR_RESTORE_U || !resize)
151
152k
                backup_lpf(f, dst[1], lr_stride[1],
152
152k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
153
152k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
154
152k
                           row_h, w, h, ss_hor, 1);
155
170k
            if (have_tt && resize)
156
34.4k
                backup_lpf(f, f->lf.cdef_lpf_line[1] + cdef_off_uv, src_stride[1],
157
34.4k
                           src[1] - offset_uv * PXSTRIDE(src_stride[1]),
158
34.4k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
159
34.4k
                           row_h, w, h, ss_hor, 0);
160
170k
        }
161
199k
        if (f->seq_hdr->cdef || restore_planes & LR_RESTORE_V) {
162
194k
            if (restore_planes & LR_RESTORE_V || !resize)
163
182k
                backup_lpf(f, dst[2], lr_stride[1],
164
182k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
165
182k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
166
182k
                           row_h, w, h, ss_hor, 1);
167
194k
            if (have_tt && resize)
168
35.4k
                backup_lpf(f, f->lf.cdef_lpf_line[2] + cdef_off_uv, src_stride[1],
169
35.4k
                           src[2] - offset_uv * PXSTRIDE(src_stride[1]),
170
35.4k
                           src_stride[1], ss_ver, f->seq_hdr->sb128, y_stripe,
171
35.4k
                           row_h, w, h, ss_hor, 0);
172
194k
        }
173
199k
    }
174
255k
}
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
555k
{
185
555k
    const Dav1dDSPContext *const dsp = f->dsp;
186
555k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[0][0];
187
188
    // filter edges between columns (e.g. block1 | block2)
189
6.31M
    for (int x = 0; x < w; x++) {
190
5.75M
        if (!have_left && !x) continue;
191
5.28M
        uint32_t hmask[4];
192
5.28M
        if (!starty4) {
193
4.32M
            hmask[0] = mask[x][0][0];
194
4.32M
            hmask[1] = mask[x][1][0];
195
4.32M
            hmask[2] = mask[x][2][0];
196
4.32M
            if (endy4 > 16) {
197
1.34M
                hmask[0] |= (unsigned) mask[x][0][1] << 16;
198
1.34M
                hmask[1] |= (unsigned) mask[x][1][1] << 16;
199
1.34M
                hmask[2] |= (unsigned) mask[x][2][1] << 16;
200
1.34M
            }
201
4.32M
        } else {
202
966k
            hmask[0] = mask[x][0][1];
203
966k
            hmask[1] = mask[x][1][1];
204
966k
            hmask[2] = mask[x][2][1];
205
966k
        }
206
5.28M
        hmask[3] = 0;
207
5.28M
        loop_filter_sb(&dst[x * 4], ls, hmask,
208
5.28M
                       (const uint8_t(*)[4]) &lvl[x][0], b4_stride,
209
5.28M
                       &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
210
5.28M
    }
211
555k
}
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
555k
{
222
555k
    const Dav1dDSPContext *const dsp = f->dsp;
223
555k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[0][1];
224
225
    //                                 block1
226
    // filter edges between rows (e.g. ------)
227
    //                                 block2
228
8.12M
    for (int y = starty4; y < endy4;
229
7.56M
         y++, dst += 4 * PXSTRIDE(ls), lvl += b4_stride)
230
7.56M
    {
231
7.56M
        if (!have_top && !y) continue;
232
7.26M
        const uint32_t vmask[4] = {
233
7.26M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << 16),
234
7.26M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << 16),
235
7.26M
            mask[y][2][0] | ((unsigned) mask[y][2][1] << 16),
236
7.26M
            0,
237
7.26M
        };
238
7.26M
        loop_filter_sb(dst, ls, vmask,
239
7.26M
                       (const uint8_t(*)[4]) &lvl[0][1], b4_stride,
240
7.26M
                       &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
241
7.26M
    }
242
555k
}
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
420k
{
254
420k
    const Dav1dDSPContext *const dsp = f->dsp;
255
420k
    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
3.69M
    for (int x = 0; x < w; x++) {
259
3.27M
        if (!have_left && !x) continue;
260
2.91M
        uint32_t hmask[3];
261
2.91M
        if (!starty4) {
262
2.46M
            hmask[0] = mask[x][0][0];
263
2.46M
            hmask[1] = mask[x][1][0];
264
2.46M
            if (endy4 > (16 >> ss_ver)) {
265
878k
                hmask[0] |= (unsigned) mask[x][0][1] << (16 >> ss_ver);
266
878k
                hmask[1] |= (unsigned) mask[x][1][1] << (16 >> ss_ver);
267
878k
            }
268
2.46M
        } else {
269
459k
            hmask[0] = mask[x][0][1];
270
459k
            hmask[1] = mask[x][1][1];
271
459k
        }
272
2.91M
        hmask[2] = 0;
273
2.91M
        loop_filter_sb(&u[x * 4], ls, hmask,
274
2.91M
                       (const uint8_t(*)[4]) &lvl[x][2], b4_stride,
275
2.91M
                       &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
276
2.91M
        loop_filter_sb(&v[x * 4], ls, hmask,
277
2.91M
                       (const uint8_t(*)[4]) &lvl[x][3], b4_stride,
278
2.91M
                       &f->lf.lim_lut, endy4 - starty4 HIGHBD_CALL_SUFFIX);
279
2.91M
    }
280
420k
}
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
420k
{
292
420k
    const Dav1dDSPContext *const dsp = f->dsp;
293
420k
    const loopfilter_sb_fn loop_filter_sb = dsp->lf.loop_filter_sb[1][1];
294
420k
    ptrdiff_t off_l = 0;
295
296
    //                                 block1
297
    // filter edges between rows (e.g. ------)
298
    //                                 block2
299
4.64M
    for (int y = starty4; y < endy4;
300
4.22M
         y++, off_l += 4 * PXSTRIDE(ls), lvl += b4_stride)
301
4.22M
    {
302
4.22M
        if (!have_top && !y) continue;
303
4.00M
        const uint32_t vmask[3] = {
304
4.00M
            mask[y][0][0] | ((unsigned) mask[y][0][1] << (16 >> ss_hor)),
305
4.00M
            mask[y][1][0] | ((unsigned) mask[y][1][1] << (16 >> ss_hor)),
306
4.00M
            0,
307
4.00M
        };
308
4.00M
        loop_filter_sb(&u[off_l], ls, vmask,
309
4.00M
                       (const uint8_t(*)[4]) &lvl[0][2], b4_stride,
310
4.00M
                       &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
311
4.00M
        loop_filter_sb(&v[off_l], ls, vmask,
312
4.00M
                       (const uint8_t(*)[4]) &lvl[0][3], b4_stride,
313
4.00M
                       &f->lf.lim_lut, w HIGHBD_CALL_SUFFIX);
314
4.00M
    }
315
420k
}
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
469k
{
321
469k
    int x, have_left;
322
    // Don't filter outside the frame
323
469k
    const int is_sb64 = !f->seq_hdr->sb128;
324
469k
    const int starty4 = (sby & is_sb64) << 4;
325
469k
    const int sbsz = 32 >> is_sb64;
326
469k
    const int sbl2 = 5 - is_sb64;
327
469k
    const int halign = (f->bh + 31) & ~31;
328
469k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
329
469k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
330
469k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
331
469k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
332
469k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
333
469k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
334
335
    // fix lpf strength at tile col boundaries
336
469k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
337
469k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
338
473k
    for (int tile_col = 1;; tile_col++) {
339
473k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
340
473k
        if ((x << sbl2) >= f->bw) break;
341
3.83k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
342
3.83k
        x >>= is_sb64;
343
344
3.83k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
345
46.2k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
346
42.4k
            const int sidx = mask >= 0x10000U;
347
42.4k
            const unsigned smask = mask >> (sidx << 4);
348
42.4k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
349
42.4k
                                !!(y_hmask[1][sidx] & smask);
350
42.4k
            y_hmask[2][sidx] &= ~smask;
351
42.4k
            y_hmask[1][sidx] &= ~smask;
352
42.4k
            y_hmask[0][sidx] &= ~smask;
353
42.4k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
354
42.4k
        }
355
356
3.83k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
357
3.07k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
358
27.2k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
359
24.2k
                 y++, uv_mask <<= 1)
360
24.2k
            {
361
24.2k
                const int sidx = uv_mask >= vmax;
362
24.2k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
363
24.2k
                const int idx = !!(uv_hmask[1][sidx] & smask);
364
24.2k
                uv_hmask[1][sidx] &= ~smask;
365
24.2k
                uv_hmask[0][sidx] &= ~smask;
366
24.2k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
367
24.2k
            }
368
3.07k
        }
369
3.83k
        lpf_y  += halign;
370
3.83k
        lpf_uv += halign >> ss_ver;
371
3.83k
    }
372
373
    // fix lpf strength at tile row boundaries
374
469k
    if (start_of_tile_row) {
375
2.64k
        const BlockContext *a;
376
2.64k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
377
6.22k
             x < f->sb128w; x++, a++)
378
3.57k
        {
379
3.57k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
380
3.57k
            const unsigned w = imin(32, f->w4 - (x << 5));
381
58.0k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
382
54.4k
                const int sidx = mask >= 0x10000U;
383
54.4k
                const unsigned smask = mask >> (sidx << 4);
384
54.4k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
385
54.4k
                                    !!(y_vmask[1][sidx] & smask);
386
54.4k
                y_vmask[2][sidx] &= ~smask;
387
54.4k
                y_vmask[1][sidx] &= ~smask;
388
54.4k
                y_vmask[0][sidx] &= ~smask;
389
54.4k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
390
54.4k
            }
391
392
3.57k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
393
2.83k
                const unsigned cw = (w + ss_hor) >> ss_hor;
394
2.83k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
395
36.7k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
396
33.8k
                    const int sidx = uv_mask >= hmax;
397
33.8k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
398
33.8k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
399
33.8k
                    uv_vmask[1][sidx] &= ~smask;
400
33.8k
                    uv_vmask[0][sidx] &= ~smask;
401
33.8k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
402
33.8k
                }
403
2.83k
            }
404
3.57k
        }
405
2.64k
    }
406
407
469k
    pixel *ptr;
408
469k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
409
1.02M
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
410
555k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
411
555k
    {
412
555k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
413
555k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
414
555k
                            imin(32, f->w4 - x * 32), starty4, endy4);
415
555k
    }
416
417
469k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
418
112k
        return;
419
420
357k
    ptrdiff_t uv_off;
421
357k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
422
778k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
423
420k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
424
420k
    {
425
420k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
426
420k
                             lflvl[x].filter_uv[0],
427
420k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
428
420k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
429
420k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
430
420k
    }
431
357k
}
dav1d_loopfilter_sbrow_cols_8bpc
Line
Count
Source
320
236k
{
321
236k
    int x, have_left;
322
    // Don't filter outside the frame
323
236k
    const int is_sb64 = !f->seq_hdr->sb128;
324
236k
    const int starty4 = (sby & is_sb64) << 4;
325
236k
    const int sbsz = 32 >> is_sb64;
326
236k
    const int sbl2 = 5 - is_sb64;
327
236k
    const int halign = (f->bh + 31) & ~31;
328
236k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
329
236k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
330
236k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
331
236k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
332
236k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
333
236k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
334
335
    // fix lpf strength at tile col boundaries
336
236k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
337
236k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
338
238k
    for (int tile_col = 1;; tile_col++) {
339
238k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
340
238k
        if ((x << sbl2) >= f->bw) break;
341
1.67k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
342
1.67k
        x >>= is_sb64;
343
344
1.67k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
345
17.7k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
346
16.0k
            const int sidx = mask >= 0x10000U;
347
16.0k
            const unsigned smask = mask >> (sidx << 4);
348
16.0k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
349
16.0k
                                !!(y_hmask[1][sidx] & smask);
350
16.0k
            y_hmask[2][sidx] &= ~smask;
351
16.0k
            y_hmask[1][sidx] &= ~smask;
352
16.0k
            y_hmask[0][sidx] &= ~smask;
353
16.0k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
354
16.0k
        }
355
356
1.67k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
357
1.32k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
358
11.0k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
359
9.71k
                 y++, uv_mask <<= 1)
360
9.71k
            {
361
9.71k
                const int sidx = uv_mask >= vmax;
362
9.71k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
363
9.71k
                const int idx = !!(uv_hmask[1][sidx] & smask);
364
9.71k
                uv_hmask[1][sidx] &= ~smask;
365
9.71k
                uv_hmask[0][sidx] &= ~smask;
366
9.71k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
367
9.71k
            }
368
1.32k
        }
369
1.67k
        lpf_y  += halign;
370
1.67k
        lpf_uv += halign >> ss_ver;
371
1.67k
    }
372
373
    // fix lpf strength at tile row boundaries
374
236k
    if (start_of_tile_row) {
375
1.56k
        const BlockContext *a;
376
1.56k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
377
3.44k
             x < f->sb128w; x++, a++)
378
1.87k
        {
379
1.87k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
380
1.87k
            const unsigned w = imin(32, f->w4 - (x << 5));
381
24.5k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
382
22.6k
                const int sidx = mask >= 0x10000U;
383
22.6k
                const unsigned smask = mask >> (sidx << 4);
384
22.6k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
385
22.6k
                                    !!(y_vmask[1][sidx] & smask);
386
22.6k
                y_vmask[2][sidx] &= ~smask;
387
22.6k
                y_vmask[1][sidx] &= ~smask;
388
22.6k
                y_vmask[0][sidx] &= ~smask;
389
22.6k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
390
22.6k
            }
391
392
1.87k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
393
1.46k
                const unsigned cw = (w + ss_hor) >> ss_hor;
394
1.46k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
395
16.4k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
396
14.9k
                    const int sidx = uv_mask >= hmax;
397
14.9k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
398
14.9k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
399
14.9k
                    uv_vmask[1][sidx] &= ~smask;
400
14.9k
                    uv_vmask[0][sidx] &= ~smask;
401
14.9k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
402
14.9k
                }
403
1.46k
            }
404
1.87k
        }
405
1.56k
    }
406
407
236k
    pixel *ptr;
408
236k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
409
513k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
410
276k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
411
276k
    {
412
276k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
413
276k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
414
276k
                            imin(32, f->w4 - x * 32), starty4, endy4);
415
276k
    }
416
417
236k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
418
49.0k
        return;
419
420
187k
    ptrdiff_t uv_off;
421
187k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
422
402k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
423
214k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
424
214k
    {
425
214k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
426
214k
                             lflvl[x].filter_uv[0],
427
214k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
428
214k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
429
214k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
430
214k
    }
431
187k
}
dav1d_loopfilter_sbrow_cols_16bpc
Line
Count
Source
320
233k
{
321
233k
    int x, have_left;
322
    // Don't filter outside the frame
323
233k
    const int is_sb64 = !f->seq_hdr->sb128;
324
233k
    const int starty4 = (sby & is_sb64) << 4;
325
233k
    const int sbsz = 32 >> is_sb64;
326
233k
    const int sbl2 = 5 - is_sb64;
327
233k
    const int halign = (f->bh + 31) & ~31;
328
233k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
329
233k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
330
233k
    const int vmask = 16 >> ss_ver, hmask = 16 >> ss_hor;
331
233k
    const unsigned vmax = 1U << vmask, hmax = 1U << hmask;
332
233k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
333
233k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
334
335
    // fix lpf strength at tile col boundaries
336
233k
    const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
337
233k
    const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
338
235k
    for (int tile_col = 1;; tile_col++) {
339
235k
        x = f->frame_hdr->tiling.col_start_sb[tile_col];
340
235k
        if ((x << sbl2) >= f->bw) break;
341
2.15k
        const int bx4 = x & is_sb64 ? 16 : 0, cbx4 = bx4 >> ss_hor;
342
2.15k
        x >>= is_sb64;
343
344
2.15k
        uint16_t (*const y_hmask)[2] = lflvl[x].filter_y[0][bx4];
345
28.4k
        for (unsigned y = starty4, mask = 1 << y; y < endy4; y++, mask <<= 1) {
346
26.3k
            const int sidx = mask >= 0x10000U;
347
26.3k
            const unsigned smask = mask >> (sidx << 4);
348
26.3k
            const int idx = 2 * !!(y_hmask[2][sidx] & smask) +
349
26.3k
                                !!(y_hmask[1][sidx] & smask);
350
26.3k
            y_hmask[2][sidx] &= ~smask;
351
26.3k
            y_hmask[1][sidx] &= ~smask;
352
26.3k
            y_hmask[0][sidx] &= ~smask;
353
26.3k
            y_hmask[imin(idx, lpf_y[y - starty4])][sidx] |= smask;
354
26.3k
        }
355
356
2.15k
        if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
357
1.74k
            uint16_t (*const uv_hmask)[2] = lflvl[x].filter_uv[0][cbx4];
358
16.2k
            for (unsigned y = starty4 >> ss_ver, uv_mask = 1 << y; y < uv_endy4;
359
14.4k
                 y++, uv_mask <<= 1)
360
14.4k
            {
361
14.4k
                const int sidx = uv_mask >= vmax;
362
14.4k
                const unsigned smask = uv_mask >> (sidx << (4 - ss_ver));
363
14.4k
                const int idx = !!(uv_hmask[1][sidx] & smask);
364
14.4k
                uv_hmask[1][sidx] &= ~smask;
365
14.4k
                uv_hmask[0][sidx] &= ~smask;
366
14.4k
                uv_hmask[imin(idx, lpf_uv[y - (starty4 >> ss_ver)])][sidx] |= smask;
367
14.4k
            }
368
1.74k
        }
369
2.15k
        lpf_y  += halign;
370
2.15k
        lpf_uv += halign >> ss_ver;
371
2.15k
    }
372
373
    // fix lpf strength at tile row boundaries
374
233k
    if (start_of_tile_row) {
375
1.07k
        const BlockContext *a;
376
1.07k
        for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
377
2.78k
             x < f->sb128w; x++, a++)
378
1.70k
        {
379
1.70k
            uint16_t (*const y_vmask)[2] = lflvl[x].filter_y[1][starty4];
380
1.70k
            const unsigned w = imin(32, f->w4 - (x << 5));
381
33.5k
            for (unsigned mask = 1, i = 0; i < w; mask <<= 1, i++) {
382
31.8k
                const int sidx = mask >= 0x10000U;
383
31.8k
                const unsigned smask = mask >> (sidx << 4);
384
31.8k
                const int idx = 2 * !!(y_vmask[2][sidx] & smask) +
385
31.8k
                                    !!(y_vmask[1][sidx] & smask);
386
31.8k
                y_vmask[2][sidx] &= ~smask;
387
31.8k
                y_vmask[1][sidx] &= ~smask;
388
31.8k
                y_vmask[0][sidx] &= ~smask;
389
31.8k
                y_vmask[imin(idx, a->tx_lpf_y[i])][sidx] |= smask;
390
31.8k
            }
391
392
1.70k
            if (f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I400) {
393
1.37k
                const unsigned cw = (w + ss_hor) >> ss_hor;
394
1.37k
                uint16_t (*const uv_vmask)[2] = lflvl[x].filter_uv[1][starty4 >> ss_ver];
395
20.2k
                for (unsigned uv_mask = 1, i = 0; i < cw; uv_mask <<= 1, i++) {
396
18.9k
                    const int sidx = uv_mask >= hmax;
397
18.9k
                    const unsigned smask = uv_mask >> (sidx << (4 - ss_hor));
398
18.9k
                    const int idx = !!(uv_vmask[1][sidx] & smask);
399
18.9k
                    uv_vmask[1][sidx] &= ~smask;
400
18.9k
                    uv_vmask[0][sidx] &= ~smask;
401
18.9k
                    uv_vmask[imin(idx, a->tx_lpf_uv[i])][sidx] |= smask;
402
18.9k
                }
403
1.37k
            }
404
1.70k
        }
405
1.07k
    }
406
407
233k
    pixel *ptr;
408
233k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
409
511k
    for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
410
278k
         x++, have_left = 1, ptr += 128, level_ptr += 32)
411
278k
    {
412
278k
        filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
413
278k
                            lflvl[x].filter_y[0], ptr, f->cur.stride[0],
414
278k
                            imin(32, f->w4 - x * 32), starty4, endy4);
415
278k
    }
416
417
233k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
418
62.9k
        return;
419
420
170k
    ptrdiff_t uv_off;
421
170k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
422
376k
    for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
423
206k
         x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
424
206k
    {
425
206k
        filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
426
206k
                             lflvl[x].filter_uv[0],
427
206k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
428
206k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
429
206k
                             starty4 >> ss_ver, uv_endy4, ss_ver);
430
206k
    }
431
170k
}
432
433
void bytefn(dav1d_loopfilter_sbrow_rows)(const Dav1dFrameContext *const f,
434
                                         pixel *const p[3], Av1Filter *const lflvl,
435
                                         int sby)
436
469k
{
437
469k
    int x;
438
    // Don't filter outside the frame
439
469k
    const int have_top = sby > 0;
440
469k
    const int is_sb64 = !f->seq_hdr->sb128;
441
469k
    const int starty4 = (sby & is_sb64) << 4;
442
469k
    const int sbsz = 32 >> is_sb64;
443
469k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
444
469k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
445
469k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
446
469k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
447
448
469k
    pixel *ptr;
449
469k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
450
1.02M
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
451
555k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
452
555k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
453
555k
                            imin(32, f->w4 - x * 32), starty4, endy4);
454
555k
    }
455
456
469k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
457
111k
        return;
458
459
357k
    ptrdiff_t uv_off;
460
357k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
461
778k
    for (uv_off = 0, x = 0; x < f->sb128w;
462
420k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
463
420k
    {
464
420k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
465
420k
                             lflvl[x].filter_uv[1],
466
420k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
467
420k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
468
420k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
469
420k
    }
470
357k
}
dav1d_loopfilter_sbrow_rows_8bpc
Line
Count
Source
436
236k
{
437
236k
    int x;
438
    // Don't filter outside the frame
439
236k
    const int have_top = sby > 0;
440
236k
    const int is_sb64 = !f->seq_hdr->sb128;
441
236k
    const int starty4 = (sby & is_sb64) << 4;
442
236k
    const int sbsz = 32 >> is_sb64;
443
236k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
444
236k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
445
236k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
446
236k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
447
448
236k
    pixel *ptr;
449
236k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
450
513k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
451
276k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
452
276k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
453
276k
                            imin(32, f->w4 - x * 32), starty4, endy4);
454
276k
    }
455
456
236k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
457
49.0k
        return;
458
459
187k
    ptrdiff_t uv_off;
460
187k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
461
402k
    for (uv_off = 0, x = 0; x < f->sb128w;
462
214k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
463
214k
    {
464
214k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
465
214k
                             lflvl[x].filter_uv[1],
466
214k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
467
214k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
468
214k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
469
214k
    }
470
187k
}
dav1d_loopfilter_sbrow_rows_16bpc
Line
Count
Source
436
232k
{
437
232k
    int x;
438
    // Don't filter outside the frame
439
232k
    const int have_top = sby > 0;
440
232k
    const int is_sb64 = !f->seq_hdr->sb128;
441
232k
    const int starty4 = (sby & is_sb64) << 4;
442
232k
    const int sbsz = 32 >> is_sb64;
443
232k
    const int ss_ver = f->cur.p.layout == DAV1D_PIXEL_LAYOUT_I420;
444
232k
    const int ss_hor = f->cur.p.layout != DAV1D_PIXEL_LAYOUT_I444;
445
232k
    const unsigned endy4 = starty4 + imin(f->h4 - sby * sbsz, sbsz);
446
232k
    const unsigned uv_endy4 = (endy4 + ss_ver) >> ss_ver;
447
448
232k
    pixel *ptr;
449
232k
    uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
450
511k
    for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
451
278k
        filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
452
278k
                            lflvl[x].filter_y[1], ptr, f->cur.stride[0],
453
278k
                            imin(32, f->w4 - x * 32), starty4, endy4);
454
278k
    }
455
456
232k
    if (!f->frame_hdr->loopfilter.level_u && !f->frame_hdr->loopfilter.level_v)
457
62.9k
        return;
458
459
169k
    ptrdiff_t uv_off;
460
169k
    level_ptr = f->lf.level + f->b4_stride * (sby * sbsz >> ss_ver);
461
376k
    for (uv_off = 0, x = 0; x < f->sb128w;
462
206k
         x++, uv_off += 128 >> ss_hor, level_ptr += 32 >> ss_hor)
463
206k
    {
464
206k
        filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
465
206k
                             lflvl[x].filter_uv[1],
466
206k
                             &p[1][uv_off], &p[2][uv_off], f->cur.stride[1],
467
206k
                             (imin(32, f->w4 - x * 32) + ss_hor) >> ss_hor,
468
206k
                             starty4 >> ss_ver, uv_endy4, ss_hor);
469
206k
    }
470
169k
}