Home | History | Annotate | Download | only in common
      1 /*
      2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
      3  *
      4  * This source code is subject to the terms of the BSD 2 Clause License and
      5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
      6  * was not distributed with this source code in the LICENSE file, you can
      7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
      8  * Media Patent License 1.0 was not distributed with this source code in the
      9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
     10  */
     11 
     12 #ifndef AOM_AV1_COMMON_ENUMS_H_
     13 #define AOM_AV1_COMMON_ENUMS_H_
     14 
     15 #include "config/aom_config.h"
     16 
     17 #include "aom/aom_codec.h"
     18 #include "aom/aom_integer.h"
     19 #include "aom_ports/mem.h"
     20 
     21 #ifdef __cplusplus
     22 extern "C" {
     23 #endif
     24 
     25 #undef MAX_SB_SIZE
     26 
     27 // Max superblock size
     28 #define MAX_SB_SIZE_LOG2 7
     29 #define MAX_SB_SIZE (1 << MAX_SB_SIZE_LOG2)
     30 #define MAX_SB_SQUARE (MAX_SB_SIZE * MAX_SB_SIZE)
     31 
     32 // Min superblock size
     33 #define MIN_SB_SIZE_LOG2 6
     34 
     35 // Pixels per Mode Info (MI) unit
     36 #define MI_SIZE_LOG2 2
     37 #define MI_SIZE (1 << MI_SIZE_LOG2)
     38 
     39 // MI-units per max superblock (MI Block - MIB)
     40 #define MAX_MIB_SIZE_LOG2 (MAX_SB_SIZE_LOG2 - MI_SIZE_LOG2)
     41 #define MAX_MIB_SIZE (1 << MAX_MIB_SIZE_LOG2)
     42 
     43 // MI-units per min superblock
     44 #define MIN_MIB_SIZE_LOG2 (MIN_SB_SIZE_LOG2 - MI_SIZE_LOG2)
     45 
     46 // Mask to extract MI offset within max MIB
     47 #define MAX_MIB_MASK (MAX_MIB_SIZE - 1)
     48 
     49 // Maximum number of tile rows and tile columns
     50 #define MAX_TILE_ROWS 64
     51 #define MAX_TILE_COLS 64
     52 
     53 #define MAX_VARTX_DEPTH 2
     54 
     55 #define MI_SIZE_64X64 (64 >> MI_SIZE_LOG2)
     56 #define MI_SIZE_128X128 (128 >> MI_SIZE_LOG2)
     57 
     58 #define MAX_PALETTE_SQUARE (64 * 64)
     59 // Maximum number of colors in a palette.
     60 #define PALETTE_MAX_SIZE 8
     61 // Minimum number of colors in a palette.
     62 #define PALETTE_MIN_SIZE 2
     63 
     64 #define FRAME_OFFSET_BITS 5
     65 #define MAX_FRAME_DISTANCE ((1 << FRAME_OFFSET_BITS) - 1)
     66 
     67 // 4 frame filter levels: y plane vertical, y plane horizontal,
     68 // u plane, and v plane
     69 #define FRAME_LF_COUNT 4
     70 #define DEFAULT_DELTA_LF_MULTI 0
     71 #define MAX_MODE_LF_DELTAS 2
     72 
     73 #define DIST_PRECISION_BITS 4
     74 #define DIST_PRECISION (1 << DIST_PRECISION_BITS)  // 16
     75 
     76 // TODO(chengchen): Temporal flag serve as experimental flag for WIP
     77 // bitmask construction.
     78 // Shall be removed when bitmask code is completely checkedin
     79 #define LOOP_FILTER_BITMASK 0
     80 
     81 #define PROFILE_BITS 3
     82 // The following three profiles are currently defined.
     83 // Profile 0.  8-bit and 10-bit 4:2:0 and 4:0:0 only.
     84 // Profile 1.  8-bit and 10-bit 4:4:4
     85 // Profile 2.  8-bit and 10-bit 4:2:2
     86 //            12-bit  4:0:0, 4:2:2 and 4:4:4
     87 // Since we have three bits for the profiles, it can be extended later.
     88 enum {
     89   PROFILE_0,
     90   PROFILE_1,
     91   PROFILE_2,
     92   MAX_PROFILES,
     93 } SENUM1BYTE(BITSTREAM_PROFILE);
     94 
     95 #define OP_POINTS_CNT_MINUS_1_BITS 5
     96 #define OP_POINTS_IDC_BITS 12
     97 
     98 // Note: Some enums use the attribute 'packed' to use smallest possible integer
     99 // type, so that we can save memory when they are used in structs/arrays.
    100 
    101 typedef enum ATTRIBUTE_PACKED {
    102   BLOCK_4X4,
    103   BLOCK_4X8,
    104   BLOCK_8X4,
    105   BLOCK_8X8,
    106   BLOCK_8X16,
    107   BLOCK_16X8,
    108   BLOCK_16X16,
    109   BLOCK_16X32,
    110   BLOCK_32X16,
    111   BLOCK_32X32,
    112   BLOCK_32X64,
    113   BLOCK_64X32,
    114   BLOCK_64X64,
    115   BLOCK_64X128,
    116   BLOCK_128X64,
    117   BLOCK_128X128,
    118   BLOCK_4X16,
    119   BLOCK_16X4,
    120   BLOCK_8X32,
    121   BLOCK_32X8,
    122   BLOCK_16X64,
    123   BLOCK_64X16,
    124   BLOCK_SIZES_ALL,
    125   BLOCK_SIZES = BLOCK_4X16,
    126   BLOCK_INVALID = 255,
    127   BLOCK_LARGEST = (BLOCK_SIZES - 1)
    128 } BLOCK_SIZE;
    129 
    130 // 4X4, 8X8, 16X16, 32X32, 64X64, 128X128
    131 #define SQR_BLOCK_SIZES 6
    132 
    133 enum {
    134   PARTITION_NONE,
    135   PARTITION_HORZ,
    136   PARTITION_VERT,
    137   PARTITION_SPLIT,
    138   PARTITION_HORZ_A,  // HORZ split and the top partition is split again
    139   PARTITION_HORZ_B,  // HORZ split and the bottom partition is split again
    140   PARTITION_VERT_A,  // VERT split and the left partition is split again
    141   PARTITION_VERT_B,  // VERT split and the right partition is split again
    142   PARTITION_HORZ_4,  // 4:1 horizontal partition
    143   PARTITION_VERT_4,  // 4:1 vertical partition
    144   EXT_PARTITION_TYPES,
    145   PARTITION_TYPES = PARTITION_SPLIT + 1,
    146   PARTITION_INVALID = 255
    147 } UENUM1BYTE(PARTITION_TYPE);
    148 
    149 typedef char PARTITION_CONTEXT;
    150 #define PARTITION_PLOFFSET 4  // number of probability models per block size
    151 #define PARTITION_BLOCK_SIZES 5
    152 #define PARTITION_CONTEXTS (PARTITION_BLOCK_SIZES * PARTITION_PLOFFSET)
    153 
    154 // block transform size
    155 enum {
    156   TX_4X4,             // 4x4 transform
    157   TX_8X8,             // 8x8 transform
    158   TX_16X16,           // 16x16 transform
    159   TX_32X32,           // 32x32 transform
    160   TX_64X64,           // 64x64 transform
    161   TX_4X8,             // 4x8 transform
    162   TX_8X4,             // 8x4 transform
    163   TX_8X16,            // 8x16 transform
    164   TX_16X8,            // 16x8 transform
    165   TX_16X32,           // 16x32 transform
    166   TX_32X16,           // 32x16 transform
    167   TX_32X64,           // 32x64 transform
    168   TX_64X32,           // 64x32 transform
    169   TX_4X16,            // 4x16 transform
    170   TX_16X4,            // 16x4 transform
    171   TX_8X32,            // 8x32 transform
    172   TX_32X8,            // 32x8 transform
    173   TX_16X64,           // 16x64 transform
    174   TX_64X16,           // 64x16 transform
    175   TX_SIZES_ALL,       // Includes rectangular transforms
    176   TX_SIZES = TX_4X8,  // Does NOT include rectangular transforms
    177   TX_SIZES_LARGEST = TX_64X64,
    178   TX_INVALID = 255  // Invalid transform size
    179 } UENUM1BYTE(TX_SIZE);
    180 
    181 #define TX_SIZE_LUMA_MIN (TX_4X4)
    182 /* We don't need to code a transform size unless the allowed size is at least
    183    one more than the minimum. */
    184 #define TX_SIZE_CTX_MIN (TX_SIZE_LUMA_MIN + 1)
    185 
    186 // Maximum tx_size categories
    187 #define MAX_TX_CATS (TX_SIZES - TX_SIZE_CTX_MIN)
    188 #define MAX_TX_DEPTH 2
    189 
    190 #define MAX_TX_SIZE_LOG2 (6)
    191 #define MAX_TX_SIZE (1 << MAX_TX_SIZE_LOG2)
    192 #define MIN_TX_SIZE_LOG2 2
    193 #define MIN_TX_SIZE (1 << MIN_TX_SIZE_LOG2)
    194 #define MAX_TX_SQUARE (MAX_TX_SIZE * MAX_TX_SIZE)
    195 
    196 // Pad 4 extra columns to remove horizontal availability check.
    197 #define TX_PAD_HOR_LOG2 2
    198 #define TX_PAD_HOR 4
    199 // Pad 6 extra rows (2 on top and 4 on bottom) to remove vertical availability
    200 // check.
    201 #define TX_PAD_TOP 0
    202 #define TX_PAD_BOTTOM 4
    203 #define TX_PAD_VER (TX_PAD_TOP + TX_PAD_BOTTOM)
    204 // Pad 16 extra bytes to avoid reading overflow in SIMD optimization.
    205 #define TX_PAD_END 16
    206 #define TX_PAD_2D ((32 + TX_PAD_HOR) * (32 + TX_PAD_VER) + TX_PAD_END)
    207 
    208 // Number of maxium size transform blocks in the maximum size superblock
    209 #define MAX_TX_BLOCKS_IN_MAX_SB_LOG2 ((MAX_SB_SIZE_LOG2 - MAX_TX_SIZE_LOG2) * 2)
    210 #define MAX_TX_BLOCKS_IN_MAX_SB (1 << MAX_TX_BLOCKS_IN_MAX_SB_LOG2)
    211 
    212 // frame transform mode
    213 enum {
    214   ONLY_4X4,         // use only 4x4 transform
    215   TX_MODE_LARGEST,  // transform size is the largest possible for pu size
    216   TX_MODE_SELECT,   // transform specified for each block
    217   TX_MODES,
    218 } UENUM1BYTE(TX_MODE);
    219 
    220 // 1D tx types
    221 enum {
    222   DCT_1D,
    223   ADST_1D,
    224   FLIPADST_1D,
    225   IDTX_1D,
    226   TX_TYPES_1D,
    227 } UENUM1BYTE(TX_TYPE_1D);
    228 
    229 enum {
    230   DCT_DCT,            // DCT in both horizontal and vertical
    231   ADST_DCT,           // ADST in vertical, DCT in horizontal
    232   DCT_ADST,           // DCT in vertical, ADST in horizontal
    233   ADST_ADST,          // ADST in both directions
    234   FLIPADST_DCT,       // FLIPADST in vertical, DCT in horizontal
    235   DCT_FLIPADST,       // DCT in vertical, FLIPADST in horizontal
    236   FLIPADST_FLIPADST,  // FLIPADST in both directions
    237   ADST_FLIPADST,      // ADST in vertical, FLIPADST in horizontal
    238   FLIPADST_ADST,      // FLIPADST in vertical, ADST in horizontal
    239   IDTX,               // Identity in both directions
    240   V_DCT,              // DCT in vertical, identity in horizontal
    241   H_DCT,              // Identity in vertical, DCT in horizontal
    242   V_ADST,             // ADST in vertical, identity in horizontal
    243   H_ADST,             // Identity in vertical, ADST in horizontal
    244   V_FLIPADST,         // FLIPADST in vertical, identity in horizontal
    245   H_FLIPADST,         // Identity in vertical, FLIPADST in horizontal
    246   TX_TYPES,
    247 } UENUM1BYTE(TX_TYPE);
    248 
    249 enum {
    250   REG_REG,
    251   REG_SMOOTH,
    252   REG_SHARP,
    253   SMOOTH_REG,
    254   SMOOTH_SMOOTH,
    255   SMOOTH_SHARP,
    256   SHARP_REG,
    257   SHARP_SMOOTH,
    258   SHARP_SHARP,
    259 } UENUM1BYTE(DUAL_FILTER_TYPE);
    260 
    261 enum {
    262   // DCT only
    263   EXT_TX_SET_DCTONLY,
    264   // DCT + Identity only
    265   EXT_TX_SET_DCT_IDTX,
    266   // Discrete Trig transforms w/o flip (4) + Identity (1)
    267   EXT_TX_SET_DTT4_IDTX,
    268   // Discrete Trig transforms w/o flip (4) + Identity (1) + 1D Hor/vert DCT (2)
    269   EXT_TX_SET_DTT4_IDTX_1DDCT,
    270   // Discrete Trig transforms w/ flip (9) + Identity (1) + 1D Hor/Ver DCT (2)
    271   EXT_TX_SET_DTT9_IDTX_1DDCT,
    272   // Discrete Trig transforms w/ flip (9) + Identity (1) + 1D Hor/Ver (6)
    273   EXT_TX_SET_ALL16,
    274   EXT_TX_SET_TYPES
    275 } UENUM1BYTE(TxSetType);
    276 
    277 #define IS_2D_TRANSFORM(tx_type) (tx_type < IDTX)
    278 
    279 #define EXT_TX_SIZES 4       // number of sizes that use extended transforms
    280 #define EXT_TX_SETS_INTER 4  // Sets of transform selections for INTER
    281 #define EXT_TX_SETS_INTRA 3  // Sets of transform selections for INTRA
    282 
    283 enum {
    284   AOM_LAST_FLAG = 1 << 0,
    285   AOM_LAST2_FLAG = 1 << 1,
    286   AOM_LAST3_FLAG = 1 << 2,
    287   AOM_GOLD_FLAG = 1 << 3,
    288   AOM_BWD_FLAG = 1 << 4,
    289   AOM_ALT2_FLAG = 1 << 5,
    290   AOM_ALT_FLAG = 1 << 6,
    291   AOM_REFFRAME_ALL = (1 << 7) - 1
    292 } UENUM1BYTE(AOM_REFFRAME);
    293 
    294 enum {
    295   UNIDIR_COMP_REFERENCE,
    296   BIDIR_COMP_REFERENCE,
    297   COMP_REFERENCE_TYPES,
    298 } UENUM1BYTE(COMP_REFERENCE_TYPE);
    299 
    300 enum { PLANE_TYPE_Y, PLANE_TYPE_UV, PLANE_TYPES } UENUM1BYTE(PLANE_TYPE);
    301 
    302 #define CFL_ALPHABET_SIZE_LOG2 4
    303 #define CFL_ALPHABET_SIZE (1 << CFL_ALPHABET_SIZE_LOG2)
    304 #define CFL_MAGS_SIZE ((2 << CFL_ALPHABET_SIZE_LOG2) + 1)
    305 #define CFL_IDX_U(idx) (idx >> CFL_ALPHABET_SIZE_LOG2)
    306 #define CFL_IDX_V(idx) (idx & (CFL_ALPHABET_SIZE - 1))
    307 
    308 enum { CFL_PRED_U, CFL_PRED_V, CFL_PRED_PLANES } UENUM1BYTE(CFL_PRED_TYPE);
    309 
    310 enum {
    311   CFL_SIGN_ZERO,
    312   CFL_SIGN_NEG,
    313   CFL_SIGN_POS,
    314   CFL_SIGNS
    315 } UENUM1BYTE(CFL_SIGN_TYPE);
    316 
    317 enum {
    318   CFL_DISALLOWED,
    319   CFL_ALLOWED,
    320   CFL_ALLOWED_TYPES
    321 } UENUM1BYTE(CFL_ALLOWED_TYPE);
    322 
    323 // CFL_SIGN_ZERO,CFL_SIGN_ZERO is invalid
    324 #define CFL_JOINT_SIGNS (CFL_SIGNS * CFL_SIGNS - 1)
    325 // CFL_SIGN_U is equivalent to (js + 1) / 3 for js in 0 to 8
    326 #define CFL_SIGN_U(js) (((js + 1) * 11) >> 5)
    327 // CFL_SIGN_V is equivalent to (js + 1) % 3 for js in 0 to 8
    328 #define CFL_SIGN_V(js) ((js + 1) - CFL_SIGNS * CFL_SIGN_U(js))
    329 
    330 // There is no context when the alpha for a given plane is zero.
    331 // So there are 2 fewer contexts than joint signs.
    332 #define CFL_ALPHA_CONTEXTS (CFL_JOINT_SIGNS + 1 - CFL_SIGNS)
    333 #define CFL_CONTEXT_U(js) (js + 1 - CFL_SIGNS)
    334 // Also, the contexts are symmetric under swapping the planes.
    335 #define CFL_CONTEXT_V(js) \
    336   (CFL_SIGN_V(js) * CFL_SIGNS + CFL_SIGN_U(js) - CFL_SIGNS)
    337 
    338 enum {
    339   PALETTE_MAP,
    340   COLOR_MAP_TYPES,
    341 } UENUM1BYTE(COLOR_MAP_TYPE);
    342 
    343 enum {
    344   TWO_COLORS,
    345   THREE_COLORS,
    346   FOUR_COLORS,
    347   FIVE_COLORS,
    348   SIX_COLORS,
    349   SEVEN_COLORS,
    350   EIGHT_COLORS,
    351   PALETTE_SIZES
    352 } UENUM1BYTE(PALETTE_SIZE);
    353 
    354 enum {
    355   PALETTE_COLOR_ONE,
    356   PALETTE_COLOR_TWO,
    357   PALETTE_COLOR_THREE,
    358   PALETTE_COLOR_FOUR,
    359   PALETTE_COLOR_FIVE,
    360   PALETTE_COLOR_SIX,
    361   PALETTE_COLOR_SEVEN,
    362   PALETTE_COLOR_EIGHT,
    363   PALETTE_COLORS
    364 } UENUM1BYTE(PALETTE_COLOR);
    365 
    366 // Note: All directional predictors must be between V_PRED and D67_PRED (both
    367 // inclusive).
    368 enum {
    369   DC_PRED,        // Average of above and left pixels
    370   V_PRED,         // Vertical
    371   H_PRED,         // Horizontal
    372   D45_PRED,       // Directional 45  degree
    373   D135_PRED,      // Directional 135 degree
    374   D113_PRED,      // Directional 113 degree
    375   D157_PRED,      // Directional 157 degree
    376   D203_PRED,      // Directional 203 degree
    377   D67_PRED,       // Directional 67  degree
    378   SMOOTH_PRED,    // Combination of horizontal and vertical interpolation
    379   SMOOTH_V_PRED,  // Vertical interpolation
    380   SMOOTH_H_PRED,  // Horizontal interpolation
    381   PAETH_PRED,     // Predict from the direction of smallest gradient
    382   NEARESTMV,
    383   NEARMV,
    384   GLOBALMV,
    385   NEWMV,
    386   // Compound ref compound modes
    387   NEAREST_NEARESTMV,
    388   NEAR_NEARMV,
    389   NEAREST_NEWMV,
    390   NEW_NEARESTMV,
    391   NEAR_NEWMV,
    392   NEW_NEARMV,
    393   GLOBAL_GLOBALMV,
    394   NEW_NEWMV,
    395   MB_MODE_COUNT,
    396   INTRA_MODE_START = DC_PRED,
    397   INTRA_MODE_END = NEARESTMV,
    398   INTRA_MODE_NUM = INTRA_MODE_END - INTRA_MODE_START,
    399   SINGLE_INTER_MODE_START = NEARESTMV,
    400   SINGLE_INTER_MODE_END = NEAREST_NEARESTMV,
    401   SINGLE_INTER_MODE_NUM = SINGLE_INTER_MODE_END - SINGLE_INTER_MODE_START,
    402   COMP_INTER_MODE_START = NEAREST_NEARESTMV,
    403   COMP_INTER_MODE_END = MB_MODE_COUNT,
    404   COMP_INTER_MODE_NUM = COMP_INTER_MODE_END - COMP_INTER_MODE_START,
    405   INTER_MODE_START = NEARESTMV,
    406   INTER_MODE_END = MB_MODE_COUNT,
    407   INTRA_MODES = PAETH_PRED + 1,  // PAETH_PRED has to be the last intra mode.
    408   INTRA_INVALID = MB_MODE_COUNT  // For uv_mode in inter blocks
    409 } UENUM1BYTE(PREDICTION_MODE);
    410 
    411 // TODO(ltrudeau) Do we really want to pack this?
    412 // TODO(ltrudeau) Do we match with PREDICTION_MODE?
    413 enum {
    414   UV_DC_PRED,        // Average of above and left pixels
    415   UV_V_PRED,         // Vertical
    416   UV_H_PRED,         // Horizontal
    417   UV_D45_PRED,       // Directional 45  degree
    418   UV_D135_PRED,      // Directional 135 degree
    419   UV_D113_PRED,      // Directional 113 degree
    420   UV_D157_PRED,      // Directional 157 degree
    421   UV_D203_PRED,      // Directional 203 degree
    422   UV_D67_PRED,       // Directional 67  degree
    423   UV_SMOOTH_PRED,    // Combination of horizontal and vertical interpolation
    424   UV_SMOOTH_V_PRED,  // Vertical interpolation
    425   UV_SMOOTH_H_PRED,  // Horizontal interpolation
    426   UV_PAETH_PRED,     // Predict from the direction of smallest gradient
    427   UV_CFL_PRED,       // Chroma-from-Luma
    428   UV_INTRA_MODES,
    429   UV_MODE_INVALID,  // For uv_mode in inter blocks
    430 } UENUM1BYTE(UV_PREDICTION_MODE);
    431 
    432 enum {
    433   SIMPLE_TRANSLATION,
    434   OBMC_CAUSAL,    // 2-sided OBMC
    435   WARPED_CAUSAL,  // 2-sided WARPED
    436   MOTION_MODES
    437 } UENUM1BYTE(MOTION_MODE);
    438 
    439 enum {
    440   II_DC_PRED,
    441   II_V_PRED,
    442   II_H_PRED,
    443   II_SMOOTH_PRED,
    444   INTERINTRA_MODES
    445 } UENUM1BYTE(INTERINTRA_MODE);
    446 
    447 enum {
    448   COMPOUND_AVERAGE,
    449   COMPOUND_DISTWTD,
    450   COMPOUND_WEDGE,
    451   COMPOUND_DIFFWTD,
    452   COMPOUND_TYPES,
    453   MASKED_COMPOUND_TYPES = 2,
    454 } UENUM1BYTE(COMPOUND_TYPE);
    455 
    456 enum {
    457   FILTER_DC_PRED,
    458   FILTER_V_PRED,
    459   FILTER_H_PRED,
    460   FILTER_D157_PRED,
    461   FILTER_PAETH_PRED,
    462   FILTER_INTRA_MODES,
    463 } UENUM1BYTE(FILTER_INTRA_MODE);
    464 
    465 enum {
    466   SEQ_LEVEL_2_0,
    467   SEQ_LEVEL_2_1,
    468   SEQ_LEVEL_2_2,
    469   SEQ_LEVEL_2_3,
    470   SEQ_LEVEL_3_0,
    471   SEQ_LEVEL_3_1,
    472   SEQ_LEVEL_3_2,
    473   SEQ_LEVEL_3_3,
    474   SEQ_LEVEL_4_0,
    475   SEQ_LEVEL_4_1,
    476   SEQ_LEVEL_4_2,
    477   SEQ_LEVEL_4_3,
    478   SEQ_LEVEL_5_0,
    479   SEQ_LEVEL_5_1,
    480   SEQ_LEVEL_5_2,
    481   SEQ_LEVEL_5_3,
    482   SEQ_LEVEL_6_0,
    483   SEQ_LEVEL_6_1,
    484   SEQ_LEVEL_6_2,
    485   SEQ_LEVEL_6_3,
    486   SEQ_LEVEL_7_0,
    487   SEQ_LEVEL_7_1,
    488   SEQ_LEVEL_7_2,
    489   SEQ_LEVEL_7_3,
    490   SEQ_LEVELS,
    491   SEQ_LEVEL_MAX = 31
    492 } UENUM1BYTE(AV1_LEVEL);
    493 
    494 #define LEVEL_BITS 5
    495 
    496 #define DIRECTIONAL_MODES 8
    497 #define MAX_ANGLE_DELTA 3
    498 #define ANGLE_STEP 3
    499 
    500 #define INTER_MODES (1 + NEWMV - NEARESTMV)
    501 
    502 #define INTER_COMPOUND_MODES (1 + NEW_NEWMV - NEAREST_NEARESTMV)
    503 
    504 #define SKIP_CONTEXTS 3
    505 #define SKIP_MODE_CONTEXTS 3
    506 
    507 #define COMP_INDEX_CONTEXTS 6
    508 #define COMP_GROUP_IDX_CONTEXTS 6
    509 
    510 #define NMV_CONTEXTS 3
    511 
    512 #define NEWMV_MODE_CONTEXTS 6
    513 #define GLOBALMV_MODE_CONTEXTS 2
    514 #define REFMV_MODE_CONTEXTS 6
    515 #define DRL_MODE_CONTEXTS 3
    516 
    517 #define GLOBALMV_OFFSET 3
    518 #define REFMV_OFFSET 4
    519 
    520 #define NEWMV_CTX_MASK ((1 << GLOBALMV_OFFSET) - 1)
    521 #define GLOBALMV_CTX_MASK ((1 << (REFMV_OFFSET - GLOBALMV_OFFSET)) - 1)
    522 #define REFMV_CTX_MASK ((1 << (8 - REFMV_OFFSET)) - 1)
    523 
    524 #define COMP_NEWMV_CTXS 5
    525 #define INTER_MODE_CONTEXTS 8
    526 
    527 #define DELTA_Q_SMALL 3
    528 #define DELTA_Q_PROBS (DELTA_Q_SMALL)
    529 #define DEFAULT_DELTA_Q_RES 4
    530 #define DELTA_LF_SMALL 3
    531 #define DELTA_LF_PROBS (DELTA_LF_SMALL)
    532 #define DEFAULT_DELTA_LF_RES 2
    533 
    534 /* Segment Feature Masks */
    535 #define MAX_MV_REF_CANDIDATES 2
    536 
    537 #define MAX_REF_MV_STACK_SIZE 8
    538 #define REF_CAT_LEVEL 640
    539 
    540 #define INTRA_INTER_CONTEXTS 4
    541 #define COMP_INTER_CONTEXTS 5
    542 #define REF_CONTEXTS 3
    543 
    544 #define COMP_REF_TYPE_CONTEXTS 5
    545 #define UNI_COMP_REF_CONTEXTS 3
    546 
    547 #define TXFM_PARTITION_CONTEXTS ((TX_SIZES - TX_8X8) * 6 - 3)
    548 typedef uint8_t TXFM_CONTEXT;
    549 
    550 // An enum for single reference types (and some derived values).
    551 enum {
    552   NONE_FRAME = -1,
    553   INTRA_FRAME,
    554   LAST_FRAME,
    555   LAST2_FRAME,
    556   LAST3_FRAME,
    557   GOLDEN_FRAME,
    558   BWDREF_FRAME,
    559   ALTREF2_FRAME,
    560   ALTREF_FRAME,
    561   REF_FRAMES,
    562 
    563   // Extra/scratch reference frame. It may be:
    564   // - used to update the ALTREF2_FRAME ref (see lshift_bwd_ref_frames()), or
    565   // - updated from ALTREF2_FRAME ref (see rshift_bwd_ref_frames()).
    566   EXTREF_FRAME = REF_FRAMES,
    567 
    568   // Number of inter (non-intra) reference types.
    569   INTER_REFS_PER_FRAME = ALTREF_FRAME - LAST_FRAME + 1,
    570 
    571   // Number of forward (aka past) reference types.
    572   FWD_REFS = GOLDEN_FRAME - LAST_FRAME + 1,
    573 
    574   // Number of backward (aka future) reference types.
    575   BWD_REFS = ALTREF_FRAME - BWDREF_FRAME + 1,
    576 
    577   SINGLE_REFS = FWD_REFS + BWD_REFS,
    578 };
    579 
    580 #define REF_FRAMES_LOG2 3
    581 
    582 // REF_FRAMES for the cm->ref_frame_map array, 1 scratch frame for the new
    583 // frame in cm->cur_frame, INTER_REFS_PER_FRAME for scaled references on the
    584 // encoder in the cpi->scaled_ref_buf array.
    585 #define FRAME_BUFFERS (REF_FRAMES + 1 + INTER_REFS_PER_FRAME)
    586 
    587 #define FWD_RF_OFFSET(ref) (ref - LAST_FRAME)
    588 #define BWD_RF_OFFSET(ref) (ref - BWDREF_FRAME)
    589 
    590 enum {
    591   LAST_LAST2_FRAMES,      // { LAST_FRAME, LAST2_FRAME }
    592   LAST_LAST3_FRAMES,      // { LAST_FRAME, LAST3_FRAME }
    593   LAST_GOLDEN_FRAMES,     // { LAST_FRAME, GOLDEN_FRAME }
    594   BWDREF_ALTREF_FRAMES,   // { BWDREF_FRAME, ALTREF_FRAME }
    595   LAST2_LAST3_FRAMES,     // { LAST2_FRAME, LAST3_FRAME }
    596   LAST2_GOLDEN_FRAMES,    // { LAST2_FRAME, GOLDEN_FRAME }
    597   LAST3_GOLDEN_FRAMES,    // { LAST3_FRAME, GOLDEN_FRAME }
    598   BWDREF_ALTREF2_FRAMES,  // { BWDREF_FRAME, ALTREF2_FRAME }
    599   ALTREF2_ALTREF_FRAMES,  // { ALTREF2_FRAME, ALTREF_FRAME }
    600   TOTAL_UNIDIR_COMP_REFS,
    601   // NOTE: UNIDIR_COMP_REFS is the number of uni-directional reference pairs
    602   //       that are explicitly signaled.
    603   UNIDIR_COMP_REFS = BWDREF_ALTREF_FRAMES + 1,
    604 } UENUM1BYTE(UNIDIR_COMP_REF);
    605 
    606 #define TOTAL_COMP_REFS (FWD_REFS * BWD_REFS + TOTAL_UNIDIR_COMP_REFS)
    607 
    608 #define COMP_REFS (FWD_REFS * BWD_REFS + UNIDIR_COMP_REFS)
    609 
    610 // NOTE: A limited number of unidirectional reference pairs can be signalled for
    611 //       compound prediction. The use of skip mode, on the other hand, makes it
    612 //       possible to have a reference pair not listed for explicit signaling.
    613 #define MODE_CTX_REF_FRAMES (REF_FRAMES + TOTAL_COMP_REFS)
    614 
    615 // Note: It includes single and compound references. So, it can take values from
    616 // NONE_FRAME to (MODE_CTX_REF_FRAMES - 1). Hence, it is not defined as an enum.
    617 typedef int8_t MV_REFERENCE_FRAME;
    618 
    619 enum {
    620   RESTORE_NONE,
    621   RESTORE_WIENER,
    622   RESTORE_SGRPROJ,
    623   RESTORE_SWITCHABLE,
    624   RESTORE_SWITCHABLE_TYPES = RESTORE_SWITCHABLE,
    625   RESTORE_TYPES = 4,
    626 } UENUM1BYTE(RestorationType);
    627 
    628 #define SUPERRES_SCALE_BITS 3
    629 #define SUPERRES_SCALE_DENOMINATOR_MIN (SCALE_NUMERATOR + 1)
    630 
    631 // In large_scale_tile coding, external references are used.
    632 #define MAX_EXTERNAL_REFERENCES 128
    633 #define MAX_TILES 512
    634 
    635 #ifdef __cplusplus
    636 }  // extern "C"
    637 #endif
    638 
    639 #endif  // AOM_AV1_COMMON_ENUMS_H_
    640