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