Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_COMMON_BLOCKD_H_ |
| 13 | #define AV1_COMMON_BLOCKD_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "./aom_config.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 16 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 17 | #include "aom_dsp/aom_dsp_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 18 | #include "aom_ports/mem.h" |
| 19 | #include "aom_scale/yv12config.h" |
| 20 | |
| 21 | #include "av1/common/common_data.h" |
| 22 | #include "av1/common/quant_common.h" |
| 23 | #include "av1/common/entropy.h" |
| 24 | #include "av1/common/entropymode.h" |
| 25 | #include "av1/common/mv.h" |
| 26 | #include "av1/common/scale.h" |
| 27 | #include "av1/common/seg_common.h" |
| 28 | #include "av1/common/tile_common.h" |
Yushin Cho | d0b77ac | 2017-10-20 17:33:16 -0700 | [diff] [blame] | 29 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 30 | #ifdef __cplusplus |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | |
| 34 | #define MAX_MB_PLANE 3 |
| 35 | |
Debargha Mukherjee | 1edf9a3 | 2017-01-07 18:54:20 -0800 | [diff] [blame] | 36 | #if CONFIG_COMPOUND_SEGMENT |
Debargha Mukherjee | 1edf9a3 | 2017-01-07 18:54:20 -0800 | [diff] [blame] | 37 | // Set COMPOUND_SEGMENT_TYPE to one of the three |
| 38 | // 0: Uniform |
| 39 | // 1: Difference weighted |
| 40 | #define COMPOUND_SEGMENT_TYPE 1 |
Debargha Mukherjee | 1edf9a3 | 2017-01-07 18:54:20 -0800 | [diff] [blame] | 41 | #define MAX_SEG_MASK_BITS 1 |
Yaowu Xu | f35f527 | 2017-05-10 08:00:02 -0700 | [diff] [blame] | 42 | |
Sarah Parker | b9f757c | 2017-01-06 17:12:24 -0800 | [diff] [blame] | 43 | // SEG_MASK_TYPES should not surpass 1 << MAX_SEG_MASK_BITS |
| 44 | typedef enum { |
Yaowu Xu | f35f527 | 2017-05-10 08:00:02 -0700 | [diff] [blame] | 45 | #if COMPOUND_SEGMENT_TYPE == 0 |
Sarah Parker | b9f757c | 2017-01-06 17:12:24 -0800 | [diff] [blame] | 46 | UNIFORM_45 = 0, |
| 47 | UNIFORM_45_INV, |
Debargha Mukherjee | 1edf9a3 | 2017-01-07 18:54:20 -0800 | [diff] [blame] | 48 | #elif COMPOUND_SEGMENT_TYPE == 1 |
Sarah Parker | 7bb84f3 | 2017-05-09 15:17:46 -0700 | [diff] [blame] | 49 | DIFFWTD_38 = 0, |
| 50 | DIFFWTD_38_INV, |
Yaowu Xu | f35f527 | 2017-05-10 08:00:02 -0700 | [diff] [blame] | 51 | #endif // COMPOUND_SEGMENT_TYPE |
Debargha Mukherjee | 1edf9a3 | 2017-01-07 18:54:20 -0800 | [diff] [blame] | 52 | SEG_MASK_TYPES, |
| 53 | } SEG_MASK_TYPE; |
| 54 | |
Sarah Parker | b9f757c | 2017-01-06 17:12:24 -0800 | [diff] [blame] | 55 | #endif // CONFIG_COMPOUND_SEGMENT |
David Barker | ac37fa3 | 2016-12-02 12:30:21 +0000 | [diff] [blame] | 56 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 57 | typedef enum { |
| 58 | KEY_FRAME = 0, |
| 59 | INTER_FRAME = 1, |
Soo-Chul Han | 65c00ae | 2017-09-07 13:12:35 -0400 | [diff] [blame] | 60 | #if CONFIG_OBU |
| 61 | INTRA_ONLY_FRAME = 2, // replaces intra-only |
| 62 | S_FRAME = 3, |
| 63 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 64 | FRAME_TYPES, |
| 65 | } FRAME_TYPE; |
| 66 | |
Debargha Mukherjee | 0f248c4 | 2017-09-07 12:40:18 -0700 | [diff] [blame] | 67 | static INLINE int is_comp_ref_allowed(BLOCK_SIZE bsize) { |
| 68 | (void)bsize; |
Debargha Mukherjee | 0f248c4 | 2017-09-07 12:40:18 -0700 | [diff] [blame] | 69 | return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8; |
Debargha Mukherjee | 0f248c4 | 2017-09-07 12:40:18 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 72 | static INLINE int is_inter_mode(PREDICTION_MODE mode) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 73 | return mode >= NEARESTMV && mode <= NEW_NEWMV; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Wei-Ting Lin | 482551b | 2017-08-03 12:29:24 -0700 | [diff] [blame] | 76 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 77 | typedef struct superblock_mi_boundaries { |
| 78 | int mi_row_begin; |
| 79 | int mi_col_begin; |
| 80 | int mi_row_end; |
| 81 | int mi_col_end; |
| 82 | } SB_MI_BD; |
| 83 | |
Wei-Ting Lin | b586de8 | 2017-08-03 15:17:38 -0700 | [diff] [blame] | 84 | typedef struct { int16_t KERNEL[4][MAX_SB_SIZE][MAX_SB_SIZE]; } NCOBMC_KERNELS; |
Wei-Ting Lin | 482551b | 2017-08-03 12:29:24 -0700 | [diff] [blame] | 85 | #endif |
| 86 | |
David Barker | ac37fa3 | 2016-12-02 12:30:21 +0000 | [diff] [blame] | 87 | typedef struct { |
| 88 | uint8_t *plane[MAX_MB_PLANE]; |
| 89 | int stride[MAX_MB_PLANE]; |
| 90 | } BUFFER_SET; |
| 91 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 92 | static INLINE int is_inter_singleref_mode(PREDICTION_MODE mode) { |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 93 | return mode >= NEARESTMV && mode <= NEWMV; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 94 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 95 | static INLINE int is_inter_compound_mode(PREDICTION_MODE mode) { |
| 96 | return mode >= NEAREST_NEARESTMV && mode <= NEW_NEWMV; |
| 97 | } |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 98 | #if CONFIG_COMPOUND_SINGLEREF |
| 99 | static INLINE int is_inter_singleref_comp_mode(PREDICTION_MODE mode) { |
| 100 | return mode >= SR_NEAREST_NEARMV && mode <= SR_NEW_NEWMV; |
| 101 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 102 | static INLINE int is_inter_anyref_comp_mode(PREDICTION_MODE mode) { |
| 103 | return is_inter_compound_mode(mode) || is_inter_singleref_comp_mode(mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 104 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 105 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 106 | |
| 107 | static INLINE PREDICTION_MODE compound_ref0_mode(PREDICTION_MODE mode) { |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 108 | static PREDICTION_MODE lut[] = { |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 109 | MB_MODE_COUNT, // DC_PRED |
| 110 | MB_MODE_COUNT, // V_PRED |
| 111 | MB_MODE_COUNT, // H_PRED |
| 112 | MB_MODE_COUNT, // D45_PRED |
| 113 | MB_MODE_COUNT, // D135_PRED |
| 114 | MB_MODE_COUNT, // D117_PRED |
| 115 | MB_MODE_COUNT, // D153_PRED |
| 116 | MB_MODE_COUNT, // D207_PRED |
| 117 | MB_MODE_COUNT, // D63_PRED |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 118 | MB_MODE_COUNT, // SMOOTH_PRED |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 119 | #if CONFIG_SMOOTH_HV |
| 120 | MB_MODE_COUNT, // SMOOTH_V_PRED |
| 121 | MB_MODE_COUNT, // SMOOTH_H_PRED |
| 122 | #endif // CONFIG_SMOOTH_HV |
Urvang Joshi | 96d1c0a | 2017-10-10 13:15:32 -0700 | [diff] [blame] | 123 | MB_MODE_COUNT, // PAETH_PRED |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 124 | MB_MODE_COUNT, // NEARESTMV |
| 125 | MB_MODE_COUNT, // NEARMV |
| 126 | MB_MODE_COUNT, // ZEROMV |
| 127 | MB_MODE_COUNT, // NEWMV |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 128 | #if CONFIG_COMPOUND_SINGLEREF |
| 129 | NEARESTMV, // SR_NEAREST_NEARMV |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 130 | // NEARESTMV, // SR_NEAREST_NEWMV |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 131 | NEARMV, // SR_NEAR_NEWMV |
| 132 | ZEROMV, // SR_ZERO_NEWMV |
| 133 | NEWMV, // SR_NEW_NEWMV |
| 134 | #endif // CONFIG_COMPOUND_SINGLEREF |
| 135 | NEARESTMV, // NEAREST_NEARESTMV |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 136 | NEARMV, // NEAR_NEARMV |
| 137 | NEARESTMV, // NEAREST_NEWMV |
| 138 | NEWMV, // NEW_NEARESTMV |
| 139 | NEARMV, // NEAR_NEWMV |
| 140 | NEWMV, // NEW_NEARMV |
| 141 | ZEROMV, // ZERO_ZEROMV |
| 142 | NEWMV, // NEW_NEWMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 143 | }; |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 144 | assert(NELEMENTS(lut) == MB_MODE_COUNT); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 145 | #if CONFIG_COMPOUND_SINGLEREF |
| 146 | assert(is_inter_anyref_comp_mode(mode)); |
| 147 | #else // !CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 148 | assert(is_inter_compound_mode(mode)); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 149 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 150 | return lut[mode]; |
| 151 | } |
| 152 | |
| 153 | static INLINE PREDICTION_MODE compound_ref1_mode(PREDICTION_MODE mode) { |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 154 | static PREDICTION_MODE lut[] = { |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 155 | MB_MODE_COUNT, // DC_PRED |
| 156 | MB_MODE_COUNT, // V_PRED |
| 157 | MB_MODE_COUNT, // H_PRED |
| 158 | MB_MODE_COUNT, // D45_PRED |
| 159 | MB_MODE_COUNT, // D135_PRED |
| 160 | MB_MODE_COUNT, // D117_PRED |
| 161 | MB_MODE_COUNT, // D153_PRED |
| 162 | MB_MODE_COUNT, // D207_PRED |
| 163 | MB_MODE_COUNT, // D63_PRED |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 164 | MB_MODE_COUNT, // SMOOTH_PRED |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 165 | #if CONFIG_SMOOTH_HV |
| 166 | MB_MODE_COUNT, // SMOOTH_V_PRED |
| 167 | MB_MODE_COUNT, // SMOOTH_H_PRED |
| 168 | #endif // CONFIG_SMOOTH_HV |
Urvang Joshi | 96d1c0a | 2017-10-10 13:15:32 -0700 | [diff] [blame] | 169 | MB_MODE_COUNT, // PAETH_PRED |
Urvang Joshi | 102245d | 2016-11-28 13:05:36 -0800 | [diff] [blame] | 170 | MB_MODE_COUNT, // NEARESTMV |
| 171 | MB_MODE_COUNT, // NEARMV |
| 172 | MB_MODE_COUNT, // ZEROMV |
| 173 | MB_MODE_COUNT, // NEWMV |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 174 | #if CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 175 | NEARMV, // SR_NEAREST_NEARMV |
| 176 | // NEWMV, // SR_NEAREST_NEWMV |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 177 | NEWMV, // SR_NEAR_NEWMV |
| 178 | NEWMV, // SR_ZERO_NEWMV |
| 179 | NEWMV, // SR_NEW_NEWMV |
| 180 | #endif // CONFIG_COMPOUND_SINGLEREF |
| 181 | NEARESTMV, // NEAREST_NEARESTMV |
Zoe Liu | 239f06b | 2017-04-20 13:10:55 -0700 | [diff] [blame] | 182 | NEARMV, // NEAR_NEARMV |
| 183 | NEWMV, // NEAREST_NEWMV |
| 184 | NEARESTMV, // NEW_NEARESTMV |
| 185 | NEWMV, // NEAR_NEWMV |
| 186 | NEARMV, // NEW_NEARMV |
| 187 | ZEROMV, // ZERO_ZEROMV |
| 188 | NEWMV, // NEW_NEWMV |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 189 | }; |
Urvang Joshi | 5a9ea00 | 2017-05-22 15:25:18 -0700 | [diff] [blame] | 190 | assert(NELEMENTS(lut) == MB_MODE_COUNT); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 191 | #if CONFIG_COMPOUND_SINGLEREF |
| 192 | assert(is_inter_anyref_comp_mode(mode)); |
| 193 | #else // !CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 194 | assert(is_inter_compound_mode(mode)); |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 195 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 196 | return lut[mode]; |
| 197 | } |
| 198 | |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 199 | static INLINE int have_nearmv_in_inter_mode(PREDICTION_MODE mode) { |
Debargha Mukherjee | bb6e134 | 2017-04-17 16:05:04 -0700 | [diff] [blame] | 200 | return (mode == NEARMV || mode == NEAR_NEARMV || mode == NEAR_NEWMV || |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 201 | #if CONFIG_COMPOUND_SINGLEREF |
| 202 | mode == SR_NEAREST_NEARMV || mode == SR_NEAR_NEWMV || |
| 203 | #endif // CONFIG_COMPOUND_SINGLEREF |
Debargha Mukherjee | bb6e134 | 2017-04-17 16:05:04 -0700 | [diff] [blame] | 204 | mode == NEW_NEARMV); |
David Barker | 3dfba99 | 2017-04-03 16:10:09 +0100 | [diff] [blame] | 205 | } |
| 206 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 207 | static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) { |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 208 | return (mode == NEWMV || mode == NEW_NEWMV || mode == NEAREST_NEWMV || |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 209 | #if CONFIG_COMPOUND_SINGLEREF |
| 210 | /* mode == SR_NEAREST_NEWMV || */ mode == SR_NEAR_NEWMV || |
| 211 | mode == SR_ZERO_NEWMV || mode == SR_NEW_NEWMV || |
| 212 | #endif // CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 7f24e1b | 2017-03-17 17:42:05 -0700 | [diff] [blame] | 213 | mode == NEW_NEARESTMV || mode == NEAR_NEWMV || mode == NEW_NEARMV); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 214 | } |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 215 | |
Sarah Parker | 2e60488 | 2017-01-17 17:31:25 -0800 | [diff] [blame] | 216 | static INLINE int use_masked_motion_search(COMPOUND_TYPE type) { |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 217 | #if CONFIG_WEDGE |
Sarah Parker | 2e60488 | 2017-01-17 17:31:25 -0800 | [diff] [blame] | 218 | return (type == COMPOUND_WEDGE); |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 219 | #else |
| 220 | (void)type; |
| 221 | return 0; |
| 222 | #endif |
Sarah Parker | 2e60488 | 2017-01-17 17:31:25 -0800 | [diff] [blame] | 223 | } |
| 224 | |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 225 | static INLINE int is_masked_compound_type(COMPOUND_TYPE type) { |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 226 | #if CONFIG_COMPOUND_SEGMENT && CONFIG_WEDGE |
Sarah Parker | 569edda | 2016-12-14 14:57:38 -0800 | [diff] [blame] | 227 | return (type == COMPOUND_WEDGE || type == COMPOUND_SEG); |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 228 | #elif !CONFIG_COMPOUND_SEGMENT && CONFIG_WEDGE |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 229 | return (type == COMPOUND_WEDGE); |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 230 | #elif CONFIG_COMPOUND_SEGMENT && !CONFIG_WEDGE |
| 231 | return (type == COMPOUND_SEG); |
Sarah Parker | 569edda | 2016-12-14 14:57:38 -0800 | [diff] [blame] | 232 | #endif // CONFIG_COMPOUND_SEGMENT |
Debargha Mukherjee | c5f735f | 2017-04-26 03:25:28 +0000 | [diff] [blame] | 233 | (void)type; |
| 234 | return 0; |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 235 | } |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 236 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 237 | /* For keyframes, intra block modes are predicted by the (already decoded) |
| 238 | modes for the Y blocks to the left and above us; for interframes, there |
| 239 | is a single probability table. */ |
| 240 | |
| 241 | typedef struct { |
| 242 | PREDICTION_MODE as_mode; |
| 243 | int_mv as_mv[2]; // first, second inter predictor motion vectors |
Yaowu Xu | f5bbbfa | 2016-09-26 09:13:38 -0700 | [diff] [blame] | 244 | int_mv pred_mv[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 245 | int_mv ref_mv[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 246 | } b_mode_info; |
| 247 | |
| 248 | typedef int8_t MV_REFERENCE_FRAME; |
| 249 | |
| 250 | typedef struct { |
| 251 | // Number of base colors for Y (0) and UV (1) |
| 252 | uint8_t palette_size[2]; |
hui su | fa4ff85 | 2017-05-15 12:20:50 -0700 | [diff] [blame] | 253 | // Value of base colors for Y, U, and V |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 254 | uint16_t palette_colors[3 * PALETTE_MAX_SIZE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 255 | } PALETTE_MODE_INFO; |
| 256 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 257 | #if CONFIG_FILTER_INTRA |
Yue Chen | 8d8638a | 2017-02-21 13:28:16 +0800 | [diff] [blame] | 258 | #define USE_3TAP_INTRA_FILTER 1 // 0: 4-tap; 1: 3-tap |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 259 | typedef struct { |
| 260 | // 1: an ext intra mode is used; 0: otherwise. |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 261 | uint8_t use_filter_intra_mode[PLANE_TYPES]; |
| 262 | FILTER_INTRA_MODE filter_intra_mode[PLANE_TYPES]; |
| 263 | } FILTER_INTRA_MODE_INFO; |
Yue Chen | 57b8ff6 | 2017-10-10 23:37:31 -0700 | [diff] [blame] | 264 | |
| 265 | static const PREDICTION_MODE fimode_to_intradir[FILTER_INTRA_MODES] = { |
| 266 | DC_PRED, V_PRED, H_PRED, D117_PRED, D153_PRED, DC_PRED |
| 267 | }; |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 268 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 269 | |
Angie Chiang | 7c2b7f2 | 2016-11-07 16:00:00 -0800 | [diff] [blame] | 270 | #if CONFIG_RD_DEBUG |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 271 | #define TXB_COEFF_COST_MAP_SIZE (2 * MAX_MIB_SIZE) |
Angie Chiang | 7c2b7f2 | 2016-11-07 16:00:00 -0800 | [diff] [blame] | 272 | #endif |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 273 | |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 274 | typedef struct RD_STATS { |
| 275 | int rate; |
| 276 | int64_t dist; |
Angie Chiang | 7bbd3b1 | 2017-04-26 11:06:09 -0700 | [diff] [blame] | 277 | // Please be careful of using rdcost, it's not guaranteed to be set all the |
| 278 | // time. |
| 279 | // TODO(angiebird): Create a set of functions to manipulate the RD_STATS. In |
| 280 | // these functions, make sure rdcost is always up-to-date according to |
| 281 | // rate/dist. |
Angie Chiang | 2a2a7dd | 2017-04-25 16:08:47 -0700 | [diff] [blame] | 282 | int64_t rdcost; |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 283 | int64_t sse; |
Angie Chiang | 7bbd3b1 | 2017-04-26 11:06:09 -0700 | [diff] [blame] | 284 | int skip; // sse should equal to dist when skip == 1 |
Jingning Han | 3bce754 | 2017-07-25 10:53:57 -0700 | [diff] [blame] | 285 | int64_t ref_rdcost; |
| 286 | int zero_rate; |
Jingning Han | 1a7f0a8 | 2017-07-27 09:48:05 -0700 | [diff] [blame] | 287 | uint8_t invalid_rate; |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 288 | #if CONFIG_RD_DEBUG |
| 289 | int txb_coeff_cost[MAX_MB_PLANE]; |
| 290 | int txb_coeff_cost_map[MAX_MB_PLANE][TXB_COEFF_COST_MAP_SIZE] |
| 291 | [TXB_COEFF_COST_MAP_SIZE]; |
Angie Chiang | 3963d63 | 2016-11-10 18:41:40 -0800 | [diff] [blame] | 292 | #endif // CONFIG_RD_DEBUG |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 293 | } RD_STATS; |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 294 | |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 295 | // This struct is used to group function args that are commonly |
| 296 | // sent together in functions related to interinter compound modes |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 297 | typedef struct { |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 298 | #if CONFIG_WEDGE |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 299 | int wedge_index; |
| 300 | int wedge_sign; |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 301 | #endif // CONFIG_WEDGE |
Sarah Parker | 569edda | 2016-12-14 14:57:38 -0800 | [diff] [blame] | 302 | #if CONFIG_COMPOUND_SEGMENT |
Sarah Parker | b9f757c | 2017-01-06 17:12:24 -0800 | [diff] [blame] | 303 | SEG_MASK_TYPE mask_type; |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 304 | uint8_t *seg_mask; |
Sarah Parker | 569edda | 2016-12-14 14:57:38 -0800 | [diff] [blame] | 305 | #endif // CONFIG_COMPOUND_SEGMENT |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 306 | COMPOUND_TYPE interinter_compound_type; |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 307 | } INTERINTER_COMPOUND_DATA; |
Sarah Parker | 6fdc853 | 2016-11-16 17:47:13 -0800 | [diff] [blame] | 308 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 309 | // This structure now relates to 8x8 block regions. |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 310 | typedef struct MB_MODE_INFO { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 311 | // Common for both INTER and INTRA blocks |
| 312 | BLOCK_SIZE sb_type; |
| 313 | PREDICTION_MODE mode; |
| 314 | TX_SIZE tx_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 315 | // TODO(jingning): This effectively assigned a separate entry for each |
| 316 | // 8x8 block. Apparently it takes much more space than needed. |
| 317 | TX_SIZE inter_tx_size[MAX_MIB_SIZE][MAX_MIB_SIZE]; |
Jingning Han | e67b38a | 2016-11-04 10:30:00 -0700 | [diff] [blame] | 318 | TX_SIZE min_tx_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 319 | int8_t skip; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 320 | int8_t segment_id; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 321 | int8_t seg_id_predicted; // valid only when temporal_update is enabled |
| 322 | |
Sarah Parker | c5ccd4c | 2017-08-03 11:27:50 -0700 | [diff] [blame] | 323 | #if CONFIG_MRC_TX |
| 324 | int valid_mrc_mask; |
| 325 | #endif // CONFIG_MRC_TX |
| 326 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 327 | // Only for INTRA blocks |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 328 | UV_PREDICTION_MODE uv_mode; |
Urvang Joshi | c6300aa | 2017-06-01 14:46:23 -0700 | [diff] [blame] | 329 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 330 | PALETTE_MODE_INFO palette_mode_info; |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 331 | #if CONFIG_INTRABC |
| 332 | uint8_t use_intrabc; |
| 333 | #endif // CONFIG_INTRABC |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 334 | |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 335 | // Only for INTER blocks |
| 336 | InterpFilters interp_filters; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 337 | MV_REFERENCE_FRAME ref_frame[2]; |
| 338 | TX_TYPE tx_type; |
Angie Chiang | cd9b03f | 2017-04-16 13:37:13 -0700 | [diff] [blame] | 339 | #if CONFIG_TXK_SEL |
Angie Chiang | 808d859 | 2017-04-06 18:36:55 -0700 | [diff] [blame] | 340 | TX_TYPE txk_type[MAX_SB_SQUARE / (TX_SIZE_W_MIN * TX_SIZE_H_MIN)]; |
| 341 | #endif |
Lester Lu | 432012f | 2017-08-17 14:39:29 -0700 | [diff] [blame] | 342 | #if CONFIG_LGT_FROM_PRED |
| 343 | int use_lgt; |
| 344 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 345 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 346 | #if CONFIG_FILTER_INTRA |
| 347 | FILTER_INTRA_MODE_INFO filter_intra_mode_info; |
| 348 | #endif // CONFIG_FILTER_INTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 349 | #if CONFIG_EXT_INTRA |
hui su | eda3d76 | 2016-12-06 16:58:23 -0800 | [diff] [blame] | 350 | // The actual prediction angle is the base angle + (angle_delta * step). |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 351 | int8_t angle_delta[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 352 | #endif // CONFIG_EXT_INTRA |
| 353 | |
Yue Chen | 4d26acb | 2017-05-01 12:28:34 -0700 | [diff] [blame] | 354 | #if CONFIG_INTERINTRA |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 355 | // interintra members |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 356 | INTERINTRA_MODE interintra_mode; |
Yue Chen | 4d26acb | 2017-05-01 12:28:34 -0700 | [diff] [blame] | 357 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 358 | // TODO(debargha): Consolidate these flags |
| 359 | int use_wedge_interintra; |
| 360 | int interintra_wedge_index; |
| 361 | int interintra_wedge_sign; |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 362 | // interinter members |
| 363 | COMPOUND_TYPE interinter_compound_type; |
| 364 | #if CONFIG_WEDGE |
| 365 | int wedge_index; |
| 366 | int wedge_sign; |
| 367 | #endif // CONFIG_WEDGE |
| 368 | #if CONFIG_COMPOUND_SEGMENT |
| 369 | SEG_MASK_TYPE mask_type; |
| 370 | #endif // CONFIG_COMPOUND_SEGMENT |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 371 | MOTION_MODE motion_mode; |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 372 | #if CONFIG_MOTION_VAR |
| 373 | int overlappable_neighbors[2]; |
Wei-Ting Lin | 85a8f70 | 2017-06-22 13:55:15 -0700 | [diff] [blame] | 374 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 375 | // Applying different weighting kernels in ncobmc |
| 376 | // In current implementation, interpolation modes only defined for squared |
| 377 | // blocks. A rectangular block is divided into two squared blocks and each |
| 378 | // squared block has an interpolation mode. |
| 379 | NCOBMC_MODE ncobmc_mode[2]; |
Wei-Ting Lin | 482551b | 2017-08-03 12:29:24 -0700 | [diff] [blame] | 380 | #endif // CONFIG_NCOBMC_ADAPT_WEIGHT |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 381 | #endif // CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 382 | int_mv mv[2]; |
| 383 | int_mv pred_mv[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 384 | uint8_t ref_mv_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 385 | #if CONFIG_EXT_PARTITION_TYPES |
| 386 | PARTITION_TYPE partition; |
| 387 | #endif |
| 388 | #if CONFIG_NEW_QUANT |
| 389 | int dq_off_index; |
| 390 | int send_dq_bit; |
| 391 | #endif // CONFIG_NEW_QUANT |
| 392 | /* deringing gain *per-superblock* */ |
Jean-Marc Valin | 5f5c132 | 2017-03-21 16:20:21 -0400 | [diff] [blame] | 393 | int8_t cdef_strength; |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 394 | int current_q_index; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 395 | #if CONFIG_EXT_DELTA_Q |
| 396 | int current_delta_lf_from_base; |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 397 | #if CONFIG_LOOPFILTER_LEVEL |
| 398 | int curr_delta_lf[FRAME_LF_COUNT]; |
| 399 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 400 | #endif |
Angie Chiang | d402282 | 2016-11-02 18:30:25 -0700 | [diff] [blame] | 401 | #if CONFIG_RD_DEBUG |
Angie Chiang | 9a44f5f | 2016-11-06 12:19:06 -0800 | [diff] [blame] | 402 | RD_STATS rd_stats; |
Angie Chiang | d402282 | 2016-11-02 18:30:25 -0700 | [diff] [blame] | 403 | int mi_row; |
| 404 | int mi_col; |
| 405 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 406 | #if CONFIG_WARPED_MOTION |
| 407 | int num_proj_ref[2]; |
| 408 | WarpedMotionParams wm_params[2]; |
| 409 | #endif // CONFIG_WARPED_MOTION |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 410 | |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 411 | #if CONFIG_CFL |
| 412 | // Index of the alpha Cb and alpha Cr combination |
Luc Trudeau | a9bd85f | 2017-05-11 14:37:56 -0400 | [diff] [blame] | 413 | int cfl_alpha_idx; |
David Michael Barr | f6eaa15 | 2017-07-19 19:42:28 +0900 | [diff] [blame] | 414 | // Joint sign of alpha Cb and alpha Cr |
| 415 | int cfl_alpha_signs; |
Luc Trudeau | f533400 | 2017-04-25 12:21:26 -0400 | [diff] [blame] | 416 | #endif |
| 417 | |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 418 | BOUNDARY_TYPE boundary_info; |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 419 | #if CONFIG_LPF_SB |
| 420 | uint8_t filt_lvl; |
Cheng Chen | 41d37c2 | 2017-09-08 19:00:21 -0700 | [diff] [blame] | 421 | int reuse_sb_lvl; |
| 422 | int sign; |
| 423 | int delta; |
Cheng Chen | f572cd3 | 2017-08-25 18:34:51 -0700 | [diff] [blame] | 424 | #endif |
Cheng Chen | ca6958c | 2017-10-10 14:00:50 -0700 | [diff] [blame^] | 425 | |
| 426 | #if CONFIG_JNT_COMP |
| 427 | int compound_idx; |
| 428 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 429 | } MB_MODE_INFO; |
| 430 | |
| 431 | typedef struct MODE_INFO { |
| 432 | MB_MODE_INFO mbmi; |
| 433 | b_mode_info bmi[4]; |
| 434 | } MODE_INFO; |
| 435 | |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 436 | #if CONFIG_INTRABC |
| 437 | static INLINE int is_intrabc_block(const MB_MODE_INFO *mbmi) { |
| 438 | return mbmi->use_intrabc; |
| 439 | } |
| 440 | #endif |
| 441 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 442 | static INLINE PREDICTION_MODE get_y_mode(const MODE_INFO *mi, int block) { |
Jingning Han | d7d2047 | 2016-12-14 11:13:48 -0800 | [diff] [blame] | 443 | (void)block; |
| 444 | return mi->mbmi.mode; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 447 | #if CONFIG_CFL |
| 448 | static INLINE PREDICTION_MODE get_uv_mode(UV_PREDICTION_MODE mode) { |
| 449 | static const PREDICTION_MODE uv2y[UV_INTRA_MODES] = { |
Urvang Joshi | 93b543a | 2017-06-01 17:32:41 -0700 | [diff] [blame] | 450 | DC_PRED, // UV_DC_PRED |
| 451 | V_PRED, // UV_V_PRED |
| 452 | H_PRED, // UV_H_PRED |
| 453 | D45_PRED, // UV_D45_PRED |
| 454 | D135_PRED, // UV_D135_PRED |
| 455 | D117_PRED, // UV_D117_PRED |
| 456 | D153_PRED, // UV_D153_PRED |
| 457 | D207_PRED, // UV_D207_PRED |
| 458 | D63_PRED, // UV_D63_PRED |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 459 | SMOOTH_PRED, // UV_SMOOTH_PRED |
| 460 | #if CONFIG_SMOOTH_HV |
| 461 | SMOOTH_V_PRED, // UV_SMOOTH_V_PRED |
| 462 | SMOOTH_H_PRED, // UV_SMOOTH_H_PRED |
| 463 | #endif // CONFIG_SMOOTH_HV |
Urvang Joshi | 96d1c0a | 2017-10-10 13:15:32 -0700 | [diff] [blame] | 464 | PAETH_PRED, // UV_PAETH_PRED |
Luc Trudeau | 6e1cd78 | 2017-06-21 13:52:36 -0400 | [diff] [blame] | 465 | DC_PRED, // CFL_PRED |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 466 | }; |
| 467 | return uv2y[mode]; |
| 468 | } |
| 469 | #else |
| 470 | static INLINE PREDICTION_MODE get_uv_mode(PREDICTION_MODE mode) { return mode; } |
| 471 | #endif // CONFIG_CFL |
| 472 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 473 | static INLINE int is_inter_block(const MB_MODE_INFO *mbmi) { |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 474 | #if CONFIG_INTRABC |
| 475 | if (is_intrabc_block(mbmi)) return 1; |
| 476 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 477 | return mbmi->ref_frame[0] > INTRA_FRAME; |
| 478 | } |
| 479 | |
| 480 | static INLINE int has_second_ref(const MB_MODE_INFO *mbmi) { |
| 481 | return mbmi->ref_frame[1] > INTRA_FRAME; |
| 482 | } |
| 483 | |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 484 | #if CONFIG_EXT_COMP_REFS |
| 485 | static INLINE int has_uni_comp_refs(const MB_MODE_INFO *mbmi) { |
| 486 | return has_second_ref(mbmi) && (!((mbmi->ref_frame[0] >= BWDREF_FRAME) ^ |
| 487 | (mbmi->ref_frame[1] >= BWDREF_FRAME))); |
| 488 | } |
| 489 | |
| 490 | static INLINE MV_REFERENCE_FRAME comp_ref0(int ref_idx) { |
| 491 | static const MV_REFERENCE_FRAME lut[] = { |
| 492 | LAST_FRAME, // LAST_LAST2_FRAMES, |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 493 | LAST_FRAME, // LAST_LAST3_FRAMES, |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 494 | LAST_FRAME, // LAST_GOLDEN_FRAMES, |
| 495 | BWDREF_FRAME, // BWDREF_ALTREF_FRAMES, |
| 496 | }; |
| 497 | assert(NELEMENTS(lut) == UNIDIR_COMP_REFS); |
| 498 | return lut[ref_idx]; |
| 499 | } |
| 500 | |
| 501 | static INLINE MV_REFERENCE_FRAME comp_ref1(int ref_idx) { |
| 502 | static const MV_REFERENCE_FRAME lut[] = { |
| 503 | LAST2_FRAME, // LAST_LAST2_FRAMES, |
Zoe Liu | fcf5fa2 | 2017-06-26 16:00:38 -0700 | [diff] [blame] | 504 | LAST3_FRAME, // LAST_LAST3_FRAMES, |
Zoe Liu | c082bbc | 2017-05-17 13:31:37 -0700 | [diff] [blame] | 505 | GOLDEN_FRAME, // LAST_GOLDEN_FRAMES, |
| 506 | ALTREF_FRAME, // BWDREF_ALTREF_FRAMES, |
| 507 | }; |
| 508 | assert(NELEMENTS(lut) == UNIDIR_COMP_REFS); |
| 509 | return lut[ref_idx]; |
| 510 | } |
| 511 | #endif // CONFIG_EXT_COMP_REFS |
| 512 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 513 | PREDICTION_MODE av1_left_block_mode(const MODE_INFO *cur_mi, |
| 514 | const MODE_INFO *left_mi, int b); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 515 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 516 | PREDICTION_MODE av1_above_block_mode(const MODE_INFO *cur_mi, |
| 517 | const MODE_INFO *above_mi, int b); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 518 | |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 519 | #if CONFIG_GLOBAL_MOTION |
| 520 | static INLINE int is_global_mv_block(const MODE_INFO *mi, int block, |
| 521 | TransformationType type) { |
| 522 | PREDICTION_MODE mode = get_y_mode(mi, block); |
| 523 | #if GLOBAL_SUB8X8_USED |
| 524 | const int block_size_allowed = 1; |
| 525 | #else |
| 526 | const BLOCK_SIZE bsize = mi->mbmi.sb_type; |
Debargha Mukherjee | c17a443 | 2017-08-28 22:22:45 -0700 | [diff] [blame] | 527 | const int block_size_allowed = |
| 528 | AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8; |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 529 | #endif // GLOBAL_SUB8X8_USED |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 530 | return (mode == ZEROMV || mode == ZERO_ZEROMV) && type > TRANSLATION && |
| 531 | block_size_allowed; |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 532 | } |
| 533 | #endif // CONFIG_GLOBAL_MOTION |
| 534 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 535 | enum mv_precision { MV_PRECISION_Q3, MV_PRECISION_Q4 }; |
| 536 | |
| 537 | struct buf_2d { |
| 538 | uint8_t *buf; |
| 539 | uint8_t *buf0; |
| 540 | int width; |
| 541 | int height; |
| 542 | int stride; |
| 543 | }; |
| 544 | |
| 545 | typedef struct macroblockd_plane { |
| 546 | tran_low_t *dqcoeff; |
| 547 | PLANE_TYPE plane_type; |
| 548 | int subsampling_x; |
| 549 | int subsampling_y; |
| 550 | struct buf_2d dst; |
| 551 | struct buf_2d pre[2]; |
| 552 | ENTROPY_CONTEXT *above_context; |
| 553 | ENTROPY_CONTEXT *left_context; |
| 554 | int16_t seg_dequant[MAX_SEGMENTS][2]; |
| 555 | #if CONFIG_NEW_QUANT |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 556 | dequant_val_type_nuq seg_dequant_nuq[MAX_SEGMENTS][QUANT_PROFILES] |
| 557 | [COEF_BANDS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 558 | #endif |
| 559 | uint8_t *color_index_map; |
| 560 | |
| 561 | // number of 4x4s in current block |
| 562 | uint16_t n4_w, n4_h; |
| 563 | // log2 of n4_w, n4_h |
| 564 | uint8_t n4_wl, n4_hl; |
Jingning Han | c47fe6c | 2016-10-21 16:40:47 -0700 | [diff] [blame] | 565 | // block size in pixels |
| 566 | uint8_t width, height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 567 | |
| 568 | #if CONFIG_AOM_QM |
Thomas Davies | dd3cf83 | 2017-10-20 15:49:57 +0100 | [diff] [blame] | 569 | qm_val_t *seg_iqmatrix[MAX_SEGMENTS][TX_SIZES_ALL]; |
| 570 | qm_val_t *seg_qmatrix[MAX_SEGMENTS][TX_SIZES_ALL]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 571 | #endif |
| 572 | // encoder |
| 573 | const int16_t *dequant; |
| 574 | #if CONFIG_NEW_QUANT |
| 575 | const dequant_val_type_nuq *dequant_val_nuq[QUANT_PROFILES]; |
| 576 | #endif // CONFIG_NEW_QUANT |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 577 | |
Yushin Cho | d0b77ac | 2017-10-20 17:33:16 -0700 | [diff] [blame] | 578 | #if CONFIG_DIST_8X8 |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 579 | DECLARE_ALIGNED(16, int16_t, pred[MAX_SB_SQUARE]); |
Yushin Cho | b7b60c5 | 2017-07-14 16:18:52 -0700 | [diff] [blame] | 580 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 581 | } MACROBLOCKD_PLANE; |
| 582 | |
Jingning Han | 3468df1 | 2016-12-05 17:53:16 -0800 | [diff] [blame] | 583 | #define BLOCK_OFFSET(x, i) \ |
| 584 | ((x) + (i) * (1 << (tx_size_wide_log2[0] + tx_size_high_log2[0]))) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 585 | |
| 586 | typedef struct RefBuffer { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 587 | int idx; |
| 588 | YV12_BUFFER_CONFIG *buf; |
| 589 | struct scale_factors sf; |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 590 | #if CONFIG_VAR_REFS |
Zoe Liu | 7b1ec7a | 2017-05-24 22:28:24 -0700 | [diff] [blame] | 591 | int is_valid; |
| 592 | #endif // CONFIG_VAR_REFS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 593 | } RefBuffer; |
| 594 | |
Yi Luo | 2ab63cb | 2017-05-11 16:44:22 -0700 | [diff] [blame] | 595 | #if CONFIG_ADAPT_SCAN |
| 596 | typedef int16_t EobThresholdMD[TX_TYPES][EOB_THRESHOLD_NUM]; |
| 597 | #endif |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 598 | |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 599 | #if CONFIG_LOOP_RESTORATION |
| 600 | typedef struct { |
| 601 | DECLARE_ALIGNED(16, InterpKernel, vfilter); |
| 602 | DECLARE_ALIGNED(16, InterpKernel, hfilter); |
| 603 | } WienerInfo; |
| 604 | |
| 605 | typedef struct { |
| 606 | int ep; |
| 607 | int xqd[2]; |
| 608 | } SgrprojInfo; |
| 609 | #endif // CONFIG_LOOP_RESTORATION |
| 610 | |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 611 | #if CONFIG_CFL |
Hui Su | 9fa9623 | 2017-10-23 15:46:04 -0700 | [diff] [blame] | 612 | #if CONFIG_DEBUG |
Luc Trudeau | 03b7e7d | 2017-09-19 13:20:52 -0400 | [diff] [blame] | 613 | #define CFL_SUB8X8_VAL_MI_SIZE (4) |
| 614 | #define CFL_SUB8X8_VAL_MI_SQUARE \ |
| 615 | (CFL_SUB8X8_VAL_MI_SIZE * CFL_SUB8X8_VAL_MI_SIZE) |
Hui Su | 9fa9623 | 2017-10-23 15:46:04 -0700 | [diff] [blame] | 616 | #endif // CONFIG_DEBUG |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 617 | typedef struct cfl_ctx { |
Luc Trudeau | 4e26d66 | 2017-09-11 13:08:40 -0400 | [diff] [blame] | 618 | // The CfL prediction buffer is used in two steps: |
| 619 | // 1. Stores Q3 reconstructed luma pixels |
| 620 | // (only Q2 is required, but Q3 is used to avoid shifts) |
| 621 | // 2. Stores Q3 AC contributions (step1 - tx block avg) |
| 622 | int16_t pred_buf_q3[MAX_SB_SQUARE]; |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 623 | |
Luc Trudeau | 4e26d66 | 2017-09-11 13:08:40 -0400 | [diff] [blame] | 624 | // Height and width currently used in the CfL prediction buffer. |
| 625 | int buf_height, buf_width; |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 626 | |
| 627 | // Height and width of the chroma prediction block currently associated with |
| 628 | // this context |
| 629 | int uv_height, uv_width; |
| 630 | |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 631 | int are_parameters_computed; |
| 632 | |
| 633 | // Chroma subsampling |
| 634 | int subsampling_x, subsampling_y; |
| 635 | |
| 636 | // Block level DC_PRED for each chromatic plane |
| 637 | int dc_pred[CFL_PRED_PLANES]; |
| 638 | |
| 639 | int mi_row, mi_col; |
| 640 | |
| 641 | // Whether the reconstructed luma pixels need to be stored |
| 642 | int store_y; |
| 643 | |
David Michael Barr | 1f8d095 | 2017-10-11 17:46:39 +0900 | [diff] [blame] | 644 | #if CONFIG_DEBUG |
| 645 | int rate; |
| 646 | #endif // CONFIG_DEBUG |
| 647 | |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 648 | int is_chroma_reference; |
Hui Su | 9fa9623 | 2017-10-23 15:46:04 -0700 | [diff] [blame] | 649 | #if CONFIG_DEBUG |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 650 | // The prediction used for sub8x8 blocks originates from multiple luma blocks, |
| 651 | // this array is used to validate that cfl_store() is called only once for |
| 652 | // each luma block |
Luc Trudeau | 03b7e7d | 2017-09-19 13:20:52 -0400 | [diff] [blame] | 653 | uint8_t sub8x8_val[CFL_SUB8X8_VAL_MI_SQUARE]; |
Hui Su | 9fa9623 | 2017-10-23 15:46:04 -0700 | [diff] [blame] | 654 | #endif // CONFIG_DEBUG |
David Michael Barr | 5b2021e | 2017-08-17 18:12:39 +0900 | [diff] [blame] | 655 | } CFL_CTX; |
| 656 | #endif // CONFIG_CFL |
| 657 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 658 | typedef struct macroblockd { |
| 659 | struct macroblockd_plane plane[MAX_MB_PLANE]; |
| 660 | uint8_t bmode_blocks_wl; |
| 661 | uint8_t bmode_blocks_hl; |
| 662 | |
| 663 | FRAME_COUNTS *counts; |
| 664 | TileInfo tile; |
| 665 | |
| 666 | int mi_stride; |
| 667 | |
| 668 | MODE_INFO **mi; |
| 669 | MODE_INFO *left_mi; |
| 670 | MODE_INFO *above_mi; |
| 671 | MB_MODE_INFO *left_mbmi; |
| 672 | MB_MODE_INFO *above_mbmi; |
| 673 | |
| 674 | int up_available; |
| 675 | int left_available; |
Jingning Han | 3da18d6 | 2017-05-02 12:43:58 -0700 | [diff] [blame] | 676 | int chroma_up_available; |
| 677 | int chroma_left_available; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 678 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 679 | const aom_prob (*partition_probs)[PARTITION_TYPES - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 680 | |
Rupert Swarbrick | 57486c5 | 2017-08-14 10:53:49 +0100 | [diff] [blame] | 681 | /* Distance of MB away from frame edges in subpixels (1/8th pixel) */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 682 | int mb_to_left_edge; |
| 683 | int mb_to_right_edge; |
| 684 | int mb_to_top_edge; |
| 685 | int mb_to_bottom_edge; |
| 686 | |
| 687 | FRAME_CONTEXT *fc; |
| 688 | |
| 689 | /* pointers to reference frames */ |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 690 | const RefBuffer *block_refs[2]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 691 | |
| 692 | /* pointer to current frame */ |
| 693 | const YV12_BUFFER_CONFIG *cur_buf; |
| 694 | |
Alex Converse | e816b31 | 2017-05-01 09:51:24 -0700 | [diff] [blame] | 695 | #if CONFIG_INTRABC |
| 696 | /* Scale of the current frame with respect to itself */ |
| 697 | struct scale_factors sf_identity; |
| 698 | #endif |
| 699 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 700 | ENTROPY_CONTEXT *above_context[MAX_MB_PLANE]; |
| 701 | ENTROPY_CONTEXT left_context[MAX_MB_PLANE][2 * MAX_MIB_SIZE]; |
| 702 | |
| 703 | PARTITION_CONTEXT *above_seg_context; |
| 704 | PARTITION_CONTEXT left_seg_context[MAX_MIB_SIZE]; |
| 705 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 706 | TXFM_CONTEXT *above_txfm_context; |
| 707 | TXFM_CONTEXT *left_txfm_context; |
Jingning Han | 331662e | 2017-05-30 17:03:32 -0700 | [diff] [blame] | 708 | TXFM_CONTEXT left_txfm_context_buffer[2 * MAX_MIB_SIZE]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 709 | |
Rupert Swarbrick | 6c54521 | 2017-09-01 17:17:25 +0100 | [diff] [blame] | 710 | #if CONFIG_LOOP_RESTORATION |
| 711 | WienerInfo wiener_info[MAX_MB_PLANE]; |
| 712 | SgrprojInfo sgrproj_info[MAX_MB_PLANE]; |
| 713 | #endif // CONFIG_LOOP_RESTORATION |
| 714 | |
Jingning Han | ff6ee6a | 2016-12-07 09:55:21 -0800 | [diff] [blame] | 715 | // block dimension in the unit of mode_info. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 716 | uint8_t n8_w, n8_h; |
| 717 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 718 | uint8_t ref_mv_count[MODE_CTX_REF_FRAMES]; |
| 719 | CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE]; |
| 720 | uint8_t is_sec_rect; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 721 | |
Thomas Davies | f77d4ad | 2017-01-10 18:55:42 +0000 | [diff] [blame] | 722 | FRAME_CONTEXT *tile_ctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 723 | /* Bit depth: 8, 10, 12 */ |
| 724 | int bd; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 725 | |
Debargha Mukherjee | 3c42c09 | 2016-09-29 09:17:36 -0700 | [diff] [blame] | 726 | int qindex[MAX_SEGMENTS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 727 | int lossless[MAX_SEGMENTS]; |
| 728 | int corrupted; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 729 | #if CONFIG_AMVR |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 730 | int cur_frame_force_integer_mv; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 731 | // same with that in AV1_COMMON |
| 732 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 733 | struct aom_internal_error_info *error_info; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 734 | #if CONFIG_GLOBAL_MOTION |
David Barker | cf3d0b0 | 2016-11-10 10:14:49 +0000 | [diff] [blame] | 735 | WarpedMotionParams *global_motion; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 736 | #endif // CONFIG_GLOBAL_MOTION |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 737 | int prev_qindex; |
| 738 | int delta_qindex; |
| 739 | int current_qindex; |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 740 | #if CONFIG_EXT_DELTA_Q |
| 741 | // Since actual frame level loop filtering level value is not available |
| 742 | // at the beginning of the tile (only available during actual filtering) |
| 743 | // at encoder side.we record the delta_lf (against the frame level loop |
| 744 | // filtering level) and code the delta between previous superblock's delta |
| 745 | // lf and current delta lf. It is equivalent to the delta between previous |
| 746 | // superblock's actual lf and current lf. |
| 747 | int prev_delta_lf_from_base; |
| 748 | int current_delta_lf_from_base; |
Cheng Chen | a97394f | 2017-09-27 15:05:14 -0700 | [diff] [blame] | 749 | #if CONFIG_LOOPFILTER_LEVEL |
| 750 | // For this experiment, we have four frame filter levels for different plane |
| 751 | // and direction. So, to support the per superblock update, we need to add |
| 752 | // a few more params as below. |
| 753 | // 0: delta loop filter level for y plane vertical |
| 754 | // 1: delta loop filter level for y plane horizontal |
| 755 | // 2: delta loop filter level for u plane |
| 756 | // 3: delta loop filter level for v plane |
| 757 | // To make it consistent with the reference to each filter level in segment, |
| 758 | // we need to -1, since |
| 759 | // SEG_LVL_ALT_LF_Y_V = 1; |
| 760 | // SEG_LVL_ALT_LF_Y_H = 2; |
| 761 | // SEG_LVL_ALT_LF_U = 3; |
| 762 | // SEG_LVL_ALT_LF_V = 4; |
| 763 | int prev_delta_lf[FRAME_LF_COUNT]; |
| 764 | int curr_delta_lf[FRAME_LF_COUNT]; |
| 765 | #endif // CONFIG_LOOPFILTER_LEVEL |
Fangwen Fu | 231fe42 | 2017-04-24 17:52:29 -0700 | [diff] [blame] | 766 | #endif |
Yi Luo | f8e87b4 | 2017-04-14 17:20:27 -0700 | [diff] [blame] | 767 | #if CONFIG_ADAPT_SCAN |
| 768 | const EobThresholdMD *eob_threshold_md; |
| 769 | #endif |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 770 | |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 771 | #if CONFIG_COMPOUND_SEGMENT |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 772 | DECLARE_ALIGNED(16, uint8_t, seg_mask[2 * MAX_SB_SQUARE]); |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 773 | #endif // CONFIG_COMPOUND_SEGMENT |
Sarah Parker | 2d0e9b7 | 2017-05-04 01:34:16 +0000 | [diff] [blame] | 774 | |
Sarah Parker | 5c6744b | 2017-08-25 17:27:45 -0700 | [diff] [blame] | 775 | #if CONFIG_MRC_TX |
| 776 | uint8_t *mrc_mask; |
| 777 | #endif // CONFIG_MRC_TX |
| 778 | |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 779 | #if CONFIG_CFL |
| 780 | CFL_CTX *cfl; |
| 781 | #endif |
Wei-Ting Lin | 482551b | 2017-08-03 12:29:24 -0700 | [diff] [blame] | 782 | |
| 783 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 784 | uint8_t *ncobmc_pred_buf[MAX_MB_PLANE]; |
| 785 | int ncobmc_pred_buf_stride[MAX_MB_PLANE]; |
| 786 | SB_MI_BD sb_mi_bd; |
| 787 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 788 | } MACROBLOCKD; |
| 789 | |
Yi Luo | 5128109 | 2017-06-26 16:36:15 -0700 | [diff] [blame] | 790 | static INLINE int get_bitdepth_data_path_index(const MACROBLOCKD *xd) { |
| 791 | return xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH ? 1 : 0; |
| 792 | } |
| 793 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 794 | static INLINE BLOCK_SIZE get_subsize(BLOCK_SIZE bsize, |
| 795 | PARTITION_TYPE partition) { |
| 796 | if (partition == PARTITION_INVALID) |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 797 | return BLOCK_INVALID; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 798 | else |
| 799 | return subsize_lookup[partition][bsize]; |
| 800 | } |
| 801 | |
| 802 | static const TX_TYPE intra_mode_to_tx_type_context[INTRA_MODES] = { |
| 803 | DCT_DCT, // DC |
| 804 | ADST_DCT, // V |
| 805 | DCT_ADST, // H |
| 806 | DCT_DCT, // D45 |
| 807 | ADST_ADST, // D135 |
| 808 | ADST_DCT, // D117 |
| 809 | DCT_ADST, // D153 |
| 810 | DCT_ADST, // D207 |
| 811 | ADST_DCT, // D63 |
Urvang Joshi | 6be4a54 | 2016-11-03 15:24:05 -0700 | [diff] [blame] | 812 | ADST_ADST, // SMOOTH |
Urvang Joshi | e6ca8e8 | 2017-03-15 14:57:41 -0700 | [diff] [blame] | 813 | #if CONFIG_SMOOTH_HV |
| 814 | ADST_DCT, // SMOOTH_V |
| 815 | DCT_ADST, // SMOOTH_H |
| 816 | #endif // CONFIG_SMOOTH_HV |
Urvang Joshi | 96d1c0a | 2017-10-10 13:15:32 -0700 | [diff] [blame] | 817 | ADST_ADST, // PAETH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 818 | }; |
| 819 | |
Jingning Han | b83e64b | 2017-03-01 14:52:04 -0800 | [diff] [blame] | 820 | #define USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4 1 |
Debargha Mukherjee | 5a488a6 | 2016-11-22 22:24:10 -0800 | [diff] [blame] | 821 | |
Sarah Parker | 076437f | 2017-03-14 17:39:53 -0700 | [diff] [blame] | 822 | #if CONFIG_RECT_TX |
Sarah Parker | 076437f | 2017-03-14 17:39:53 -0700 | [diff] [blame] | 823 | static INLINE int is_rect_tx(TX_SIZE tx_size) { return tx_size >= TX_SIZES; } |
| 824 | #endif // CONFIG_RECT_TX |
| 825 | |
Rupert Swarbrick | fcff0b2 | 2017-10-05 09:26:04 +0100 | [diff] [blame] | 826 | static INLINE int block_signals_txsize(BLOCK_SIZE bsize) { |
Sebastien Alaiwan | fb83877 | 2017-10-24 12:02:54 +0200 | [diff] [blame] | 827 | #if CONFIG_RECT_TX |
Rupert Swarbrick | fcff0b2 | 2017-10-05 09:26:04 +0100 | [diff] [blame] | 828 | return bsize > BLOCK_4X4; |
| 829 | #else |
| 830 | return bsize >= BLOCK_8X8; |
| 831 | #endif |
| 832 | } |
| 833 | |
Sarah Parker | 2e08d96 | 2017-08-01 19:51:20 -0700 | [diff] [blame] | 834 | #if CONFIG_MRC_TX |
| 835 | #define USE_MRC_INTRA 0 |
| 836 | #define USE_MRC_INTER 1 |
Sarah Parker | 99e7daa | 2017-08-29 10:30:13 -0700 | [diff] [blame] | 837 | #define SIGNAL_MRC_MASK_INTRA (USE_MRC_INTRA && 0) |
| 838 | #define SIGNAL_MRC_MASK_INTER (USE_MRC_INTER && 1) |
| 839 | #define SIGNAL_ANY_MRC_MASK (SIGNAL_MRC_MASK_INTRA || SIGNAL_MRC_MASK_INTER) |
Sarah Parker | 2e08d96 | 2017-08-01 19:51:20 -0700 | [diff] [blame] | 840 | #endif // CONFIG_MRC_TX |
| 841 | |
Jingning Han | b83e64b | 2017-03-01 14:52:04 -0800 | [diff] [blame] | 842 | #if CONFIG_EXT_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 843 | #define ALLOW_INTRA_EXT_TX 1 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 844 | |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 845 | // Number of transform types in each set type |
| 846 | static const int av1_num_ext_tx_set[EXT_TX_SET_TYPES] = { |
| 847 | 1, 2, |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 848 | #if CONFIG_MRC_TX |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 849 | 2, 3, |
| 850 | #endif // CONFIG_MRC_TX |
| 851 | 5, 7, 12, 16, |
| 852 | }; |
| 853 | |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame] | 854 | static const int av1_ext_tx_set_idx_to_type[2][AOMMAX(EXT_TX_SETS_INTRA, |
| 855 | EXT_TX_SETS_INTER)] = { |
| 856 | { |
| 857 | // Intra |
| 858 | EXT_TX_SET_DCTONLY, EXT_TX_SET_DTT4_IDTX_1DDCT, EXT_TX_SET_DTT4_IDTX, |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 859 | #if CONFIG_MRC_TX |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame] | 860 | EXT_TX_SET_MRC_DCT, |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 861 | #endif // CONFIG_MRC_TX |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame] | 862 | }, |
| 863 | { |
| 864 | // Inter |
| 865 | EXT_TX_SET_DCTONLY, EXT_TX_SET_ALL16, EXT_TX_SET_DTT9_IDTX_1DDCT, |
| 866 | EXT_TX_SET_DCT_IDTX, |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 867 | #if CONFIG_MRC_TX |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame] | 868 | EXT_TX_SET_MRC_DCT_IDTX, |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 869 | #endif // CONFIG_MRC_TX |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame] | 870 | } |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 871 | }; |
| 872 | |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 873 | #if CONFIG_MRC_TX |
| 874 | static const int av1_ext_tx_used[EXT_TX_SET_TYPES][TX_TYPES] = { |
| 875 | { |
| 876 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 877 | }, |
| 878 | { |
| 879 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, |
| 880 | }, |
| 881 | { |
| 882 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, |
| 883 | }, |
| 884 | { |
| 885 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, |
| 886 | }, |
| 887 | { |
| 888 | 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, |
| 889 | }, |
| 890 | { |
| 891 | 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, |
| 892 | }, |
| 893 | { |
| 894 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, |
| 895 | }, |
| 896 | { |
| 897 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, |
| 898 | }, |
| 899 | }; |
| 900 | #else // CONFIG_MRC_TX |
| 901 | static const int av1_ext_tx_used[EXT_TX_SET_TYPES][TX_TYPES] = { |
| 902 | { |
| 903 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 904 | }, |
| 905 | { |
| 906 | 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, |
| 907 | }, |
| 908 | { |
| 909 | 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, |
| 910 | }, |
| 911 | { |
| 912 | 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, |
| 913 | }, |
| 914 | { |
| 915 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, |
| 916 | }, |
| 917 | { |
| 918 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 919 | }, |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 920 | }; |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 921 | #endif // CONFIG_MRC_TX |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 922 | |
| 923 | static INLINE TxSetType get_ext_tx_set_type(TX_SIZE tx_size, BLOCK_SIZE bs, |
Sarah Parker | 5effe3f | 2017-02-23 12:49:10 -0800 | [diff] [blame] | 924 | int is_inter, int use_reduced_set) { |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 925 | const TX_SIZE tx_size_sqr_up = txsize_sqr_up_map[tx_size]; |
| 926 | const TX_SIZE tx_size_sqr = txsize_sqr_map[tx_size]; |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 927 | #if USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4 |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 928 | (void)bs; |
Debargha Mukherjee | 570423c | 2017-10-01 00:35:20 -0700 | [diff] [blame] | 929 | if (tx_size_sqr_up > TX_32X32) return EXT_TX_SET_DCTONLY; |
Jingning Han | 1a00cff | 2016-12-28 14:53:14 -0800 | [diff] [blame] | 930 | #else |
Debargha Mukherjee | 570423c | 2017-10-01 00:35:20 -0700 | [diff] [blame] | 931 | if (tx_size_sqr_up > TX_32X32 || bs < BLOCK_8X8) return EXT_TX_SET_DCTONLY; |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 932 | #endif // USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4 |
Sarah Parker | 5effe3f | 2017-02-23 12:49:10 -0800 | [diff] [blame] | 933 | if (use_reduced_set) |
| 934 | return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DTT4_IDTX; |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 935 | #if CONFIG_MRC_TX |
Sarah Parker | 2e08d96 | 2017-08-01 19:51:20 -0700 | [diff] [blame] | 936 | if (tx_size == TX_32X32) { |
| 937 | if (is_inter && USE_MRC_INTER) |
| 938 | return EXT_TX_SET_MRC_DCT_IDTX; |
| 939 | else if (!is_inter && USE_MRC_INTRA) |
| 940 | return EXT_TX_SET_MRC_DCT; |
| 941 | } |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 942 | #endif // CONFIG_MRC_TX |
Nathan E. Egge | f73e47e | 2017-10-22 06:41:55 -0400 | [diff] [blame] | 943 | #if CONFIG_DAALA_TX32 |
| 944 | if (tx_size_sqr_up > TX_32X32) |
| 945 | return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DCTONLY; |
| 946 | if (is_inter) |
| 947 | return (tx_size_sqr >= TX_16X16 ? EXT_TX_SET_DTT9_IDTX_1DDCT |
| 948 | : EXT_TX_SET_ALL16); |
| 949 | else |
| 950 | return (tx_size_sqr >= TX_16X16 ? EXT_TX_SET_DTT4_IDTX |
| 951 | : EXT_TX_SET_DTT4_IDTX_1DDCT); |
| 952 | #endif |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 953 | if (tx_size_sqr_up == TX_32X32) |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 954 | return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DCTONLY; |
| 955 | if (is_inter) |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 956 | return (tx_size_sqr == TX_16X16 ? EXT_TX_SET_DTT9_IDTX_1DDCT |
| 957 | : EXT_TX_SET_ALL16); |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 958 | else |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 959 | return (tx_size_sqr == TX_16X16 ? EXT_TX_SET_DTT4_IDTX |
| 960 | : EXT_TX_SET_DTT4_IDTX_1DDCT); |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 961 | } |
| 962 | |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame] | 963 | // Maps tx set types to the indices. |
| 964 | static const int ext_tx_set_index[2][EXT_TX_SET_TYPES] = { |
| 965 | { |
| 966 | // Intra |
| 967 | 0, -1, |
| 968 | #if CONFIG_MRC_TX |
| 969 | 3, -1, |
| 970 | #endif // CONFIG_MRC_TX |
| 971 | 2, 1, -1, -1, |
| 972 | }, |
| 973 | { |
| 974 | // Inter |
| 975 | 0, 3, |
| 976 | #if CONFIG_MRC_TX |
| 977 | -1, 4, |
| 978 | #endif // CONFIG_MRC_TX |
| 979 | -1, -1, 2, 1, |
| 980 | }, |
| 981 | }; |
| 982 | |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 983 | static INLINE int get_ext_tx_set(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter, |
Sarah Parker | 5effe3f | 2017-02-23 12:49:10 -0800 | [diff] [blame] | 984 | int use_reduced_set) { |
Debargha Mukherjee | 08542b9 | 2017-02-21 01:08:14 -0800 | [diff] [blame] | 985 | const TxSetType set_type = |
Sarah Parker | 5effe3f | 2017-02-23 12:49:10 -0800 | [diff] [blame] | 986 | get_ext_tx_set_type(tx_size, bs, is_inter, use_reduced_set); |
Hui Su | 4a9be2a | 2017-09-19 14:41:49 -0700 | [diff] [blame] | 987 | return ext_tx_set_index[is_inter][set_type]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Sarah Parker | e68a3e4 | 2017-02-16 14:03:24 -0800 | [diff] [blame] | 990 | static INLINE int get_ext_tx_types(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter, |
Sarah Parker | 5effe3f | 2017-02-23 12:49:10 -0800 | [diff] [blame] | 991 | int use_reduced_set) { |
| 992 | const int set_type = |
| 993 | get_ext_tx_set_type(tx_size, bs, is_inter, use_reduced_set); |
Hui Su | ddbcde2 | 2017-09-18 17:22:02 -0700 | [diff] [blame] | 994 | return av1_num_ext_tx_set[set_type]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Lester Lu | 432012f | 2017-08-17 14:39:29 -0700 | [diff] [blame] | 997 | #if CONFIG_LGT_FROM_PRED |
| 998 | static INLINE int is_lgt_allowed(PREDICTION_MODE mode, TX_SIZE tx_size) { |
| 999 | if (!LGT_FROM_PRED_INTRA && !is_inter_mode(mode)) return 0; |
| 1000 | if (!LGT_FROM_PRED_INTER && is_inter_mode(mode)) return 0; |
| 1001 | |
| 1002 | switch (mode) { |
| 1003 | case D45_PRED: |
| 1004 | case D63_PRED: |
| 1005 | case D117_PRED: |
| 1006 | case V_PRED: |
| 1007 | #if CONFIG_SMOOTH_HV |
| 1008 | case SMOOTH_V_PRED: |
| 1009 | #endif |
| 1010 | return tx_size_wide[tx_size] <= 8; |
| 1011 | case D135_PRED: |
| 1012 | case D153_PRED: |
| 1013 | case D207_PRED: |
| 1014 | case H_PRED: |
| 1015 | #if CONFIG_SMOOTH_HV |
| 1016 | case SMOOTH_H_PRED: |
| 1017 | #endif |
| 1018 | return tx_size_high[tx_size] <= 8; |
| 1019 | case DC_PRED: |
| 1020 | case SMOOTH_PRED: return 0; |
Urvang Joshi | 96d1c0a | 2017-10-10 13:15:32 -0700 | [diff] [blame] | 1021 | case PAETH_PRED: |
Lester Lu | 432012f | 2017-08-17 14:39:29 -0700 | [diff] [blame] | 1022 | default: return tx_size_wide[tx_size] <= 8 || tx_size_high[tx_size] <= 8; |
| 1023 | } |
| 1024 | } |
| 1025 | #endif // CONFIG_LGT_FROM_PRED |
| 1026 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1027 | #if CONFIG_RECT_TX |
| 1028 | static INLINE int is_rect_tx_allowed_bsize(BLOCK_SIZE bsize) { |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1029 | static const char LUT[BLOCK_SIZES_ALL] = { |
Jingning Han | f4e097b | 2017-01-20 09:23:58 -0800 | [diff] [blame] | 1030 | 0, // BLOCK_2X2 |
| 1031 | 0, // BLOCK_2X4 |
| 1032 | 0, // BLOCK_4X2 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1033 | 0, // BLOCK_4X4 |
| 1034 | 1, // BLOCK_4X8 |
| 1035 | 1, // BLOCK_8X4 |
| 1036 | 0, // BLOCK_8X8 |
| 1037 | 1, // BLOCK_8X16 |
| 1038 | 1, // BLOCK_16X8 |
| 1039 | 0, // BLOCK_16X16 |
| 1040 | 1, // BLOCK_16X32 |
| 1041 | 1, // BLOCK_32X16 |
| 1042 | 0, // BLOCK_32X32 |
Debargha Mukherjee | 1a86b01 | 2017-10-02 23:58:11 -0700 | [diff] [blame] | 1043 | 1, // BLOCK_32X64 |
| 1044 | 1, // BLOCK_64X32 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1045 | 0, // BLOCK_64X64 |
| 1046 | #if CONFIG_EXT_PARTITION |
| 1047 | 0, // BLOCK_64X128 |
| 1048 | 0, // BLOCK_128X64 |
| 1049 | 0, // BLOCK_128X128 |
| 1050 | #endif // CONFIG_EXT_PARTITION |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1051 | 0, // BLOCK_4X16 |
| 1052 | 0, // BLOCK_16X4 |
| 1053 | 0, // BLOCK_8X32 |
| 1054 | 0, // BLOCK_32X8 |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1055 | 0, // BLOCK_16X64 |
| 1056 | 0, // BLOCK_64X16 |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1057 | #if CONFIG_EXT_PARTITION |
| 1058 | 0, // BLOCK_32X128 |
| 1059 | 0, // BLOCK_128X32 |
| 1060 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1061 | }; |
| 1062 | |
| 1063 | return LUT[bsize]; |
| 1064 | } |
| 1065 | |
Yue Chen | 49587a7 | 2016-09-28 17:09:47 -0700 | [diff] [blame] | 1066 | static INLINE int is_rect_tx_allowed(const MACROBLOCKD *xd, |
| 1067 | const MB_MODE_INFO *mbmi) { |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1068 | return is_rect_tx_allowed_bsize(mbmi->sb_type) && |
Yue Chen | 49587a7 | 2016-09-28 17:09:47 -0700 | [diff] [blame] | 1069 | !xd->lossless[mbmi->segment_id]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1070 | } |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 1071 | #endif // CONFIG_RECT_TX |
| 1072 | #endif // CONFIG_EXT_TX |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1073 | |
Sebastien Alaiwan | fb83877 | 2017-10-24 12:02:54 +0200 | [diff] [blame] | 1074 | #if CONFIG_RECT_TX_EXT |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1075 | static INLINE int is_quarter_tx_allowed_bsize(BLOCK_SIZE bsize) { |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1076 | static const char LUT_QTTX[BLOCK_SIZES_ALL] = { |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1077 | 0, // BLOCK_2X2 |
| 1078 | 0, // BLOCK_2X4 |
| 1079 | 0, // BLOCK_4X2 |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1080 | 0, // BLOCK_4X4 |
| 1081 | 0, // BLOCK_4X8 |
| 1082 | 0, // BLOCK_8X4 |
| 1083 | 0, // BLOCK_8X8 |
| 1084 | 1, // BLOCK_8X16 |
| 1085 | 1, // BLOCK_16X8 |
| 1086 | 0, // BLOCK_16X16 |
| 1087 | 0, // BLOCK_16X32 |
| 1088 | 0, // BLOCK_32X16 |
| 1089 | 0, // BLOCK_32X32 |
| 1090 | 0, // BLOCK_32X64 |
| 1091 | 0, // BLOCK_64X32 |
| 1092 | 0, // BLOCK_64X64 |
| 1093 | #if CONFIG_EXT_PARTITION |
| 1094 | 0, // BLOCK_64X128 |
| 1095 | 0, // BLOCK_128X64 |
| 1096 | 0, // BLOCK_128X128 |
| 1097 | #endif // CONFIG_EXT_PARTITION |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1098 | 0, // BLOCK_4X16 |
| 1099 | 0, // BLOCK_16X4 |
| 1100 | 0, // BLOCK_8X32 |
| 1101 | 0, // BLOCK_32X8 |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 1102 | 0, // BLOCK_16X64 |
| 1103 | 0, // BLOCK_64X16 |
Rupert Swarbrick | 2fa6e1c | 2017-09-11 12:38:10 +0100 | [diff] [blame] | 1104 | #if CONFIG_EXT_PARTITION |
| 1105 | 0, // BLOCK_32X128 |
| 1106 | 0, // BLOCK_128X32 |
| 1107 | #endif // CONFIG_EXT_PARTITION |
Yue Chen | 56e226e | 2017-05-02 16:21:40 -0700 | [diff] [blame] | 1108 | }; |
| 1109 | |
| 1110 | return LUT_QTTX[bsize]; |
| 1111 | } |
| 1112 | |
| 1113 | static INLINE int is_quarter_tx_allowed(const MACROBLOCKD *xd, |
| 1114 | const MB_MODE_INFO *mbmi, |
| 1115 | int is_inter) { |
| 1116 | return is_quarter_tx_allowed_bsize(mbmi->sb_type) && is_inter && |
| 1117 | !xd->lossless[mbmi->segment_id]; |
| 1118 | } |
Yue Chen | d6bdd46 | 2017-07-19 16:05:43 -0700 | [diff] [blame] | 1119 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1120 | |
| 1121 | static INLINE TX_SIZE tx_size_from_tx_mode(BLOCK_SIZE bsize, TX_MODE tx_mode, |
| 1122 | int is_inter) { |
| 1123 | const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[tx_mode]; |
Sebastien Alaiwan | fb83877 | 2017-10-24 12:02:54 +0200 | [diff] [blame] | 1124 | #if CONFIG_RECT_TX |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1125 | const TX_SIZE max_rect_tx_size = max_txsize_rect_lookup[bsize]; |
Jingning Han | 70e5f3f | 2016-11-09 17:03:07 -0800 | [diff] [blame] | 1126 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1127 | const TX_SIZE max_tx_size = max_txsize_lookup[bsize]; |
Sebastien Alaiwan | fb83877 | 2017-10-24 12:02:54 +0200 | [diff] [blame] | 1128 | #endif // CONFIG_RECT_TX |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1129 | (void)is_inter; |
Sebastien Alaiwan | fb83877 | 2017-10-24 12:02:54 +0200 | [diff] [blame] | 1130 | #if CONFIG_RECT_TX |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1131 | if (bsize == BLOCK_4X4) |
| 1132 | return AOMMIN(max_txsize_lookup[bsize], largest_tx_size); |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1133 | if (txsize_sqr_map[max_rect_tx_size] <= largest_tx_size) |
| 1134 | return max_rect_tx_size; |
| 1135 | else |
| 1136 | return largest_tx_size; |
| 1137 | #elif CONFIG_EXT_TX && CONFIG_RECT_TX |
| 1138 | if (txsize_sqr_up_map[max_rect_tx_size] <= largest_tx_size) { |
| 1139 | return max_rect_tx_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1140 | } else { |
Urvang Joshi | feb925f | 2016-12-05 10:37:29 -0800 | [diff] [blame] | 1141 | return largest_tx_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1142 | } |
| 1143 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1144 | return AOMMIN(max_tx_size, largest_tx_size); |
Sebastien Alaiwan | fb83877 | 2017-10-24 12:02:54 +0200 | [diff] [blame] | 1145 | #endif // CONFIG_RECT_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1148 | #if CONFIG_EXT_INTRA |
hui su | 0a6731f | 2017-04-26 15:23:47 -0700 | [diff] [blame] | 1149 | #define MAX_ANGLE_DELTA 3 |
| 1150 | #define ANGLE_STEP 3 |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1151 | extern const int16_t dr_intra_derivative[90]; |
hui su | 02c7974 | 2017-05-16 17:19:04 -0700 | [diff] [blame] | 1152 | static const uint8_t mode_to_angle_map[] = { |
Urvang Joshi | 93b543a | 2017-06-01 17:32:41 -0700 | [diff] [blame] | 1153 | 0, 90, 180, 45, 135, 111, 157, 203, 67, 0, 0, |
hui su | 02c7974 | 2017-05-16 17:19:04 -0700 | [diff] [blame] | 1154 | #if CONFIG_SMOOTH_HV |
| 1155 | 0, 0, |
| 1156 | #endif // CONFIG_SMOOTH_HV |
hui su | 5db9743 | 2016-10-14 16:10:14 -0700 | [diff] [blame] | 1157 | }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1158 | #endif // CONFIG_EXT_INTRA |
| 1159 | |
Monty Montgomery | cb55dad | 2017-07-11 16:59:52 -0400 | [diff] [blame] | 1160 | #if CONFIG_DCT_ONLY |
| 1161 | #define FIXED_TX_TYPE 1 |
| 1162 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1163 | #define FIXED_TX_TYPE 0 |
Monty Montgomery | cb55dad | 2017-07-11 16:59:52 -0400 | [diff] [blame] | 1164 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1165 | |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 1166 | // Converts block_index for given transform size to index of the block in raster |
| 1167 | // order. |
| 1168 | static INLINE int av1_block_index_to_raster_order(TX_SIZE tx_size, |
| 1169 | int block_idx) { |
| 1170 | // For transform size 4x8, the possible block_idx values are 0 & 2, because |
| 1171 | // block_idx values are incremented in steps of size 'tx_width_unit x |
| 1172 | // tx_height_unit'. But, for this transform size, block_idx = 2 corresponds to |
| 1173 | // block number 1 in raster order, inside an 8x8 MI block. |
| 1174 | // For any other transform size, the two indices are equivalent. |
| 1175 | return (tx_size == TX_4X8 && block_idx == 2) ? 1 : block_idx; |
| 1176 | } |
| 1177 | |
| 1178 | // Inverse of above function. |
| 1179 | // Note: only implemented for transform sizes 4x4, 4x8 and 8x4 right now. |
| 1180 | static INLINE int av1_raster_order_to_block_index(TX_SIZE tx_size, |
| 1181 | int raster_order) { |
| 1182 | assert(tx_size == TX_4X4 || tx_size == TX_4X8 || tx_size == TX_8X4); |
| 1183 | // We ensure that block indices are 0 & 2 if tx size is 4x8 or 8x4. |
| 1184 | return (tx_size == TX_4X4) ? raster_order : (raster_order > 0) ? 2 : 0; |
| 1185 | } |
| 1186 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1187 | static INLINE TX_TYPE get_default_tx_type(PLANE_TYPE plane_type, |
| 1188 | const MACROBLOCKD *xd, int block_idx, |
| 1189 | TX_SIZE tx_size) { |
| 1190 | const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi; |
| 1191 | |
Monty Montgomery | cb55dad | 2017-07-11 16:59:52 -0400 | [diff] [blame] | 1192 | if (CONFIG_DCT_ONLY || is_inter_block(mbmi) || plane_type != PLANE_TYPE_Y || |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1193 | xd->lossless[mbmi->segment_id] || tx_size >= TX_32X32) |
| 1194 | return DCT_DCT; |
| 1195 | |
| 1196 | return intra_mode_to_tx_type_context[plane_type == PLANE_TYPE_Y |
| 1197 | ? get_y_mode(xd->mi[0], block_idx) |
Luc Trudeau | d6d9eee | 2017-07-12 12:36:50 -0400 | [diff] [blame] | 1198 | : get_uv_mode(mbmi->uv_mode)]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1201 | static INLINE TX_TYPE av1_get_tx_type(PLANE_TYPE plane_type, |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 1202 | const MACROBLOCKD *xd, int blk_row, |
| 1203 | int blk_col, int block, TX_SIZE tx_size) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1204 | const MODE_INFO *const mi = xd->mi[0]; |
| 1205 | const MB_MODE_INFO *const mbmi = &mi->mbmi; |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 1206 | (void)blk_row; |
| 1207 | (void)blk_col; |
Alex Converse | daa15e4 | 2017-05-02 14:27:16 -0700 | [diff] [blame] | 1208 | #if CONFIG_INTRABC && (!CONFIG_EXT_TX || CONFIG_TXK_SEL) |
| 1209 | // TODO(aconverse@google.com): Handle INTRABC + EXT_TX + TXK_SEL |
Alex Converse | 2874430 | 2017-04-13 14:46:22 -0700 | [diff] [blame] | 1210 | if (is_intrabc_block(mbmi)) return DCT_DCT; |
Alex Converse | daa15e4 | 2017-05-02 14:27:16 -0700 | [diff] [blame] | 1211 | #endif // CONFIG_INTRABC && (!CONFIG_EXT_TX || CONFIG_TXK_SEL) |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1212 | |
| 1213 | #if CONFIG_TXK_SEL |
| 1214 | TX_TYPE tx_type; |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 1215 | if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] >= TX_32X32) { |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1216 | tx_type = DCT_DCT; |
| 1217 | } else { |
Jingning Han | 19b5c8f | 2017-07-06 15:10:12 -0700 | [diff] [blame] | 1218 | if (plane_type == PLANE_TYPE_Y) |
| 1219 | tx_type = mbmi->txk_type[(blk_row << 4) + blk_col]; |
| 1220 | else if (is_inter_block(mbmi)) |
| 1221 | tx_type = mbmi->txk_type[(blk_row << 5) + (blk_col << 1)]; |
| 1222 | else |
| 1223 | tx_type = intra_mode_to_tx_type_context[mbmi->uv_mode]; |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1224 | } |
| 1225 | assert(tx_type >= DCT_DCT && tx_type < TX_TYPES); |
| 1226 | return tx_type; |
| 1227 | #endif // CONFIG_TXK_SEL |
| 1228 | |
James Zern | 7cdaa60 | 2017-04-20 20:12:46 -0700 | [diff] [blame] | 1229 | #if FIXED_TX_TYPE |
Angie Chiang | c2ebfbf | 2017-04-15 13:56:58 -0700 | [diff] [blame] | 1230 | const int block_raster_idx = av1_block_index_to_raster_order(tx_size, block); |
James Zern | 7cdaa60 | 2017-04-20 20:12:46 -0700 | [diff] [blame] | 1231 | return get_default_tx_type(plane_type, xd, block_raster_idx, tx_size); |
hui su | 45b6475 | 2017-07-12 16:54:35 -0700 | [diff] [blame] | 1232 | #endif // FIXED_TX_TYPE |
| 1233 | |
| 1234 | #if CONFIG_EXT_TX |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 1235 | #if CONFIG_MRC_TX |
| 1236 | if (mbmi->tx_type == MRC_DCT) { |
Sarah Parker | 2e08d96 | 2017-08-01 19:51:20 -0700 | [diff] [blame] | 1237 | assert(((is_inter_block(mbmi) && USE_MRC_INTER) || |
| 1238 | (!is_inter_block(mbmi) && USE_MRC_INTRA)) && |
| 1239 | "INVALID BLOCK TYPE FOR MRC_DCT"); |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 1240 | if (plane_type == PLANE_TYPE_Y) { |
| 1241 | assert(tx_size == TX_32X32); |
| 1242 | return mbmi->tx_type; |
| 1243 | } |
| 1244 | return DCT_DCT; |
| 1245 | } |
| 1246 | #endif // CONFIG_MRC_TX |
Nathan E. Egge | 856d179 | 2017-10-26 17:55:20 -0400 | [diff] [blame] | 1247 | #if CONFIG_DAALA_TX32 |
| 1248 | if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] > TX_32X32) |
| 1249 | #else |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1250 | if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] > TX_32X32 || |
| 1251 | (txsize_sqr_map[tx_size] >= TX_32X32 && !is_inter_block(mbmi))) |
Nathan E. Egge | 856d179 | 2017-10-26 17:55:20 -0400 | [diff] [blame] | 1252 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1253 | return DCT_DCT; |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 1254 | if (plane_type == PLANE_TYPE_Y) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1255 | #if !ALLOW_INTRA_EXT_TX |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 1256 | if (is_inter_block(mbmi)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1257 | #endif // ALLOW_INTRA_EXT_TX |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 1258 | return mbmi->tx_type; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1259 | } |
| 1260 | |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 1261 | if (is_inter_block(mbmi)) { |
| 1262 | // UV Inter only |
| 1263 | return (mbmi->tx_type == IDTX && txsize_sqr_map[tx_size] >= TX_32X32) |
| 1264 | ? DCT_DCT |
| 1265 | : mbmi->tx_type; |
| 1266 | } |
| 1267 | |
Thomas Daede | b7e72f3 | 2017-04-26 13:40:31 -0700 | [diff] [blame] | 1268 | (void)block; |
Sebastien Alaiwan | d8b93f5 | 2017-10-17 09:22:01 +0200 | [diff] [blame] | 1269 | return intra_mode_to_tx_type_context[get_uv_mode(mbmi->uv_mode)]; |
Debargha Mukherjee | 6ea917e | 2017-10-19 09:31:29 -0700 | [diff] [blame] | 1270 | #else // CONFIG_EXT_TX |
Angie Chiang | 752ccce | 2017-04-09 13:41:13 -0700 | [diff] [blame] | 1271 | (void)block; |
Sarah Parker | 53f93db | 2017-07-11 17:20:04 -0700 | [diff] [blame] | 1272 | #if CONFIG_MRC_TX |
| 1273 | if (mbmi->tx_type == MRC_DCT) { |
| 1274 | if (plane_type == PLANE_TYPE_Y && !xd->lossless[mbmi->segment_id]) { |
| 1275 | assert(tx_size == TX_32X32); |
| 1276 | return mbmi->tx_type; |
| 1277 | } |
| 1278 | return DCT_DCT; |
| 1279 | } |
| 1280 | #endif // CONFIG_MRC_TX |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1281 | if (plane_type != PLANE_TYPE_Y || xd->lossless[mbmi->segment_id] || |
| 1282 | txsize_sqr_map[tx_size] >= TX_32X32) |
| 1283 | return DCT_DCT; |
| 1284 | return mbmi->tx_type; |
| 1285 | #endif // CONFIG_EXT_TX |
| 1286 | } |
| 1287 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1288 | void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1289 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 1290 | static INLINE int tx_size_to_depth(TX_SIZE tx_size) { |
Timothy B. Terriberry | fe0fb1d | 2017-05-18 12:15:16 -0700 | [diff] [blame] | 1291 | return (int)(tx_size - TX_SIZE_LUMA_MIN); |
Jingning Han | 4e1737a | 2016-10-25 16:05:02 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 1294 | static INLINE TX_SIZE depth_to_tx_size(int depth) { |
Timothy B. Terriberry | fe0fb1d | 2017-05-18 12:15:16 -0700 | [diff] [blame] | 1295 | return (TX_SIZE)(depth + TX_SIZE_LUMA_MIN); |
Jingning Han | 4e1737a | 2016-10-25 16:05:02 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1298 | static INLINE TX_SIZE av1_get_uv_tx_size(const MB_MODE_INFO *mbmi, |
| 1299 | const struct macroblockd_plane *pd) { |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1300 | const TX_SIZE uv_txsize = |
| 1301 | uv_txsize_lookup[mbmi->sb_type][mbmi->tx_size][pd->subsampling_x] |
| 1302 | [pd->subsampling_y]; |
Debargha Mukherjee | 2f12340 | 2016-08-30 17:43:38 -0700 | [diff] [blame] | 1303 | assert(uv_txsize != TX_INVALID); |
| 1304 | return uv_txsize; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1307 | static INLINE TX_SIZE av1_get_tx_size(int plane, const MACROBLOCKD *xd) { |
Angie Chiang | 80b8226 | 2017-02-24 11:39:47 -0800 | [diff] [blame] | 1308 | const MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1309 | if (plane == 0) return mbmi->tx_size; |
Angie Chiang | 80b8226 | 2017-02-24 11:39:47 -0800 | [diff] [blame] | 1310 | const MACROBLOCKD_PLANE *pd = &xd->plane[plane]; |
hui su | 0c6244b | 2017-07-12 17:11:43 -0700 | [diff] [blame] | 1311 | return av1_get_uv_tx_size(mbmi, pd); |
Angie Chiang | 80b8226 | 2017-02-24 11:39:47 -0800 | [diff] [blame] | 1312 | } |
| 1313 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1314 | static INLINE BLOCK_SIZE |
| 1315 | get_plane_block_size(BLOCK_SIZE bsize, const struct macroblockd_plane *pd) { |
| 1316 | return ss_size_lookup[bsize][pd->subsampling_x][pd->subsampling_y]; |
| 1317 | } |
| 1318 | |
Timothy B. Terriberry | a2d5cde | 2017-05-10 18:33:50 -0700 | [diff] [blame] | 1319 | void av1_reset_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col, |
| 1320 | BLOCK_SIZE bsize); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1321 | |
| 1322 | typedef void (*foreach_transformed_block_visitor)(int plane, int block, |
| 1323 | int blk_row, int blk_col, |
| 1324 | BLOCK_SIZE plane_bsize, |
| 1325 | TX_SIZE tx_size, void *arg); |
| 1326 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1327 | void av1_foreach_transformed_block_in_plane( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1328 | const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane, |
| 1329 | foreach_transformed_block_visitor visit, void *arg); |
| 1330 | |
Angie Chiang | 0397eda | 2017-03-15 16:57:14 -0700 | [diff] [blame] | 1331 | #if CONFIG_LV_MAP |
| 1332 | void av1_foreach_transformed_block(const MACROBLOCKD *const xd, |
Jingning Han | 94652b8 | 2017-04-04 09:45:02 -0700 | [diff] [blame] | 1333 | BLOCK_SIZE bsize, int mi_row, int mi_col, |
Angie Chiang | 0397eda | 2017-03-15 16:57:14 -0700 | [diff] [blame] | 1334 | foreach_transformed_block_visitor visit, |
| 1335 | void *arg); |
| 1336 | #endif |
| 1337 | |
iole moccagatta | f25a4cf | 2016-11-11 23:57:57 -0800 | [diff] [blame] | 1338 | #if CONFIG_COEF_INTERLEAVE |
| 1339 | static INLINE int get_max_4x4_size(int num_4x4, int mb_to_edge, |
| 1340 | int subsampling) { |
| 1341 | return num_4x4 + (mb_to_edge >= 0 ? 0 : mb_to_edge >> (5 + subsampling)); |
| 1342 | } |
| 1343 | |
| 1344 | void av1_foreach_transformed_block_interleave( |
| 1345 | const MACROBLOCKD *const xd, BLOCK_SIZE bsize, |
| 1346 | foreach_transformed_block_visitor visit, void *arg); |
| 1347 | #endif |
| 1348 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1349 | void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd, |
Jingning Han | eee4315 | 2016-12-05 09:58:45 -0800 | [diff] [blame] | 1350 | int plane, TX_SIZE tx_size, int has_eob, int aoff, |
| 1351 | int loff); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1352 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1353 | static INLINE int is_interintra_allowed_bsize(const BLOCK_SIZE bsize) { |
Debargha Mukherjee | 37f6fe6 | 2017-02-10 21:44:13 -0800 | [diff] [blame] | 1354 | #if CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1355 | // TODO(debargha): Should this be bsize < BLOCK_LARGEST? |
| 1356 | return (bsize >= BLOCK_8X8) && (bsize < BLOCK_64X64); |
Debargha Mukherjee | 37f6fe6 | 2017-02-10 21:44:13 -0800 | [diff] [blame] | 1357 | #else |
| 1358 | (void)bsize; |
| 1359 | return 0; |
| 1360 | #endif // CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | static INLINE int is_interintra_allowed_mode(const PREDICTION_MODE mode) { |
Debargha Mukherjee | 37f6fe6 | 2017-02-10 21:44:13 -0800 | [diff] [blame] | 1364 | #if CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1365 | return (mode >= NEARESTMV) && (mode <= NEWMV); |
Debargha Mukherjee | 37f6fe6 | 2017-02-10 21:44:13 -0800 | [diff] [blame] | 1366 | #else |
| 1367 | (void)mode; |
| 1368 | return 0; |
| 1369 | #endif // CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | static INLINE int is_interintra_allowed_ref(const MV_REFERENCE_FRAME rf[2]) { |
Debargha Mukherjee | 37f6fe6 | 2017-02-10 21:44:13 -0800 | [diff] [blame] | 1373 | #if CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1374 | return (rf[0] > INTRA_FRAME) && (rf[1] <= INTRA_FRAME); |
Debargha Mukherjee | 37f6fe6 | 2017-02-10 21:44:13 -0800 | [diff] [blame] | 1375 | #else |
| 1376 | (void)rf; |
| 1377 | return 0; |
| 1378 | #endif // CONFIG_INTERINTRA |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | static INLINE int is_interintra_allowed(const MB_MODE_INFO *mbmi) { |
| 1382 | return is_interintra_allowed_bsize(mbmi->sb_type) && |
| 1383 | is_interintra_allowed_mode(mbmi->mode) && |
| 1384 | is_interintra_allowed_ref(mbmi->ref_frame); |
| 1385 | } |
| 1386 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 1387 | static INLINE int is_interintra_allowed_bsize_group(int group) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1388 | int i; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 1389 | for (i = 0; i < BLOCK_SIZES_ALL; i++) { |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 1390 | if (size_group_lookup[i] == group && |
| 1391 | is_interintra_allowed_bsize((BLOCK_SIZE)i)) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1392 | return 1; |
Urvang Joshi | cb586f3 | 2016-09-20 11:36:33 -0700 | [diff] [blame] | 1393 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1394 | } |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
| 1398 | static INLINE int is_interintra_pred(const MB_MODE_INFO *mbmi) { |
| 1399 | return (mbmi->ref_frame[1] == INTRA_FRAME) && is_interintra_allowed(mbmi); |
| 1400 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1401 | |
Sarah Parker | 106b3cb | 2017-04-21 12:13:37 -0700 | [diff] [blame] | 1402 | static INLINE int get_vartx_max_txsize(const MB_MODE_INFO *const mbmi, |
Rupert Swarbrick | 4e7b7d6 | 2017-09-28 17:30:44 +0100 | [diff] [blame] | 1403 | BLOCK_SIZE bsize, int subsampled) { |
Sarah Parker | 106b3cb | 2017-04-21 12:13:37 -0700 | [diff] [blame] | 1404 | (void)mbmi; |
Rupert Swarbrick | 4e7b7d6 | 2017-09-28 17:30:44 +0100 | [diff] [blame] | 1405 | TX_SIZE max_txsize = max_txsize_rect_lookup[bsize]; |
Rupert Swarbrick | 4e7b7d6 | 2017-09-28 17:30:44 +0100 | [diff] [blame] | 1406 | |
| 1407 | #if CONFIG_EXT_PARTITION && CONFIG_TX64X64 |
| 1408 | // The decoder is designed so that it can process 64x64 luma pixels at a |
| 1409 | // time. If this is a chroma plane with subsampling and bsize corresponds to |
| 1410 | // a subsampled BLOCK_128X128 then the lookup above will give TX_64X64. That |
| 1411 | // mustn't be used for the subsampled plane (because it would be bigger than |
| 1412 | // a 64x64 luma block) so we round down to TX_32X32. |
Debargha Mukherjee | 1fa2446 | 2017-10-19 14:33:39 -0700 | [diff] [blame] | 1413 | if (subsampled && txsize_sqr_up_map[max_txsize] == TX_64X64) { |
| 1414 | max_txsize = TX_32X32; |
| 1415 | } |
Rupert Swarbrick | 4e7b7d6 | 2017-09-28 17:30:44 +0100 | [diff] [blame] | 1416 | #else |
| 1417 | (void)subsampled; |
| 1418 | #endif |
| 1419 | |
| 1420 | return max_txsize; |
Sarah Parker | 106b3cb | 2017-04-21 12:13:37 -0700 | [diff] [blame] | 1421 | } |
Sarah Parker | 106b3cb | 2017-04-21 12:13:37 -0700 | [diff] [blame] | 1422 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1423 | #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
| 1424 | static INLINE int is_motion_variation_allowed_bsize(BLOCK_SIZE bsize) { |
Debargha Mukherjee | c17a443 | 2017-08-28 22:22:45 -0700 | [diff] [blame] | 1425 | return AOMMIN(block_size_wide[bsize], block_size_high[bsize]) >= 8; |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
Yue Chen | 8636da6 | 2017-04-03 01:23:44 -0700 | [diff] [blame] | 1428 | static INLINE int is_motion_variation_allowed_compound( |
| 1429 | const MB_MODE_INFO *mbmi) { |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 1430 | #if CONFIG_COMPOUND_SINGLEREF |
Zoe Liu | 85b6646 | 2017-04-20 14:28:19 -0700 | [diff] [blame] | 1431 | if (!has_second_ref(mbmi) && !is_inter_singleref_comp_mode(mbmi->mode)) |
| 1432 | #else |
Yue Chen | 8636da6 | 2017-04-03 01:23:44 -0700 | [diff] [blame] | 1433 | if (!has_second_ref(mbmi)) |
Sebastien Alaiwan | 0bdea0d | 2017-10-02 15:15:05 +0200 | [diff] [blame] | 1434 | #endif // CONFIG_COMPOUND_SINGLEREF |
Yue Chen | 8636da6 | 2017-04-03 01:23:44 -0700 | [diff] [blame] | 1435 | return 1; |
| 1436 | else |
| 1437 | return 0; |
| 1438 | } |
| 1439 | |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1440 | #if CONFIG_MOTION_VAR |
Yue Chen | 1bd42be | 2017-03-15 18:07:04 -0700 | [diff] [blame] | 1441 | // input: log2 of length, 0(4), 1(8), ... |
| 1442 | static const int max_neighbor_obmc[6] = { 0, 1, 2, 3, 4, 4 }; |
| 1443 | |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1444 | static INLINE int check_num_overlappable_neighbors(const MB_MODE_INFO *mbmi) { |
Yue Chen | 1bd42be | 2017-03-15 18:07:04 -0700 | [diff] [blame] | 1445 | return !(mbmi->overlappable_neighbors[0] == 0 && |
| 1446 | mbmi->overlappable_neighbors[1] == 0); |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1447 | } |
Wei-Ting Lin | 2088528 | 2017-08-28 17:18:18 -0700 | [diff] [blame] | 1448 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
| 1449 | static INLINE NCOBMC_MODE ncobmc_mode_allowed_bsize(BLOCK_SIZE bsize) { |
| 1450 | if (bsize < BLOCK_8X8 || bsize >= BLOCK_64X64) |
| 1451 | return NO_OVERLAP; |
| 1452 | else |
| 1453 | return MAX_NCOBMC_MODES; |
| 1454 | } |
| 1455 | #endif // CONFIG_NCOBMC_ADAPT_WEIGHT |
| 1456 | #endif // CONFIG_MOTION_VAR |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1457 | |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1458 | static INLINE MOTION_MODE motion_mode_allowed( |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1459 | #if CONFIG_GLOBAL_MOTION |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1460 | int block, const WarpedMotionParams *gm_params, |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1461 | #endif // CONFIG_GLOBAL_MOTION |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 1462 | #if CONFIG_WARPED_MOTION |
| 1463 | const MACROBLOCKD *xd, |
| 1464 | #endif |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1465 | const MODE_INFO *mi) { |
| 1466 | const MB_MODE_INFO *mbmi = &mi->mbmi; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1467 | #if CONFIG_AMVR |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 1468 | if (xd->cur_frame_force_integer_mv == 0) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1469 | #endif |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1470 | #if CONFIG_GLOBAL_MOTION |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1471 | const TransformationType gm_type = gm_params[mbmi->ref_frame[0]].wmtype; |
| 1472 | if (is_global_mv_block(mi, block, gm_type)) return SIMPLE_TRANSLATION; |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1473 | #endif // CONFIG_GLOBAL_MOTION |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1474 | #if CONFIG_AMVR |
| 1475 | } |
| 1476 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1477 | if (is_motion_variation_allowed_bsize(mbmi->sb_type) && |
Yue Chen | 8636da6 | 2017-04-03 01:23:44 -0700 | [diff] [blame] | 1478 | is_inter_mode(mbmi->mode) && mbmi->ref_frame[1] != INTRA_FRAME && |
| 1479 | is_motion_variation_allowed_compound(mbmi)) { |
Yue Chen | 5329a2b | 2017-02-28 17:33:00 +0800 | [diff] [blame] | 1480 | #if CONFIG_MOTION_VAR |
| 1481 | if (!check_num_overlappable_neighbors(mbmi)) return SIMPLE_TRANSLATION; |
| 1482 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1483 | #if CONFIG_WARPED_MOTION |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 1484 | if (!has_second_ref(mbmi) && mbmi->num_proj_ref[0] >= 1 && |
Wei-Ting Lin | 2088528 | 2017-08-28 17:18:18 -0700 | [diff] [blame] | 1485 | !av1_is_scaled(&(xd->block_refs[0]->sf))) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1486 | #if CONFIG_AMVR |
RogerZhou | 10a0380 | 2017-10-26 11:49:48 -0700 | [diff] [blame] | 1487 | if (xd->cur_frame_force_integer_mv) { |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1488 | return OBMC_CAUSAL; |
| 1489 | } |
| 1490 | #endif |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1491 | return WARPED_CAUSAL; |
Hui Su | 12231bd | 2017-09-07 18:01:15 -0700 | [diff] [blame] | 1492 | } |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1493 | |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1494 | #endif // CONFIG_WARPED_MOTION |
| 1495 | #if CONFIG_MOTION_VAR |
Wei-Ting Lin | 2088528 | 2017-08-28 17:18:18 -0700 | [diff] [blame] | 1496 | #if CONFIG_NCOBMC_ADAPT_WEIGHT |
Hui Su | 12231bd | 2017-09-07 18:01:15 -0700 | [diff] [blame] | 1497 | if (ncobmc_mode_allowed_bsize(mbmi->sb_type) < NO_OVERLAP) |
| 1498 | return NCOBMC_ADAPT_WEIGHT; |
| 1499 | else |
Wei-Ting Lin | 2088528 | 2017-08-28 17:18:18 -0700 | [diff] [blame] | 1500 | #endif |
Hui Su | 12231bd | 2017-09-07 18:01:15 -0700 | [diff] [blame] | 1501 | return OBMC_CAUSAL; |
Yue Chen | 69f18e1 | 2016-09-08 14:48:15 -0700 | [diff] [blame] | 1502 | #else |
| 1503 | return SIMPLE_TRANSLATION; |
| 1504 | #endif // CONFIG_MOTION_VAR |
| 1505 | } else { |
| 1506 | return SIMPLE_TRANSLATION; |
| 1507 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1508 | } |
| 1509 | |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1510 | static INLINE void assert_motion_mode_valid(MOTION_MODE mode, |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1511 | #if CONFIG_GLOBAL_MOTION |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1512 | int block, |
| 1513 | const WarpedMotionParams *gm_params, |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1514 | #endif // CONFIG_GLOBAL_MOTION |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 1515 | #if CONFIG_WARPED_MOTION |
| 1516 | const MACROBLOCKD *xd, |
| 1517 | #endif |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1518 | const MODE_INFO *mi) { |
| 1519 | const MOTION_MODE last_motion_mode_allowed = motion_mode_allowed( |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1520 | #if CONFIG_GLOBAL_MOTION |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1521 | block, gm_params, |
Sarah Parker | 0eea89f | 2017-07-11 11:56:36 -0700 | [diff] [blame] | 1522 | #endif // CONFIG_GLOBAL_MOTION |
Yue Chen | 52c5173 | 2017-07-11 15:08:30 -0700 | [diff] [blame] | 1523 | #if CONFIG_WARPED_MOTION |
| 1524 | xd, |
| 1525 | #endif |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1526 | mi); |
Wei-Ting Lin | 2088528 | 2017-08-28 17:18:18 -0700 | [diff] [blame] | 1527 | |
Sarah Parker | 19234cc | 2017-03-10 16:43:25 -0800 | [diff] [blame] | 1528 | // Check that the input mode is not illegal |
| 1529 | if (last_motion_mode_allowed < mode) |
| 1530 | assert(0 && "Illegal motion mode selected"); |
| 1531 | } |
| 1532 | |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1533 | #if CONFIG_MOTION_VAR |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1534 | static INLINE int is_neighbor_overlappable(const MB_MODE_INFO *mbmi) { |
| 1535 | return (is_inter_block(mbmi)); |
| 1536 | } |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 1537 | #endif // CONFIG_MOTION_VAR |
| 1538 | #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1539 | |
Hui Su | e87fb23 | 2017-10-05 15:00:15 -0700 | [diff] [blame] | 1540 | static INLINE int av1_allow_palette(int allow_screen_content_tools, |
| 1541 | BLOCK_SIZE sb_type) { |
| 1542 | return allow_screen_content_tools && sb_type >= BLOCK_8X8 && |
| 1543 | sb_type <= BLOCK_LARGEST; |
| 1544 | } |
| 1545 | |
Urvang Joshi | 56ba91b | 2017-01-10 13:22:09 -0800 | [diff] [blame] | 1546 | // Returns sub-sampled dimensions of the given block. |
| 1547 | // The output values for 'rows_within_bounds' and 'cols_within_bounds' will |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 1548 | // differ from 'height' and 'width' when part of the block is outside the |
| 1549 | // right |
Urvang Joshi | 56ba91b | 2017-01-10 13:22:09 -0800 | [diff] [blame] | 1550 | // and/or bottom image boundary. |
| 1551 | static INLINE void av1_get_block_dimensions(BLOCK_SIZE bsize, int plane, |
| 1552 | const MACROBLOCKD *xd, int *width, |
| 1553 | int *height, |
| 1554 | int *rows_within_bounds, |
| 1555 | int *cols_within_bounds) { |
| 1556 | const int block_height = block_size_high[bsize]; |
| 1557 | const int block_width = block_size_wide[bsize]; |
| 1558 | const int block_rows = (xd->mb_to_bottom_edge >= 0) |
| 1559 | ? block_height |
| 1560 | : (xd->mb_to_bottom_edge >> 3) + block_height; |
| 1561 | const int block_cols = (xd->mb_to_right_edge >= 0) |
| 1562 | ? block_width |
| 1563 | : (xd->mb_to_right_edge >> 3) + block_width; |
| 1564 | const struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 1565 | assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_x == 0)); |
| 1566 | assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_y == 0)); |
| 1567 | assert(block_width >= block_cols); |
| 1568 | assert(block_height >= block_rows); |
| 1569 | if (width) *width = block_width >> pd->subsampling_x; |
| 1570 | if (height) *height = block_height >> pd->subsampling_y; |
| 1571 | if (rows_within_bounds) *rows_within_bounds = block_rows >> pd->subsampling_y; |
| 1572 | if (cols_within_bounds) *cols_within_bounds = block_cols >> pd->subsampling_x; |
| 1573 | } |
| 1574 | |
Sarah Parker | efd8af2 | 2017-08-25 16:36:06 -0700 | [diff] [blame] | 1575 | /* clang-format off */ |
| 1576 | typedef aom_cdf_prob (*MapCdf)[PALETTE_COLOR_INDEX_CONTEXTS] |
| 1577 | [CDF_SIZE(PALETTE_COLORS)]; |
| 1578 | typedef const int (*ColorCost)[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS] |
| 1579 | [PALETTE_COLORS]; |
| 1580 | /* clang-format on */ |
| 1581 | |
| 1582 | typedef struct { |
| 1583 | int rows; |
| 1584 | int cols; |
| 1585 | int n_colors; |
| 1586 | int plane_width; |
| 1587 | int plane_height; |
| 1588 | uint8_t *color_map; |
| 1589 | MapCdf map_cdf; |
| 1590 | ColorCost color_cost; |
| 1591 | } Av1ColorMapParam; |
| 1592 | |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1593 | #if CONFIG_GLOBAL_MOTION |
| 1594 | static INLINE int is_nontrans_global_motion(const MACROBLOCKD *xd) { |
| 1595 | const MODE_INFO *mi = xd->mi[0]; |
| 1596 | const MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1597 | int ref; |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1598 | |
| 1599 | // First check if all modes are ZEROMV |
Debargha Mukherjee | edced25 | 2017-10-20 00:02:00 -0700 | [diff] [blame] | 1600 | if (mbmi->mode != ZEROMV && mbmi->mode != ZERO_ZEROMV) return 0; |
Jingning Han | 3ca0e67 | 2017-04-14 19:48:05 -0700 | [diff] [blame] | 1601 | |
| 1602 | #if !GLOBAL_SUB8X8_USED |
| 1603 | if (mbmi->sb_type < BLOCK_8X8) return 0; |
| 1604 | #endif |
| 1605 | |
Yue Chen | 19e7aa8 | 2016-11-30 14:05:39 -0800 | [diff] [blame] | 1606 | // Now check if all global motion is non translational |
| 1607 | for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) { |
| 1608 | if (xd->global_motion[mbmi->ref_frame[ref]].wmtype <= TRANSLATION) return 0; |
| 1609 | } |
| 1610 | return 1; |
| 1611 | } |
| 1612 | #endif // CONFIG_GLOBAL_MOTION |
| 1613 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 1614 | static INLINE PLANE_TYPE get_plane_type(int plane) { |
Luc Trudeau | 005feb6 | 2017-02-22 13:34:01 -0500 | [diff] [blame] | 1615 | return (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV; |
| 1616 | } |
| 1617 | |
Angie Chiang | 155bf9a | 2017-08-06 19:52:57 -0700 | [diff] [blame] | 1618 | static INLINE void transpose_uint8(uint8_t *dst, int dst_stride, |
| 1619 | const uint8_t *src, int src_stride, int w, |
| 1620 | int h) { |
| 1621 | int r, c; |
| 1622 | for (r = 0; r < h; ++r) |
| 1623 | for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c]; |
| 1624 | } |
| 1625 | |
| 1626 | static INLINE void transpose_uint16(uint16_t *dst, int dst_stride, |
| 1627 | const uint16_t *src, int src_stride, int w, |
| 1628 | int h) { |
| 1629 | int r, c; |
| 1630 | for (r = 0; r < h; ++r) |
| 1631 | for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c]; |
| 1632 | } |
| 1633 | |
| 1634 | static INLINE void transpose_int16(int16_t *dst, int dst_stride, |
| 1635 | const int16_t *src, int src_stride, int w, |
| 1636 | int h) { |
| 1637 | int r, c; |
| 1638 | for (r = 0; r < h; ++r) |
| 1639 | for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c]; |
| 1640 | } |
| 1641 | |
| 1642 | static INLINE void transpose_int32(int32_t *dst, int dst_stride, |
| 1643 | const int32_t *src, int src_stride, int w, |
| 1644 | int h) { |
| 1645 | int r, c; |
| 1646 | for (r = 0; r < h; ++r) |
| 1647 | for (c = 0; c < w; ++c) dst[c * dst_stride + r] = src[r * src_stride + c]; |
| 1648 | } |
| 1649 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1650 | #ifdef __cplusplus |
| 1651 | } // extern "C" |
| 1652 | #endif |
| 1653 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1654 | #endif // AV1_COMMON_BLOCKD_H_ |