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 * @file 23 * ih264_trans_macros.h 24 * 25 * @brief 26 * The file contains definitions of macros that perform forward and inverse 27 * quantization 28 * 29 * @author 30 * Ittiam 31 * 32 * @remark 33 * None 34 * 35 ******************************************************************************* 36 */ 37 38 #ifndef IH264_TRANS_MACROS_H_ 39 #define IH264_TRANS_MACROS_H_ 40 41 /*****************************************************************************/ 42 /* Function Macros */ 43 /*****************************************************************************/ 44 45 /** 46 ****************************************************************************** 47 * @brief Macro to perform forward quantization. 48 * @description The value to be quantized is first compared with a threshold. 49 * If the value is less than the threshold, the quantization value is returned 50 * as zero else the value is quantized traditionally as per the rules of 51 * h264 specification 52 ****************************************************************************** 53 */ 54 #define FWD_QUANT(i4_value, threshold, scale, rndfactor, qbits, u4_nnz) \ 55 {\ 56 WORD32 i4_sign;\ 57 UWORD32 u4_abs_value;\ 58 if (i4_value < 0)\ 59 {\ 60 u4_abs_value = -i4_value;\ 61 i4_sign = -1;\ 62 }\ 63 else\ 64 {\ 65 u4_abs_value = i4_value;\ 66 i4_sign = 1;\ 67 }\ 68 if (u4_abs_value < threshold)\ 69 {\ 70 i4_value = 0;\ 71 }\ 72 else\ 73 {\ 74 u4_abs_value *= scale;\ 75 u4_abs_value += rndfactor;\ 76 u4_abs_value >>= qbits;\ 77 i4_value = u4_abs_value;\ 78 if (i4_sign == -1) i4_value = -i4_value;\ 79 if (i4_value)\ 80 {\ 81 u4_nnz++;\ 82 }\ 83 }\ 84 } 85 86 /** 87 ****************************************************************************** 88 * @brief Macro to perform inverse quantization. 89 * @remarks The value can also be de-quantized as 90 * if (u4_qp_div_6 < 4) 91 * { 92 * i4_value = (quant_scale * weight_scale * i4_value + (1 << (3-u4_qp_div_6))) 93 * i4_value >>= (4 - u4_qp_div_6) 94 * } 95 * else 96 * { 97 * i4_value = (quant_scale * weight_scale * i4_value) << (u4_qp_div_6 -4) 98 * } 99 ****************************************************************************** 100 */ 101 #define INV_QUANT(i4_value, quant_scale, weight_scale, u4_qp_div_6, rndfactor, qbits)\ 102 {\ 103 i4_value *= quant_scale;\ 104 i4_value *= weight_scale;\ 105 i4_value += rndfactor;\ 106 i4_value <<= u4_qp_div_6;\ 107 i4_value >>= qbits;\ 108 } 109 110 #define QUANT_H264(x,y,w,z,shft) (shft = ABS(x),\ 111 shft *= y,\ 112 shft += z,\ 113 shft = shft>>w,\ 114 shft = SIGNXY(shft,x)) 115 116 #define IQUANT_H264(x,y,wscal,w,shft) (shft = x, \ 117 shft *=y, \ 118 shft *=wscal, \ 119 shft = shft<<w) 120 121 #define IQUANT_lev_H264(x,y,wscal,add_f,w,shft) (shft = x, \ 122 shft *=y, \ 123 shft *=wscal, \ 124 shft+= add_f, \ 125 shft = shft>>w) 126 127 #endif /* IH264_TRANS_MACROS_H_ */ 128