1 /******************************************************************************
2 *
3 * Copyright (C) 2022 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 * @file
23 * isvc_trans_quant.h
24 *
25 * @brief
26 * Contains declarations for forward and inverse transform paths for H264
27 *
28 * @author
29 * Ittiam
30 *
31 * @remarks
32 *
33 *******************************************************************************
34 */
35
36 #ifndef _ISVC_TRANS_QUANT_ITRANS_IQUANT_H_
37 #define _ISVC_TRANS_QUANT_ITRANS_IQUANT_H_
38
39 #include <stdint.h>
40
41 #include "ih264_typedefs.h"
42 #include "ih264_debug.h"
43 #include "ih264_macros.h"
44 #include "isvc_macros.h"
45 #include "isvc_structs.h"
46
47 /* With and without residual_pred use */
48 #define NUM_RESI_TRANS_QUANT_VARIANTS 2
49
50 #define NUM_IQ_IT_RECON_VARIANTS 3
51
52 /* Structs */
53 typedef struct resi_trans_quant_constants_t
54 {
55 const UWORD16 *pu2_scale_matrix;
56
57 const UWORD16 *pu2_threshold_matrix;
58
59 UWORD32 u4_qbits;
60
61 UWORD32 u4_round_factor;
62 } resi_trans_quant_constants_t;
63
64 typedef struct iq_it_res_rec_constants_t
65 {
66 const UWORD16 *pu2_iscal_mat;
67
68 const UWORD16 *pu2_weigh_mat;
69
70 UWORD32 u4_qp_div_6;
71 } iq_it_res_rec_constants_t;
72
73 /* Typedefs */
74 typedef void FT_RESI_TRANS_DCTRANS_QUANT(UWORD8 *pu1_src, UWORD8 *pu1_pred, WORD16 *pi2_out,
75 WORD32 src_strd, WORD32 pred_strd, WORD32 dst_strd,
76 const UWORD16 *pu2_scale_mat,
77 const UWORD16 *pu2_thresh_mat, UWORD32 u4_qbit,
78 UWORD32 u4_round_fact, UWORD8 *pu1_nnz);
79
80 typedef void FT_IDCTRANS_IQUANT_ITRANS_RECON(WORD16 *pi2_src, UWORD8 *pu1_pred, UWORD8 *pu1_out,
81 WORD32 src_strd, WORD32 pred_strd, WORD32 out_strd,
82 const UWORD16 *pu2_iscale_mat,
83 const UWORD16 *pu2_weigh_mat, UWORD32 qp_div,
84 UWORD32 pi4_cntrl, WORD32 *pi4_tmp);
85
86 typedef void FT_RESI_TRANS_QUANT(buffer_container_t *ps_src, buffer_container_t *ps_pred,
87 buffer_container_t *ps_out, buffer_container_t *ps_upsampled_res,
88 resi_trans_quant_constants_t *ps_quant_constants, UWORD8 *pu1_nnz,
89 WORD16 *pi2_dc_out, UWORD8 u1_use_upsampled_res);
90
91 typedef void FT_LUMA_16X16_RESI_TRANS_DCTRANS_QUANT(
92 UWORD8 *pu1_src, UWORD8 *pu1_pred, WORD16 *pi2_out, WORD32 src_strd, WORD32 pred_strd,
93 WORD32 dst_strd, const UWORD16 *pu2_scale_matrix, const UWORD16 *pu2_threshold_matrix,
94 UWORD32 u4_qbits, UWORD32 u4_round_factor, UWORD8 *pu1_nnz, UWORD32 u4_dc_flag);
95
96 typedef void FT_CHROMA_8X8_RESI_TRANS_DCTRANS_QUANT(
97 UWORD8 *pu1_src, UWORD8 *pu1_pred, WORD16 *pi2_out, WORD32 src_strd, WORD32 pred_strd,
98 WORD32 dst_strd, const UWORD16 *pu2_scale_matrix, const UWORD16 *pu2_threshold_matrix,
99 UWORD32 u4_qbits, UWORD32 u4_round_factor, UWORD8 *pu1_nnz);
100
101 typedef void FT_IQ_IT_RECON(buffer_container_t *ps_src, buffer_container_t *ps_pred,
102 buffer_container_t *ps_res_pred, buffer_container_t *ps_res,
103 buffer_container_t *ps_rec,
104 iq_it_res_rec_constants_t *ps_iq_it_res_rec_constants, WORD16 *pi2_tmp,
105 WORD16 *pi2_dc_src, WORD32 i4_iq_start_idx, UWORD8 u1_res_accumulate);
106
107 typedef void FT_LUMA_16X16_IDCTRANS_IQUANT_ITRANS_RECON(
108 WORD16 *pi2_src, UWORD8 *pu1_pred, UWORD8 *pu1_out, WORD32 src_strd, WORD32 pred_strd,
109 WORD32 out_strd, const UWORD16 *pu2_iscale_mat, const UWORD16 *pu2_weigh_mat, UWORD32 qp_div,
110 UWORD32 pi4_cntrl, UWORD32 u4_dc_trans_flag, WORD32 *pi4_tmp);
111
112 typedef void FT_CHROMA_8X8_IDCTRANS_IQUANT_ITRANS_RECON(
113 WORD16 *pi2_src, UWORD8 *pu1_pred, UWORD8 *pu1_out, WORD32 src_strd, WORD32 pred_strd,
114 WORD32 out_strd, const UWORD16 *pu2_iscale_mat, const UWORD16 *pu2_weigh_mat, UWORD32 qp_div,
115 UWORD32 pi4_cntrl, WORD32 *pi4_tmp);
116
117 typedef void FT_IHADAMARD_SCALING(WORD16 *pi2_src, WORD16 *pi2_out, const UWORD16 *pu2_iscal_mat,
118 const UWORD16 *pu2_weigh_mat, UWORD32 u4_qp_div_6,
119 WORD32 *pi4_tmp);
120
121 typedef void FT_HADAMARD_QUANT(WORD16 *pi2_src, WORD16 *pi2_dst,
122 resi_trans_quant_constants_t *ps_quant_constants, UWORD8 *pu1_nnz);
123
124 /*****************************************************************************/
125 /* Extern Function Declarations */
126 /*****************************************************************************/
127
128 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_4x4;
129 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_chroma_4x4;
130 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_8x8;
131 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4;
132 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_8x8;
133 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_dc;
134 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4;
135 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_dc;
136 extern FT_IQ_IT_RECON isvc_zcbf_iquant_itrans_recon_4x4;
137 extern FT_IQ_IT_RECON isvc_chroma_zcbf_iquant_itrans_recon_4x4;
138 extern FT_IHADAMARD_SCALING ih264_ihadamard_scaling_4x4;
139 extern FT_IHADAMARD_SCALING ih264_ihadamard_scaling_2x2_uv;
140 extern FT_HADAMARD_QUANT isvc_hadamard_quant_4x4;
141 extern FT_HADAMARD_QUANT isvc_hadamard_quant_2x2_uv;
142
143 /* A9 Declarations */
144 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_4x4_a9;
145 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_chroma_4x4_a9;
146 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_a9;
147 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_8x8_a9;
148 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_dc_a9;
149 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_8x8_dc_a9;
150 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_a9;
151 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_dc_a9;
152 extern FT_LUMA_16X16_RESI_TRANS_DCTRANS_QUANT isvc_luma_16x16_resi_trans_dctrans_quant_a9;
153 extern FT_CHROMA_8X8_RESI_TRANS_DCTRANS_QUANT isvc_chroma_8x8_resi_trans_dctrans_quant_a9;
154 extern FT_LUMA_16X16_IDCTRANS_IQUANT_ITRANS_RECON isvc_luma_16x16_idctrans_iquant_itrans_recon_a9;
155 extern FT_CHROMA_8X8_IDCTRANS_IQUANT_ITRANS_RECON isvc_chroma_8x8_idctrans_iquant_itrans_recon_a9;
156 extern FT_IHADAMARD_SCALING ih264_ihadamard_scaling_4x4_a9;
157 extern FT_IHADAMARD_SCALING ih264_ihadamard_scaling_2x2_uv_a9;
158 extern FT_HADAMARD_QUANT isvc_hadamard_quant_4x4_a9;
159 extern FT_HADAMARD_QUANT isvc_hadamard_quant_2x2_uv_a9;
160
161 /* Av8 Declarations */
162 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_4x4_av8;
163 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_chroma_4x4_av8;
164 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_av8;
165 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_8x8_av8;
166 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_dc_av8;
167 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_8x8_dc_av8;
168 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_av8;
169 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_dc_av8;
170 extern FT_IHADAMARD_SCALING ih264_ihadamard_scaling_4x4_av8;
171 extern FT_IHADAMARD_SCALING ih264_ihadamard_scaling_2x2_uv_av8;
172
173 /* NEON Declarations */
174 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_4x4_neon;
175 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_4x4_with_residual_sub_neon;
176 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_chroma_4x4_neon;
177 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_chroma_4x4_with_residual_sub_neon;
178
179 /* SSSE3 Declarations */
180 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_ssse3;
181 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_8x8_ssse3;
182 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_dc_ssse3;
183 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_8x8_dc_ssse3;
184 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_dc_ssse3;
185 extern FT_IHADAMARD_SCALING ih264_ihadamard_scaling_4x4_ssse3;
186 extern FT_IHADAMARD_SCALING ih264_ihadamard_scaling_2x2_uv_ssse3;
187
188 /* SSSE42 Declarations */
189 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_4x4_sse42;
190 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_4x4_with_res_pred_sse42;
191 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_chroma_4x4_sse42;
192 extern FT_RESI_TRANS_QUANT isvc_resi_trans_quant_chroma_4x4_with_res_pred_sse42;
193
194 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_sse42;
195 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_res_4x4_sse42;
196 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_res_4x4_with_res_acc_sse42;
197
198 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_sse42;
199 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_res_chroma_4x4_sse42;
200 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_res_chroma_4x4_with_res_acc_sse42;
201
202 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_dc_4x4_sse42;
203 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_res_dc_4x4_sse42;
204 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_res_dc_with_res_acc_4x4_sse42;
205
206 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_dc_sse42;
207 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_res_chroma_4x4_dc_sse42;
208 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_res_chroma_4x4_dc_with_res_acc_sse42;
209
210 extern FT_IHADAMARD_SCALING ih264_ihadamard_scaling_4x4_sse42;
211
212 extern FT_HADAMARD_QUANT isvc_hadamard_quant_4x4_sse42;
213 extern FT_HADAMARD_QUANT isvc_hadamard_quant_2x2_uv_sse42;
214
215 /* NEON Declarations */
216 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_neon;
217 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_with_res_output_neon;
218 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_with_res_accumulate_neon;
219
220 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_neon;
221 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_with_res_output_neon;
222 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_with_res_accumulate_neon;
223
224 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_dc_neon;
225 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_dc_with_res_output_neon;
226 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_4x4_dc_with_res_accumulate_neon;
227
228 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_dc_neon;
229 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_dc_with_res_output_neon;
230 extern FT_IQ_IT_RECON isvc_iquant_itrans_recon_chroma_4x4_dc_with_res_accumulate_neon;
231
isvc_get_resi_trans_quant_variant_idx(UWORD8 u1_use_upsampled_res)232 static FORCEINLINE UWORD8 isvc_get_resi_trans_quant_variant_idx(UWORD8 u1_use_upsampled_res)
233 {
234 return u1_use_upsampled_res;
235 }
236
isvc_get_iq_it_recon_variant_idx(UWORD8 u1_is_intra,UWORD8 u1_res_accumulate)237 static FORCEINLINE UWORD8 isvc_get_iq_it_recon_variant_idx(UWORD8 u1_is_intra,
238 UWORD8 u1_res_accumulate)
239 {
240 ASSERT(!((1 == u1_is_intra) && (1 == u1_res_accumulate)));
241
242 return u1_is_intra * 2 + u1_res_accumulate;
243 }
244
isvc_get_residue(WORD16 i2_it_out,WORD16 i2_res_pred,UWORD8 u1_res_accumulate)245 static FORCEINLINE WORD16 isvc_get_residue(WORD16 i2_it_out, WORD16 i2_res_pred,
246 UWORD8 u1_res_accumulate)
247 {
248 return (u1_res_accumulate
249 ? (CLIP3(-((WORD16) UINT8_MAX), ((WORD16) UINT8_MAX), i2_it_out + i2_res_pred))
250 : (CLIP3(-((WORD16) UINT8_MAX), ((WORD16) UINT8_MAX), i2_it_out)));
251 }
252
253 #endif
254