Coverage Report

Created: 2026-05-16 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/dav1d/src/intra_edge.c
Line
Count
Source
1
/*
2
 * Copyright © 2018-2023, VideoLAN and dav1d authors
3
 * Copyright © 2018-2023, 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 <stdlib.h>
31
32
#include "common/attributes.h"
33
34
#include "src/intra_edge.h"
35
#include "src/levels.h"
36
37
struct ModeSelMem {
38
    EdgeBranch *nwc[3 /* 64x64, 32x32, 16x16 */];
39
    EdgeTip *nt;
40
};
41
42
/* Because we're using 16-bit offsets to refer to other nodes those arrays
43
 * are placed in a struct to ensure they're consecutive in memory. */
44
static struct {
45
    EdgeBranch branch_sb128[1 + 4 + 16 + 64];
46
    EdgeTip tip_sb128[256];
47
    EdgeBranch branch_sb64[1 + 4 + 16];
48
    EdgeTip tip_sb64[64];
49
} ALIGN(nodes, 16);
50
51
const EdgeNode *dav1d_intra_edge_tree[2] = {
52
    (EdgeNode*)nodes.branch_sb128, (EdgeNode*)nodes.branch_sb64
53
};
54
55
static COLD void init_edges(EdgeNode *const node,
56
                            const enum BlockLevel bl,
57
                            const enum EdgeFlags edge_flags)
58
0
{
59
0
    node->o = edge_flags;
60
0
    node->h[0] = edge_flags | EDGE_ALL_LEFT_HAS_BOTTOM;
61
0
    node->v[0] = edge_flags | EDGE_ALL_TOP_HAS_RIGHT;
62
63
0
    if (bl == BL_8X8) {
64
0
        EdgeTip *const nt = (EdgeTip *) node;
65
66
0
        node->h[1] = edge_flags & (EDGE_ALL_LEFT_HAS_BOTTOM |
67
0
                                   EDGE_I420_TOP_HAS_RIGHT);
68
0
        node->v[1] = edge_flags & (EDGE_ALL_TOP_HAS_RIGHT |
69
0
                                   EDGE_I420_LEFT_HAS_BOTTOM |
70
0
                                   EDGE_I422_LEFT_HAS_BOTTOM);
71
72
0
        nt->split[0] = (edge_flags & EDGE_ALL_TOP_HAS_RIGHT) |
73
0
                       EDGE_I422_LEFT_HAS_BOTTOM;
74
0
        nt->split[1] = edge_flags | EDGE_I444_TOP_HAS_RIGHT;
75
0
        nt->split[2] = edge_flags & (EDGE_I420_TOP_HAS_RIGHT |
76
0
                                     EDGE_I420_LEFT_HAS_BOTTOM |
77
0
                                     EDGE_I422_LEFT_HAS_BOTTOM);
78
0
    } else {
79
0
        EdgeBranch *const nwc = (EdgeBranch *) node;
80
81
0
        node->h[1] = edge_flags & EDGE_ALL_LEFT_HAS_BOTTOM;
82
0
        node->v[1] = edge_flags & EDGE_ALL_TOP_HAS_RIGHT;
83
84
0
        nwc->h4 = EDGE_ALL_LEFT_HAS_BOTTOM;
85
0
        nwc->v4 = EDGE_ALL_TOP_HAS_RIGHT;
86
0
        if (bl == BL_16X16) {
87
0
            nwc->h4 |= edge_flags & EDGE_I420_TOP_HAS_RIGHT;
88
0
            nwc->v4 |= edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM |
89
0
                                     EDGE_I422_LEFT_HAS_BOTTOM);
90
0
        }
91
0
    }
92
0
}
93
94
0
#define PTR_OFFSET(a, b) ((uint16_t)((uintptr_t)(b) - (uintptr_t)(a)))
95
96
static COLD void init_mode_node(EdgeBranch *const nwc,
97
                               const enum BlockLevel bl,
98
                               struct ModeSelMem *const mem,
99
                               const int top_has_right,
100
                               const int left_has_bottom)
101
0
{
102
0
    init_edges(&nwc->node, bl,
103
0
               (top_has_right ? EDGE_ALL_TOP_HAS_RIGHT : 0) |
104
0
               (left_has_bottom ? EDGE_ALL_LEFT_HAS_BOTTOM : 0));
105
0
    if (bl == BL_16X16) {
106
0
        for (int n = 0; n < 4; n++) {
107
0
            EdgeTip *const nt = mem->nt++;
108
0
            nwc->split_offset[n] = PTR_OFFSET(nwc, nt);
109
0
            init_edges(&nt->node, bl + 1,
110
0
                       ((n == 3 || (n == 1 && !top_has_right)) ? 0 :
111
0
                        EDGE_ALL_TOP_HAS_RIGHT) |
112
0
                       (!(n == 0 || (n == 2 && left_has_bottom)) ? 0 :
113
0
                        EDGE_ALL_LEFT_HAS_BOTTOM));
114
0
        }
115
0
    } else {
116
0
        for (int n = 0; n < 4; n++) {
117
0
            EdgeBranch *const nwc_child = mem->nwc[bl]++;
118
0
            nwc->split_offset[n] = PTR_OFFSET(nwc, nwc_child);
119
0
            init_mode_node(nwc_child, bl + 1, mem,
120
0
                           !(n == 3 || (n == 1 && !top_has_right)),
121
0
                           n == 0 || (n == 2 && left_has_bottom));
122
0
        }
123
0
    }
124
0
}
125
126
0
COLD void dav1d_init_intra_edge_tree(void) {
127
    // This function is guaranteed to be called only once
128
0
    struct ModeSelMem mem;
129
130
0
    mem.nwc[BL_128X128] = &nodes.branch_sb128[1];
131
0
    mem.nwc[BL_64X64] = &nodes.branch_sb128[1 + 4];
132
0
    mem.nwc[BL_32X32] = &nodes.branch_sb128[1 + 4 + 16];
133
0
    mem.nt = nodes.tip_sb128;
134
0
    init_mode_node(nodes.branch_sb128, BL_128X128, &mem, 1, 0);
135
0
    assert(mem.nwc[BL_128X128] == &nodes.branch_sb128[1 + 4]);
136
0
    assert(mem.nwc[BL_64X64] == &nodes.branch_sb128[1 + 4 + 16]);
137
0
    assert(mem.nwc[BL_32X32] == &nodes.branch_sb128[1 + 4 + 16 + 64]);
138
0
    assert(mem.nt == &nodes.tip_sb128[256]);
139
140
0
    mem.nwc[BL_128X128] = NULL;
141
0
    mem.nwc[BL_64X64] = &nodes.branch_sb64[1];
142
0
    mem.nwc[BL_32X32] = &nodes.branch_sb64[1 + 4];
143
0
    mem.nt = nodes.tip_sb64;
144
0
    init_mode_node(nodes.branch_sb64, BL_64X64, &mem, 1, 0);
145
0
    assert(mem.nwc[BL_64X64] == &nodes.branch_sb64[1 + 4]);
146
0
    assert(mem.nwc[BL_32X32] == &nodes.branch_sb64[1 + 4 + 16]);
147
0
    assert(mem.nt == &nodes.tip_sb64[64]);
148
0
}