• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(
30     const AV1_COMMON *cm, const MACROBLOCKD *xd, int wpx, int hpx,
31     TX_SIZE tx_size, PREDICTION_MODE mode, int angle_delta, int use_palette,
32     FILTER_INTRA_MODE filter_intra_mode, const uint8_t *ref, int ref_stride,
33     uint8_t *dst, int dst_stride, int col_off, int row_off, int plane);
34 
35 // Mapping of interintra to intra mode for use in the intra component
36 static const PREDICTION_MODE interintra_to_intra_mode[INTERINTRA_MODES] = {
37   DC_PRED, V_PRED, H_PRED, SMOOTH_PRED
38 };
39 
40 // Mapping of intra mode to the interintra mode
41 static const INTERINTRA_MODE intra_to_interintra_mode[INTRA_MODES] = {
42   II_DC_PRED, II_V_PRED, II_H_PRED, II_V_PRED,      II_SMOOTH_PRED, II_V_PRED,
43   II_H_PRED,  II_H_PRED, II_V_PRED, II_SMOOTH_PRED, II_SMOOTH_PRED
44 };
45 
46 #define FILTER_INTRA_SCALE_BITS 4
47 
av1_is_directional_mode(PREDICTION_MODE mode)48 static INLINE int av1_is_directional_mode(PREDICTION_MODE mode) {
49   return mode >= V_PRED && mode <= D67_PRED;
50 }
51 
av1_use_angle_delta(BLOCK_SIZE bsize)52 static INLINE int av1_use_angle_delta(BLOCK_SIZE bsize) {
53   return bsize >= BLOCK_8X8;
54 }
55 
av1_allow_intrabc(const AV1_COMMON * const cm)56 static INLINE int av1_allow_intrabc(const AV1_COMMON *const cm) {
57   return frame_is_intra_only(cm) && cm->features.allow_screen_content_tools &&
58          cm->features.allow_intrabc;
59 }
60 
av1_filter_intra_allowed_bsize(const AV1_COMMON * const cm,BLOCK_SIZE bs)61 static INLINE int av1_filter_intra_allowed_bsize(const AV1_COMMON *const cm,
62                                                  BLOCK_SIZE bs) {
63   if (!cm->seq_params.enable_filter_intra || bs == BLOCK_INVALID) return 0;
64 
65   return block_size_wide[bs] <= 32 && block_size_high[bs] <= 32;
66 }
67 
av1_filter_intra_allowed(const AV1_COMMON * const cm,const MB_MODE_INFO * mbmi)68 static INLINE int av1_filter_intra_allowed(const AV1_COMMON *const cm,
69                                            const MB_MODE_INFO *mbmi) {
70   return mbmi->mode == DC_PRED &&
71          mbmi->palette_mode_info.palette_size[0] == 0 &&
72          av1_filter_intra_allowed_bsize(cm, mbmi->sb_type);
73 }
74 
75 extern const int8_t av1_filter_intra_taps[FILTER_INTRA_MODES][8][8];
76 
77 static const int16_t dr_intra_derivative[90] = {
78   // More evenly spread out angles and limited to 10-bit
79   // Values that are 0 will never be used
80   //                    Approx angle
81   0,    0, 0,        //
82   1023, 0, 0,        // 3, ...
83   547,  0, 0,        // 6, ...
84   372,  0, 0, 0, 0,  // 9, ...
85   273,  0, 0,        // 14, ...
86   215,  0, 0,        // 17, ...
87   178,  0, 0,        // 20, ...
88   151,  0, 0,        // 23, ... (113 & 203 are base angles)
89   132,  0, 0,        // 26, ...
90   116,  0, 0,        // 29, ...
91   102,  0, 0, 0,     // 32, ...
92   90,   0, 0,        // 36, ...
93   80,   0, 0,        // 39, ...
94   71,   0, 0,        // 42, ...
95   64,   0, 0,        // 45, ... (45 & 135 are base angles)
96   57,   0, 0,        // 48, ...
97   51,   0, 0,        // 51, ...
98   45,   0, 0, 0,     // 54, ...
99   40,   0, 0,        // 58, ...
100   35,   0, 0,        // 61, ...
101   31,   0, 0,        // 64, ...
102   27,   0, 0,        // 67, ... (67 & 157 are base angles)
103   23,   0, 0,        // 70, ...
104   19,   0, 0,        // 73, ...
105   15,   0, 0, 0, 0,  // 76, ...
106   11,   0, 0,        // 81, ...
107   7,    0, 0,        // 84, ...
108   3,    0, 0,        // 87, ...
109 };
110 
111 // Get the shift (up-scaled by 256) in X w.r.t a unit change in Y.
112 // If angle > 0 && angle < 90, dx = -((int)(256 / t));
113 // If angle > 90 && angle < 180, dx = (int)(256 / t);
114 // If angle > 180 && angle < 270, dx = 1;
av1_get_dx(int angle)115 static INLINE int av1_get_dx(int angle) {
116   if (angle > 0 && angle < 90) {
117     return dr_intra_derivative[angle];
118   } else if (angle > 90 && angle < 180) {
119     return dr_intra_derivative[180 - angle];
120   } else {
121     // In this case, we are not really going to use dx. We may return any value.
122     return 1;
123   }
124 }
125 
126 // Get the shift (up-scaled by 256) in Y w.r.t a unit change in X.
127 // If angle > 0 && angle < 90, dy = 1;
128 // If angle > 90 && angle < 180, dy = (int)(256 * t);
129 // If angle > 180 && angle < 270, dy = -((int)(256 * t));
av1_get_dy(int angle)130 static INLINE int av1_get_dy(int angle) {
131   if (angle > 90 && angle < 180) {
132     return dr_intra_derivative[angle - 90];
133   } else if (angle > 180 && angle < 270) {
134     return dr_intra_derivative[270 - angle];
135   } else {
136     // In this case, we are not really going to use dy. We may return any value.
137     return 1;
138   }
139 }
140 
av1_use_intra_edge_upsample(int bs0,int bs1,int delta,int type)141 static INLINE int av1_use_intra_edge_upsample(int bs0, int bs1, int delta,
142                                               int type) {
143   const int d = abs(delta);
144   const int blk_wh = bs0 + bs1;
145   if (d == 0 || d >= 40) return 0;
146   return type ? (blk_wh <= 8) : (blk_wh <= 16);
147 }
148 #ifdef __cplusplus
149 }  // extern "C"
150 #endif
151 #endif  // AOM_AV1_COMMON_RECONINTRA_H_
152