1*495ae853SAndroid Build Coastguard Worker /****************************************************************************** 2*495ae853SAndroid Build Coastguard Worker * 3*495ae853SAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 4*495ae853SAndroid Build Coastguard Worker * 5*495ae853SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 6*495ae853SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 7*495ae853SAndroid Build Coastguard Worker * You may obtain a copy of the License at: 8*495ae853SAndroid Build Coastguard Worker * 9*495ae853SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 10*495ae853SAndroid Build Coastguard Worker * 11*495ae853SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 12*495ae853SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 13*495ae853SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14*495ae853SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 15*495ae853SAndroid Build Coastguard Worker * limitations under the License. 16*495ae853SAndroid Build Coastguard Worker * 17*495ae853SAndroid Build Coastguard Worker ***************************************************************************** 18*495ae853SAndroid Build Coastguard Worker * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 19*495ae853SAndroid Build Coastguard Worker */ 20*495ae853SAndroid Build Coastguard Worker 21*495ae853SAndroid Build Coastguard Worker /** 22*495ae853SAndroid Build Coastguard Worker ******************************************************************************* 23*495ae853SAndroid Build Coastguard Worker * @file 24*495ae853SAndroid Build Coastguard Worker * ih264_trans_macros.h 25*495ae853SAndroid Build Coastguard Worker * 26*495ae853SAndroid Build Coastguard Worker * @brief 27*495ae853SAndroid Build Coastguard Worker * The file contains definitions of macros that perform forward and inverse 28*495ae853SAndroid Build Coastguard Worker * quantization 29*495ae853SAndroid Build Coastguard Worker * 30*495ae853SAndroid Build Coastguard Worker * @author 31*495ae853SAndroid Build Coastguard Worker * ittiam 32*495ae853SAndroid Build Coastguard Worker * 33*495ae853SAndroid Build Coastguard Worker * @remark 34*495ae853SAndroid Build Coastguard Worker * none 35*495ae853SAndroid Build Coastguard Worker * 36*495ae853SAndroid Build Coastguard Worker ******************************************************************************* 37*495ae853SAndroid Build Coastguard Worker */ 38*495ae853SAndroid Build Coastguard Worker 39*495ae853SAndroid Build Coastguard Worker #ifndef _IH264_TRANS_MACROS_H_ 40*495ae853SAndroid Build Coastguard Worker #define _IH264_TRANS_MACROS_H_ 41*495ae853SAndroid Build Coastguard Worker 42*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/ 43*495ae853SAndroid Build Coastguard Worker /* Function Macros */ 44*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/ 45*495ae853SAndroid Build Coastguard Worker 46*495ae853SAndroid Build Coastguard Worker /** 47*495ae853SAndroid Build Coastguard Worker ****************************************************************************** 48*495ae853SAndroid Build Coastguard Worker * @brief Macro to perform forward quantization. 49*495ae853SAndroid Build Coastguard Worker * @description The value to be quantized is first compared with a threshold. 50*495ae853SAndroid Build Coastguard Worker * If the value is less than the threshold, the quantization value is returned 51*495ae853SAndroid Build Coastguard Worker * as zero else the value is quantized traditionally as per the rules of 52*495ae853SAndroid Build Coastguard Worker * h264 specification 53*495ae853SAndroid Build Coastguard Worker ****************************************************************************** 54*495ae853SAndroid Build Coastguard Worker */ 55*495ae853SAndroid Build Coastguard Worker #define FWD_QUANT(i4_value, threshold, scale, rndfactor, qbits, u4_nnz) \ 56*495ae853SAndroid Build Coastguard Worker {\ 57*495ae853SAndroid Build Coastguard Worker WORD32 i4_sign;\ 58*495ae853SAndroid Build Coastguard Worker UWORD32 u4_abs_value;\ 59*495ae853SAndroid Build Coastguard Worker if (i4_value < 0)\ 60*495ae853SAndroid Build Coastguard Worker {\ 61*495ae853SAndroid Build Coastguard Worker u4_abs_value = -i4_value;\ 62*495ae853SAndroid Build Coastguard Worker i4_sign = -1;\ 63*495ae853SAndroid Build Coastguard Worker }\ 64*495ae853SAndroid Build Coastguard Worker else\ 65*495ae853SAndroid Build Coastguard Worker {\ 66*495ae853SAndroid Build Coastguard Worker u4_abs_value = i4_value;\ 67*495ae853SAndroid Build Coastguard Worker i4_sign = 1;\ 68*495ae853SAndroid Build Coastguard Worker }\ 69*495ae853SAndroid Build Coastguard Worker if (u4_abs_value < threshold)\ 70*495ae853SAndroid Build Coastguard Worker {\ 71*495ae853SAndroid Build Coastguard Worker i4_value = 0;\ 72*495ae853SAndroid Build Coastguard Worker }\ 73*495ae853SAndroid Build Coastguard Worker else\ 74*495ae853SAndroid Build Coastguard Worker {\ 75*495ae853SAndroid Build Coastguard Worker u4_abs_value *= scale;\ 76*495ae853SAndroid Build Coastguard Worker u4_abs_value += rndfactor;\ 77*495ae853SAndroid Build Coastguard Worker u4_abs_value >>= qbits;\ 78*495ae853SAndroid Build Coastguard Worker i4_value = u4_abs_value;\ 79*495ae853SAndroid Build Coastguard Worker if (i4_sign == -1) i4_value = -i4_value;\ 80*495ae853SAndroid Build Coastguard Worker if (i4_value)\ 81*495ae853SAndroid Build Coastguard Worker {\ 82*495ae853SAndroid Build Coastguard Worker u4_nnz++;\ 83*495ae853SAndroid Build Coastguard Worker }\ 84*495ae853SAndroid Build Coastguard Worker }\ 85*495ae853SAndroid Build Coastguard Worker } 86*495ae853SAndroid Build Coastguard Worker 87*495ae853SAndroid Build Coastguard Worker /** 88*495ae853SAndroid Build Coastguard Worker ****************************************************************************** 89*495ae853SAndroid Build Coastguard Worker * @brief Macro to perform inverse quantization. 90*495ae853SAndroid Build Coastguard Worker * @remarks The value can also be de-quantized as 91*495ae853SAndroid Build Coastguard Worker * if (u4_qp_div_6 < 4) 92*495ae853SAndroid Build Coastguard Worker * { 93*495ae853SAndroid Build Coastguard Worker * i4_value = (quant_scale * weight_scale * i4_value + (1 << (3-u4_qp_div_6))) 94*495ae853SAndroid Build Coastguard Worker * i4_value >>= (4 - u4_qp_div_6) 95*495ae853SAndroid Build Coastguard Worker * } 96*495ae853SAndroid Build Coastguard Worker * else 97*495ae853SAndroid Build Coastguard Worker * { 98*495ae853SAndroid Build Coastguard Worker * i4_value = (quant_scale * weight_scale * i4_value) << (u4_qp_div_6 -4) 99*495ae853SAndroid Build Coastguard Worker * } 100*495ae853SAndroid Build Coastguard Worker ****************************************************************************** 101*495ae853SAndroid Build Coastguard Worker */ 102*495ae853SAndroid Build Coastguard Worker #define INV_QUANT(i4_value, quant_scale, weight_scale, u4_qp_div_6, rndfactor, qbits)\ 103*495ae853SAndroid Build Coastguard Worker {\ 104*495ae853SAndroid Build Coastguard Worker i4_value *= quant_scale;\ 105*495ae853SAndroid Build Coastguard Worker i4_value *= weight_scale;\ 106*495ae853SAndroid Build Coastguard Worker i4_value += rndfactor;\ 107*495ae853SAndroid Build Coastguard Worker i4_value <<= u4_qp_div_6;\ 108*495ae853SAndroid Build Coastguard Worker i4_value >>= qbits;\ 109*495ae853SAndroid Build Coastguard Worker } 110*495ae853SAndroid Build Coastguard Worker 111*495ae853SAndroid Build Coastguard Worker #define QUANT_H264(x,y,w,z,shft) (shft = ABS(x),\ 112*495ae853SAndroid Build Coastguard Worker shft *= y,\ 113*495ae853SAndroid Build Coastguard Worker shft += z,\ 114*495ae853SAndroid Build Coastguard Worker shft = shft>>w,\ 115*495ae853SAndroid Build Coastguard Worker shft = SIGNXY(shft,x)) 116*495ae853SAndroid Build Coastguard Worker 117*495ae853SAndroid Build Coastguard Worker #define IQUANT_H264(x,y,wscal,w,shft) (shft = x, \ 118*495ae853SAndroid Build Coastguard Worker shft *=y, \ 119*495ae853SAndroid Build Coastguard Worker shft *=wscal, \ 120*495ae853SAndroid Build Coastguard Worker shft = shft<<w) 121*495ae853SAndroid Build Coastguard Worker 122*495ae853SAndroid Build Coastguard Worker #define IQUANT_lev_H264(x,y,wscal,add_f,w,shft) (shft = x, \ 123*495ae853SAndroid Build Coastguard Worker shft *=y, \ 124*495ae853SAndroid Build Coastguard Worker shft *=wscal, \ 125*495ae853SAndroid Build Coastguard Worker shft+= add_f, \ 126*495ae853SAndroid Build Coastguard Worker shft = shft>>w) 127*495ae853SAndroid Build Coastguard Worker 128*495ae853SAndroid Build Coastguard Worker #endif /* _IH264_TRANS_MACROS_H_ */ 129