xref: /aosp_15_r20/external/libavc/encoder/ih264e_core_coding.h (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
1 /******************************************************************************
2  *
3  * Copyright (C) 2015 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 
21 /**
22 ******************************************************************************
23 * @file
24 *  ih264e_core_coding.h
25 *
26 * @brief
27 *  This file contains declarations necessary for core coding of luma and chroma
28 *  blocks
29 *
30 * @author
31 *  ittiam
32 *
33 * @remarks
34 *  none
35 ******************************************************************************
36 */
37 
38 #ifndef _IH264E_CORE_CODING_H_
39 #define _IH264E_CORE_CODING_H_
40 
41 /*****************************************************************************/
42 /* Macros                                                                    */
43 /*****************************************************************************/
44 
45 /**
46 ******************************************************************************
47  *  @brief      Enable/Disable Hadamard transform of DC Coeff's
48 ******************************************************************************
49  */
50 #define DISABLE_DC_TRANSFORM 0
51 #define ENABLE_DC_TRANSFORM 1
52 
53 /**
54 *******************************************************************************
55  *  @brief bit masks for DC and AC control flags
56 *******************************************************************************
57  */
58 
59 #define DC_COEFF_CNT_LUMA_MB        16
60 #define NUM_4X4_BLKS_LUMA_MB_ROW    4
61 #define NUM_LUMA4x4_BLOCKS_IN_MB    16
62 #define NUM_CHROMA4x4_BLOCKS_IN_MB  8
63 
64 #define SIZE_4X4_BLK_HRZ            TRANS_SIZE_4
65 #define SIZE_4X4_BLK_VERT           TRANS_SIZE_4
66 
67 #define CNTRL_FLAG_DC_MASK_LUMA     0x0000FFFF
68 #define CNTRL_FLAG_AC_MASK_LUMA     0xFFFF0000
69 
70 #define CNTRL_FLAG_AC_MASK_CHROMA_U 0xF0000000
71 #define CNTRL_FLAG_DC_MASK_CHROMA_U 0x0000F000
72 
73 #define CNTRL_FLAG_AC_MASK_CHROMA_V 0x0F000000
74 #define CNTRL_FLAG_DC_MASK_CHROMA_V 0x00000F00
75 
76 #define CNTRL_FLAG_AC_MASK_CHROMA   ( CNTRL_FLAG_AC_MASK_CHROMA_U | CNTRL_FLAG_AC_MASK_CHROMA_V )
77 #define CNTRL_FLAG_DC_MASK_CHROMA   ( CNTRL_FLAG_DC_MASK_CHROMA_U | CNTRL_FLAG_DC_MASK_CHROMA_V )
78 
79 #define CNTRL_FLAG_DCBLK_MASK_CHROMA 0x0000C000
80 
81 /**
82 *******************************************************************************
83  *  @brief macros for transforms
84 *******************************************************************************
85  */
86 #define DEQUEUE_BLKID_FROM_CONTROL( u4_cntrl,  blk_lin_id)                     \
87 {                                                                              \
88      blk_lin_id = CLZ(u4_cntrl);                                               \
89      u4_cntrl &= (0x7FFFFFFF >> blk_lin_id);                                   \
90 };
91 
92 #define IND2SUB_LUMA_MB(u4_blk_id,i4_offset_x,i4_offset_y)                     \
93 {                                                                              \
94      i4_offset_x = (u4_blk_id % 4) << 2;                                       \
95      i4_offset_y = (u4_blk_id / 4) << 2;                                       \
96 }
97 
98 #define IND2SUB_CHROMA_MB(u4_blk_id,i4_offset_x,i4_offset_y)                   \
99 {                                                                              \
100      i4_offset_x = ((u4_blk_id & 0x1 ) << 3) + (u4_blk_id > 3);                \
101      i4_offset_y = (u4_blk_id & 0x2) << 1;                                     \
102 }
103 
104 
105 /*****************************************************************************/
106 /* Function Declarations                                                     */
107 /*****************************************************************************/
108 
109 void ih264e_luma_16x16_resi_trans_dctrans_quant(
110                 codec_t *ps_codec, UWORD8 *pu1_src, UWORD8 *pu1_pred,
111                 WORD16 *pi2_out, WORD32 src_strd, WORD32 pred_strd,
112                 WORD32 dst_strd, const UWORD16 *pu2_scale_matrix,
113                 const UWORD16 *pu2_threshold_matrix, UWORD32 u4_qbits,
114                 UWORD32 u4_round_factor, UWORD8 *pu1_nnz, UWORD32 u4_dc_flag);
115 
116 void ih264e_luma_16x16_idctrans_iquant_itrans_recon(
117                 codec_t *ps_codec, WORD16 *pi2_src, UWORD8 *pu1_pred,
118                 UWORD8 *pu1_out, WORD32 src_strd, WORD32 pred_strd,
119                 WORD32 out_strd, const UWORD16 *pu2_iscale_mat,
120                 const UWORD16 *pu2_weigh_mat, UWORD32 qp_div, UWORD32 u4_cntrl,
121                 UWORD32 u4_dc_trans_flag, WORD32 *pi4_tmp);
122 
123 void ih264e_chroma_8x8_resi_trans_dctrans_quant(
124                 codec_t *ps_codec, UWORD8 *pu1_src, UWORD8 *pu1_pred,
125                 WORD16 *pi2_out, WORD32 src_strd, WORD32 pred_strd,
126                 WORD32 out_strd, const UWORD16 *pu2_scale_matrix,
127                 const UWORD16 *pu2_threshold_matrix, UWORD32 u4_qbits,
128                 UWORD32 u4_round_factor, UWORD8 *pu1_nnz_c);
129 
130 void ih264e_chroma_8x8_idctrans_iquant_itrans_recon(
131                 codec_t *ps_codec, WORD16 *pi2_src, UWORD8 *pu1_pred,
132                 UWORD8 *pu1_out, WORD32 src_strd, WORD32 pred_strd,
133                 WORD32 out_strd, const UWORD16 *pu2_iscale_mat,
134                 const UWORD16 *pu2_weigh_mat, UWORD32 qp_div, UWORD32 u4_cntrl,
135                 WORD32 *pi4_tmp);
136 
137 void ih264e_pack_l_mb_i16(WORD16 *pi2_res_mb, void **pv_mb_coeff_data,
138                           WORD32 i4_res_strd, UWORD8 *u1_cbp_l, UWORD8 *pu1_nnz,
139                           UWORD32 *pu4_cntrl);
140 
141 void ih264e_pack_c_mb(WORD16 *pi2_res_mb, void **pv_mb_coeff_data,
142                       WORD32 i4_res_strd, UWORD8 *u1_cbp_c, UWORD8 *pu1_nnz,
143                       UWORD32 u4_kill_coffs_flag, UWORD32 *pu4_cntrl,
144                       UWORD32 u4_swap_uv);
145 
146 UWORD8 ih264e_code_luma_intra_macroblock_16x16(process_ctxt_t *ps_proc);
147 
148 UWORD8 ih264e_code_luma_intra_macroblock_4x4(process_ctxt_t *ps_proc);
149 
150 UWORD8 ih264e_code_luma_intra_macroblock_4x4_rdopt_on(process_ctxt_t *ps_proc);
151 
152 UWORD8 ih264e_code_chroma_intra_macroblock_8x8(process_ctxt_t *ps_proc);
153 
154 UWORD8 ih264e_code_luma_inter_macroblock_16x16(process_ctxt_t *ps_proc);
155 
156 UWORD8 ih264e_code_chroma_inter_macroblock_8x8(process_ctxt_t *ps_proc);
157 
158 #endif /* _IH264E_CORE_CODING_H_ */
159