Coverage Report

Created: 2026-12-01 06:52

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
16.1M
{
87
16.1M
    const int bitdepth = bitdepth_from_max(bitdepth_max);
88
16.1M
    assert(y < h && x < w);
89
90
16.1M
    switch (mode) {
91
745k
    case VERT_PRED:
92
1.99M
    case HOR_PRED:
93
2.27M
    case DIAG_DOWN_LEFT_PRED:
94
2.60M
    case DIAG_DOWN_RIGHT_PRED:
95
2.83M
    case VERT_RIGHT_PRED:
96
3.19M
    case HOR_DOWN_PRED:
97
3.80M
    case HOR_UP_PRED:
98
4.20M
    case VERT_LEFT_PRED: {
99
4.20M
        *angle = av1_mode_to_angle_map[mode - VERT_PRED] + 3 * *angle;
100
101
4.20M
        if (*angle <= 90)
102
1.23M
            mode = *angle < 90 && have_top ? Z1_PRED : VERT_PRED;
103
2.97M
        else if (*angle < 180)
104
1.41M
            mode = Z2_PRED;
105
1.55M
        else
106
1.55M
            mode = *angle > 180 && have_left ? Z3_PRED : HOR_PRED;
107
4.20M
        break;
108
3.80M
    }
109
7.38M
    case DC_PRED:
110
8.93M
    case PAETH_PRED:
111
8.93M
        mode = av1_mode_conv[mode][have_left][have_top];
112
8.93M
        break;
113
3.05M
    default:
114
3.05M
        break;
115
16.1M
    }
116
117
16.1M
    const pixel *dst_top;
118
16.1M
    if (have_top &&
119
13.5M
        (av1_intra_prediction_edges[mode].needs_top ||
120
1.30M
         av1_intra_prediction_edges[mode].needs_topleft ||
121
689k
         (av1_intra_prediction_edges[mode].needs_left && !have_left)))
122
13.0M
    {
123
13.0M
        if (prefilter_toplevel_sb_edge) {
124
2.11M
            dst_top = &prefilter_toplevel_sb_edge[x * 4];
125
10.9M
        } else {
126
10.9M
            dst_top = &dst[-PXSTRIDE(stride)];
127
10.9M
        }
128
13.0M
    }
129
130
16.1M
    if (av1_intra_prediction_edges[mode].needs_left) {
131
12.5M
        const int sz = th << 2;
132
12.5M
        pixel *const left = &topleft_out[-sz];
133
134
12.5M
        if (have_left) {
135
11.4M
            const int px_have = imin(sz, (h - y) << 2);
136
137
148M
            for (int i = 0; i < px_have; i++)
138
137M
                left[sz - 1 - i] = dst[PXSTRIDE(stride) * i - 1];
139
11.4M
            if (px_have < sz)
140
621k
                pixel_set(left, left[sz - px_have], sz - px_have);
141
11.4M
        } else {
142
1.12M
            pixel_set(left, have_top ? *dst_top : ((1 << bitdepth) >> 1) + 1, sz);
143
1.12M
        }
144
145
12.5M
        if (av1_intra_prediction_edges[mode].needs_bottomleft) {
146
753k
            const int have_bottomleft = (!have_left || y + th >= h) ? 0 :
147
753k
                                        (edge_flags & EDGE_I444_LEFT_HAS_BOTTOM);
148
149
753k
            if (have_bottomleft) {
150
179k
                const int px_have = imin(sz, (h - y - th) << 2);
151
152
2.02M
                for (int i = 0; i < px_have; i++)
153
1.84M
                    left[-(i + 1)] = dst[(sz + i) * PXSTRIDE(stride) - 1];
154
179k
                if (px_have < sz)
155
3.91k
                    pixel_set(left - sz, left[-px_have], sz - px_have);
156
573k
            } else {
157
573k
                pixel_set(left - sz, left[0], sz);
158
573k
            }
159
753k
        }
160
12.5M
    }
161
162
16.1M
    if (av1_intra_prediction_edges[mode].needs_top) {
163
13.0M
        const int sz = tw << 2;
164
13.0M
        pixel *const top = &topleft_out[1];
165
166
13.0M
        if (have_top) {
167
12.1M
            const int px_have = imin(sz, (w - x) << 2);
168
12.1M
            pixel_copy(top, dst_top, px_have);
169
12.1M
            if (px_have < sz)
170
1.22M
                pixel_set(top + px_have, top[px_have - 1], sz - px_have);
171
12.1M
        } else {
172
873k
            pixel_set(top, have_left ? dst[-1] : ((1 << bitdepth) >> 1) - 1, sz);
173
873k
        }
174
175
13.0M
        if (av1_intra_prediction_edges[mode].needs_topright) {
176
717k
            const int have_topright = (!have_top || x + tw >= w) ? 0 :
177
717k
                                      (edge_flags & EDGE_I444_TOP_HAS_RIGHT);
178
179
717k
            if (have_topright) {
180
405k
                const int px_have = imin(sz, (w - x - tw) << 2);
181
182
405k
                pixel_copy(top + sz, &dst_top[sz], px_have);
183
405k
                if (px_have < sz)
184
11.8k
                    pixel_set(top + sz + px_have, top[sz + px_have - 1],
185
6.22k
                              sz - px_have);
186
405k
            } else {
187
312k
                pixel_set(top + sz, top[sz - 1], sz);
188
312k
            }
189
717k
        }
190
13.0M
    }
191
192
16.1M
    if (av1_intra_prediction_edges[mode].needs_topleft) {
193
4.52M
        if (have_left)
194
4.00M
            *topleft_out = have_top ? dst_top[-1] : dst[-1];
195
517k
        else
196
517k
            *topleft_out = have_top ? *dst_top : (1 << bitdepth) >> 1;
197
198
4.52M
        if (mode == Z2_PRED && tw + th >= 6 && filter_edge)
199
362k
            *topleft_out = ((topleft_out[-1] + topleft_out[1]) * 5 +
200
362k
                            topleft_out[0] * 6 + 8) >> 4;
201
4.52M
    }
202
203
16.1M
    return mode;
204
16.1M
}
dav1d_prepare_intra_edges_8bpc
Line
Count
Source
86
7.93M
{
87
7.93M
    const int bitdepth = bitdepth_from_max(bitdepth_max);
88
7.93M
    assert(y < h && x < w);
89
90
7.93M
    switch (mode) {
91
346k
    case VERT_PRED:
92
939k
    case HOR_PRED:
93
1.08M
    case DIAG_DOWN_LEFT_PRED:
94
1.25M
    case DIAG_DOWN_RIGHT_PRED:
95
1.36M
    case VERT_RIGHT_PRED:
96
1.52M
    case HOR_DOWN_PRED:
97
1.83M
    case HOR_UP_PRED:
98
2.04M
    case VERT_LEFT_PRED: {
99
2.04M
        *angle = av1_mode_to_angle_map[mode - VERT_PRED] + 3 * *angle;
100
101
2.04M
        if (*angle <= 90)
102
616k
            mode = *angle < 90 && have_top ? Z1_PRED : VERT_PRED;
103
1.43M
        else if (*angle < 180)
104
683k
            mode = Z2_PRED;
105
747k
        else
106
747k
            mode = *angle > 180 && have_left ? Z3_PRED : HOR_PRED;
107
2.04M
        break;
108
1.83M
    }
109
3.51M
    case DC_PRED:
110
4.40M
    case PAETH_PRED:
111
4.40M
        mode = av1_mode_conv[mode][have_left][have_top];
112
4.40M
        break;
113
1.53M
    default:
114
1.53M
        break;
115
7.93M
    }
116
117
7.93M
    const pixel *dst_top;
118
7.93M
    if (have_top &&
119
6.66M
        (av1_intra_prediction_edges[mode].needs_top ||
120
627k
         av1_intra_prediction_edges[mode].needs_topleft ||
121
316k
         (av1_intra_prediction_edges[mode].needs_left && !have_left)))
122
6.46M
    {
123
6.46M
        if (prefilter_toplevel_sb_edge) {
124
1.03M
            dst_top = &prefilter_toplevel_sb_edge[x * 4];
125
5.42M
        } else {
126
5.42M
            dst_top = &dst[-PXSTRIDE(stride)];
127
5.42M
        }
128
6.46M
    }
129
130
7.93M
    if (av1_intra_prediction_edges[mode].needs_left) {
131
6.20M
        const int sz = th << 2;
132
6.20M
        pixel *const left = &topleft_out[-sz];
133
134
6.20M
        if (have_left) {
135
5.69M
            const int px_have = imin(sz, (h - y) << 2);
136
137
72.7M
            for (int i = 0; i < px_have; i++)
138
67.0M
                left[sz - 1 - i] = dst[PXSTRIDE(stride) * i - 1];
139
5.69M
            if (px_have < sz)
140
301k
                pixel_set(left, left[sz - px_have], sz - px_have);
141
5.69M
        } else {
142
513k
            pixel_set(left, have_top ? *dst_top : ((1 << bitdepth) >> 1) + 1, sz);
143
513k
        }
144
145
6.20M
        if (av1_intra_prediction_edges[mode].needs_bottomleft) {
146
376k
            const int have_bottomleft = (!have_left || y + th >= h) ? 0 :
147
376k
                                        (edge_flags & EDGE_I444_LEFT_HAS_BOTTOM);
148
149
376k
            if (have_bottomleft) {
150
86.7k
                const int px_have = imin(sz, (h - y - th) << 2);
151
152
933k
                for (int i = 0; i < px_have; i++)
153
846k
                    left[-(i + 1)] = dst[(sz + i) * PXSTRIDE(stride) - 1];
154
86.7k
                if (px_have < sz)
155
2.13k
                    pixel_set(left - sz, left[-px_have], sz - px_have);
156
289k
            } else {
157
289k
                pixel_set(left - sz, left[0], sz);
158
289k
            }
159
376k
        }
160
6.20M
    }
161
162
7.93M
    if (av1_intra_prediction_edges[mode].needs_top) {
163
6.46M
        const int sz = tw << 2;
164
6.46M
        pixel *const top = &topleft_out[1];
165
166
6.46M
        if (have_top) {
167
6.03M
            const int px_have = imin(sz, (w - x) << 2);
168
6.03M
            pixel_copy(top, dst_top, px_have);
169
6.03M
            if (px_have < sz)
170
569k
                pixel_set(top + px_have, top[px_have - 1], sz - px_have);
171
6.03M
        } else {
172
434k
            pixel_set(top, have_left ? dst[-1] : ((1 << bitdepth) >> 1) - 1, sz);
173
434k
        }
174
175
6.46M
        if (av1_intra_prediction_edges[mode].needs_topright) {
176
372k
            const int have_topright = (!have_top || x + tw >= w) ? 0 :
177
372k
                                      (edge_flags & EDGE_I444_TOP_HAS_RIGHT);
178
179
372k
            if (have_topright) {
180
220k
                const int px_have = imin(sz, (w - x - tw) << 2);
181
182
220k
                pixel_copy(top + sz, &dst_top[sz], px_have);
183
220k
                if (px_have < sz)
184
6.22k
                    pixel_set(top + sz + px_have, top[sz + px_have - 1],
185
6.22k
                              sz - px_have);
186
220k
            } else {
187
151k
                pixel_set(top + sz, top[sz - 1], sz);
188
151k
            }
189
372k
        }
190
6.46M
    }
191
192
7.93M
    if (av1_intra_prediction_edges[mode].needs_topleft) {
193
2.35M
        if (have_left)
194
2.10M
            *topleft_out = have_top ? dst_top[-1] : dst[-1];
195
244k
        else
196
244k
            *topleft_out = have_top ? *dst_top : (1 << bitdepth) >> 1;
197
198
2.35M
        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.35M
    }
202
203
7.93M
    return mode;
204
7.93M
}
dav1d_prepare_intra_edges_16bpc
Line
Count
Source
86
8.18M
{
87
8.18M
    const int bitdepth = bitdepth_from_max(bitdepth_max);
88
8.18M
    assert(y < h && x < w);
89
90
8.18M
    switch (mode) {
91
399k
    case VERT_PRED:
92
1.05M
    case HOR_PRED:
93
1.19M
    case DIAG_DOWN_LEFT_PRED:
94
1.35M
    case DIAG_DOWN_RIGHT_PRED:
95
1.47M
    case VERT_RIGHT_PRED:
96
1.66M
    case HOR_DOWN_PRED:
97
1.97M
    case HOR_UP_PRED:
98
2.16M
    case VERT_LEFT_PRED: {
99
2.16M
        *angle = av1_mode_to_angle_map[mode - VERT_PRED] + 3 * *angle;
100
101
2.16M
        if (*angle <= 90)
102
620k
            mode = *angle < 90 && have_top ? Z1_PRED : VERT_PRED;
103
1.54M
        else if (*angle < 180)
104
734k
            mode = Z2_PRED;
105
806k
        else
106
806k
            mode = *angle > 180 && have_left ? Z3_PRED : HOR_PRED;
107
2.16M
        break;
108
1.97M
    }
109
3.86M
    case DC_PRED:
110
4.53M
    case PAETH_PRED:
111
4.53M
        mode = av1_mode_conv[mode][have_left][have_top];
112
4.53M
        break;
113
1.51M
    default:
114
1.51M
        break;
115
8.18M
    }
116
117
8.18M
    const pixel *dst_top;
118
8.18M
    if (have_top &&
119
6.83M
        (av1_intra_prediction_edges[mode].needs_top ||
120
680k
         av1_intra_prediction_edges[mode].needs_topleft ||
121
372k
         (av1_intra_prediction_edges[mode].needs_left && !have_left)))
122
6.61M
    {
123
6.61M
        if (prefilter_toplevel_sb_edge) {
124
1.08M
            dst_top = &prefilter_toplevel_sb_edge[x * 4];
125
5.53M
        } else {
126
5.53M
            dst_top = &dst[-PXSTRIDE(stride)];
127
5.53M
        }
128
6.61M
    }
129
130
8.18M
    if (av1_intra_prediction_edges[mode].needs_left) {
131
6.37M
        const int sz = th << 2;
132
6.37M
        pixel *const left = &topleft_out[-sz];
133
134
6.37M
        if (have_left) {
135
5.75M
            const int px_have = imin(sz, (h - y) << 2);
136
137
75.8M
            for (int i = 0; i < px_have; i++)
138
70.1M
                left[sz - 1 - i] = dst[PXSTRIDE(stride) * i - 1];
139
5.75M
            if (px_have < sz)
140
320k
                pixel_set(left, left[sz - px_have], sz - px_have);
141
5.75M
        } else {
142
613k
            pixel_set(left, have_top ? *dst_top : ((1 << bitdepth) >> 1) + 1, sz);
143
613k
        }
144
145
6.37M
        if (av1_intra_prediction_edges[mode].needs_bottomleft) {
146
376k
            const int have_bottomleft = (!have_left || y + th >= h) ? 0 :
147
376k
                                        (edge_flags & EDGE_I444_LEFT_HAS_BOTTOM);
148
149
376k
            if (have_bottomleft) {
150
93.1k
                const int px_have = imin(sz, (h - y - th) << 2);
151
152
1.09M
                for (int i = 0; i < px_have; i++)
153
1.00M
                    left[-(i + 1)] = dst[(sz + i) * PXSTRIDE(stride) - 1];
154
93.1k
                if (px_have < sz)
155
1.77k
                    pixel_set(left - sz, left[-px_have], sz - px_have);
156
283k
            } else {
157
283k
                pixel_set(left - sz, left[0], sz);
158
283k
            }
159
376k
        }
160
6.37M
    }
161
162
8.18M
    if (av1_intra_prediction_edges[mode].needs_top) {
163
6.58M
        const int sz = tw << 2;
164
6.58M
        pixel *const top = &topleft_out[1];
165
166
6.58M
        if (have_top) {
167
6.14M
            const int px_have = imin(sz, (w - x) << 2);
168
6.14M
            pixel_copy(top, dst_top, px_have);
169
6.14M
            if (px_have < sz)
170
659k
                pixel_set(top + px_have, top[px_have - 1], sz - px_have);
171
6.14M
        } else {
172
439k
            pixel_set(top, have_left ? dst[-1] : ((1 << bitdepth) >> 1) - 1, sz);
173
439k
        }
174
175
6.58M
        if (av1_intra_prediction_edges[mode].needs_topright) {
176
345k
            const int have_topright = (!have_top || x + tw >= w) ? 0 :
177
345k
                                      (edge_flags & EDGE_I444_TOP_HAS_RIGHT);
178
179
345k
            if (have_topright) {
180
184k
                const int px_have = imin(sz, (w - x - tw) << 2);
181
182
184k
                pixel_copy(top + sz, &dst_top[sz], px_have);
183
184k
                if (px_have < sz)
184
5.57k
                    pixel_set(top + sz + px_have, top[sz + px_have - 1],
185
5.57k
                              sz - px_have);
186
184k
            } else {
187
160k
                pixel_set(top + sz, top[sz - 1], sz);
188
160k
            }
189
345k
        }
190
6.58M
    }
191
192
8.18M
    if (av1_intra_prediction_edges[mode].needs_topleft) {
193
2.17M
        if (have_left)
194
1.90M
            *topleft_out = have_top ? dst_top[-1] : dst[-1];
195
272k
        else
196
272k
            *topleft_out = have_top ? *dst_top : (1 << bitdepth) >> 1;
197
198
2.17M
        if (mode == Z2_PRED && tw + th >= 6 && filter_edge)
199
191k
            *topleft_out = ((topleft_out[-1] + topleft_out[1]) * 5 +
200
191k
                            topleft_out[0] * 6 + 8) >> 4;
201
2.17M
    }
202
203
8.18M
    return mode;
204
8.18M
}