Coverage Report

Created: 2026-09-13 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/ipred_prepare_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 <stdint.h>
31
#include <string.h>
32
33
#include "common/intops.h"
34
35
#include "src/ipred_prepare.h"
36
37
static const uint8_t av1_mode_conv[N_INTRA_PRED_MODES]
38
                                  [2 /* have_left */][2 /* have_top */] =
39
{
40
    [DC_PRED]    = { { DC_128_PRED,  TOP_DC_PRED },
41
                     { LEFT_DC_PRED, DC_PRED     } },
42
    [PAETH_PRED] = { { DC_128_PRED,  VERT_PRED   },
43
                     { HOR_PRED,     PAETH_PRED  } },
44
};
45
46
static const uint8_t av1_mode_to_angle_map[8] = {
47
    90, 180, 45, 135, 113, 157, 203, 67
48
};
49
50
static const struct {
51
    uint8_t needs_left:1;
52
    uint8_t needs_top:1;
53
    uint8_t needs_topleft:1;
54
    uint8_t needs_topright:1;
55
    uint8_t needs_bottomleft:1;
56
} av1_intra_prediction_edges[N_IMPL_INTRA_PRED_MODES] = {
57
    [DC_PRED]       = { .needs_top  = 1, .needs_left = 1 },
58
    [VERT_PRED]     = { .needs_top  = 1 },
59
    [HOR_PRED]      = { .needs_left = 1 },
60
    [LEFT_DC_PRED]  = { .needs_left = 1 },
61
    [TOP_DC_PRED]   = { .needs_top  = 1 },
62
    [DC_128_PRED]   = { 0 },
63
    [Z1_PRED]       = { .needs_top = 1, .needs_topright = 1,
64
                        .needs_topleft = 1 },
65
    [Z2_PRED]       = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
66
    [Z3_PRED]       = { .needs_left = 1, .needs_bottomleft = 1,
67
                        .needs_topleft = 1 },
68
    [SMOOTH_PRED]   = { .needs_left = 1, .needs_top = 1 },
69
    [SMOOTH_V_PRED] = { .needs_left = 1, .needs_top = 1 },
70
    [SMOOTH_H_PRED] = { .needs_left = 1, .needs_top = 1 },
71
    [PAETH_PRED]    = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
72
    [FILTER_PRED]   = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
73
};
74
75
enum IntraPredMode
76
bytefn(dav1d_prepare_intra_edges)(const int x, const int have_left,
77
                                  const int y, const int have_top,
78
                                  const int w, const int h,
79
                                  const enum EdgeFlags edge_flags,
80
                                  const pixel *const dst,
81
                                  const ptrdiff_t stride,
82
                                  const pixel *prefilter_toplevel_sb_edge,
83
                                  enum IntraPredMode mode, int *const angle,
84
                                  const int tw, const int th, const int filter_edge,
85
                                  pixel *const topleft_out HIGHBD_DECL_SUFFIX)
86
10.1M
{
87
10.1M
    const int bitdepth = bitdepth_from_max(bitdepth_max);
88
10.1M
    assert(y < h && x < w);
89
90
10.1M
    switch (mode) {
91
499k
    case VERT_PRED:
92
1.31M
    case HOR_PRED:
93
1.48M
    case DIAG_DOWN_LEFT_PRED:
94
1.65M
    case DIAG_DOWN_RIGHT_PRED:
95
1.79M
    case VERT_RIGHT_PRED:
96
2.00M
    case HOR_DOWN_PRED:
97
2.40M
    case HOR_UP_PRED:
98
2.62M
    case VERT_LEFT_PRED: {
99
2.62M
        *angle = av1_mode_to_angle_map[mode - VERT_PRED] + 3 * *angle;
100
101
2.62M
        if (*angle <= 90)
102
759k
            mode = *angle < 90 && have_top ? Z1_PRED : VERT_PRED;
103
1.86M
        else if (*angle < 180)
104
841k
            mode = Z2_PRED;
105
1.02M
        else
106
1.02M
            mode = *angle > 180 && have_left ? Z3_PRED : HOR_PRED;
107
2.62M
        break;
108
2.40M
    }
109
4.59M
    case DC_PRED:
110
5.62M
    case PAETH_PRED:
111
5.62M
        mode = av1_mode_conv[mode][have_left][have_top];
112
5.62M
        break;
113
1.93M
    default:
114
1.93M
        break;
115
10.1M
    }
116
117
10.1M
    const pixel *dst_top;
118
10.1M
    if (have_top &&
119
8.75M
        (av1_intra_prediction_edges[mode].needs_top ||
120
895k
         av1_intra_prediction_edges[mode].needs_topleft ||
121
429k
         (av1_intra_prediction_edges[mode].needs_left && !have_left)))
122
8.45M
    {
123
8.45M
        if (prefilter_toplevel_sb_edge) {
124
1.29M
            dst_top = &prefilter_toplevel_sb_edge[x * 4];
125
7.16M
        } else {
126
7.16M
            dst_top = &dst[-PXSTRIDE(stride)];
127
7.16M
        }
128
8.45M
    }
129
130
10.1M
    if (av1_intra_prediction_edges[mode].needs_left) {
131
8.15M
        const int sz = th << 2;
132
8.15M
        pixel *const left = &topleft_out[-sz];
133
134
8.15M
        if (have_left) {
135
7.55M
            const int px_have = imin(sz, (h - y) << 2);
136
137
91.6M
            for (int i = 0; i < px_have; i++)
138
84.0M
                left[sz - 1 - i] = dst[PXSTRIDE(stride) * i - 1];
139
7.55M
            if (px_have < sz)
140
289k
                pixel_set(left, left[sz - px_have], sz - px_have);
141
7.55M
        } else {
142
604k
            pixel_set(left, have_top ? *dst_top : ((1 << bitdepth) >> 1) + 1, sz);
143
604k
        }
144
145
8.15M
        if (av1_intra_prediction_edges[mode].needs_bottomleft) {
146
529k
            const int have_bottomleft = (!have_left || y + th >= h) ? 0 :
147
528k
                                        (edge_flags & EDGE_I444_LEFT_HAS_BOTTOM);
148
149
528k
            if (have_bottomleft) {
150
126k
                const int px_have = imin(sz, (h - y - th) << 2);
151
152
1.28M
                for (int i = 0; i < px_have; i++)
153
1.15M
                    left[-(i + 1)] = dst[(sz + i) * PXSTRIDE(stride) - 1];
154
126k
                if (px_have < sz)
155
3.22k
                    pixel_set(left - sz, left[-px_have], sz - px_have);
156
401k
            } else {
157
401k
                pixel_set(left - sz, left[0], sz);
158
401k
            }
159
528k
        }
160
8.15M
    }
161
162
10.1M
    if (av1_intra_prediction_edges[mode].needs_top) {
163
8.25M
        const int sz = tw << 2;
164
8.25M
        pixel *const top = &topleft_out[1];
165
166
8.25M
        if (have_top) {
167
7.83M
            const int px_have = imin(sz, (w - x) << 2);
168
7.83M
            pixel_copy(top, dst_top, px_have);
169
7.83M
            if (px_have < sz)
170
678k
                pixel_set(top + px_have, top[px_have - 1], sz - px_have);
171
7.83M
        } else {
172
419k
            pixel_set(top, have_left ? dst[-1] : ((1 << bitdepth) >> 1) - 1, sz);
173
419k
        }
174
175
8.25M
        if (av1_intra_prediction_edges[mode].needs_topright) {
176
437k
            const int have_topright = (!have_top || x + tw >= w) ? 0 :
177
437k
                                      (edge_flags & EDGE_I444_TOP_HAS_RIGHT);
178
179
437k
            if (have_topright) {
180
256k
                const int px_have = imin(sz, (w - x - tw) << 2);
181
182
256k
                pixel_copy(top + sz, &dst_top[sz], px_have);
183
256k
                if (px_have < sz)
184
10.1k
                    pixel_set(top + sz + px_have, top[sz + px_have - 1],
185
4.68k
                              sz - px_have);
186
256k
            } else {
187
181k
                pixel_set(top + sz, top[sz - 1], sz);
188
181k
            }
189
437k
        }
190
8.25M
    }
191
192
10.1M
    if (av1_intra_prediction_edges[mode].needs_topleft) {
193
3.03M
        if (have_left)
194
2.75M
            *topleft_out = have_top ? dst_top[-1] : dst[-1];
195
271k
        else
196
271k
            *topleft_out = have_top ? *dst_top : (1 << bitdepth) >> 1;
197
198
3.03M
        if (mode == Z2_PRED && tw + th >= 6 && filter_edge)
199
221k
            *topleft_out = ((topleft_out[-1] + topleft_out[1]) * 5 +
200
221k
                            topleft_out[0] * 6 + 8) >> 4;
201
3.03M
    }
202
203
10.1M
    return mode;
204
10.1M
}
dav1d_prepare_intra_edges_8bpc
Line
Count
Source
86
4.93M
{
87
4.93M
    const int bitdepth = bitdepth_from_max(bitdepth_max);
88
4.93M
    assert(y < h && x < w);
89
90
4.93M
    switch (mode) {
91
232k
    case VERT_PRED:
92
611k
    case HOR_PRED:
93
690k
    case DIAG_DOWN_LEFT_PRED:
94
774k
    case DIAG_DOWN_RIGHT_PRED:
95
840k
    case VERT_RIGHT_PRED:
96
935k
    case HOR_DOWN_PRED:
97
1.10M
    case HOR_UP_PRED:
98
1.21M
    case VERT_LEFT_PRED: {
99
1.21M
        *angle = av1_mode_to_angle_map[mode - VERT_PRED] + 3 * *angle;
100
101
1.21M
        if (*angle <= 90)
102
354k
            mode = *angle < 90 && have_top ? Z1_PRED : VERT_PRED;
103
857k
        else if (*angle < 180)
104
397k
            mode = Z2_PRED;
105
460k
        else
106
460k
            mode = *angle > 180 && have_left ? Z3_PRED : HOR_PRED;
107
1.21M
        break;
108
1.10M
    }
109
2.23M
    case DC_PRED:
110
2.82M
    case PAETH_PRED:
111
2.82M
        mode = av1_mode_conv[mode][have_left][have_top];
112
2.82M
        break;
113
897k
    default:
114
897k
        break;
115
4.93M
    }
116
117
4.93M
    const pixel *dst_top;
118
4.93M
    if (have_top &&
119
4.29M
        (av1_intra_prediction_edges[mode].needs_top ||
120
403k
         av1_intra_prediction_edges[mode].needs_topleft ||
121
201k
         (av1_intra_prediction_edges[mode].needs_left && !have_left)))
122
4.15M
    {
123
4.15M
        if (prefilter_toplevel_sb_edge) {
124
714k
            dst_top = &prefilter_toplevel_sb_edge[x * 4];
125
3.43M
        } else {
126
3.43M
            dst_top = &dst[-PXSTRIDE(stride)];
127
3.43M
        }
128
4.15M
    }
129
130
4.93M
    if (av1_intra_prediction_edges[mode].needs_left) {
131
3.98M
        const int sz = th << 2;
132
3.98M
        pixel *const left = &topleft_out[-sz];
133
134
3.98M
        if (have_left) {
135
3.70M
            const int px_have = imin(sz, (h - y) << 2);
136
137
44.8M
            for (int i = 0; i < px_have; i++)
138
41.1M
                left[sz - 1 - i] = dst[PXSTRIDE(stride) * i - 1];
139
3.70M
            if (px_have < sz)
140
142k
                pixel_set(left, left[sz - px_have], sz - px_have);
141
3.70M
        } else {
142
283k
            pixel_set(left, have_top ? *dst_top : ((1 << bitdepth) >> 1) + 1, sz);
143
283k
        }
144
145
3.98M
        if (av1_intra_prediction_edges[mode].needs_bottomleft) {
146
230k
            const int have_bottomleft = (!have_left || y + th >= h) ? 0 :
147
230k
                                        (edge_flags & EDGE_I444_LEFT_HAS_BOTTOM);
148
149
230k
            if (have_bottomleft) {
150
57.8k
                const int px_have = imin(sz, (h - y - th) << 2);
151
152
541k
                for (int i = 0; i < px_have; i++)
153
483k
                    left[-(i + 1)] = dst[(sz + i) * PXSTRIDE(stride) - 1];
154
57.8k
                if (px_have < sz)
155
904
                    pixel_set(left - sz, left[-px_have], sz - px_have);
156
172k
            } else {
157
172k
                pixel_set(left - sz, left[0], sz);
158
172k
            }
159
230k
        }
160
3.98M
    }
161
162
4.93M
    if (av1_intra_prediction_edges[mode].needs_top) {
163
4.08M
        const int sz = tw << 2;
164
4.08M
        pixel *const top = &topleft_out[1];
165
166
4.08M
        if (have_top) {
167
3.88M
            const int px_have = imin(sz, (w - x) << 2);
168
3.88M
            pixel_copy(top, dst_top, px_have);
169
3.88M
            if (px_have < sz)
170
313k
                pixel_set(top + px_have, top[px_have - 1], sz - px_have);
171
3.88M
        } else {
172
196k
            pixel_set(top, have_left ? dst[-1] : ((1 << bitdepth) >> 1) - 1, sz);
173
196k
        }
174
175
4.08M
        if (av1_intra_prediction_edges[mode].needs_topright) {
176
210k
            const int have_topright = (!have_top || x + tw >= w) ? 0 :
177
210k
                                      (edge_flags & EDGE_I444_TOP_HAS_RIGHT);
178
179
210k
            if (have_topright) {
180
123k
                const int px_have = imin(sz, (w - x - tw) << 2);
181
182
123k
                pixel_copy(top + sz, &dst_top[sz], px_have);
183
123k
                if (px_have < sz)
184
4.68k
                    pixel_set(top + sz + px_have, top[sz + px_have - 1],
185
4.68k
                              sz - px_have);
186
123k
            } else {
187
86.7k
                pixel_set(top + sz, top[sz - 1], sz);
188
86.7k
            }
189
210k
        }
190
4.08M
    }
191
192
4.93M
    if (av1_intra_prediction_edges[mode].needs_topleft) {
193
1.53M
        if (have_left)
194
1.40M
            *topleft_out = have_top ? dst_top[-1] : dst[-1];
195
130k
        else
196
130k
            *topleft_out = have_top ? *dst_top : (1 << bitdepth) >> 1;
197
198
1.53M
        if (mode == Z2_PRED && tw + th >= 6 && filter_edge)
199
96.6k
            *topleft_out = ((topleft_out[-1] + topleft_out[1]) * 5 +
200
96.6k
                            topleft_out[0] * 6 + 8) >> 4;
201
1.53M
    }
202
203
4.93M
    return mode;
204
4.93M
}
dav1d_prepare_intra_edges_16bpc
Line
Count
Source
86
5.21M
{
87
5.21M
    const int bitdepth = bitdepth_from_max(bitdepth_max);
88
5.21M
    assert(y < h && x < w);
89
90
5.21M
    switch (mode) {
91
267k
    case VERT_PRED:
92
704k
    case HOR_PRED:
93
793k
    case DIAG_DOWN_LEFT_PRED:
94
882k
    case DIAG_DOWN_RIGHT_PRED:
95
956k
    case VERT_RIGHT_PRED:
96
1.06M
    case HOR_DOWN_PRED:
97
1.29M
    case HOR_UP_PRED:
98
1.41M
    case VERT_LEFT_PRED: {
99
1.41M
        *angle = av1_mode_to_angle_map[mode - VERT_PRED] + 3 * *angle;
100
101
1.41M
        if (*angle <= 90)
102
405k
            mode = *angle < 90 && have_top ? Z1_PRED : VERT_PRED;
103
1.00M
        else if (*angle < 180)
104
443k
            mode = Z2_PRED;
105
563k
        else
106
563k
            mode = *angle > 180 && have_left ? Z3_PRED : HOR_PRED;
107
1.41M
        break;
108
1.29M
    }
109
2.35M
    case DC_PRED:
110
2.79M
    case PAETH_PRED:
111
2.79M
        mode = av1_mode_conv[mode][have_left][have_top];
112
2.79M
        break;
113
1.03M
    default:
114
1.03M
        break;
115
5.21M
    }
116
117
5.20M
    const pixel *dst_top;
118
5.20M
    if (have_top &&
119
4.46M
        (av1_intra_prediction_edges[mode].needs_top ||
120
491k
         av1_intra_prediction_edges[mode].needs_topleft ||
121
228k
         (av1_intra_prediction_edges[mode].needs_left && !have_left)))
122
4.30M
    {
123
4.30M
        if (prefilter_toplevel_sb_edge) {
124
581k
            dst_top = &prefilter_toplevel_sb_edge[x * 4];
125
3.72M
        } else {
126
3.72M
            dst_top = &dst[-PXSTRIDE(stride)];
127
3.72M
        }
128
4.30M
    }
129
130
5.20M
    if (av1_intra_prediction_edges[mode].needs_left) {
131
4.17M
        const int sz = th << 2;
132
4.17M
        pixel *const left = &topleft_out[-sz];
133
134
4.17M
        if (have_left) {
135
3.85M
            const int px_have = imin(sz, (h - y) << 2);
136
137
46.7M
            for (int i = 0; i < px_have; i++)
138
42.9M
                left[sz - 1 - i] = dst[PXSTRIDE(stride) * i - 1];
139
3.85M
            if (px_have < sz)
140
146k
                pixel_set(left, left[sz - px_have], sz - px_have);
141
3.85M
        } else {
142
321k
            pixel_set(left, have_top ? *dst_top : ((1 << bitdepth) >> 1) + 1, sz);
143
321k
        }
144
145
4.17M
        if (av1_intra_prediction_edges[mode].needs_bottomleft) {
146
298k
            const int have_bottomleft = (!have_left || y + th >= h) ? 0 :
147
297k
                                        (edge_flags & EDGE_I444_LEFT_HAS_BOTTOM);
148
149
297k
            if (have_bottomleft) {
150
68.9k
                const int px_have = imin(sz, (h - y - th) << 2);
151
152
743k
                for (int i = 0; i < px_have; i++)
153
674k
                    left[-(i + 1)] = dst[(sz + i) * PXSTRIDE(stride) - 1];
154
68.9k
                if (px_have < sz)
155
2.32k
                    pixel_set(left - sz, left[-px_have], sz - px_have);
156
228k
            } else {
157
228k
                pixel_set(left - sz, left[0], sz);
158
228k
            }
159
297k
        }
160
4.17M
    }
161
162
5.20M
    if (av1_intra_prediction_edges[mode].needs_top) {
163
4.17M
        const int sz = tw << 2;
164
4.17M
        pixel *const top = &topleft_out[1];
165
166
4.17M
        if (have_top) {
167
3.95M
            const int px_have = imin(sz, (w - x) << 2);
168
3.95M
            pixel_copy(top, dst_top, px_have);
169
3.95M
            if (px_have < sz)
170
365k
                pixel_set(top + px_have, top[px_have - 1], sz - px_have);
171
3.95M
        } else {
172
223k
            pixel_set(top, have_left ? dst[-1] : ((1 << bitdepth) >> 1) - 1, sz);
173
223k
        }
174
175
4.17M
        if (av1_intra_prediction_edges[mode].needs_topright) {
176
227k
            const int have_topright = (!have_top || x + tw >= w) ? 0 :
177
227k
                                      (edge_flags & EDGE_I444_TOP_HAS_RIGHT);
178
179
227k
            if (have_topright) {
180
132k
                const int px_have = imin(sz, (w - x - tw) << 2);
181
182
132k
                pixel_copy(top + sz, &dst_top[sz], px_have);
183
132k
                if (px_have < sz)
184
5.48k
                    pixel_set(top + sz + px_have, top[sz + px_have - 1],
185
5.48k
                              sz - px_have);
186
132k
            } else {
187
94.4k
                pixel_set(top + sz, top[sz - 1], sz);
188
94.4k
            }
189
227k
        }
190
4.17M
    }
191
192
5.20M
    if (av1_intra_prediction_edges[mode].needs_topleft) {
193
1.49M
        if (have_left)
194
1.35M
            *topleft_out = have_top ? dst_top[-1] : dst[-1];
195
141k
        else
196
141k
            *topleft_out = have_top ? *dst_top : (1 << bitdepth) >> 1;
197
198
1.49M
        if (mode == Z2_PRED && tw + th >= 6 && filter_edge)
199
124k
            *topleft_out = ((topleft_out[-1] + topleft_out[1]) * 5 +
200
124k
                            topleft_out[0] * 6 + 8) >> 4;
201
1.49M
    }
202
203
5.20M
    return mode;
204
5.21M
}