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_trans_data.c 25 * 26 * @brief 27 * Contains definition of global variables for H264 encoder 28 * 29 * @author 30 * ittiam 31 * 32 * @remarks 33 * 34 ******************************************************************************* 35 */ 36 37 /*****************************************************************************/ 38 /* File Includes */ 39 /*****************************************************************************/ 40 41 /* User Include Files */ 42 #include "ih264_typedefs.h" 43 #include "ih264_trans_data.h" 44 45 /*****************************************************************************/ 46 /* Global definitions */ 47 /*****************************************************************************/ 48 49 /** 50 ****************************************************************************** 51 * @brief Scale Table for quantizing 4x4 subblock. To quantize a given 4x4 DCT 52 * transformed block, the coefficient at index location (i,j) is scaled by one of 53 * the constants in this table and right shift the result by (QP_BITS_h264_4x4 + 54 * floor(qp/6)), here qp is the quantization parameter used to quantize the mb. 55 * 56 * input : qp%6, index location (i,j) 57 * output : scale constant. 58 * 59 * @remarks 16 constants for each index position of the subblock and 6 for each 60 * qp%6 in the range 0-5 inclusive. 61 ****************************************************************************** 62 */ 63 const UWORD16 gu2_quant_scale_matrix_4x4[96] = 64 { 65 13107, 8066, 13107, 8066, 66 8066, 5243, 8066, 5243, 67 13107, 8066, 13107, 8066, 68 8066, 5243, 8066, 5243, 69 70 11916, 7490, 11916, 7490, 71 7490, 4660, 7490, 4660, 72 11916, 7490, 11916, 7490, 73 7490, 4660, 7490, 4660, 74 75 10082, 6554, 10082, 6554, 76 6554, 4194, 6554, 4194, 77 10082, 6554, 10082, 6554, 78 6554, 4194, 6554, 4194, 79 80 9362, 5825, 9362, 5825, 81 5825, 3647, 5825, 3647, 82 9362, 5825, 9362, 5825, 83 5825, 3647, 5825, 3647, 84 85 8192, 5243, 8192, 5243, 86 5243, 3355, 5243, 3355, 87 8192, 5243, 8192, 5243, 88 5243, 3355, 5243, 3355, 89 90 7282, 4559, 7282, 4559, 91 4559, 2893, 4559, 2893, 92 7282, 4559, 7282, 4559, 93 4559, 2893, 4559, 2893, 94 }; 95 96 /** 97 ****************************************************************************** 98 * @brief Round Factor for quantizing subblock. While quantizing a given 4x4 DCT 99 * transformed block, the coefficient at index location (i,j) is scaled by one of 100 * the constants in the table gu2_forward_quant_scalar_4x4 and then right shift 101 * the result by (QP_BITS_h264_4x4 + floor(qp/6)). 102 * Before right shifting a round factor is added. 103 * The round factor can be any value [a * (1 << (QP_BITS_h264_4x4 + floor(qp/6)))] 104 * for 'a' lies in the range 0-0.5. 105 * Here qp is the quantization parameter used to quantize the mb. 106 * 107 * input : qp/6 108 * output : round factor. 109 * 110 * @remarks The round factor is constructed by setting a = 1/3 111 * 112 * round factor constructed by setting a = 1/3 113 { 114 10922, 21845, 43690, 87381, 115 174762, 349525, 699050, 1398101, 116 2796202, 117 } 118 * round factor constructed by setting a = 0.49 119 { 120 16056, 32112, 64225, 121 128450, 256901, 513802, 122 1027604, 2055208, 4110417, 123 } 124 * round factor constructed by setting a = 0.5 125 { 126 16384, 32768, 65536, 127 131072, 262144, 524288, 128 1048576, 2097152, 4194304, 129 } 130 ****************************************************************************** 131 */ 132 const UWORD32 gu4_forward_quant_round_factor_4x4[9] = 133 { 134 10922, 21845, 43690, 87381, 135 174762, 349525, 699050, 1398101, 136 2796202, 137 }; 138 139 /** 140 ****************************************************************************** 141 * @brief Threshold Table. Quantizing the given DCT coefficient is done only if 142 * it exceeds the threshold value presented in this table. 143 * 144 * input : qp/6, qp%6, index location (i,j) 145 * output : Threshold constant. 146 * 147 * @remarks 16 constants for each index position of the subblock and 6 for each 148 * qp%6 in the range 0-5 inclusive and 9 for each qp/6 in the range 0-51. 149 ****************************************************************************** 150 */ 151 const UWORD16 gu2_forward_quant_threshold_4x4[96] = 152 { 153 426, 693, 426, 693, 154 693, 1066, 693, 1066, 155 426, 693, 426, 693, 156 693, 1066, 693, 1066, 157 158 469, 746, 469, 746, 159 746, 1200, 746, 1200, 160 469, 746, 469, 746, 161 746, 1200, 746, 1200, 162 163 554, 853, 554, 853, 164 853, 1333, 853, 1333, 165 554, 853, 554, 853, 166 853, 1333, 853, 1333, 167 168 597, 960, 597, 960, 169 960, 1533, 960, 1533, 170 597, 960, 597, 960, 171 960, 1533, 960, 1533, 172 173 682, 1066, 682, 1066, 174 1066, 1666, 1066, 1666, 175 682, 1066, 682, 1066, 176 1066, 1666, 1066, 1666, 177 178 767, 1226, 767, 1226, 179 1226, 1933, 1226, 1933, 180 767, 1226, 767, 1226, 181 1226, 1933, 1226, 1933, 182 }; 183 184 /** 185 ****************************************************************************** 186 * @brief Scale Table for quantizing 8x8 subblock. To quantize a given 8x8 DCT 187 * transformed block, the coefficient at index location (i,j) is scaled by one of 188 * the constants in this table and right shift the result by (QP_BITS_h264_8x8 + 189 * floor(qp/6)), here qp is the quantization parameter used to quantize the mb. 190 * 191 * input : qp%6, index location (i,j) 192 * output : scale constant. 193 * 194 * @remarks 64 constants for each index position of the subblock and 6 for each 195 * qp%6 in the range 0-5 inclusive. 196 ****************************************************************************** 197 */ 198 const UWORD16 gu2_quant_scale_matrix_8x8 [384] = 199 { 200 13107, 12222, 16777, 12222, 13107, 12222, 16777, 12222, 201 12222, 11428, 15481, 11428, 12222, 11428, 15481, 11428, 202 16777, 15481, 20972, 15481, 16777, 15481, 20972, 15481, 203 12222, 11428, 15481, 11428, 12222, 11428, 15481, 11428, 204 13107, 12222, 16777, 12222, 13107, 12222, 16777, 12222, 205 12222, 11428, 15481, 11428, 12222, 11428, 15481, 11428, 206 16777, 15481, 20972, 15481, 16777, 15481, 20972, 15481, 207 12222, 11428, 15481, 11428, 12222, 11428, 15481, 11428, 208 209 11916, 11058, 14980, 11058, 11916, 11058, 14980, 11058, 210 11058, 10826, 14290, 10826, 11058, 10826, 14290, 10826, 211 14980, 14290, 19174, 14290, 14980, 14290, 19174, 14290, 212 11058, 10826, 14290, 10826, 11058, 10826, 14290, 10826, 213 11916, 11058, 14980, 11058, 11916, 11058, 14980, 11058, 214 11058, 10826, 14290, 10826, 11058, 10826, 14290, 10826, 215 14980, 14290, 19174, 14290, 14980, 14290, 19174, 14290, 216 11058, 10826, 14290, 10826, 11058, 10826, 14290, 10826, 217 218 10082, 9675, 12710, 9675, 10082, 9675, 12710, 9675, 219 9675, 8943, 11985, 8943, 9675, 8943, 11985, 8943, 220 12710, 11985, 15978, 11985, 12710, 11985, 15978, 11985, 221 9675, 8943, 11985, 8943, 9675, 8943, 11985, 8943, 222 10082, 9675, 12710, 9675, 10082, 9675, 12710, 9675, 223 9675, 8943, 11985, 8943, 9675, 8943, 11985, 8943, 224 12710, 11985, 15978, 11985, 12710, 11985, 15978, 11985, 225 9675, 8943, 11985, 8943, 9675, 8943, 11985, 8943, 226 227 9362, 8931, 11984, 8931, 9362, 8931, 11984, 8931, 228 8931, 8228, 11259, 8228, 8931, 8228, 11259, 8228, 229 11984, 11259, 14913, 11259, 11984, 11259, 14913, 11259, 230 8931, 8228, 11259, 8228, 8931, 8228, 11259, 8228, 231 9362, 8931, 11984, 8931, 9362, 8931, 11984, 8931, 232 8931, 8228, 11259, 8228, 8931, 8228, 11259, 8228, 233 11984, 11259, 14913, 11259, 11984, 11259, 14913, 11259, 234 8931, 8228, 11259, 8228, 8931, 8228, 11259, 8228, 235 236 8192, 7740, 10486, 7740, 8192, 7740, 10486, 7740, 237 7740, 7346, 9777, 7346, 7740, 7346, 9777, 7346, 238 10486, 9777, 13159, 9777, 10486, 9777, 13159, 9777, 239 7740, 7346, 9777, 7346, 7740, 7346, 9777, 7346, 240 8192, 7740, 10486, 7740, 8192, 7740, 10486, 7740, 241 7740, 7346, 9777, 7346, 7740, 7346, 9777, 7346, 242 10486, 9777, 13159, 9777, 10486, 9777, 13159, 9777, 243 7740, 7346, 9777, 7346, 7740, 7346, 9777, 7346, 244 245 7282, 6830, 9118, 6830, 7282, 6830, 9118, 6830, 246 6830, 6428, 8640, 6428, 6830, 6428, 8640, 6428, 247 9118, 8640, 11570, 8640, 9118, 8640, 11570, 8640, 248 6830, 6428, 8640, 6428, 6830, 6428, 8640, 6428, 249 7282, 6830, 9118, 6830, 7282, 6830, 9118, 6830, 250 6830, 6428, 8640, 6428, 6830, 6428, 8640, 6428, 251 9118, 8640, 11570, 8640, 9118, 8640, 11570, 8640, 252 6830, 6428, 8640, 6428, 6830, 6428, 8640, 6428, 253 }; 254 255 /** 256 ****************************************************************************** 257 * @brief Specification of QPc as a function of qPi 258 * input : qp luma 259 * output : qp chroma. 260 * @remarks Refer Table 8-15 of h264 specification. 261 ****************************************************************************** 262 */ 263 const UWORD8 gu1_qpc_fqpi[52] = 264 { 265 0, 1, 2, 3, 4, 5, 6, 7, 266 8, 9, 10, 11, 12, 13, 14, 15, 267 16, 17, 18, 19, 20, 21, 22, 23, 268 24, 25, 26, 27, 28, 29, 29, 30, 269 31, 32, 32, 33, 34, 34, 35, 35, 270 36, 36, 37, 37, 37, 38, 38, 38, 271 39, 39, 39, 39, 272 }; 273