00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "global.h"
00013 #include "memalloc.h"
00014
00015 extern char *GetConfigFileContent (char *Filename, int error_type);
00016
00017 #define MAX_ITEMS_TO_PARSE 1000
00018
00019 const int quant_coef[6][4][4] = {
00020 {{13107, 8066,13107, 8066},{ 8066, 5243, 8066, 5243},{13107, 8066,13107, 8066},{ 8066, 5243, 8066, 5243}},
00021 {{11916, 7490,11916, 7490},{ 7490, 4660, 7490, 4660},{11916, 7490,11916, 7490},{ 7490, 4660, 7490, 4660}},
00022 {{10082, 6554,10082, 6554},{ 6554, 4194, 6554, 4194},{10082, 6554,10082, 6554},{ 6554, 4194, 6554, 4194}},
00023 {{ 9362, 5825, 9362, 5825},{ 5825, 3647, 5825, 3647},{ 9362, 5825, 9362, 5825},{ 5825, 3647, 5825, 3647}},
00024 {{ 8192, 5243, 8192, 5243},{ 5243, 3355, 5243, 3355},{ 8192, 5243, 8192, 5243},{ 5243, 3355, 5243, 3355}},
00025 {{ 7282, 4559, 7282, 4559},{ 4559, 2893, 4559, 2893},{ 7282, 4559, 7282, 4559},{ 4559, 2893, 4559, 2893}}
00026 };
00027
00028 const int dequant_coef[6][4][4] = {
00029 {{10, 13, 10, 13},{ 13, 16, 13, 16},{10, 13, 10, 13},{ 13, 16, 13, 16}},
00030 {{11, 14, 11, 14},{ 14, 18, 14, 18},{11, 14, 11, 14},{ 14, 18, 14, 18}},
00031 {{13, 16, 13, 16},{ 16, 20, 16, 20},{13, 16, 13, 16},{ 16, 20, 16, 20}},
00032 {{14, 18, 14, 18},{ 18, 23, 18, 23},{14, 18, 14, 18},{ 18, 23, 18, 23}},
00033 {{16, 20, 16, 20},{ 20, 25, 20, 25},{16, 20, 16, 20},{ 20, 25, 20, 25}},
00034 {{18, 23, 18, 23},{ 23, 29, 23, 29},{18, 23, 18, 23},{ 23, 29, 23, 29}}
00035 };
00036
00037 const int quant_coef8[6][8][8] =
00038 {
00039 {
00040 {13107, 12222, 16777, 12222, 13107, 12222, 16777, 12222},
00041 {12222, 11428, 15481, 11428, 12222, 11428, 15481, 11428},
00042 {16777, 15481, 20972, 15481, 16777, 15481, 20972, 15481},
00043 {12222, 11428, 15481, 11428, 12222, 11428, 15481, 11428},
00044 {13107, 12222, 16777, 12222, 13107, 12222, 16777, 12222},
00045 {12222, 11428, 15481, 11428, 12222, 11428, 15481, 11428},
00046 {16777, 15481, 20972, 15481, 16777, 15481, 20972, 15481},
00047 {12222, 11428, 15481, 11428, 12222, 11428, 15481, 11428}
00048 },
00049 {
00050 {11916, 11058, 14980, 11058, 11916, 11058, 14980, 11058},
00051 {11058, 10826, 14290, 10826, 11058, 10826, 14290, 10826},
00052 {14980, 14290, 19174, 14290, 14980, 14290, 19174, 14290},
00053 {11058, 10826, 14290, 10826, 11058, 10826, 14290, 10826},
00054 {11916, 11058, 14980, 11058, 11916, 11058, 14980, 11058},
00055 {11058, 10826, 14290, 10826, 11058, 10826, 14290, 10826},
00056 {14980, 14290, 19174, 14290, 14980, 14290, 19174, 14290},
00057 {11058, 10826, 14290, 10826, 11058, 10826, 14290, 10826}
00058 },
00059 {
00060 {10082, 9675, 12710, 9675, 10082, 9675, 12710, 9675},
00061 {9675, 8943, 11985, 8943, 9675, 8943, 11985, 8943},
00062 {12710, 11985, 15978, 11985, 12710, 11985, 15978, 11985},
00063 {9675, 8943, 11985, 8943, 9675, 8943, 11985, 8943},
00064 {10082, 9675, 12710, 9675, 10082, 9675, 12710, 9675},
00065 {9675, 8943, 11985, 8943, 9675, 8943, 11985, 8943},
00066 {12710, 11985, 15978, 11985, 12710, 11985, 15978, 11985},
00067 {9675, 8943, 11985, 8943, 9675, 8943, 11985, 8943}
00068 },
00069 {
00070 {9362, 8931, 11984, 8931, 9362, 8931, 11984, 8931},
00071 {8931, 8228, 11259, 8228, 8931, 8228, 11259, 8228},
00072 {11984, 11259, 14913, 11259, 11984, 11259, 14913, 11259},
00073 {8931, 8228, 11259, 8228, 8931, 8228, 11259, 8228},
00074 {9362, 8931, 11984, 8931, 9362, 8931, 11984, 8931},
00075 {8931, 8228, 11259, 8228, 8931, 8228, 11259, 8228},
00076 {11984, 11259, 14913, 11259, 11984, 11259, 14913, 11259},
00077 {8931, 8228, 11259, 8228, 8931, 8228, 11259, 8228}
00078 },
00079 {
00080 {8192, 7740, 10486, 7740, 8192, 7740, 10486, 7740},
00081 {7740, 7346, 9777, 7346, 7740, 7346, 9777, 7346},
00082 {10486, 9777, 13159, 9777, 10486, 9777, 13159, 9777},
00083 {7740, 7346, 9777, 7346, 7740, 7346, 9777, 7346},
00084 {8192, 7740, 10486, 7740, 8192, 7740, 10486, 7740},
00085 {7740, 7346, 9777, 7346, 7740, 7346, 9777, 7346},
00086 {10486, 9777, 13159, 9777, 10486, 9777, 13159, 9777},
00087 {7740, 7346, 9777, 7346, 7740, 7346, 9777, 7346}
00088 },
00089 {
00090 {7282, 6830, 9118, 6830, 7282, 6830, 9118, 6830},
00091 {6830, 6428, 8640, 6428, 6830, 6428, 8640, 6428},
00092 {9118, 8640, 11570, 8640, 9118, 8640, 11570, 8640},
00093 {6830, 6428, 8640, 6428, 6830, 6428, 8640, 6428},
00094 {7282, 6830, 9118, 6830, 7282, 6830, 9118, 6830},
00095 {6830, 6428, 8640, 6428, 6830, 6428, 8640, 6428},
00096 {9118, 8640, 11570, 8640, 9118, 8640, 11570, 8640},
00097 {6830, 6428, 8640, 6428, 6830, 6428, 8640, 6428}
00098 }
00099 };
00100
00101
00102
00103 const int dequant_coef8[6][8][8] =
00104 {
00105 {
00106 {20, 19, 25, 19, 20, 19, 25, 19},
00107 {19, 18, 24, 18, 19, 18, 24, 18},
00108 {25, 24, 32, 24, 25, 24, 32, 24},
00109 {19, 18, 24, 18, 19, 18, 24, 18},
00110 {20, 19, 25, 19, 20, 19, 25, 19},
00111 {19, 18, 24, 18, 19, 18, 24, 18},
00112 {25, 24, 32, 24, 25, 24, 32, 24},
00113 {19, 18, 24, 18, 19, 18, 24, 18}
00114 },
00115 {
00116 {22, 21, 28, 21, 22, 21, 28, 21},
00117 {21, 19, 26, 19, 21, 19, 26, 19},
00118 {28, 26, 35, 26, 28, 26, 35, 26},
00119 {21, 19, 26, 19, 21, 19, 26, 19},
00120 {22, 21, 28, 21, 22, 21, 28, 21},
00121 {21, 19, 26, 19, 21, 19, 26, 19},
00122 {28, 26, 35, 26, 28, 26, 35, 26},
00123 {21, 19, 26, 19, 21, 19, 26, 19}
00124 },
00125 {
00126 {26, 24, 33, 24, 26, 24, 33, 24},
00127 {24, 23, 31, 23, 24, 23, 31, 23},
00128 {33, 31, 42, 31, 33, 31, 42, 31},
00129 {24, 23, 31, 23, 24, 23, 31, 23},
00130 {26, 24, 33, 24, 26, 24, 33, 24},
00131 {24, 23, 31, 23, 24, 23, 31, 23},
00132 {33, 31, 42, 31, 33, 31, 42, 31},
00133 {24, 23, 31, 23, 24, 23, 31, 23}
00134 },
00135 {
00136 {28, 26, 35, 26, 28, 26, 35, 26},
00137 {26, 25, 33, 25, 26, 25, 33, 25},
00138 {35, 33, 45, 33, 35, 33, 45, 33},
00139 {26, 25, 33, 25, 26, 25, 33, 25},
00140 {28, 26, 35, 26, 28, 26, 35, 26},
00141 {26, 25, 33, 25, 26, 25, 33, 25},
00142 {35, 33, 45, 33, 35, 33, 45, 33},
00143 {26, 25, 33, 25, 26, 25, 33, 25}
00144 },
00145 {
00146 {32, 30, 40, 30, 32, 30, 40, 30},
00147 {30, 28, 38, 28, 30, 28, 38, 28},
00148 {40, 38, 51, 38, 40, 38, 51, 38},
00149 {30, 28, 38, 28, 30, 28, 38, 28},
00150 {32, 30, 40, 30, 32, 30, 40, 30},
00151 {30, 28, 38, 28, 30, 28, 38, 28},
00152 {40, 38, 51, 38, 40, 38, 51, 38},
00153 {30, 28, 38, 28, 30, 28, 38, 28}
00154 },
00155 {
00156 {36, 34, 46, 34, 36, 34, 46, 34},
00157 {34, 32, 43, 32, 34, 32, 43, 32},
00158 {46, 43, 58, 43, 46, 43, 58, 43},
00159 {34, 32, 43, 32, 34, 32, 43, 32},
00160 {36, 34, 46, 34, 36, 34, 46, 34},
00161 {34, 32, 43, 32, 34, 32, 43, 32},
00162 {46, 43, 58, 43, 46, 43, 58, 43},
00163 {34, 32, 43, 32, 34, 32, 43, 32}
00164 }
00165 };
00166
00167
00168 int matrix4x4_check[6] = {0, 0, 0, 0, 0, 0};
00169 int matrix8x8_check[6] = {0, 0, 0, 0, 0, 0};
00170
00171 static const char MatrixType4x4[6][20] =
00172 {
00173 "INTRA4X4_LUMA",
00174 "INTRA4X4_CHROMAU",
00175 "INTRA4X4_CHROMAV",
00176 "INTER4X4_LUMA",
00177 "INTER4X4_CHROMAU",
00178 "INTER4X4_CHROMAV"
00179 };
00180
00181 static const char MatrixType8x8[6][20] =
00182 {
00183 "INTRA8X8_LUMA",
00184 "INTER8X8_LUMA",
00185 "INTRA8X8_CHROMAU",
00186 "INTER8X8_CHROMAU",
00187 "INTRA8X8_CHROMAV",
00188 "INTER8X8_CHROMAV"
00189 };
00190
00191 int *****LevelScale4x4Comp;
00192 int *****LevelScale8x8Comp;
00193
00194 int *****InvLevelScale4x4Comp;
00195 int *****InvLevelScale8x8Comp;
00196
00197 short ScalingList4x4input[6][16];
00198 short ScalingList8x8input[6][64];
00199 short ScalingList4x4[6][16];
00200 short ScalingList8x8[6][64];
00201
00202 short UseDefaultScalingMatrix4x4Flag[6];
00203 short UseDefaultScalingMatrix8x8Flag[6];
00204
00205 int *qp_per_matrix;
00206 int *qp_rem_matrix;
00207
00208 static const short Quant_intra_default[16] =
00209 {
00210 6,13,20,28,
00211 13,20,28,32,
00212 20,28,32,37,
00213 28,32,37,42
00214 };
00215
00216 static const short Quant_inter_default[16] =
00217 {
00218 10,14,20,24,
00219 14,20,24,27,
00220 20,24,27,30,
00221 24,27,30,34
00222 };
00223
00224 static const short Quant8_intra_default[64] =
00225 {
00226 6,10,13,16,18,23,25,27,
00227 10,11,16,18,23,25,27,29,
00228 13,16,18,23,25,27,29,31,
00229 16,18,23,25,27,29,31,33,
00230 18,23,25,27,29,31,33,36,
00231 23,25,27,29,31,33,36,38,
00232 25,27,29,31,33,36,38,40,
00233 27,29,31,33,36,38,40,42
00234 };
00235
00236 static const short Quant8_inter_default[64] =
00237 {
00238 9,13,15,17,19,21,22,24,
00239 13,13,17,19,21,22,24,25,
00240 15,17,19,21,22,24,25,27,
00241 17,19,21,22,24,25,27,28,
00242 19,21,22,24,25,27,28,30,
00243 21,22,24,25,27,28,30,32,
00244 22,24,25,27,28,30,32,33,
00245 24,25,27,28,30,32,33,35
00246 };
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 int CheckParameterName (char *s, int *type)
00263 {
00264 int i = 0;
00265
00266 *type = 0;
00267 while ((MatrixType4x4[i] != NULL) && (i<6))
00268 {
00269 if (0==strcmp (MatrixType4x4[i], s))
00270 return i;
00271 else
00272 i++;
00273 }
00274
00275 i = 0;
00276 *type = 1;
00277 while ((MatrixType8x8[i] != NULL) && (i<6))
00278 {
00279 if (0==strcmp (MatrixType8x8[i], s))
00280 return i;
00281 else
00282 i++;
00283 }
00284
00285 return -1;
00286 }
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298 void ParseMatrix (char *buf, int bufsize)
00299 {
00300 char *items[MAX_ITEMS_TO_PARSE];
00301 int MapIdx;
00302 int item = 0;
00303 int InString = 0, InItem = 0;
00304 char *p = buf;
00305 char *bufend = &buf[bufsize];
00306 int IntContent;
00307 int i, j, range, type, cnt;
00308 short *ScalingList;
00309
00310 while (p < bufend)
00311 {
00312 switch (*p)
00313 {
00314 case 13:
00315 p++;
00316 break;
00317 case '#':
00318 *p = '\0';
00319 while (*p != '\n' && p < bufend)
00320 p++;
00321 InString = 0;
00322 InItem = 0;
00323 break;
00324 case '\n':
00325 InItem = 0;
00326 InString = 0;
00327 *p++='\0';
00328 break;
00329 case ' ':
00330 case '\t':
00331 if (InString)
00332 p++;
00333 else
00334 {
00335 *p++ = '\0';
00336 InItem = 0;
00337 }
00338 break;
00339
00340 case '"':
00341 *p++ = '\0';
00342 if (!InString)
00343 {
00344 items[item++] = p;
00345 InItem = ~InItem;
00346 }
00347 else
00348 InItem = 0;
00349 InString = ~InString;
00350 break;
00351
00352 case ',':
00353 p++;
00354 InItem = 0;
00355 break;
00356
00357 default:
00358 if (!InItem)
00359 {
00360 items[item++] = p;
00361 InItem = ~InItem;
00362 }
00363 p++;
00364 }
00365 }
00366
00367 item--;
00368
00369 for (i=0; i<item; i+=cnt)
00370 {
00371 cnt=0;
00372 if (0 > (MapIdx = CheckParameterName (items[i+cnt], &type)))
00373 {
00374 snprintf (errortext, ET_SIZE, " Parsing error in quantization matrix config file: Parameter Name '%s' not recognized.", items[i+cnt]);
00375 error (errortext, 300);
00376 }
00377 cnt++;
00378 if (strcmp ("=", items[i+cnt]))
00379 {
00380 snprintf (errortext, ET_SIZE, " Parsing error in quantization matrix config file: '=' expected as the second token in each item.");
00381 error (errortext, 300);
00382 }
00383 cnt++;
00384
00385 if (!type)
00386 {
00387 range = 16;
00388 ScalingList = ScalingList4x4input[MapIdx];
00389 matrix4x4_check[MapIdx] = 1;
00390 }
00391 else
00392 {
00393 range = 64;
00394 ScalingList = ScalingList8x8input[MapIdx];
00395 matrix8x8_check[MapIdx] = 1;
00396 }
00397
00398 for(j=0; j<range; j++)
00399 {
00400 if (1 != sscanf (items[i+cnt+j], "%d", &IntContent))
00401 {
00402 snprintf (errortext, ET_SIZE, " Parsing error in quantization matrix file: Expected numerical value for Parameter of %s, found '%s'.", items[i], items[i+cnt+j]);
00403 error (errortext, 300);
00404 }
00405
00406 ScalingList[j] = (short)IntContent;
00407 }
00408 cnt+=j;
00409 printf (".");
00410 }
00411 }
00412
00413
00414
00415
00416
00417
00418
00419
00420 void PatchMatrix(void)
00421 {
00422 short *ScalingList;
00423 int i, cnt, fail;
00424
00425 for(i=0; i<6; i++)
00426 {
00427 if(params->ScalingListPresentFlag[i])
00428 {
00429 ScalingList=ScalingList4x4input[i];
00430 if(matrix4x4_check[i])
00431 {
00432 fail=0;
00433 for(cnt=0; cnt<16; cnt++)
00434 {
00435 if(ScalingList[cnt]<0 || ScalingList[cnt]>255)
00436 {
00437 fail=1;
00438 break;
00439 }
00440 }
00441
00442 if(fail)
00443 {
00444 printf("\n%s value exceed range. (Value must be 1 to 255)\n", MatrixType4x4[i]);
00445 printf("Setting default values for this matrix.");
00446 if(i>2)
00447 memcpy(ScalingList, Quant_inter_default, sizeof(short)*16);
00448 else
00449 memcpy(ScalingList, Quant_intra_default, sizeof(short)*16);
00450 }
00451 }
00452 else
00453 {
00454 printf("\n%s matrix definition not found. Setting default values.", MatrixType4x4[i]);
00455 if(i>2)
00456 memcpy(ScalingList, Quant_inter_default, sizeof(short)*16);
00457 else
00458 memcpy(ScalingList, Quant_intra_default, sizeof(short)*16);
00459 }
00460 }
00461
00462 if(params->ScalingListPresentFlag[i+6])
00463 {
00464 ScalingList=ScalingList8x8input[i];
00465 if(matrix8x8_check[i])
00466 {
00467 fail=0;
00468 for(cnt=0; cnt<64; cnt++)
00469 {
00470 if(ScalingList[cnt]<0 || ScalingList[cnt]>255)
00471 {
00472 fail=1;
00473 break;
00474 }
00475 }
00476
00477 if(fail)
00478 {
00479 printf("\n%s value exceed range. (Value must be 1 to 255)\n", MatrixType8x8[i]);
00480 printf("Setting default values for this matrix.");
00481 if(i==1 || i==3 || i==5)
00482 memcpy(ScalingList, Quant8_inter_default, sizeof(short)*64);
00483 else
00484 memcpy(ScalingList, Quant8_intra_default, sizeof(short)*64);
00485 }
00486 }
00487 else
00488 {
00489 printf("\n%s matrix definition not found. Setting default values.", MatrixType8x8[i]);
00490 if(i==1 || i==3 || i==5)
00491 memcpy(ScalingList, Quant8_inter_default, sizeof(short)*64);
00492 else
00493 memcpy(ScalingList, Quant8_intra_default, sizeof(short)*64);
00494 }
00495 }
00496 }
00497 }
00498
00499
00500
00501
00502
00503
00504
00505 void allocate_QMatrix (void)
00506 {
00507 int bitdepth_qp_scale = 6*(params->output.bit_depth[0] - 8);
00508 int i;
00509
00510 if ((qp_per_matrix = (int*)malloc((MAX_QP + 1 + bitdepth_qp_scale)*sizeof(int))) == NULL)
00511 no_mem_exit("allocate_QMatrix: qp_per_matrix");
00512 if ((qp_rem_matrix = (int*)malloc((MAX_QP + 1 + bitdepth_qp_scale)*sizeof(int))) == NULL)
00513 no_mem_exit("allocate_QMatrix: qp_per_matrix");
00514
00515 for (i = 0; i < MAX_QP + bitdepth_qp_scale + 1; i++)
00516 {
00517 qp_per_matrix[i] = i / 6;
00518 qp_rem_matrix[i] = i % 6;
00519 }
00520
00521 get_mem5Dint(&LevelScale4x4Comp, 3, 2, 6, 4, 4);
00522 get_mem5Dint(&LevelScale8x8Comp, 3, 2, 6, 8, 8);
00523
00524 get_mem5Dint(&InvLevelScale4x4Comp, 3, 2, 6, 4, 4);
00525 get_mem5Dint(&InvLevelScale8x8Comp, 3, 2, 6, 8, 8);
00526 }
00527
00528
00529
00530
00531
00532
00533
00534 void free_QMatrix ()
00535 {
00536 free(qp_rem_matrix);
00537 free(qp_per_matrix);
00538
00539 free_mem5Dint(LevelScale4x4Comp);
00540 free_mem5Dint(LevelScale8x8Comp);
00541
00542 free_mem5Dint(InvLevelScale4x4Comp);
00543 free_mem5Dint(InvLevelScale8x8Comp);
00544 }
00545
00546
00547
00548
00549
00550
00551
00552
00553 void Init_QMatrix (void)
00554 {
00555 char *content;
00556
00557
00558 allocate_QMatrix ();
00559
00560 if(params->ScalingMatrixPresentFlag)
00561 {
00562 printf ("Parsing QMatrix file %s ", params->QmatrixFile);
00563 content = GetConfigFileContent(params->QmatrixFile, 0);
00564 if(content!='\0')
00565 ParseMatrix(content, strlen (content));
00566 else
00567 printf("\nError: %s\nProceeding with default values for all matrices.", errortext);
00568
00569 PatchMatrix();
00570 printf("\n");
00571
00572 memset(UseDefaultScalingMatrix4x4Flag, 0, 6 * sizeof(short));
00573 memset(UseDefaultScalingMatrix8x8Flag, 0, 6 * sizeof(short));
00574
00575 free(content);
00576 }
00577 }
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591 void CalculateQuantParam(void)
00592 {
00593 int i, j, k, temp;
00594 int present[6];
00595 int no_q_matrix=FALSE;
00596
00597 if(!active_sps->seq_scaling_matrix_present_flag && !active_pps->pic_scaling_matrix_present_flag)
00598 no_q_matrix=TRUE;
00599 else
00600 {
00601 memset(present, 0, 6 * sizeof(int));
00602
00603 if(active_sps->seq_scaling_matrix_present_flag)
00604 for(i=0; i<6; i++)
00605 present[i] = active_sps->seq_scaling_list_present_flag[i];
00606
00607 if(active_pps->pic_scaling_matrix_present_flag)
00608 for(i=0; i<6; i++)
00609 {
00610 if((i==0) || (i==3))
00611 present[i] |= active_pps->pic_scaling_list_present_flag[i];
00612 else
00613 present[i] = active_pps->pic_scaling_list_present_flag[i];
00614 }
00615 }
00616
00617 if(no_q_matrix==TRUE)
00618 {
00619 for(k=0; k<6; k++)
00620 for(j=0; j<4; j++)
00621 for(i=0; i<4; i++)
00622 {
00623 LevelScale4x4Comp[0][1][k][j][i] = quant_coef[k][j][i];
00624 InvLevelScale4x4Comp[0][1][k][j][i] = dequant_coef[k][j][i]<<4;
00625
00626 LevelScale4x4Comp[1][1][k][j][i] = quant_coef[k][j][i];
00627 InvLevelScale4x4Comp[1][1][k][j][i] = dequant_coef[k][j][i]<<4;
00628
00629 LevelScale4x4Comp[2][1][k][j][i] = quant_coef[k][j][i];
00630 InvLevelScale4x4Comp[2][1][k][j][i] = dequant_coef[k][j][i]<<4;
00631
00632
00633 LevelScale4x4Comp[0][0][k][j][i] = quant_coef[k][j][i];
00634 InvLevelScale4x4Comp[0][0][k][j][i] = dequant_coef[k][j][i]<<4;
00635
00636 LevelScale4x4Comp[1][0][k][j][i] = quant_coef[k][j][i];
00637 InvLevelScale4x4Comp[1][0][k][j][i] = dequant_coef[k][j][i]<<4;
00638
00639 LevelScale4x4Comp[2][0][k][j][i] = quant_coef[k][j][i];
00640 InvLevelScale4x4Comp[2][0][k][j][i] = dequant_coef[k][j][i]<<4;
00641 }
00642 }
00643 else
00644 {
00645 for(k=0; k<6; k++)
00646 {
00647 for(j=0; j<4; j++)
00648 {
00649 for(i=0; i<4; i++)
00650 {
00651 temp = (j<<2)+i;
00652 if((!present[0]) || UseDefaultScalingMatrix4x4Flag[0])
00653 {
00654 LevelScale4x4Comp[0][1][k][j][i] = (quant_coef[k][j][i]<<4)/Quant_intra_default[temp];
00655 InvLevelScale4x4Comp[0][1][k][j][i] = dequant_coef[k][j][i]*Quant_intra_default[temp];
00656 }
00657 else
00658 {
00659 LevelScale4x4Comp[0][1][k][j][i] = (quant_coef[k][j][i]<<4)/ScalingList4x4[0][temp];
00660 InvLevelScale4x4Comp[0][1][k][j][i] = dequant_coef[k][j][i]*ScalingList4x4[0][temp];
00661 }
00662
00663 if(!present[1])
00664 {
00665 LevelScale4x4Comp[1][1][k][j][i] = LevelScale4x4Comp[0][1][k][j][i];
00666 InvLevelScale4x4Comp[1][1][k][j][i] = InvLevelScale4x4Comp[0][1][k][j][i];
00667 }
00668 else
00669 {
00670 LevelScale4x4Comp[1][1][k][j][i] = (quant_coef[k][j][i]<<4)/(UseDefaultScalingMatrix4x4Flag[1] ? Quant_intra_default[temp]:ScalingList4x4[1][temp]);
00671 InvLevelScale4x4Comp[1][1][k][j][i] = dequant_coef[k][j][i]*(UseDefaultScalingMatrix4x4Flag[1] ? Quant_intra_default[temp]:ScalingList4x4[1][temp]);
00672 }
00673
00674 if(!present[2])
00675 {
00676 LevelScale4x4Comp[2][1][k][j][i] = LevelScale4x4Comp[1][1][k][j][i];
00677 InvLevelScale4x4Comp[2][1][k][j][i] = InvLevelScale4x4Comp[1][1][k][j][i];
00678 }
00679 else
00680 {
00681 LevelScale4x4Comp[2][1][k][j][i] = (quant_coef[k][j][i]<<4)/(UseDefaultScalingMatrix4x4Flag[2] ? Quant_intra_default[temp]:ScalingList4x4[2][temp]);
00682 InvLevelScale4x4Comp[2][1][k][j][i] = dequant_coef[k][j][i]*(UseDefaultScalingMatrix4x4Flag[2] ? Quant_intra_default[temp]:ScalingList4x4[2][temp]);
00683 }
00684
00685 if((!present[3]) || UseDefaultScalingMatrix4x4Flag[3])
00686 {
00687 LevelScale4x4Comp[0][0][k][j][i] = (quant_coef[k][j][i]<<4)/Quant_inter_default[temp];
00688 InvLevelScale4x4Comp[0][0][k][j][i] = dequant_coef[k][j][i]*Quant_inter_default[temp];
00689 }
00690 else
00691 {
00692 LevelScale4x4Comp[0][0][k][j][i] = (quant_coef[k][j][i]<<4)/ScalingList4x4[3][temp];
00693 InvLevelScale4x4Comp[0][0][k][j][i] = dequant_coef[k][j][i]*ScalingList4x4[3][temp];
00694 }
00695
00696 if(!present[4])
00697 {
00698 LevelScale4x4Comp[1][0][k][j][i] = LevelScale4x4Comp[0][0][k][j][i];
00699 InvLevelScale4x4Comp[1][0][k][j][i] = InvLevelScale4x4Comp[0][0][k][j][i];
00700 }
00701 else
00702 {
00703 LevelScale4x4Comp[1][0][k][j][i] = (quant_coef[k][j][i]<<4)/(UseDefaultScalingMatrix4x4Flag[4] ? Quant_inter_default[temp]:ScalingList4x4[4][temp]);
00704 InvLevelScale4x4Comp[1][0][k][j][i] = dequant_coef[k][j][i]*(UseDefaultScalingMatrix4x4Flag[4] ? Quant_inter_default[temp]:ScalingList4x4[4][temp]);
00705 }
00706
00707 if(!present[5])
00708 {
00709 LevelScale4x4Comp[2][0][k][j][i] = LevelScale4x4Comp[1][0][k][j][i];
00710 InvLevelScale4x4Comp[2][0][k][j][i] = InvLevelScale4x4Comp[1][0][k][j][i];
00711 }
00712 else
00713 {
00714 LevelScale4x4Comp[2][0][k][j][i] = (quant_coef[k][j][i]<<4)/(UseDefaultScalingMatrix4x4Flag[5] ? Quant_inter_default[temp]:ScalingList4x4[5][temp]);
00715 InvLevelScale4x4Comp[2][0][k][j][i] = dequant_coef[k][j][i]*(UseDefaultScalingMatrix4x4Flag[5] ? Quant_inter_default[temp]:ScalingList4x4[5][temp]);
00716 }
00717 }
00718 }
00719 }
00720 }
00721 }
00722
00723
00724
00725
00726
00727
00728
00729
00730 void CalculateQuant8Param()
00731 {
00732 int i, j, k, temp;
00733 int n_ScalingList8x8;
00734 int present[6];
00735 int no_q_matrix=FALSE;
00736
00737
00738 n_ScalingList8x8 = ( active_sps->chroma_format_idc != 3 ) ? 2 : 6;
00739
00740 if(!active_sps->seq_scaling_matrix_present_flag && !active_pps->pic_scaling_matrix_present_flag)
00741 no_q_matrix=TRUE;
00742 else
00743 {
00744 memset(present, 0, sizeof(int)*n_ScalingList8x8);
00745
00746 if(active_sps->seq_scaling_matrix_present_flag)
00747 for(i=0; i<n_ScalingList8x8; i++)
00748 present[i] = active_sps->seq_scaling_list_present_flag[i+6];
00749
00750 if(active_pps->pic_scaling_matrix_present_flag)
00751 for(i=0; i<n_ScalingList8x8; i++)
00752 {
00753 if( i==0 || i==1 )
00754 present[i] |= active_pps->pic_scaling_list_present_flag[i+6];
00755 else
00756 present[i] = active_pps->pic_scaling_list_present_flag[i+6];
00757 }
00758 }
00759
00760 if(no_q_matrix==TRUE)
00761 {
00762 for(k=0; k<6; k++)
00763 for(j=0; j<8; j++)
00764 for(i=0; i<8; i++)
00765 {
00766
00767 LevelScale8x8Comp[0][1][k][j][i] = quant_coef8[k][j][i];
00768 InvLevelScale8x8Comp[0][1][k][j][i] = dequant_coef8[k][j][i]<<4;
00769
00770
00771 LevelScale8x8Comp[0][0][k][j][i] = quant_coef8[k][j][i];
00772 InvLevelScale8x8Comp[0][0][k][j][i] = dequant_coef8[k][j][i]<<4;
00773
00774 if( n_ScalingList8x8 > 2 )
00775 {
00776
00777 LevelScale8x8Comp[1][1][k][j][i] = quant_coef8[k][j][i];
00778 InvLevelScale8x8Comp[1][1][k][j][i] = dequant_coef8[k][j][i]<<4;
00779
00780
00781 LevelScale8x8Comp[2][1][k][j][i] = quant_coef8[k][j][i];
00782 InvLevelScale8x8Comp[2][1][k][j][i] = dequant_coef8[k][j][i]<<4;
00783
00784
00785 LevelScale8x8Comp[1][0][k][j][i] = quant_coef8[k][j][i];
00786 InvLevelScale8x8Comp[1][0][k][j][i] = dequant_coef8[k][j][i]<<4;
00787
00788
00789 LevelScale8x8Comp[2][0][k][j][i] = quant_coef8[k][j][i];
00790 InvLevelScale8x8Comp[2][0][k][j][i] = dequant_coef8[k][j][i]<<4;
00791
00792 }
00793 }
00794 }
00795 else
00796 {
00797 for(k=0; k<6; k++)
00798 for(j=0; j<8; j++)
00799 for(i=0; i<8; i++)
00800 {
00801 temp = (j<<3)+i;
00802 if((!present[0]) || UseDefaultScalingMatrix8x8Flag[0])
00803 {
00804 LevelScale8x8Comp[0][1][k][j][i] = (quant_coef8[k][j][i]<<4)/Quant8_intra_default[temp];
00805 InvLevelScale8x8Comp[0][1][k][j][i] = dequant_coef8[k][j][i]*Quant8_intra_default[temp];
00806 }
00807 else
00808 {
00809 LevelScale8x8Comp[0][1][k][j][i] = (quant_coef8[k][j][i]<<4)/ScalingList8x8[0][temp];
00810 InvLevelScale8x8Comp[0][1][k][j][i] = dequant_coef8[k][j][i]*ScalingList8x8[0][temp];
00811 }
00812
00813 if((!present[1]) || UseDefaultScalingMatrix8x8Flag[1])
00814 {
00815 LevelScale8x8Comp[0][0][k][j][i] = (quant_coef8[k][j][i]<<4)/Quant8_inter_default[temp];
00816 InvLevelScale8x8Comp[0][0][k][j][i] = dequant_coef8[k][j][i]*Quant8_inter_default[temp];
00817 }
00818 else
00819 {
00820 LevelScale8x8Comp[0][0][k][j][i] = (quant_coef8[k][j][i]<<4)/ScalingList8x8[1][temp];
00821 InvLevelScale8x8Comp[0][0][k][j][i] = dequant_coef8[k][j][i]*ScalingList8x8[1][temp];
00822 }
00823
00824 if( n_ScalingList8x8 > 2 )
00825 {
00826
00827
00828 if(!present[2])
00829 {
00830 LevelScale8x8Comp[1][1][k][j][i] = LevelScale8x8Comp[0][1][k][j][i];
00831 InvLevelScale8x8Comp[1][1][k][j][i] = InvLevelScale8x8Comp[0][1][k][j][i];
00832 }
00833 else
00834 {
00835 LevelScale8x8Comp[1][1][k][j][i] = (quant_coef8[k][j][i]<<4)/(UseDefaultScalingMatrix8x8Flag[2] ? Quant8_intra_default[temp]:ScalingList8x8[2][temp]);
00836 InvLevelScale8x8Comp[1][1][k][j][i] = dequant_coef8[k][j][i]*(UseDefaultScalingMatrix8x8Flag[2] ? Quant8_intra_default[temp]:ScalingList8x8[2][temp]);
00837 }
00838
00839
00840 if(!present[3])
00841 {
00842 LevelScale8x8Comp[1][0][k][j][i] = LevelScale8x8Comp[0][0][k][j][i];
00843 InvLevelScale8x8Comp[1][0][k][j][i] = InvLevelScale8x8Comp[0][0][k][j][i];
00844 }
00845 else
00846 {
00847 LevelScale8x8Comp[1][0][k][j][i] = (quant_coef8[k][j][i]<<4)/(UseDefaultScalingMatrix8x8Flag[3] ? Quant8_inter_default[temp]:ScalingList8x8[3][temp]);
00848 InvLevelScale8x8Comp[1][0][k][j][i] = dequant_coef8[k][j][i]*(UseDefaultScalingMatrix8x8Flag[3] ? Quant8_inter_default[temp]:ScalingList8x8[3][temp]);
00849 }
00850
00851
00852 if(!present[4])
00853 {
00854 LevelScale8x8Comp[2][1][k][j][i] = LevelScale8x8Comp[1][1][k][j][i];
00855 InvLevelScale8x8Comp[2][1][k][j][i] = InvLevelScale8x8Comp[1][1][k][j][i];
00856 }
00857 else
00858 {
00859 LevelScale8x8Comp[2][1][k][j][i] = (quant_coef8[k][j][i]<<4)/(UseDefaultScalingMatrix8x8Flag[4] ? Quant8_intra_default[temp]:ScalingList8x8[4][temp]);
00860 InvLevelScale8x8Comp[2][1][k][j][i] = dequant_coef8[k][j][i]*(UseDefaultScalingMatrix8x8Flag[4] ? Quant8_intra_default[temp]:ScalingList8x8[4][temp]);
00861 }
00862
00863
00864 if(!present[5])
00865 {
00866 LevelScale8x8Comp[2][0][k][j][i] = LevelScale8x8Comp[1][0][k][j][i];
00867 InvLevelScale8x8Comp[2][0][k][j][i] = InvLevelScale8x8Comp[1][0][k][j][i];
00868 }
00869 else
00870 {
00871 LevelScale8x8Comp[2][0][k][j][i] = (quant_coef8[k][j][i]<<4)/(UseDefaultScalingMatrix8x8Flag[5] ? Quant8_inter_default[temp]:ScalingList8x8[5][temp]);
00872 InvLevelScale8x8Comp[2][0][k][j][i] = dequant_coef8[k][j][i]*(UseDefaultScalingMatrix8x8Flag[5] ? Quant8_inter_default[temp]:ScalingList8x8[5][temp]);
00873 }
00874
00875 }
00876 }
00877 }
00878 }
00879