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