00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "contributors.h"
00011
00012 #include <math.h>
00013 #include <float.h>
00014
00015 #include "global.h"
00016 #include "image.h"
00017 #include "fmo.h"
00018 #include "macroblock.h"
00019 #include "mb_access.h"
00020 #include "rdoq.h"
00021 #include "block.h"
00022
00023
00024
00025
00026
00027
00028
00029 int estSyntaxElement_Level_VLC1(SyntaxElement *se)
00030 {
00031 int level = se->value1;
00032 int sign = (level < 0 ? 1 : 0);
00033 int levabs = iabs(level);
00034
00035 if (levabs < 8)
00036 {
00037 se->len = levabs * 2 + sign - 1;
00038 }
00039 else if (levabs < 16)
00040 {
00041
00042 se->len = 19;
00043 }
00044 else
00045 {
00046
00047 se->len = 28;
00048 }
00049
00050 return (se->len);
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 int estSyntaxElement_Level_VLCN(SyntaxElement *se, int vlc)
00062 {
00063 int level = se->value1;
00064 int levabs = iabs(level) - 1;
00065
00066 int shift = vlc - 1;
00067 int escape = (15 << shift);
00068
00069 if (levabs < escape)
00070 {
00071 se->len = ((levabs) >> shift) + 1 + vlc;
00072 }
00073 else
00074 {
00075 se->len = 28;
00076 }
00077
00078 return (se->len);
00079 }
00080
00081 int cmp(const void *arg1, const void *arg2)
00082 {
00083 return (((levelDataStruct *)arg2)->levelDouble - ((levelDataStruct *)arg1)->levelDouble);
00084 }
00085
00086
00087
00088
00089
00090
00091
00092 int est_CAVLC_bits (ImageParameters *p_Img, int level_to_enc[16], int sign_to_enc[16], int nnz, int block_type)
00093 {
00094 int no_bits = 0;
00095 SyntaxElement se;
00096
00097 int coeff_ctr, scan_pos = 0;
00098 int k, level = 1, run = -1, vlcnum;
00099 int numcoeff = 0, lastcoeff = 0, numtrailingones = 0;
00100 int numones = 0, totzeros = 0, zerosleft, numcoef;
00101 int numcoeff_vlc;
00102 int level_two_or_higher;
00103 int max_coeff_num = 0, cdc = (block_type == CHROMA_DC ? 1 : 0);
00104 int yuv = p_Img->yuv_format - 1;
00105 static const int incVlc[] = {0, 3, 6, 12, 24, 48, 32768};
00106
00107 int pLevel[16] = {0};
00108 int pRun[16] = {0};
00109
00110 static const int Token_lentab[3][4][17] =
00111 {
00112 {
00113 { 1, 6, 8, 9,10,11,13,13,13,14,14,15,15,16,16,16,16},
00114 { 0, 2, 6, 8, 9,10,11,13,13,14,14,15,15,15,16,16,16},
00115 { 0, 0, 3, 7, 8, 9,10,11,13,13,14,14,15,15,16,16,16},
00116 { 0, 0, 0, 5, 6, 7, 8, 9,10,11,13,14,14,15,15,16,16}
00117 },
00118 {
00119 { 2, 6, 6, 7, 8, 8, 9,11,11,12,12,12,13,13,13,14,14},
00120 { 0, 2, 5, 6, 6, 7, 8, 9,11,11,12,12,13,13,14,14,14},
00121 { 0, 0, 3, 6, 6, 7, 8, 9,11,11,12,12,13,13,13,14,14},
00122 { 0, 0, 0, 4, 4, 5, 6, 6, 7, 9,11,11,12,13,13,13,14}
00123 },
00124 {
00125 { 4, 6, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9,10,10,10,10},
00126 { 0, 4, 5, 5, 5, 5, 6, 6, 7, 8, 8, 9, 9, 9,10,10,10},
00127 { 0, 0, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10},
00128 { 0, 0, 0, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 9,10,10,10}
00129 }
00130 };
00131
00132 static const int Totalzeros_lentab[TOTRUN_NUM][16] =
00133 {
00134 { 1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9},
00135 { 3,3,3,3,3,4,4,4,4,5,5,6,6,6,6},
00136 { 4,3,3,3,4,4,3,3,4,5,5,6,5,6},
00137 { 5,3,4,4,3,3,3,4,3,4,5,5,5},
00138 { 4,4,4,3,3,3,3,3,4,5,4,5},
00139 { 6,5,3,3,3,3,3,3,4,3,6},
00140 { 6,5,3,3,3,2,3,4,3,6},
00141 { 6,4,5,3,2,2,3,3,6},
00142 { 6,6,4,2,2,3,2,5},
00143 { 5,5,3,2,2,2,4},
00144 { 4,4,3,3,1,3},
00145 { 4,4,2,1,3},
00146 { 3,3,1,2},
00147 { 2,2,1},
00148 { 1,1},
00149 };
00150 static const int Run_lentab[TOTRUN_NUM][16] =
00151 {
00152 {1,1},
00153 {1,2,2},
00154 {2,2,2,2},
00155 {2,2,2,3,3},
00156 {2,2,3,3,3,3},
00157 {2,3,3,3,3,3,3},
00158 {3,3,3,3,3,3,3,4,5,6,7,8,9,10,11},
00159 };
00160 static const int Token_lentab_cdc[3][4][17] =
00161 {
00162
00163 {{ 2, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
00164 { 0, 1, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
00165 { 0, 0, 3, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
00166 { 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}},
00167
00168 {{ 1, 7, 7, 9, 9,10,11,12,13, 0, 0, 0, 0, 0, 0, 0, 0},
00169 { 0, 2, 7, 7, 9,10,11,12,12, 0, 0, 0, 0, 0, 0, 0, 0},
00170 { 0, 0, 3, 7, 7, 9,10,11,12, 0, 0, 0, 0, 0, 0, 0, 0},
00171 { 0, 0, 0, 5, 6, 7, 7,10,11, 0, 0, 0, 0, 0, 0, 0, 0}},
00172
00173 {{ 1, 6, 8, 9,10,11,13,13,13,14,14,15,15,16,16,16,16},
00174 { 0, 2, 6, 8, 9,10,11,13,13,14,14,15,15,15,16,16,16},
00175 { 0, 0, 3, 7, 8, 9,10,11,13,13,14,14,15,15,16,16,16},
00176 { 0, 0, 0, 5, 6, 7, 8, 9,10,11,13,14,14,15,15,16,16}}
00177 };
00178 static const int Totalzeros_lentab_cdc[3][TOTRUN_NUM][16] =
00179 {
00180
00181 {{ 1,2,3,3},
00182 { 1,2,2},
00183 { 1,1}},
00184
00185 {{ 1,3,3,4,4,4,5,5},
00186 { 3,2,3,3,3,3,3},
00187 { 3,3,2,2,3,3},
00188 { 3,2,2,2,3},
00189 { 2,2,2,2},
00190 { 2,2,1},
00191 { 1,1}},
00192
00193 {{ 1,3,3,4,4,5,5,6,6,7,7,8,8,9,9,9},
00194 { 3,3,3,3,3,4,4,4,4,5,5,6,6,6,6},
00195 { 4,3,3,3,4,4,3,3,4,5,5,6,5,6},
00196 { 5,3,4,4,3,3,3,4,3,4,5,5,5},
00197 { 4,4,4,3,3,3,3,3,4,5,4,5},
00198 { 6,5,3,3,3,3,3,3,4,3,6},
00199 { 6,5,3,3,3,2,3,4,3,6},
00200 { 6,4,5,3,2,2,3,3,6},
00201 { 6,6,4,2,2,3,2,5},
00202 { 5,5,3,2,2,2,4},
00203 { 4,4,3,3,1,3},
00204 { 4,4,2,1,3},
00205 { 3,3,1,2},
00206 { 2,2,1},
00207 { 1,1}}
00208 };
00209
00210
00211 max_coeff_num = ( (block_type == CHROMA_DC) ? p_Img->num_cdc_coeff :
00212 ( (block_type == LUMA_INTRA16x16AC || block_type == CB_INTRA16x16AC || block_type == CR_INTRA16x16AC || block_type == CHROMA_AC) ? 15 : 16) );
00213
00214
00215 for (coeff_ctr = 0; coeff_ctr < max_coeff_num; coeff_ctr++)
00216 {
00217 run++;
00218 level = level_to_enc[coeff_ctr];
00219 if (level != 0)
00220 {
00221 pLevel[scan_pos] = isignab(level, sign_to_enc[coeff_ctr]);
00222 pRun [scan_pos] = run;
00223 ++scan_pos;
00224 run = -1;
00225 }
00226 }
00227
00228 level = 1;
00229 for(k = 0; (k < max_coeff_num) && level != 0; k++)
00230 {
00231 level = pLevel[k];
00232 run = pRun[k];
00233
00234 if (level)
00235 {
00236 totzeros += run;
00237 if (iabs(level) == 1)
00238 {
00239 numones ++;
00240 numtrailingones ++;
00241 numtrailingones = imin(numtrailingones, 3);
00242 }
00243 else
00244 {
00245 numtrailingones = 0;
00246 }
00247 numcoeff ++;
00248 lastcoeff = k;
00249 }
00250 }
00251
00252 if (!cdc)
00253 {
00254 if (nnz < 2)
00255 {
00256 numcoeff_vlc = 0;
00257 }
00258 else if (nnz < 4)
00259 {
00260 numcoeff_vlc = 1;
00261 }
00262 else if (nnz < 8)
00263 {
00264 numcoeff_vlc = 2;
00265 }
00266 else
00267 {
00268 numcoeff_vlc = 3;
00269 }
00270 }
00271 else
00272 {
00273
00274
00275 numcoeff_vlc = 0;
00276 }
00277
00278 se.value1 = numcoeff;
00279 se.value2 = numtrailingones;
00280 se.len = numcoeff_vlc;
00281
00282 if (!cdc)
00283 {
00284 if (se.len == 3)
00285 no_bits += 6;
00286 else
00287 no_bits += Token_lentab[se.len][se.value2][se.value1];
00288 }
00289 else
00290 no_bits += Token_lentab_cdc[yuv][se.value2][se.value1];
00291
00292 if (!numcoeff)
00293 return no_bits;
00294 else
00295 {
00296 if (numtrailingones)
00297 no_bits += numtrailingones;
00298
00299
00300 level_two_or_higher = (numcoeff > 3 && numtrailingones == 3) ? 0 : 1;
00301
00302 vlcnum = (numcoeff > 10 && numtrailingones < 3) ? 1 : 0;
00303
00304 for (k = lastcoeff - numtrailingones; k >= 0; k--)
00305 {
00306 level = pLevel[k];
00307
00308 se.value1 = level;
00309
00310 if (level_two_or_higher)
00311 {
00312 level_two_or_higher = 0;
00313 if (se.value1 > 0)
00314 se.value1 --;
00315 else
00316 se.value1 ++;
00317 }
00318
00319
00320 if (vlcnum == 0)
00321 estSyntaxElement_Level_VLC1(&se);
00322 else
00323 estSyntaxElement_Level_VLCN(&se, vlcnum);
00324
00325
00326 if (iabs(level) > incVlc[vlcnum])
00327 vlcnum++;
00328
00329 if ((k == lastcoeff - numtrailingones) && iabs(level) > 3)
00330 vlcnum = 2;
00331
00332 no_bits += se.len;
00333 }
00334
00335
00336 if (numcoeff < max_coeff_num)
00337 {
00338 se.value1 = totzeros;
00339
00340 vlcnum = numcoeff-1;
00341
00342 se.len = vlcnum;
00343
00344 if (!cdc)
00345 no_bits += Totalzeros_lentab[se.len][se.value1];
00346 else
00347 no_bits += Totalzeros_lentab_cdc[yuv][se.len][se.value1];
00348 }
00349
00350
00351 zerosleft = totzeros;
00352 numcoef = numcoeff;
00353 for (k = lastcoeff; k >= 0; k--)
00354 {
00355 run = pRun[k];
00356
00357 se.value1 = run;
00358
00359
00360
00361 if ((!zerosleft) || (numcoeff <= 1 ))
00362 break;
00363
00364 if (numcoef > 1 && zerosleft)
00365 {
00366 vlcnum = imin(zerosleft - 1, RUNBEFORE_NUM_M1);
00367 se.len = vlcnum;
00368 no_bits += Run_lentab[se.len][se.value1];
00369 zerosleft -= run;
00370 numcoef --;
00371 }
00372 }
00373 }
00374
00375 return no_bits;
00376 }
00377
00378
00379
00380
00381
00382
00383
00384
00385 void est_RunLevel_CAVLC(Macroblock *currMB, levelDataStruct *levelData, int *levelTrellis, int block_type,
00386 int b8, int b4, int coeff_num, double lambda)
00387 {
00388 int k, lastnonzero = -1, coeff_ctr;
00389 int level_to_enc[16] = {0}, sign_to_enc[16] = {0};
00390 int cstat, bestcstat = 0;
00391 int nz_coeff=0;
00392 double lagr, lagrAcc = 0, minlagr = 0;
00393 ImageParameters *p_Img = currMB->p_Img;
00394
00395 int subblock_x = ((b8 & 0x1) == 0) ? (((b4 & 0x1) == 0) ? 0 : 1) : (((b4 & 0x1) == 0) ? 2 : 3);
00396
00397 int subblock_y = (b8 < 2) ? ((b4 < 2) ? 0 : 1) :((b4 < 2) ? 2 : 3);
00398
00399 int nnz;
00400 levelDataStruct *dataLevel = &levelData[0];
00401
00402 if (block_type != CHROMA_AC)
00403 nnz = predict_nnz(currMB, LUMA, subblock_x, subblock_y);
00404 else
00405 nnz = predict_nnz_chroma(currMB, currMB->subblock_x >> 2, (currMB->subblock_y >> 2) + 4);
00406
00407 for (coeff_ctr=0;coeff_ctr < coeff_num;coeff_ctr++)
00408 {
00409 levelTrellis[coeff_ctr] = 0;
00410
00411 for(k=0; k < dataLevel->noLevels; k++)
00412 {
00413 dataLevel->errLevel[k] /= 32768;
00414 }
00415
00416 lagrAcc += dataLevel->errLevel[dataLevel->noLevels - 1];
00417
00418 level_to_enc[coeff_ctr] = dataLevel->pre_level;
00419 sign_to_enc[coeff_ctr] = dataLevel->sign;
00420
00421 if(dataLevel->noLevels > 1)
00422 {
00423 dataLevel->coeff_ctr = coeff_ctr;
00424 lastnonzero = coeff_ctr;
00425 }
00426 else
00427 dataLevel->coeff_ctr = -1;
00428 dataLevel++;
00429 }
00430
00431 if(lastnonzero != -1)
00432 {
00433
00434 qsort(levelData, lastnonzero + 1, sizeof(levelDataStruct), cmp);
00435
00436 dataLevel = &levelData[lastnonzero];
00437
00438 for(coeff_ctr = lastnonzero; coeff_ctr >= 0; coeff_ctr--)
00439 {
00440 if(dataLevel->noLevels == 1)
00441 {
00442 dataLevel--;
00443 continue;
00444 }
00445
00446 lagrAcc -= dataLevel->errLevel[dataLevel->noLevels-1];
00447 for(cstat=0; cstat<dataLevel->noLevels; cstat++)
00448 {
00449 level_to_enc[dataLevel->coeff_ctr] = dataLevel->level[cstat];
00450 lagr = lagrAcc + dataLevel->errLevel[cstat];
00451
00452 lagr += lambda * est_CAVLC_bits( p_Img, level_to_enc, sign_to_enc, nnz, block_type);
00453
00454 if(cstat==0 || lagr<minlagr)
00455 {
00456 minlagr = lagr;
00457 bestcstat = cstat;
00458 }
00459 }
00460 lagrAcc += dataLevel->errLevel[bestcstat];
00461 level_to_enc[dataLevel->coeff_ctr] = dataLevel->level[bestcstat];
00462 dataLevel--;
00463 }
00464
00465 for(coeff_ctr = 0; coeff_ctr <= lastnonzero; coeff_ctr++)
00466 {
00467 levelTrellis[coeff_ctr] = level_to_enc[coeff_ctr];
00468 if (level_to_enc[coeff_ctr] != 0)
00469 nz_coeff++;
00470 }
00471 }
00472
00473 p_Img->nz_coeff [p_Img->current_mb_nr ][subblock_x][subblock_y] = nz_coeff;
00474 }
00475
00476
00477
00478
00479
00480
00481
00482 void init_trellis_data_4x4_CAVLC(Macroblock *currMB, int **tblock, int block_x, int qp_per, int qp_rem, LevelQuantParams **q_params_4x4,
00483 const byte *p_scan, levelDataStruct *dataLevel, int type)
00484 {
00485 Slice *currSlice = currMB->p_slice;
00486 int i, j, coeff_ctr;
00487 int *m7;
00488 int end_coeff_ctr = ( ( type == LUMA_4x4 ) ? 16 : 15 );
00489 int q_bits = Q_BITS + qp_per;
00490 int q_offset = ( 1 << (q_bits - 1) );
00491 int level, lowerInt, k;
00492 double err, estErr;
00493
00494
00495 for (coeff_ctr = 0; coeff_ctr < end_coeff_ctr; coeff_ctr++)
00496 {
00497 i = *p_scan++;
00498 j = *p_scan++;
00499
00500 m7 = &tblock[j][block_x + i];
00501
00502 if (*m7 == 0)
00503 {
00504 dataLevel->levelDouble = 0;
00505 dataLevel->level[0] = 0;
00506 dataLevel->noLevels = 1;
00507 err = 0.0;
00508 dataLevel->errLevel[0] = 0.0;
00509 dataLevel->pre_level = 0;
00510 dataLevel->sign = 0;
00511 }
00512 else
00513 {
00514 estErr = ((double) estErr4x4[qp_rem][j][i]) / currSlice->norm_factor_4x4;
00515
00516 dataLevel->levelDouble = iabs(*m7 * q_params_4x4[j][i].ScaleComp);
00517 level = (dataLevel->levelDouble >> q_bits);
00518
00519 lowerInt = (((int)dataLevel->levelDouble - (level << q_bits)) < q_offset )? 1 : 0;
00520
00521 dataLevel->level[0] = 0;
00522 if (level == 0 && lowerInt == 1)
00523 {
00524 dataLevel->noLevels = 1;
00525 }
00526 else if (level == 0 && lowerInt == 0)
00527 {
00528 dataLevel->level[1] = 1;
00529 dataLevel->noLevels = 2;
00530 }
00531 else if (level > 0 && lowerInt == 1)
00532 {
00533 dataLevel->level[1] = level;
00534 dataLevel->noLevels = 2;
00535 }
00536 else
00537 {
00538 dataLevel->level[1] = level;
00539 dataLevel->level[2] = level + 1;
00540 dataLevel->noLevels = 3;
00541 }
00542
00543 for (k = 0; k < dataLevel->noLevels; k++)
00544 {
00545 err = (double)(dataLevel->level[k] << q_bits) - (double)dataLevel->levelDouble;
00546 dataLevel->errLevel[k] = (err * err * estErr);
00547 }
00548
00549 if(dataLevel->noLevels == 1)
00550 dataLevel->pre_level = 0;
00551 else
00552 dataLevel->pre_level = (iabs (*m7) * q_params_4x4[j][i].ScaleComp + q_params_4x4[j][i].OffsetComp) >> q_bits;
00553 dataLevel->sign = isign(*m7);
00554 }
00555 dataLevel++;
00556 }
00557 }
00558
00559
00560
00561
00562
00563
00564
00565 void init_trellis_data_DC_CAVLC(Macroblock *currMB, int **tblock, int qp_per, int qp_rem,
00566 LevelQuantParams *q_params_4x4, const byte *p_scan,
00567 levelDataStruct *dataLevel)
00568 {
00569 Slice *currSlice = currMB->p_slice;
00570 int i, j, coeff_ctr, end_coeff_ctr = 16;
00571 int q_bits = Q_BITS + qp_per + 1;
00572 int q_offset = ( 1 << (q_bits - 1) );
00573 int level, lowerInt, k;
00574 int *m7;
00575 double err, estErr = (double) estErr4x4[qp_rem][0][0] / currSlice->norm_factor_4x4;
00576
00577 for (coeff_ctr = 0; coeff_ctr < end_coeff_ctr; coeff_ctr++)
00578 {
00579 i = *p_scan++;
00580 j = *p_scan++;
00581 m7 = &tblock[j][i];
00582
00583 if (*m7 == 0)
00584 {
00585 dataLevel->levelDouble = 0;
00586 dataLevel->level[0] = 0;
00587 dataLevel->noLevels = 1;
00588 err = 0.0;
00589 dataLevel->errLevel[0] = 0.0;
00590 dataLevel->pre_level = 0;
00591 dataLevel->sign = 0;
00592 }
00593 else
00594 {
00595 dataLevel->levelDouble = iabs(*m7 * q_params_4x4->ScaleComp);
00596 level = (dataLevel->levelDouble >> q_bits);
00597
00598 lowerInt=( ((int)dataLevel->levelDouble - (level<<q_bits)) < q_offset )? 1 : 0;
00599
00600 dataLevel->level[0] = 0;
00601 if (level == 0 && lowerInt == 1)
00602 {
00603 dataLevel->noLevels = 1;
00604 }
00605 else if (level == 0 && lowerInt == 0)
00606 {
00607 dataLevel->level[1] = 1;
00608 dataLevel->noLevels = 2;
00609 }
00610 else if (level > 0 && lowerInt == 1)
00611 {
00612 dataLevel->level[1] = level;
00613 dataLevel->noLevels = 2;
00614 }
00615 else
00616 {
00617 dataLevel->level[1] = level;
00618 dataLevel->level[2] = level + 1;
00619 dataLevel->noLevels = 3;
00620 }
00621
00622 for (k = 0; k < dataLevel->noLevels; k++)
00623 {
00624 err = (double)(dataLevel->level[k] << q_bits) - (double)dataLevel->levelDouble;
00625 dataLevel->errLevel[k] = (err * err * estErr);
00626 }
00627
00628 if(dataLevel->noLevels == 1)
00629 dataLevel->pre_level = 0;
00630 else
00631 dataLevel->pre_level = (iabs (*m7) * q_params_4x4->ScaleComp + q_params_4x4->OffsetComp) >> q_bits;
00632 dataLevel->sign = isign(*m7);
00633 }
00634 dataLevel++;
00635 }
00636 }
00637
00638
00639
00640
00641
00642
00643
00644 void init_trellis_data_8x8_CAVLC(Macroblock *currMB, int **tblock, int block_x, int qp_per, int qp_rem, LevelQuantParams **q_params_8x8,
00645 const byte *p_scan, levelDataStruct levelData[4][16])
00646 {
00647 Slice *currSlice = currMB->p_slice;
00648 int i, j, block, coeff_ctr;
00649 int *m7;
00650 int q_bits = Q_BITS_8 + qp_per;
00651 int q_offset = ( 1 << (q_bits - 1) );
00652 double err, estErr;
00653 int level, lowerInt, k;
00654
00655 levelDataStruct *dataLevel = &levelData[0][0];
00656
00657 for (coeff_ctr = 0; coeff_ctr < 16; coeff_ctr++)
00658 {
00659 for (block = 0; block < 4; block++)
00660 {
00661 i = *p_scan++;
00662 j = *p_scan++;
00663
00664 m7 = &tblock[j][block_x + i];
00665
00666 dataLevel = &levelData[block][coeff_ctr];
00667 if (*m7 == 0)
00668 {
00669 dataLevel->levelDouble = 0;
00670 dataLevel->level[0] = 0;
00671 dataLevel->noLevels = 1;
00672 err = 0.0;
00673 dataLevel->errLevel[0] = 0.0;
00674 dataLevel->pre_level = 0;
00675 dataLevel->sign = 0;
00676 }
00677 else
00678 {
00679 estErr = (double) estErr8x8[qp_rem][j][i] / currSlice->norm_factor_8x8;
00680
00681 dataLevel->levelDouble = iabs(*m7 * q_params_8x8[j][i].ScaleComp);
00682 level = (dataLevel->levelDouble >> q_bits);
00683
00684 lowerInt = (((int)dataLevel->levelDouble - (level << q_bits)) < q_offset ) ? 1 : 0;
00685
00686 dataLevel->level[0] = 0;
00687 if (level == 0 && lowerInt == 1)
00688 {
00689 dataLevel->noLevels = 1;
00690 }
00691 else if (level == 0 && lowerInt == 0)
00692 {
00693 dataLevel->level[1] = 1;
00694 dataLevel->noLevels = 2;
00695 }
00696 else if (level > 0 && lowerInt == 1)
00697 {
00698 if (level > 1)
00699 {
00700 dataLevel->level[1] = level - 1;
00701 dataLevel->level[2] = level;
00702 dataLevel->noLevels = 3;
00703 }
00704 else
00705 {
00706 dataLevel->level[1] = level;
00707 dataLevel->noLevels = 2;
00708 }
00709 }
00710 else
00711 {
00712 dataLevel->level[1] = level;
00713 dataLevel->level[2] = level + 1;
00714 dataLevel->noLevels = 3;
00715 }
00716
00717 for (k = 0; k < dataLevel->noLevels; k++)
00718 {
00719 err = (double)(dataLevel->level[k] << q_bits) - (double)dataLevel->levelDouble;
00720 dataLevel->errLevel[k] = err * err * estErr;
00721 }
00722
00723 if(dataLevel->noLevels == 1)
00724 dataLevel->pre_level = 0;
00725 else
00726 dataLevel->pre_level = (iabs (*m7) * q_params_8x8[j][i].ScaleComp + q_params_8x8[j][i].OffsetComp) >> q_bits;
00727 dataLevel->sign = isign(*m7);
00728 }
00729 }
00730 }
00731 }
00732
00733