xref: /aosp_15_r20/external/libaom/av1/common/reconintra.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #ifndef AOM_AV1_COMMON_RECONINTRA_H_
13 #define AOM_AV1_COMMON_RECONINTRA_H_
14 
15 #include <stdlib.h>
16 
17 #include "aom/aom_integer.h"
18 #include "av1/common/av1_common_int.h"
19 #include "av1/common/blockd.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 void av1_init_intra_predictors(void);
26 void av1_predict_intra_block_facade(const AV1_COMMON *cm, MACROBLOCKD *xd,
27                                     int plane, int blk_col, int blk_row,
28                                     TX_SIZE tx_size);
29 void av1_predict_intra_block(const MACROBLOCKD *xd, BLOCK_SIZE sb_size,
30                              int enable_intra_edge_filter, int wpx, int hpx,
31                              TX_SIZE tx_size, PREDICTION_MODE mode,
32                              int angle_delta, int use_palette,
33                              FILTER_INTRA_MODE filter_intra_mode,
34                              const uint8_t *ref, int ref_stride, uint8_t *dst,
35                              int dst_stride, int col_off, int row_off,
36                              int plane);
37 
38 // Mapping of interintra to intra mode for use in the intra component
39 static const PREDICTION_MODE interintra_to_intra_mode[INTERINTRA_MODES] = {
40   DC_PRED, V_PRED, H_PRED, SMOOTH_PRED
41 };
42 
43 // Mapping of intra mode to the interintra mode
44 static const INTERINTRA_MODE intra_to_interintra_mode[INTRA_MODES] = {
45   II_DC_PRED, II_V_PRED, II_H_PRED, II_V_PRED,      II_SMOOTH_PRED, II_V_PRED,
46   II_H_PRED,  II_H_PRED, II_V_PRED, II_SMOOTH_PRED, II_SMOOTH_PRED
47 };
48 
49 #define FILTER_INTRA_SCALE_BITS 4
50 
av1_is_directional_mode(PREDICTION_MODE mode)51 static inline int av1_is_directional_mode(PREDICTION_MODE mode) {
52   return mode >= V_PRED && mode <= D67_PRED;
53 }
54 
av1_is_diagonal_mode(PREDICTION_MODE mode)55 static inline int av1_is_diagonal_mode(PREDICTION_MODE mode) {
56   return mode >= D45_PRED && mode <= D67_PRED;
57 }
58 
av1_use_angle_delta(BLOCK_SIZE bsize)59 static inline int av1_use_angle_delta(BLOCK_SIZE bsize) {
60   return bsize >= BLOCK_8X8;
61 }
62 
av1_allow_intrabc(const AV1_COMMON * const cm)63 static inline int av1_allow_intrabc(const AV1_COMMON *const cm) {
64   return frame_is_intra_only(cm) && cm->features.allow_screen_content_tools &&
65          cm->features.allow_intrabc;
66 }
67 
av1_filter_intra_allowed_bsize(const AV1_COMMON * const cm,BLOCK_SIZE bs)68 static inline int av1_filter_intra_allowed_bsize(const AV1_COMMON *const cm,
69                                                  BLOCK_SIZE bs) {
70   if (!cm->seq_params->enable_filter_intra || bs == BLOCK_INVALID) return 0;
71 
72   return block_size_wide[bs] <= 32 && block_size_high[bs] <= 32;
73 }
74 
av1_filter_intra_allowed(const AV1_COMMON * const cm,const MB_MODE_INFO * mbmi)75 static inline int av1_filter_intra_allowed(const AV1_COMMON *const cm,
76                                            const MB_MODE_INFO *mbmi) {
77   return mbmi->mode == DC_PRED &&
78          mbmi->palette_mode_info.palette_size[0] == 0 &&
79          av1_filter_intra_allowed_bsize(cm, mbmi->bsize);
80 }
81 
82 extern const int8_t av1_filter_intra_taps[FILTER_INTRA_MODES][8][8];
83 
84 static const int16_t dr_intra_derivative[90] = {
85   // More evenly spread out angles and limited to 10-bit
86   // Values that are 0 will never be used
87   //                    Approx angle
88   0,    0, 0,        //
89   1023, 0, 0,        // 3, ...
90   547,  0, 0,        // 6, ...
91   372,  0, 0, 0, 0,  // 9, ...
92   273,  0, 0,        // 14, ...
93   215,  0, 0,        // 17, ...
94   178,  0, 0,        // 20, ...
95   151,  0, 0,        // 23, ... (113 & 203 are base angles)
96   132,  0, 0,        // 26, ...
97   116,  0, 0,        // 29, ...
98   102,  0, 0, 0,     // 32, ...
99   90,   0, 0,        // 36, ...
100   80,   0, 0,        // 39, ...
101   71,   0, 0,        // 42, ...
102   64,   0, 0,        // 45, ... (45 & 135 are base angles)
103   57,   0, 0,        // 48, ...
104   51,   0, 0,        // 51, ...
105   45,   0, 0, 0,     // 54, ...
106   40,   0, 0,        // 58, ...
107   35,   0, 0,        // 61, ...
108   31,   0, 0,        // 64, ...
109   27,   0, 0,        // 67, ... (67 & 157 are base angles)
110   23,   0, 0,        // 70, ...
111   19,   0, 0,        // 73, ...
112   15,   0, 0, 0, 0,  // 76, ...
113   11,   0, 0,        // 81, ...
114   7,    0, 0,        // 84, ...
115   3,    0, 0,        // 87, ...
116 };
117 
118 // Get the shift (up-scaled by 256) in X w.r.t a unit change in Y.
119 // If angle > 0 && angle < 90, dx = -((int)(256 / t));
120 // If angle > 90 && angle < 180, dx = (int)(256 / t);
121 // If angle > 180 && angle < 270, dx = 1;
av1_get_dx(int angle)122 static inline int av1_get_dx(int angle) {
123   if (angle > 0 && angle < 90) {
124     return dr_intra_derivative[angle];
125   } else if (angle > 90 && angle < 180) {
126     return dr_intra_derivative[180 - angle];
127   } else {
128     // In this case, we are not really going to use dx. We may return any value.
129     return 1;
130   }
131 }
132 
133 // Get the shift (up-scaled by 256) in Y w.r.t a unit change in X.
134 // If angle > 0 && angle < 90, dy = 1;
135 // If angle > 90 && angle < 180, dy = (int)(256 * t);
136 // If angle > 180 && angle < 270, dy = -((int)(256 * t));
av1_get_dy(int angle)137 static inline int av1_get_dy(int angle) {
138   if (angle > 90 && angle < 180) {
139     return dr_intra_derivative[angle - 90];
140   } else if (angle > 180 && angle < 270) {
141     return dr_intra_derivative[270 - angle];
142   } else {
143     // In this case, we are not really going to use dy. We may return any value.
144     return 1;
145   }
146 }
147 
av1_use_intra_edge_upsample(int bs0,int bs1,int delta,int type)148 static inline int av1_use_intra_edge_upsample(int bs0, int bs1, int delta,
149                                               int type) {
150   const int d = abs(delta);
151   const int blk_wh = bs0 + bs1;
152   if (d == 0 || d >= 40) return 0;
153   return type ? (blk_wh <= 8) : (blk_wh <= 16);
154 }
155 #ifdef __cplusplus
156 }  // extern "C"
157 #endif
158 #endif  // AOM_AV1_COMMON_RECONINTRA_H_
159