xref: /aosp_15_r20/external/libdav1d/src/ipred_prepare.h (revision c09093415860a1c2373dacd84c4fde00c507cdfd)
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 #ifndef DAV1D_SRC_IPRED_PREPARE_H
29 #define DAV1D_SRC_IPRED_PREPARE_H
30 
31 #include <stddef.h>
32 #include <stdint.h>
33 
34 #include "common/bitdepth.h"
35 
36 #include "src/env.h"
37 #include "src/intra_edge.h"
38 #include "src/levels.h"
39 
40 /*
41  * Luma intra edge preparation.
42  *
43  * x/y/start/w/h are in luma block (4px) units:
44  * - x and y are the absolute block positions in the image;
45  * - start/w/h are the *dependent tile* boundary positions. In practice, start
46  *   is the horizontal tile start, w is the horizontal tile end, the vertical
47  *   tile start is assumed to be 0 and h is the vertical image end.
48  *
49  * edge_flags signals which edges are available for this transform-block inside
50  * the given partition, as well as for the partition inside the superblock
51  * structure.
52  *
53  * dst and stride are pointers to the top/left position of the current block,
54  * and can be used to locate the top, left, top/left, top/right and bottom/left
55  * edge pointers also.
56  *
57  * angle is the angle_delta [-3..3] on input, and the absolute angle on output.
58  *
59  * mode is the intra prediction mode as coded in the bitstream. The return value
60  * is this same mode, converted to an index in the DSP functions.
61  *
62  * tw/th are the size of the transform block in block (4px) units.
63  *
64  * topleft_out is a pointer to scratch memory that will be filled with the edge
65  * pixels. The memory array should have space to be indexed in the [-2*w,2*w]
66  * range, in the following order:
67  * - [0] will be the top/left edge pixel;
68  * - [1..w] will be the top edge pixels (1 being left-most, w being right-most);
69  * - [w+1..2*w] will be the top/right edge pixels;
70  * - [-1..-w] will be the left edge pixels (-1 being top-most, -w being bottom-
71  *   most);
72  * - [-w-1..-2*w] will be the bottom/left edge pixels.
73  * Each edge may remain uninitialized if it is not used by the returned mode
74  * index. If edges are not available (because the edge position is outside the
75  * tile dimensions or because edge_flags indicates lack of edge availability),
76  * they will be extended from nearby edges as defined by the av1 spec.
77  */
78 enum IntraPredMode
79     bytefn(dav1d_prepare_intra_edges)(int x, int have_left, int y, int have_top,
80                                       int w, int h, enum EdgeFlags edge_flags,
81                                       const pixel *dst, ptrdiff_t stride,
82                                       const pixel *prefilter_toplevel_sb_edge,
83                                       enum IntraPredMode mode, int *angle,
84                                       int tw, int th, int filter_edge,
85                                       pixel *topleft_out HIGHBD_DECL_SUFFIX);
86 
87 // These flags are OR'd with the angle argument into intra predictors.
88 // ANGLE_USE_EDGE_FILTER_FLAG signals that edges should be convolved
89 // with a filter before using them to predict values in a block.
90 // ANGLE_SMOOTH_EDGE_FLAG means that edges are smooth and should use
91 // reduced filter strength.
92 #define ANGLE_USE_EDGE_FILTER_FLAG 1024
93 #define ANGLE_SMOOTH_EDGE_FLAG      512
94 
sm_flag(const BlockContext * const b,const int idx)95 static inline int sm_flag(const BlockContext *const b, const int idx) {
96     if (!b->intra[idx]) return 0;
97     const enum IntraPredMode m = b->mode[idx];
98     return (m == SMOOTH_PRED || m == SMOOTH_H_PRED ||
99             m == SMOOTH_V_PRED) ? ANGLE_SMOOTH_EDGE_FLAG : 0;
100 }
101 
sm_uv_flag(const BlockContext * const b,const int idx)102 static inline int sm_uv_flag(const BlockContext *const b, const int idx) {
103     const enum IntraPredMode m = b->uvmode[idx];
104     return (m == SMOOTH_PRED || m == SMOOTH_H_PRED ||
105             m == SMOOTH_V_PRED) ? ANGLE_SMOOTH_EDGE_FLAG : 0;
106 }
107 
108 #endif /* DAV1D_SRC_IPRED_PREPARE_H */
109