/src/libavc/common/ih264_ihadamard_scaling.c
Line | Count | Source |
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 | | * ih264_ihadamard_scaling.c |
25 | | * |
26 | | * @brief |
27 | | * Contains definition of functions for h264 inverse hadamard 4x4 transform and |
28 | | * scaling |
29 | | * |
30 | | * @author |
31 | | * ittiam |
32 | | * |
33 | | * @par List of Functions: |
34 | | * - ih264_ihadamard_scaling_4x4 |
35 | | * - ih264_ihadamard_scaling_2x2_uv |
36 | | * |
37 | | * @remarks |
38 | | * none |
39 | | * |
40 | | ******************************************************************************* |
41 | | */ |
42 | | |
43 | | /*****************************************************************************/ |
44 | | /* File Includes */ |
45 | | /*****************************************************************************/ |
46 | | |
47 | | /* User Include Files */ |
48 | | #include "ih264_typedefs.h" |
49 | | #include "ih264_macros.h" |
50 | | #include "ih264_defs.h" |
51 | | #include "ih264_trans_macros.h" |
52 | | #include "ih264_trans_data.h" |
53 | | #include "ih264_size_defs.h" |
54 | | #include "ih264_structs.h" |
55 | | #include "ih264_trans_quant_itrans_iquant.h" |
56 | | |
57 | | |
58 | | /*****************************************************************************/ |
59 | | /* Function Definitions */ |
60 | | /*****************************************************************************/ |
61 | | |
62 | | /** |
63 | | ******************************************************************************** |
64 | | * |
65 | | * @brief This function performs a 4x4 inverse hadamard transform on the luma |
66 | | * DC coefficients and then performs scaling. |
67 | | * |
68 | | * @par Description: |
69 | | * The DC coefficients pass through a 2-stage inverse hadamard transform. |
70 | | * This inverse transformed content is scaled to based on Qp value. |
71 | | * |
72 | | * @param[in] pi2_src |
73 | | * input 4x4 block of DC coefficients |
74 | | * |
75 | | * @param[out] pi2_out |
76 | | * output 4x4 block |
77 | | * |
78 | | * @param[in] pu2_iscal_mat |
79 | | * pointer to scaling list |
80 | | * |
81 | | * @param[in] pu2_weigh_mat |
82 | | * pointer to weight matrix |
83 | | * |
84 | | * @param[in] u4_qp_div_6 |
85 | | * Floor (qp/6) |
86 | | * |
87 | | * @param[in] pi4_tmp |
88 | | * temporary buffer of size 1*16 |
89 | | * |
90 | | * @returns none |
91 | | * |
92 | | * @remarks none |
93 | | * |
94 | | ******************************************************************************* |
95 | | */ |
96 | | void ih264_ihadamard_scaling_4x4(WORD16* pi2_src, |
97 | | WORD16* pi2_out, |
98 | | const UWORD16 *pu2_iscal_mat, |
99 | | const UWORD16 *pu2_weigh_mat, |
100 | | UWORD32 u4_qp_div_6, |
101 | | WORD32* pi4_tmp) |
102 | 841k | { |
103 | 841k | WORD32 i; |
104 | 841k | WORD32 x0, x1, x2, x3, x4, x5, x6, x7; |
105 | 841k | WORD16 *pi2_src_ptr, *pi2_out_ptr; |
106 | 841k | WORD32 *pi4_tmp_ptr; |
107 | 841k | WORD32 rnd_fact = (u4_qp_div_6 < 6) ? (1 << (5 - u4_qp_div_6)) : 0; |
108 | | |
109 | 841k | pi4_tmp_ptr = pi4_tmp; |
110 | 841k | pi2_src_ptr = pi2_src; |
111 | 841k | pi2_out_ptr = pi2_out; |
112 | | |
113 | | /* horizontal transform */ |
114 | 4.20M | for(i = 0; i < SUB_BLK_WIDTH_4x4; i++) |
115 | 3.36M | { |
116 | 3.36M | x4 = pi2_src_ptr[0]; |
117 | 3.36M | x5 = pi2_src_ptr[1]; |
118 | 3.36M | x6 = pi2_src_ptr[2]; |
119 | 3.36M | x7 = pi2_src_ptr[3]; |
120 | | |
121 | 3.36M | x0 = x4 + x7; |
122 | 3.36M | x1 = x5 + x6; |
123 | 3.36M | x2 = x5 - x6; |
124 | 3.36M | x3 = x4 - x7; |
125 | | |
126 | 3.36M | pi4_tmp_ptr[0] = x0 + x1; |
127 | 3.36M | pi4_tmp_ptr[1] = x2 + x3; |
128 | 3.36M | pi4_tmp_ptr[2] = x0 - x1; |
129 | 3.36M | pi4_tmp_ptr[3] = x3 - x2; |
130 | | |
131 | 3.36M | pi4_tmp_ptr += SUB_BLK_WIDTH_4x4; |
132 | 3.36M | pi2_src_ptr += SUB_BLK_WIDTH_4x4; |
133 | 3.36M | } |
134 | | |
135 | | /* vertical transform */ |
136 | 841k | pi4_tmp_ptr = pi4_tmp; |
137 | 4.20M | for(i = 0; i < SUB_BLK_WIDTH_4x4; i++) |
138 | 3.35M | { |
139 | 3.35M | x4 = pi4_tmp_ptr[0]; |
140 | 3.35M | x5 = pi4_tmp_ptr[4]; |
141 | 3.35M | x6 = pi4_tmp_ptr[8]; |
142 | 3.35M | x7 = pi4_tmp_ptr[12]; |
143 | | |
144 | 3.35M | x0 = x4 + x7; |
145 | 3.35M | x1 = x5 + x6; |
146 | 3.35M | x2 = x5 - x6; |
147 | 3.35M | x3 = x4 - x7; |
148 | | |
149 | 3.35M | pi4_tmp_ptr[0] = x0 + x1; |
150 | 3.35M | pi4_tmp_ptr[4] = x2 + x3; |
151 | 3.35M | pi4_tmp_ptr[8] = x0 - x1; |
152 | 3.35M | pi4_tmp_ptr[12] = x3 - x2; |
153 | | |
154 | 3.35M | pi4_tmp_ptr++; |
155 | 3.35M | } |
156 | 841k | pi4_tmp_ptr = pi4_tmp; |
157 | | |
158 | | /* scaling */ |
159 | 14.2M | for(i = 0; i < (SUB_BLK_WIDTH_4x4 * SUB_BLK_WIDTH_4x4); i++) |
160 | 13.3M | { |
161 | 13.3M | INV_QUANT(pi4_tmp_ptr[i], pu2_iscal_mat[0], pu2_weigh_mat[0], |
162 | 13.3M | u4_qp_div_6, rnd_fact, 6); |
163 | 13.3M | pi2_out_ptr[i] = pi4_tmp_ptr[i]; |
164 | 13.3M | } |
165 | 841k | } |
166 | | |
167 | | /** |
168 | | ******************************************************************************** |
169 | | * |
170 | | * @brief This function performs a 2x2 inverse hadamard transform on the chroma |
171 | | * DC coefficients and then performs scaling. |
172 | | * |
173 | | * @par Description: |
174 | | * The DC coefficients pass through a 2-stage inverse hadamard transform. |
175 | | * This inverse transformed content is scaled to based on Qp value. |
176 | | * |
177 | | * @param[in] pi2_src |
178 | | * input 2x2 block of DC coefficients |
179 | | * |
180 | | * @param[out] pi2_out |
181 | | * output 2x2 block |
182 | | * |
183 | | * @param[in] pu2_iscal_mat |
184 | | * pointer to scaling list |
185 | | * |
186 | | * @param[in] pu2_weigh_mat |
187 | | * pointer to weight matrix |
188 | | * |
189 | | * @param[in] u4_qp_div_6 |
190 | | * Floor (qp/6) |
191 | | * |
192 | | * @param[in] pi4_tmp |
193 | | * temporary buffer of size 1*16 |
194 | | * |
195 | | * @returns none |
196 | | * |
197 | | * @remarks none |
198 | | * |
199 | | ******************************************************************************* |
200 | | */ |
201 | | void ih264_ihadamard_scaling_2x2_uv(WORD16* pi2_src, |
202 | | WORD16* pi2_out, |
203 | | const UWORD16 *pu2_iscal_mat, |
204 | | const UWORD16 *pu2_weigh_mat, |
205 | | UWORD32 u4_qp_div_6, |
206 | | WORD32* pi4_tmp) |
207 | 838k | { |
208 | 838k | WORD32 i4_x0, i4_x1, i4_x2, i4_x3, i4_x4, i4_x5, i4_x6, i4_x7; |
209 | 838k | WORD32 i4_y0, i4_y1, i4_y2, i4_y3, i4_y4, i4_y5, i4_y6, i4_y7; |
210 | | |
211 | 838k | UNUSED(pi4_tmp); |
212 | | |
213 | | /* U Plane */ |
214 | 838k | i4_x4 = pi2_src[0]; |
215 | 838k | i4_x5 = pi2_src[1]; |
216 | 838k | i4_x6 = pi2_src[2]; |
217 | 838k | i4_x7 = pi2_src[3]; |
218 | | |
219 | 838k | i4_x0 = i4_x4 + i4_x5; |
220 | 838k | i4_x1 = i4_x4 - i4_x5; |
221 | 838k | i4_x2 = i4_x6 + i4_x7; |
222 | 838k | i4_x3 = i4_x6 - i4_x7; |
223 | | |
224 | 838k | i4_x4 = i4_x0 + i4_x2; |
225 | 838k | i4_x5 = i4_x1 + i4_x3; |
226 | 838k | i4_x6 = i4_x0 - i4_x2; |
227 | 838k | i4_x7 = i4_x1 - i4_x3; |
228 | | |
229 | 838k | INV_QUANT(i4_x4, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, 0, 5); |
230 | 838k | INV_QUANT(i4_x5, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, 0, 5); |
231 | 838k | INV_QUANT(i4_x6, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, 0, 5); |
232 | 838k | INV_QUANT(i4_x7, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, 0, 5); |
233 | | |
234 | 838k | pi2_out[0] = i4_x4; |
235 | 838k | pi2_out[1] = i4_x5; |
236 | 838k | pi2_out[2] = i4_x6; |
237 | 838k | pi2_out[3] = i4_x7; |
238 | | |
239 | | /* V Plane */ |
240 | 838k | i4_y4 = pi2_src[4]; |
241 | 838k | i4_y5 = pi2_src[5]; |
242 | 838k | i4_y6 = pi2_src[6]; |
243 | 838k | i4_y7 = pi2_src[7]; |
244 | | |
245 | 838k | i4_y0 = i4_y4 + i4_y5; |
246 | 838k | i4_y1 = i4_y4 - i4_y5; |
247 | 838k | i4_y2 = i4_y6 + i4_y7; |
248 | 838k | i4_y3 = i4_y6 - i4_y7; |
249 | | |
250 | 838k | i4_y4 = i4_y0 + i4_y2; |
251 | 838k | i4_y5 = i4_y1 + i4_y3; |
252 | 838k | i4_y6 = i4_y0 - i4_y2; |
253 | 838k | i4_y7 = i4_y1 - i4_y3; |
254 | | |
255 | 838k | INV_QUANT(i4_y4, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, 0, 5); |
256 | 838k | INV_QUANT(i4_y5, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, 0, 5); |
257 | 838k | INV_QUANT(i4_y6, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, 0, 5); |
258 | 838k | INV_QUANT(i4_y7, pu2_iscal_mat[0], pu2_weigh_mat[0], u4_qp_div_6, 0, 5); |
259 | | |
260 | 838k | pi2_out[4] = i4_y4; |
261 | 838k | pi2_out[5] = i4_y5; |
262 | 838k | pi2_out[6] = i4_y6; |
263 | 838k | pi2_out[7] = i4_y7; |
264 | 838k | } |