1 /*
2 * Copyright(c) 2019 Netflix, Inc.
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 https://www.aomedia.org/license/software-license. 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 https://www.aomedia.org/license/patent-license.
10 */
11 
12 #ifndef EbDecBlock_h
13 #define EbDecBlock_h
14 
15 #include "EbDefinitions.h"
16 #include "EbRestoration.h"
17 #include "EbBlockStructures.h"
18 
19 #define MODE_INFO_DBG 0
20 
21 static const BlockSize partition_subsize[10][BlockSizeS_ALL] = {
22     {BLOCK_4X4,     BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X8,     BLOCK_INVALID, BLOCK_INVALID,
23      BLOCK_16X16,   BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X32,   BLOCK_INVALID, BLOCK_INVALID,
24      BLOCK_64X64,   BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X128, BLOCK_INVALID, BLOCK_INVALID,
25      BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID},
26     {BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X4,    BLOCK_INVALID, BLOCK_INVALID,
27      BLOCK_16X8,    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X16,  BLOCK_INVALID, BLOCK_INVALID,
28      BLOCK_64X32,   BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X64, BLOCK_INVALID, BLOCK_INVALID,
29      BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID},
30     {BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X8,    BLOCK_INVALID, BLOCK_INVALID,
31      BLOCK_8X16,    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X32,  BLOCK_INVALID, BLOCK_INVALID,
32      BLOCK_32X64,   BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X128, BLOCK_INVALID, BLOCK_INVALID,
33      BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID},
34     {BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X4,    BLOCK_INVALID, BLOCK_INVALID,
35      BLOCK_8X8,     BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X16,  BLOCK_INVALID, BLOCK_INVALID,
36      BLOCK_32X32,   BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X64,  BLOCK_INVALID, BLOCK_INVALID,
37      BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID},
38     {BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X4,    BLOCK_INVALID, BLOCK_INVALID,
39      BLOCK_16X8,    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X16,  BLOCK_INVALID, BLOCK_INVALID,
40      BLOCK_64X32,   BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X64, BLOCK_INVALID, BLOCK_INVALID,
41      BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID},
42     {BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X4,    BLOCK_INVALID, BLOCK_INVALID,
43      BLOCK_16X8,    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X16,  BLOCK_INVALID, BLOCK_INVALID,
44      BLOCK_64X32,   BLOCK_INVALID, BLOCK_INVALID, BLOCK_128X64, BLOCK_INVALID, BLOCK_INVALID,
45      BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID},
46     {BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X8,    BLOCK_INVALID, BLOCK_INVALID,
47      BLOCK_8X16,    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X32,  BLOCK_INVALID, BLOCK_INVALID,
48      BLOCK_32X64,   BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X128, BLOCK_INVALID, BLOCK_INVALID,
49      BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID},
50     {BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_4X8,    BLOCK_INVALID, BLOCK_INVALID,
51      BLOCK_8X16,    BLOCK_INVALID, BLOCK_INVALID, BLOCK_16X32,  BLOCK_INVALID, BLOCK_INVALID,
52      BLOCK_32X64,   BLOCK_INVALID, BLOCK_INVALID, BLOCK_64X128, BLOCK_INVALID, BLOCK_INVALID,
53      BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID},
54     {BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
55      BLOCK_16X4,    BLOCK_INVALID, BLOCK_INVALID, BLOCK_32X8,    BLOCK_INVALID, BLOCK_INVALID,
56      BLOCK_64X16,   BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
57      BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID},
58     {BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
59      BLOCK_4X16,    BLOCK_INVALID, BLOCK_INVALID, BLOCK_8X32,    BLOCK_INVALID, BLOCK_INVALID,
60      BLOCK_16X64,   BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID,
61      BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID, BLOCK_INVALID}};
62 
63 #define MFMV_STACK_SIZE 3
64 typedef struct TemporalMvRef {
65     /* Motion Filed MV */
66     IntMv  mf_mv0;
67     int8_t ref_frame_offset;
68 } TemporalMvRef;
69 
70 typedef struct TransformInfo {
71     /*!< Specifies the transform size to be used for this TU. */
72     TxSize tx_size;
73 
74     /*!< Specifies the transform type for the TU. */
75     TxType txk_type;
76 
77     /*!< Code Block Flag, 0: No residual for the block
78                           1: Residual exists for the block */
79     int8_t cbf;
80 
81     /*!< x offset for a block in mi unit*/
82     uint8_t txb_x_offset;
83     /*!< y offset for a block in mi unit */
84     uint8_t txb_y_offset;
85 
86 } TransformInfo_t;
87 
88 typedef struct SBInfo {
89     int8_t * sb_cdef_strength; /*!< At 64x64 blk level */
90     int32_t *sb_delta_q; /*!< At SB level */
91     int32_t *sb_delta_lf; /*!< At SB level */
92 
93     TransformInfo_t *sb_trans_info[MAX_MB_PLANE - 1];
94 
95     int32_t *sb_coeff[MAX_MB_PLANE];
96 
97     BlockModeInfo *sb_mode_info;
98 
99     int32_t num_block;
100 
101 } SBInfo;
102 
103 typedef struct PartitionInfo {
104     /*!< Specifies the vertical location of the block in units of 4x4 luma samples. */
105     uint16_t mi_row;
106 
107     /*!< Specifies the horizontal location of the block in units of 4x4 luma samples. */
108     uint16_t mi_col;
109 
110     BlockModeInfo *mi;
111 
112     SBInfo *sb_info;
113 
114     BlockModeInfo *left_mbmi;
115 
116     BlockModeInfo *above_mbmi;
117 
118     BlockModeInfo *chroma_left_mbmi;
119 
120     BlockModeInfo *chroma_above_mbmi;
121 
122     /*!< Indicates if the information from the block above cab be used on the luma plane. */
123     uint8_t up_available;
124 
125     /*!< Indicates if the information from the block to the left can be used on the luma plane. */
126     uint8_t left_available;
127 
128     // TO-DO bhavna Verify if this is necessary. Can this info be accessed from elsewhere
129     uint8_t neighbors_ref_counts[REF_FRAMES];
130 
131     /*!< Indicates if the information from the block above cab be used on the chroma plane. */
132     uint8_t chroma_up_available;
133 
134     /*!< Indicates if the information from the block to the left can be used on the chroma plane. */
135     uint8_t chroma_left_available;
136 
137     /*!< Distance of MB away from frame edges in subpixels (1/8th pixel).  */
138     int32_t mb_to_left_edge;
139 
140     int32_t mb_to_right_edge;
141 
142     int32_t mb_to_top_edge;
143 
144     int32_t mb_to_bottom_edge;
145 
146     /*!< Block Size width & height in pixels. */
147     int32_t wpx[3];
148 
149     int32_t hpx[3];
150 
151     /*!< 1 indicates that the block is to be coded as fully lossless,
152      *   0 indicates lossy coding */
153     //int lossless;
154 
155     //BlockPlane plane[MAX_MB_PLANE];
156 
157     /*!< Pointer to global warp params of current frame */
158     const EbWarpedMotionParams *ps_global_motion;
159 
160     /*!< Pointer to local warp params based on nieghbour mv sample projection */
161     EbWarpedMotionParams local_warp_params;
162 
163     WienerInfo wiener_info[MAX_MB_PLANE];
164 
165     SgrprojInfo sgrproj_info[MAX_MB_PLANE];
166 
167     /*!< Motion vectors available in the stack */
168     CandidateMv ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE];
169 
170     /*!< Represents an offset used in derivation of the input index to the cb component scaling function */
171     uint16_t cb_offset[MAX_MB_PLANE];
172 
173     /*!< Holds the index for the blocks Y plane and UV plane top left samples. */
174     uint16_t color_index_map_offset[2];
175 
176     /* CFL ctxt */
177     void *pv_cfl_ctxt;
178 
179     int is_sec_rect;
180 
181     int num_samples;
182 
183     /*!< chroma sub-sampling format */
184     uint8_t subsampling_x;
185     uint8_t subsampling_y;
186 
187     /*ToDo: block_ref_sf are used both in parsing & decoding sides,
188       we need implement a logic to avoid two sides calculation of block_ref_sf*/
189     /* pointers to reference frame scale factors */
190     const struct ScaleFactors *block_ref_sf[2];
191     const struct ScaleFactors *sf_identity;
192 
193     int8_t *cdef_strength;
194 
195     int32_t is_chroma_ref;
196     /*MC temp buff for dynamic padding*/
197     uint8_t *mc_buf[2];
198 } PartitionInfo;
199 
200 #endif //EbDecBlock_h
201