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_iquant_recon.c 22 * 23 * @brief 24 * Contains function definitions for inverse quantization and 25 * reconstruction of chroma interleaved data. 26 * 27 * @author 28 * 100470 29 * 30 * @par List of Functions: 31 * - ihevc_chroma_iquant_recon_4x4() 32 * - ihevc_chroma_iquant_recon_8x8() 33 * - ihevc_chroma_iquant_recon_16x16() 34 * 35 * @remarks 36 * None 37 * 38 ******************************************************************************* 39 */ 40 41 #include <stdio.h> 42 #include <string.h> 43 #include "ihevc_typedefs.h" 44 #include "ihevc_macros.h" 45 #include "ihevc_platform_macros.h" 46 #include "ihevc_defs.h" 47 #include "ihevc_trans_tables.h" 48 #include "ihevc_chroma_iquant_recon.h" 49 #include "ihevc_func_selector.h" 50 #include "ihevc_trans_macros.h" 51 52 /* All the functions work one component(U or V) of interleaved data depending upon pointers passed to it */ 53 /* Data visualization */ 54 /* U V U V U V U V */ 55 /* U V U V U V U V */ 56 /* U V U V U V U V */ 57 /* U V U V U V U V */ 58 /* If the pointer points to first byte of above stream (U) , functions will operate on U component */ 59 /* If the pointer points to second byte of above stream (V) , functions will operate on V component */ 60 61 /** 62 ******************************************************************************* 63 * 64 * @brief 65 * This function performs inverse quantization and reconstruction for 4x4 66 * input block 67 * 68 * @par Description: 69 * This function performs inverse quantization and reconstruction for 4x4 70 * input block 71 * 72 * @param[in] pi2_src 73 * Input 4x4 coefficients 74 * 75 * @param[in] pu1_pred 76 * Prediction 4x4 block 77 * 78 * @param[in] pi2_dequant_coeff 79 * Dequant Coeffs 80 * 81 * @param[out] pu1_dst 82 * Output 4x4 block 83 * 84 * @param[in] qp_div 85 * Quantization parameter / 6 86 * 87 * @param[in] qp_rem 88 * Quantization parameter % 6 89 * 90 * @param[in] src_strd 91 * Input stride 92 * 93 * @param[in] pred_strd 94 * Prediction stride 95 * 96 * @param[in] dst_strd 97 * Output Stride 98 * 99 * @param[in] zero_cols 100 * Zero columns in pi2_src 101 * 102 * @returns Void 103 * 104 * @remarks 105 * None 106 * 107 ******************************************************************************* 108 */ 109 110 111 void ihevc_chroma_iquant_recon_4x4(WORD16 *pi2_src, 112 UWORD8 *pu1_pred, 113 WORD16 *pi2_dequant_coeff, 114 UWORD8 *pu1_dst, 115 WORD32 qp_div, /* qpscaled / 6 */ 116 WORD32 qp_rem, /* qpscaled % 6 */ 117 WORD32 src_strd, 118 WORD32 pred_strd, 119 WORD32 dst_strd, 120 WORD32 zero_cols) 121 { 122 123 { 124 /* Inverse Quant and recon */ 125 { 126 WORD32 i, j; 127 WORD32 shift_iq; 128 WORD32 trans_size; 129 /* Inverse Quantization constants */ 130 { 131 WORD32 log2_trans_size, bit_depth; 132 133 log2_trans_size = 2; 134 bit_depth = 8 + 0; 135 shift_iq = bit_depth + log2_trans_size - 5; 136 } 137 138 trans_size = TRANS_SIZE_4; 139 140 for(i = 0; i < trans_size; i++) 141 { 142 /* Checking for Zero Cols */ 143 if((zero_cols & 1) == 1) 144 { 145 for(j = 0; j < trans_size; j++) 146 pu1_dst[j * dst_strd] = pu1_pred[j * pred_strd]; 147 } 148 else 149 { 150 for(j = 0; j < trans_size; j++) 151 { 152 WORD32 iquant_out; 153 IQUANT_4x4(iquant_out, 154 pi2_src[j * src_strd], 155 pi2_dequant_coeff[j * trans_size] * g_ihevc_iquant_scales[qp_rem], 156 shift_iq, qp_div); 157 iquant_out = (iquant_out + 16) >> 5; 158 pu1_dst[j * dst_strd] = 159 CLIP_U8(iquant_out + pu1_pred[j * pred_strd]); 160 } 161 } 162 pi2_src++; 163 pi2_dequant_coeff++; 164 pu1_pred += 2; 165 pu1_dst += 2; 166 167 zero_cols = zero_cols >> 1; 168 } 169 } 170 } 171 } 172 173 /** 174 ******************************************************************************* 175 * 176 * @brief 177 * This function performs inverse quantization and reconstruction for 8x8 178 * input block 179 * 180 * @par Description: 181 * This function performs inverse quantization and reconstruction for 8x8 182 * input block 183 * 184 * @param[in] pi2_src 185 * Input 8x8 coefficients 186 * 187 * @param[in] pu1_pred 188 * Prediction 8x8 block 189 * 190 * @param[in] pi2_dequant_coeff 191 * Dequant Coeffs 192 * 193 * @param[out] pu1_dst 194 * Output 8x8 block 195 * 196 * @param[in] qp_div 197 * Quantization parameter / 6 198 * 199 * @param[in] qp_rem 200 * Quantization parameter % 6 201 * 202 * @param[in] src_strd 203 * Input stride 204 * 205 * @param[in] pred_strd 206 * Prediction stride 207 * 208 * @param[in] dst_strd 209 * Output Stride 210 * 211 * @param[in] zero_cols 212 * Zero columns in pi2_src 213 * 214 * @returns Void 215 * 216 * @remarks 217 * None 218 * 219 ******************************************************************************* 220 */ 221 222 223 void ihevc_chroma_iquant_recon_8x8(WORD16 *pi2_src, 224 UWORD8 *pu1_pred, 225 WORD16 *pi2_dequant_coeff, 226 UWORD8 *pu1_dst, 227 WORD32 qp_div, /* qpscaled / 6 */ 228 WORD32 qp_rem, /* qpscaled % 6 */ 229 WORD32 src_strd, 230 WORD32 pred_strd, 231 WORD32 dst_strd, 232 WORD32 zero_cols) 233 { 234 235 { 236 /* Inverse Quant and recon */ 237 { 238 WORD32 i, j; 239 WORD32 shift_iq; 240 WORD32 trans_size; 241 /* Inverse Quantization constants */ 242 { 243 WORD32 log2_trans_size, bit_depth; 244 245 log2_trans_size = 3; 246 bit_depth = 8 + 0; 247 shift_iq = bit_depth + log2_trans_size - 5; 248 } 249 250 trans_size = TRANS_SIZE_8; 251 252 for(i = 0; i < trans_size; i++) 253 { 254 /* Checking for Zero Cols */ 255 if((zero_cols & 1) == 1) 256 { 257 for(j = 0; j < trans_size; j++) 258 pu1_dst[j * dst_strd] = pu1_pred[j * pred_strd]; 259 } 260 else 261 { 262 for(j = 0; j < trans_size; j++) 263 { 264 WORD32 iquant_out; 265 IQUANT(iquant_out, 266 pi2_src[j * src_strd], 267 pi2_dequant_coeff[j * trans_size] * g_ihevc_iquant_scales[qp_rem], 268 shift_iq, qp_div); 269 iquant_out = (iquant_out + 16) >> 5; 270 pu1_dst[j * dst_strd] = 271 CLIP_U8(iquant_out + pu1_pred[j * pred_strd]); 272 } 273 } 274 pi2_src++; 275 pi2_dequant_coeff++; 276 pu1_pred += 2; 277 pu1_dst += 2; 278 279 zero_cols = zero_cols >> 1; 280 } 281 } 282 } 283 } 284 285 /** 286 ******************************************************************************* 287 * 288 * @brief 289 * This function performs inverse quantization and reconstruction for 16x16 290 * input block 291 * 292 * @par Description: 293 * This function performs inverse quantization and reconstruction for 16x16 294 * input block 295 * 296 * @param[in] pi2_src 297 * Input 16x16 coefficients 298 * 299 * @param[in] pu1_pred 300 * Prediction 16x16 block 301 * 302 * @param[in] pi2_dequant_coeff 303 * Dequant Coeffs 304 * 305 * @param[out] pu1_dst 306 * Output 16x16 block 307 * 308 * @param[in] qp_div 309 * Quantization parameter / 6 310 * 311 * @param[in] qp_rem 312 * Quantization parameter % 6 313 * 314 * @param[in] src_strd 315 * Input stride 316 * 317 * @param[in] pred_strd 318 * Prediction stride 319 * 320 * @param[in] dst_strd 321 * Output Stride 322 * 323 * @param[in] zero_cols 324 * Zero columns in pi2_src 325 * 326 * @returns Void 327 * 328 * @remarks 329 * None 330 * 331 ******************************************************************************* 332 */ 333 334 335 void ihevc_chroma_iquant_recon_16x16(WORD16 *pi2_src, 336 UWORD8 *pu1_pred, 337 WORD16 *pi2_dequant_coeff, 338 UWORD8 *pu1_dst, 339 WORD32 qp_div, /* qpscaled / 6 */ 340 WORD32 qp_rem, /* qpscaled % 6 */ 341 WORD32 src_strd, 342 WORD32 pred_strd, 343 WORD32 dst_strd, 344 WORD32 zero_cols) 345 346 { 347 348 { 349 /* Inverse Quant and recon */ 350 { 351 WORD32 i, j; 352 WORD32 shift_iq; 353 WORD32 trans_size; 354 /* Inverse Quantization constants */ 355 { 356 WORD32 log2_trans_size, bit_depth; 357 358 log2_trans_size = 4; 359 bit_depth = 8 + 0; 360 shift_iq = bit_depth + log2_trans_size - 5; 361 } 362 363 trans_size = TRANS_SIZE_16; 364 365 for(i = 0; i < trans_size; i++) 366 { 367 /* Checking for Zero Cols */ 368 if((zero_cols & 1) == 1) 369 { 370 for(j = 0; j < trans_size; j++) 371 pu1_dst[j * dst_strd] = pu1_pred[j * pred_strd]; 372 } 373 else 374 { 375 for(j = 0; j < trans_size; j++) 376 { 377 WORD32 iquant_out; 378 IQUANT(iquant_out, 379 pi2_src[j * src_strd], 380 pi2_dequant_coeff[j * trans_size] * g_ihevc_iquant_scales[qp_rem], 381 shift_iq, qp_div); 382 iquant_out = (iquant_out + 16) >> 5; 383 pu1_dst[j * dst_strd] = 384 CLIP_U8(iquant_out + pu1_pred[j * pred_strd]); 385 } 386 } 387 pi2_src++; 388 pi2_dequant_coeff++; 389 pu1_pred += 2; 390 pu1_dst += 2; 391 392 zero_cols = zero_cols >> 1; 393 } 394 } 395 } 396 } 397 398 399