Coverage Report

Created: 2026-05-30 06:10

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
9.02M
{
87
9.02M
    const int bitdepth = bitdepth_from_max(bitdepth_max);
88
9.02M
    assert(y < h && x < w);
89
90
9.02M
    switch (mode) {
91
326k
    case VERT_PRED:
92
886k
    case HOR_PRED:
93
1.00M
    case DIAG_DOWN_LEFT_PRED:
94
1.11M
    case DIAG_DOWN_RIGHT_PRED:
95
1.22M
    case VERT_RIGHT_PRED:
96
1.36M
    case HOR_DOWN_PRED:
97
1.69M
    case HOR_UP_PRED:
98
1.85M
    case VERT_LEFT_PRED: {
99
1.85M
        *angle = av1_mode_to_angle_map[mode - VERT_PRED] + 3 * *angle;
100
101
1.85M
        if (*angle <= 90)
102
522k
            mode = *angle < 90 && have_top ? Z1_PRED : VERT_PRED;
103
1.33M
        else if (*angle < 180)
104
590k
            mode = Z2_PRED;
105
745k
        else
106
745k
            mode = *angle > 180 && have_left ? Z3_PRED : HOR_PRED;
107
1.85M
        break;
108
1.69M
    }
109
4.94M
    case DC_PRED:
110
5.67M
    case PAETH_PRED:
111
5.67M
        mode = av1_mode_conv[mode][have_left][have_top];
112
5.67M
        break;
113
1.55M
    default:
114
1.55M
        break;
115
9.02M
    }
116
117
9.02M
    const pixel *dst_top;
118
9.02M
    if (have_top &&
119
8.09M
        (av1_intra_prediction_edges[mode].needs_top ||
120
661k
         av1_intra_prediction_edges[mode].needs_topleft ||
121
297k
         (av1_intra_prediction_edges[mode].needs_left && !have_left)))
122
7.88M
    {
123
7.88M
        if (prefilter_toplevel_sb_edge) {
124
1.12M
            dst_top = &prefilter_toplevel_sb_edge[x * 4];
125
6.75M
        } else {
126
6.75M
            dst_top = &dst[-PXSTRIDE(stride)];
127
6.75M
        }
128
7.88M
    }
129
130
9.02M
    if (av1_intra_prediction_edges[mode].needs_left) {
131
7.43M
        const int sz = th << 2;
132
7.43M
        pixel *const left = &topleft_out[-sz];
133
134
7.43M
        if (have_left) {
135
7.02M
            const int px_have = imin(sz, (h - y) << 2);
136
137
82.4M
            for (int i = 0; i < px_have; i++)
138
75.4M
                left[sz - 1 - i] = dst[PXSTRIDE(stride) * i - 1];
139
7.02M
            if (px_have < sz)
140
213k
                pixel_set(left, left[sz - px_have], sz - px_have);
141
7.02M
        } else {
142
411k
            pixel_set(left, have_top ? *dst_top : ((1 << bitdepth) >> 1) + 1, sz);
143
411k
        }
144
145
7.43M
        if (av1_intra_prediction_edges[mode].needs_bottomleft) {
146
407k
            const int have_bottomleft = (!have_left || y + th >= h) ? 0 :
147
407k
                                        (edge_flags & EDGE_I444_LEFT_HAS_BOTTOM);
148
149
407k
            if (have_bottomleft) {
150
99.6k
                const int px_have = imin(sz, (h - y - th) << 2);
151
152
1.14M
                for (int i = 0; i < px_have; i++)
153
1.04M
                    left[-(i + 1)] = dst[(sz + i) * PXSTRIDE(stride) - 1];
154
99.6k
                if (px_have < sz)
155
1.03k
                    pixel_set(left - sz, left[-px_have], sz - px_have);
156
307k
            } else {
157
307k
                pixel_set(left - sz, left[0], sz);
158
307k
            }
159
407k
        }
160
7.43M
    }
161
162
9.02M
    if (av1_intra_prediction_edges[mode].needs_top) {
163
7.66M
        const int sz = tw << 2;
164
7.66M
        pixel *const top = &topleft_out[1];
165
166
7.66M
        if (have_top) {
167
7.39M
            const int px_have = imin(sz, (w - x) << 2);
168
7.39M
            pixel_copy(top, dst_top, px_have);
169
7.39M
            if (px_have < sz)
170
496k
                pixel_set(top + px_have, top[px_have - 1], sz - px_have);
171
7.39M
        } else {
172
274k
            pixel_set(top, have_left ? dst[-1] : ((1 << bitdepth) >> 1) - 1, sz);
173
274k
        }
174
175
7.66M
        if (av1_intra_prediction_edges[mode].needs_topright) {
176
311k
            const int have_topright = (!have_top || x + tw >= w) ? 0 :
177
311k
                                      (edge_flags & EDGE_I444_TOP_HAS_RIGHT);
178
179
311k
            if (have_topright) {
180
176k
                const int px_have = imin(sz, (w - x - tw) << 2);
181
182
176k
                pixel_copy(top + sz, &dst_top[sz], px_have);
183
176k
                if (px_have < sz)
184
3.34k
                    pixel_set(top + sz + px_have, top[sz + px_have - 1],
185
1.69k
                              sz - px_have);
186
176k
            } else {
187
134k
                pixel_set(top + sz, top[sz - 1], sz);
188
134k
            }
189
311k
        }
190
7.66M
    }
191
192
9.02M
    if (av1_intra_prediction_edges[mode].needs_topleft) {
193
2.15M
        if (have_left)
194
1.97M
            *topleft_out = have_top ? dst_top[-1] : dst[-1];
195
182k
        else
196
182k
            *topleft_out = have_top ? *dst_top : (1 << bitdepth) >> 1;
197
198
2.15M
        if (mode == Z2_PRED && tw + th >= 6 && filter_edge)
199
171k
            *topleft_out = ((topleft_out[-1] + topleft_out[1]) * 5 +
200
171k
                            topleft_out[0] * 6 + 8) >> 4;
201
2.15M
    }
202
203
9.02M
    return mode;
204
9.02M
}
dav1d_prepare_intra_edges_8bpc
Line
Count
Source
86
4.10M
{
87
4.10M
    const int bitdepth = bitdepth_from_max(bitdepth_max);
88
4.10M
    assert(y < h && x < w);
89
90
4.10M
    switch (mode) {
91
147k
    case VERT_PRED:
92
404k
    case HOR_PRED:
93
457k
    case DIAG_DOWN_LEFT_PRED:
94
513k
    case DIAG_DOWN_RIGHT_PRED:
95
571k
    case VERT_RIGHT_PRED:
96
633k
    case HOR_DOWN_PRED:
97
801k
    case HOR_UP_PRED:
98
881k
    case VERT_LEFT_PRED: {
99
881k
        *angle = av1_mode_to_angle_map[mode - VERT_PRED] + 3 * *angle;
100
101
881k
        if (*angle <= 90)
102
245k
            mode = *angle < 90 && have_top ? Z1_PRED : VERT_PRED;
103
636k
        else if (*angle < 180)
104
279k
            mode = Z2_PRED;
105
357k
        else
106
357k
            mode = *angle > 180 && have_left ? Z3_PRED : HOR_PRED;
107
881k
        break;
108
801k
    }
109
2.03M
    case DC_PRED:
110
2.45M
    case PAETH_PRED:
111
2.45M
        mode = av1_mode_conv[mode][have_left][have_top];
112
2.45M
        break;
113
811k
    default:
114
811k
        break;
115
4.10M
    }
116
117
4.09M
    const pixel *dst_top;
118
4.09M
    if (have_top &&
119
3.65M
        (av1_intra_prediction_edges[mode].needs_top ||
120
320k
         av1_intra_prediction_edges[mode].needs_topleft ||
121
141k
         (av1_intra_prediction_edges[mode].needs_left && !have_left)))
122
3.56M
    {
123
3.56M
        if (prefilter_toplevel_sb_edge) {
124
574k
            dst_top = &prefilter_toplevel_sb_edge[x * 4];
125
2.98M
        } else {
126
2.98M
            dst_top = &dst[-PXSTRIDE(stride)];
127
2.98M
        }
128
3.56M
    }
129
130
4.09M
    if (av1_intra_prediction_edges[mode].needs_left) {
131
3.28M
        const int sz = th << 2;
132
3.28M
        pixel *const left = &topleft_out[-sz];
133
134
3.28M
        if (have_left) {
135
3.07M
            const int px_have = imin(sz, (h - y) << 2);
136
137
38.3M
            for (int i = 0; i < px_have; i++)
138
35.2M
                left[sz - 1 - i] = dst[PXSTRIDE(stride) * i - 1];
139
3.07M
            if (px_have < sz)
140
96.1k
                pixel_set(left, left[sz - px_have], sz - px_have);
141
3.07M
        } else {
142
216k
            pixel_set(left, have_top ? *dst_top : ((1 << bitdepth) >> 1) + 1, sz);
143
216k
        }
144
145
3.28M
        if (av1_intra_prediction_edges[mode].needs_bottomleft) {
146
196k
            const int have_bottomleft = (!have_left || y + th >= h) ? 0 :
147
196k
                                        (edge_flags & EDGE_I444_LEFT_HAS_BOTTOM);
148
149
196k
            if (have_bottomleft) {
150
41.8k
                const int px_have = imin(sz, (h - y - th) << 2);
151
152
424k
                for (int i = 0; i < px_have; i++)
153
382k
                    left[-(i + 1)] = dst[(sz + i) * PXSTRIDE(stride) - 1];
154
41.8k
                if (px_have < sz)
155
395
                    pixel_set(left - sz, left[-px_have], sz - px_have);
156
155k
            } else {
157
155k
                pixel_set(left - sz, left[0], sz);
158
155k
            }
159
196k
        }
160
3.28M
    }
161
162
4.09M
    if (av1_intra_prediction_edges[mode].needs_top) {
163
3.43M
        const int sz = tw << 2;
164
3.43M
        pixel *const top = &topleft_out[1];
165
166
3.43M
        if (have_top) {
167
3.30M
            const int px_have = imin(sz, (w - x) << 2);
168
3.30M
            pixel_copy(top, dst_top, px_have);
169
3.30M
            if (px_have < sz)
170
239k
                pixel_set(top + px_have, top[px_have - 1], sz - px_have);
171
3.30M
        } else {
172
126k
            pixel_set(top, have_left ? dst[-1] : ((1 << bitdepth) >> 1) - 1, sz);
173
126k
        }
174
175
3.43M
        if (av1_intra_prediction_edges[mode].needs_topright) {
176
148k
            const int have_topright = (!have_top || x + tw >= w) ? 0 :
177
148k
                                      (edge_flags & EDGE_I444_TOP_HAS_RIGHT);
178
179
148k
            if (have_topright) {
180
86.7k
                const int px_have = imin(sz, (w - x - tw) << 2);
181
182
86.7k
                pixel_copy(top + sz, &dst_top[sz], px_have);
183
86.7k
                if (px_have < sz)
184
1.69k
                    pixel_set(top + sz + px_have, top[sz + px_have - 1],
185
1.69k
                              sz - px_have);
186
86.7k
            } else {
187
61.7k
                pixel_set(top + sz, top[sz - 1], sz);
188
61.7k
            }
189
148k
        }
190
3.43M
    }
191
192
4.09M
    if (av1_intra_prediction_edges[mode].needs_topleft) {
193
1.11M
        if (have_left)
194
1.02M
            *topleft_out = have_top ? dst_top[-1] : dst[-1];
195
92.1k
        else
196
92.1k
            *topleft_out = have_top ? *dst_top : (1 << bitdepth) >> 1;
197
198
1.11M
        if (mode == Z2_PRED && tw + th >= 6 && filter_edge)
199
72.0k
            *topleft_out = ((topleft_out[-1] + topleft_out[1]) * 5 +
200
72.0k
                            topleft_out[0] * 6 + 8) >> 4;
201
1.11M
    }
202
203
4.09M
    return mode;
204
4.10M
}
dav1d_prepare_intra_edges_16bpc
Line
Count
Source
86
4.92M
{
87
4.92M
    const int bitdepth = bitdepth_from_max(bitdepth_max);
88
4.92M
    assert(y < h && x < w);
89
90
4.92M
    switch (mode) {
91
178k
    case VERT_PRED:
92
482k
    case HOR_PRED:
93
543k
    case DIAG_DOWN_LEFT_PRED:
94
601k
    case DIAG_DOWN_RIGHT_PRED:
95
656k
    case VERT_RIGHT_PRED:
96
730k
    case HOR_DOWN_PRED:
97
892k
    case HOR_UP_PRED:
98
976k
    case VERT_LEFT_PRED: {
99
976k
        *angle = av1_mode_to_angle_map[mode - VERT_PRED] + 3 * *angle;
100
101
976k
        if (*angle <= 90)
102
276k
            mode = *angle < 90 && have_top ? Z1_PRED : VERT_PRED;
103
699k
        else if (*angle < 180)
104
311k
            mode = Z2_PRED;
105
388k
        else
106
388k
            mode = *angle > 180 && have_left ? Z3_PRED : HOR_PRED;
107
976k
        break;
108
892k
    }
109
2.91M
    case DC_PRED:
110
3.21M
    case PAETH_PRED:
111
3.21M
        mode = av1_mode_conv[mode][have_left][have_top];
112
3.21M
        break;
113
742k
    default:
114
742k
        break;
115
4.92M
    }
116
117
4.92M
    const pixel *dst_top;
118
4.92M
    if (have_top &&
119
4.43M
        (av1_intra_prediction_edges[mode].needs_top ||
120
341k
         av1_intra_prediction_edges[mode].needs_topleft ||
121
156k
         (av1_intra_prediction_edges[mode].needs_left && !have_left)))
122
4.32M
    {
123
4.32M
        if (prefilter_toplevel_sb_edge) {
124
552k
            dst_top = &prefilter_toplevel_sb_edge[x * 4];
125
3.76M
        } else {
126
3.76M
            dst_top = &dst[-PXSTRIDE(stride)];
127
3.76M
        }
128
4.32M
    }
129
130
4.92M
    if (av1_intra_prediction_edges[mode].needs_left) {
131
4.14M
        const int sz = th << 2;
132
4.14M
        pixel *const left = &topleft_out[-sz];
133
134
4.14M
        if (have_left) {
135
3.95M
            const int px_have = imin(sz, (h - y) << 2);
136
137
44.1M
            for (int i = 0; i < px_have; i++)
138
40.2M
                left[sz - 1 - i] = dst[PXSTRIDE(stride) * i - 1];
139
3.95M
            if (px_have < sz)
140
117k
                pixel_set(left, left[sz - px_have], sz - px_have);
141
3.95M
        } else {
142
194k
            pixel_set(left, have_top ? *dst_top : ((1 << bitdepth) >> 1) + 1, sz);
143
194k
        }
144
145
4.14M
        if (av1_intra_prediction_edges[mode].needs_bottomleft) {
146
210k
            const int have_bottomleft = (!have_left || y + th >= h) ? 0 :
147
210k
                                        (edge_flags & EDGE_I444_LEFT_HAS_BOTTOM);
148
149
210k
            if (have_bottomleft) {
150
57.7k
                const int px_have = imin(sz, (h - y - th) << 2);
151
152
720k
                for (int i = 0; i < px_have; i++)
153
662k
                    left[-(i + 1)] = dst[(sz + i) * PXSTRIDE(stride) - 1];
154
57.7k
                if (px_have < sz)
155
636
                    pixel_set(left - sz, left[-px_have], sz - px_have);
156
152k
            } else {
157
152k
                pixel_set(left - sz, left[0], sz);
158
152k
            }
159
210k
        }
160
4.14M
    }
161
162
4.92M
    if (av1_intra_prediction_edges[mode].needs_top) {
163
4.23M
        const int sz = tw << 2;
164
4.23M
        pixel *const top = &topleft_out[1];
165
166
4.23M
        if (have_top) {
167
4.08M
            const int px_have = imin(sz, (w - x) << 2);
168
4.08M
            pixel_copy(top, dst_top, px_have);
169
4.08M
            if (px_have < sz)
170
257k
                pixel_set(top + px_have, top[px_have - 1], sz - px_have);
171
4.08M
        } else {
172
148k
            pixel_set(top, have_left ? dst[-1] : ((1 << bitdepth) >> 1) - 1, sz);
173
148k
        }
174
175
4.23M
        if (av1_intra_prediction_edges[mode].needs_topright) {
176
162k
            const int have_topright = (!have_top || x + tw >= w) ? 0 :
177
162k
                                      (edge_flags & EDGE_I444_TOP_HAS_RIGHT);
178
179
162k
            if (have_topright) {
180
89.7k
                const int px_have = imin(sz, (w - x - tw) << 2);
181
182
89.7k
                pixel_copy(top + sz, &dst_top[sz], px_have);
183
89.7k
                if (px_have < sz)
184
1.64k
                    pixel_set(top + sz + px_have, top[sz + px_have - 1],
185
1.64k
                              sz - px_have);
186
89.7k
            } else {
187
72.7k
                pixel_set(top + sz, top[sz - 1], sz);
188
72.7k
            }
189
162k
        }
190
4.23M
    }
191
192
4.92M
    if (av1_intra_prediction_edges[mode].needs_topleft) {
193
1.04M
        if (have_left)
194
950k
            *topleft_out = have_top ? dst_top[-1] : dst[-1];
195
89.9k
        else
196
89.9k
            *topleft_out = have_top ? *dst_top : (1 << bitdepth) >> 1;
197
198
1.04M
        if (mode == Z2_PRED && tw + th >= 6 && filter_edge)
199
99.1k
            *topleft_out = ((topleft_out[-1] + topleft_out[1]) * 5 +
200
99.1k
                            topleft_out[0] * 6 + 8) >> 4;
201
1.04M
    }
202
203
4.92M
    return mode;
204
4.92M
}