/src/libhevc/common/ihevc_chroma_itrans_recon.c
Line | Count | Source |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore |
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 | | /** |
19 | | ******************************************************************************* |
20 | | * @file |
21 | | * ihevc_chroma_itrans_recon.c |
22 | | * |
23 | | * @brief |
24 | | * Contains function definitions for inverse transform and reconstruction |
25 | | * of chroma interleaved data. |
26 | | * |
27 | | * @author |
28 | | * 100470 |
29 | | * |
30 | | * @par List of Functions: |
31 | | * - ihevc_chroma_itrans_recon_4x4() |
32 | | * |
33 | | * @remarks |
34 | | * None |
35 | | * |
36 | | ******************************************************************************* |
37 | | */ |
38 | | |
39 | | #include <stdio.h> |
40 | | #include <string.h> |
41 | | #include "ihevc_typedefs.h" |
42 | | #include "ihevc_macros.h" |
43 | | #include "ihevc_platform_macros.h" |
44 | | #include "ihevc_defs.h" |
45 | | #include "ihevc_trans_tables.h" |
46 | | #include "ihevc_chroma_itrans_recon.h" |
47 | | #include "ihevc_func_selector.h" |
48 | | #include "ihevc_trans_macros.h" |
49 | | |
50 | | /* All the functions work one component(U or V) of interleaved data depending upon pointers passed to it */ |
51 | | /* Data visualization */ |
52 | | /* U V U V U V U V */ |
53 | | /* U V U V U V U V */ |
54 | | /* U V U V U V U V */ |
55 | | /* U V U V U V U V */ |
56 | | /* If the pointer points to first byte of above stream (U) , functions will operate on U component */ |
57 | | /* If the pointer points to second byte of above stream (V) , functions will operate on V component */ |
58 | | |
59 | | /** |
60 | | ******************************************************************************* |
61 | | * |
62 | | * @brief |
63 | | * This function performs Inverse transform and reconstruction for 4x4 |
64 | | * input block |
65 | | * |
66 | | * @par Description: |
67 | | * Performs inverse transform and adds the prediction data and clips output |
68 | | * to 8 bit |
69 | | * |
70 | | * @param[in] pi2_src |
71 | | * Input 4x4 coefficients |
72 | | * |
73 | | * @param[in] pi2_tmp |
74 | | * Temporary 4x4 buffer for storing inverse transform |
75 | | * 1st stage output |
76 | | * |
77 | | * @param[in] pu1_pred |
78 | | * Prediction 4x4 block |
79 | | * |
80 | | * @param[out] pu1_dst |
81 | | * Output 4x4 block |
82 | | * |
83 | | * @param[in] src_strd |
84 | | * Input stride |
85 | | * |
86 | | * @param[in] pred_strd |
87 | | * Prediction stride |
88 | | * |
89 | | * @param[in] dst_strd |
90 | | * Output Stride |
91 | | * |
92 | | * @param[in] shift |
93 | | * Output shift |
94 | | * |
95 | | * @param[in] zero_cols |
96 | | * Zero columns in pi2_src |
97 | | * |
98 | | * @returns Void |
99 | | * |
100 | | * @remarks |
101 | | * None |
102 | | * |
103 | | ******************************************************************************* |
104 | | */ |
105 | | |
106 | | |
107 | | void ihevc_chroma_itrans_recon_4x4(WORD16 *pi2_src, |
108 | | WORD16 *pi2_tmp, |
109 | | UWORD8 *pu1_pred, |
110 | | UWORD8 *pu1_dst, |
111 | | WORD32 src_strd, |
112 | | WORD32 pred_strd, |
113 | | WORD32 dst_strd, |
114 | | WORD32 zero_cols, |
115 | | WORD32 zero_rows) |
116 | 2.49M | { |
117 | 2.49M | WORD32 j; |
118 | 2.49M | WORD32 e[2], o[2]; |
119 | 2.49M | WORD32 add; |
120 | 2.49M | WORD32 shift; |
121 | 2.49M | WORD16 *pi2_tmp_orig; |
122 | 2.49M | WORD32 trans_size; |
123 | 2.49M | UNUSED(zero_rows); |
124 | 2.49M | trans_size = TRANS_SIZE_4; |
125 | | |
126 | 2.49M | pi2_tmp_orig = pi2_tmp; |
127 | | |
128 | | /* Inverse Transform 1st stage */ |
129 | 2.49M | shift = IT_SHIFT_STAGE_1; |
130 | 2.49M | add = 1 << (shift - 1); |
131 | | |
132 | 12.4M | for(j = 0; j < trans_size; j++) |
133 | 9.96M | { |
134 | | /* Checking for Zero Cols */ |
135 | 9.96M | if((zero_cols & 1) == 1) |
136 | 190k | { |
137 | 190k | memset(pi2_tmp, 0, trans_size * sizeof(WORD16)); |
138 | 190k | } |
139 | 9.77M | else |
140 | 9.77M | { |
141 | | |
142 | | /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */ |
143 | 9.77M | o[0] = g_ai2_ihevc_trans_4[1][0] * pi2_src[src_strd] |
144 | 9.77M | + g_ai2_ihevc_trans_4[3][0] * pi2_src[3 * src_strd]; |
145 | 9.77M | o[1] = g_ai2_ihevc_trans_4[1][1] * pi2_src[src_strd] |
146 | 9.77M | + g_ai2_ihevc_trans_4[3][1] * pi2_src[3 * src_strd]; |
147 | 9.77M | e[0] = g_ai2_ihevc_trans_4[0][0] * pi2_src[0] |
148 | 9.77M | + g_ai2_ihevc_trans_4[2][0] * pi2_src[2 * src_strd]; |
149 | 9.77M | e[1] = g_ai2_ihevc_trans_4[0][1] * pi2_src[0] |
150 | 9.77M | + g_ai2_ihevc_trans_4[2][1] * pi2_src[2 * src_strd]; |
151 | | |
152 | 9.77M | pi2_tmp[0] = |
153 | 9.77M | CLIP_S16(((e[0] + o[0] + add) >> shift)); |
154 | 9.77M | pi2_tmp[1] = |
155 | 9.77M | CLIP_S16(((e[1] + o[1] + add) >> shift)); |
156 | 9.77M | pi2_tmp[2] = |
157 | 9.77M | CLIP_S16(((e[1] - o[1] + add) >> shift)); |
158 | 9.77M | pi2_tmp[3] = |
159 | 9.77M | CLIP_S16(((e[0] - o[0] + add) >> shift)); |
160 | | |
161 | 9.77M | } |
162 | 9.96M | pi2_src++; |
163 | 9.96M | pi2_tmp += trans_size; |
164 | 9.96M | zero_cols = zero_cols >> 1; |
165 | 9.96M | } |
166 | | |
167 | 2.49M | pi2_tmp = pi2_tmp_orig; |
168 | | |
169 | | /* Inverse Transform 2nd stage */ |
170 | 2.49M | shift = IT_SHIFT_STAGE_2; |
171 | 2.49M | add = 1 << (shift - 1); |
172 | | |
173 | 12.4M | for(j = 0; j < trans_size; j++) |
174 | 9.96M | { |
175 | 9.96M | WORD32 itrans_out; |
176 | | /* Utilizing symmetry properties to the maximum to minimize the number of multiplications */ |
177 | 9.96M | o[0] = g_ai2_ihevc_trans_4[1][0] * pi2_tmp[trans_size] |
178 | 9.96M | + g_ai2_ihevc_trans_4[3][0] * pi2_tmp[3 * trans_size]; |
179 | 9.96M | o[1] = g_ai2_ihevc_trans_4[1][1] * pi2_tmp[trans_size] |
180 | 9.96M | + g_ai2_ihevc_trans_4[3][1] * pi2_tmp[3 * trans_size]; |
181 | 9.96M | e[0] = g_ai2_ihevc_trans_4[0][0] * pi2_tmp[0] |
182 | 9.96M | + g_ai2_ihevc_trans_4[2][0] * pi2_tmp[2 * trans_size]; |
183 | 9.96M | e[1] = g_ai2_ihevc_trans_4[0][1] * pi2_tmp[0] |
184 | 9.96M | + g_ai2_ihevc_trans_4[2][1] * pi2_tmp[2 * trans_size]; |
185 | | |
186 | 9.96M | itrans_out = |
187 | 9.96M | CLIP_S16(((e[0] + o[0] + add) >> shift)); |
188 | 9.96M | pu1_dst[0 * 2] = CLIP_U8((itrans_out + pu1_pred[0 * 2])); |
189 | 9.96M | itrans_out = |
190 | 9.96M | CLIP_S16(((e[1] + o[1] + add) >> shift)); |
191 | 9.96M | pu1_dst[1 * 2] = CLIP_U8((itrans_out + pu1_pred[1 * 2])); |
192 | 9.96M | itrans_out = |
193 | 9.96M | CLIP_S16(((e[1] - o[1] + add) >> shift)); |
194 | 9.96M | pu1_dst[2 * 2] = CLIP_U8((itrans_out + pu1_pred[2 * 2])); |
195 | 9.96M | itrans_out = |
196 | 9.96M | CLIP_S16(((e[0] - o[0] + add) >> shift)); |
197 | 9.96M | pu1_dst[3 * 2] = CLIP_U8((itrans_out + pu1_pred[3 * 2])); |
198 | | |
199 | 9.96M | pi2_tmp++; |
200 | 9.96M | pu1_pred += pred_strd; |
201 | 9.96M | pu1_dst += dst_strd; |
202 | | |
203 | 9.96M | } |
204 | 2.49M | } |
205 | | |