00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "momusys.h"
00041 #include "vlc.h"
00042 #include "putvlc.h"
00043 #include "bitstream.h"
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 Int
00078 PutDCsize_lum (Int size, Image *bitstream)
00079 {
00080 MOMCHECK(size >= 0 && size < 13);
00081
00082 BitstreamPutBits (bitstream, DCtab_lum[size].code, DCtab_lum[size].len);
00083
00084 return DCtab_lum[size].len;
00085 }
00086
00087
00088 Int
00089 PutDCsize_chrom (Int size, Image *bitstream)
00090 {
00091 MOMCHECK (size >= 0 && size < 13);
00092
00093 BitstreamPutBits (bitstream, DCtab_chrom[size].code, DCtab_chrom[size].len);
00094
00095 return DCtab_chrom[size].len;
00096 }
00097
00098
00099 Int
00100 PutMV (Int mvint, Image *bitstream)
00101 {
00102 Int sign = 0;
00103 Int absmv;
00104
00105 if (mvint > 32)
00106 {
00107 absmv = -mvint + 65;
00108 sign = 1;
00109 }
00110 else
00111 absmv = mvint;
00112
00113 BitstreamPutBits (bitstream, mvtab[absmv].code, mvtab[absmv].len);
00114
00115 if (mvint != 0)
00116 {
00117 BitstreamPutBits (bitstream, sign, 1);
00118 return mvtab[absmv].len + 1;
00119 }
00120 else
00121 return mvtab[absmv].len;
00122 }
00123
00124
00125 Int
00126 PutMCBPC_Intra (Int cbpc, Int mode, Image *bitstream)
00127 {
00128 Int ind;
00129
00130 ind = ((mode >> 1) & 3) | ((cbpc & 3) << 2);
00131
00132 BitstreamPutBits (bitstream, mcbpc_intra_tab[ind].code, mcbpc_intra_tab[ind].len);
00133
00134 return mcbpc_intra_tab[ind].len;
00135 }
00136
00137
00138 Int
00139 PutMCBPC_Inter (Int cbpc, Int mode, Image *bitstream)
00140 {
00141 Int ind;
00142
00143 ind = (mode & 7) | ((cbpc & 3) << 3);
00144
00145 BitstreamPutBits (bitstream, mcbpc_inter_tab[ind].code,
00146 mcbpc_inter_tab[ind].len);
00147
00148 return mcbpc_inter_tab[ind].len;
00149 }
00150
00151
00152 Int
00153 PutMCBPC_Sprite (Int cbpc, Int mode, Image *bitstream)
00154 {
00155 Int ind;
00156
00157 ind = (mode & 7) | ((cbpc & 3) << 3);
00158
00159 BitstreamPutBits (bitstream, mcbpc_sprite_tab[ind].code,
00160 mcbpc_sprite_tab[ind].len);
00161
00162 return mcbpc_sprite_tab[ind].len;
00163 }
00164
00165
00166 Int
00167 PutCBPY (Int cbpy, Char intra, Int *MB_transp_pattern, Image *bitstream)
00168 {
00169 Int ind;
00170 Int index=0;
00171
00172
00173
00174 if (intra == 0) cbpy = 15 - cbpy;
00175
00176 ind = cbpy;
00177 BitstreamPutBits (bitstream, cbpy_tab[ind].code, cbpy_tab[ind].len);
00178 return cbpy_tab[ind].len;
00179 }
00180
00181
00182 Int
00183 PutCoeff_Inter(Int run, Int level, Int last, Image *bitstream)
00184 {
00185 Int length = 0;
00186
00187 MOMCHECK (last >= 0 && last < 2);
00188 MOMCHECK (run >= 0 && run < 64);
00189 MOMCHECK (level > 0 && level < 128);
00190
00191 if (last == 0)
00192 {
00193 if (run < 2 && level < 13 )
00194 {
00195 BitstreamPutBits (bitstream, (LInt)coeff_tab0[run][level-1].code,
00196 (LInt)coeff_tab0[run][level-1].len);
00197
00198 length = coeff_tab0[run][level-1].len;
00199 }
00200 else if (run > 1 && run < 27 && level < 5)
00201 {
00202 BitstreamPutBits (bitstream, (LInt)coeff_tab1[run-2][level-1].code,
00203 (LInt)coeff_tab1[run-2][level-1].len);
00204
00205 length = coeff_tab1[run-2][level-1].len;
00206 }
00207 }
00208 else if (last == 1)
00209 {
00210 if (run < 2 && level < 4)
00211 {
00212 BitstreamPutBits (bitstream, (LInt)coeff_tab2[run][level-1].code,
00213 (LInt)coeff_tab2[run][level-1].len);
00214
00215 length = coeff_tab2[run][level-1].len;
00216 }
00217 else if (run > 1 && run < 42 && level == 1)
00218 {
00219 BitstreamPutBits (bitstream, (LInt)coeff_tab3[run-2].code,
00220 (LInt)coeff_tab3[run-2].len);
00221
00222 length = coeff_tab3[run-2].len;
00223 }
00224 }
00225 return length;
00226 }
00227
00228
00229 Int
00230 PutCoeff_Intra(Int run, Int level, Int last, Image *bitstream)
00231 {
00232 Int length = 0;
00233
00234 MOMCHECK (last >= 0 && last < 2);
00235 MOMCHECK (run >= 0 && run < 64);
00236 MOMCHECK (level > 0 && level < 128);
00237
00238 if (last == 0)
00239 {
00240 if (run == 0 && level < 28 )
00241 {
00242 BitstreamPutBits(bitstream, (LInt)coeff_tab4[level-1].code,
00243 (LInt)coeff_tab4[level-1].len);
00244
00245 length = coeff_tab4[level-1].len;
00246 }
00247 else if (run == 1 && level < 11)
00248 {
00249 BitstreamPutBits(bitstream, (LInt)coeff_tab5[level-1].code,
00250 (LInt)coeff_tab5[level-1].len);
00251
00252 length = coeff_tab5[level-1].len;
00253 }
00254 else if (run > 1 && run < 10 && level < 6)
00255 {
00256 BitstreamPutBits(bitstream, (LInt)coeff_tab6[run-2][level-1].code,
00257 (LInt)coeff_tab6[run-2][level-1].len);
00258
00259 length = coeff_tab6[run-2][level-1].len;
00260 }
00261 else if (run > 9 && run < 15 && level == 1)
00262 {
00263 BitstreamPutBits(bitstream, (LInt)coeff_tab7[run-10].code,
00264 (LInt)coeff_tab7[run-10].len);
00265
00266 length = coeff_tab7[run-10].len;
00267 }
00268 }
00269 else if (last == 1)
00270 {
00271 if (run == 0 && level < 9)
00272 {
00273 BitstreamPutBits(bitstream, (LInt)coeff_tab8[level-1].code,
00274 (LInt)coeff_tab8[level-1].len);
00275
00276 length = coeff_tab8[level-1].len;
00277 }
00278 else if (run > 0 && run < 7 && level < 4)
00279 {
00280 BitstreamPutBits(bitstream, (LInt)coeff_tab9[run-1][level-1].code,
00281 (LInt)coeff_tab9[run-1][level-1].len);
00282
00283 length = coeff_tab9[run-1][level-1].len;
00284 }
00285 else if (run > 6 && run < 21 && level == 1)
00286 {
00287 BitstreamPutBits(bitstream, (LInt)coeff_tab10[run-7].code,
00288 (LInt)coeff_tab10[run-7].len);
00289
00290 length = coeff_tab10[run-7].len;
00291 }
00292 }
00293 return length;
00294 }
00295
00296
00297 Int
00298 PutCoeff_Inter_RVLC(Int run, Int level, Int last, Image *bitstream)
00299 {
00300 Int length = 0;
00301
00302 MOMCHECK (last >= 0 && last < 2);
00303 MOMCHECK (run >= 0 && run < 64);
00304 MOMCHECK (level > 0 && level < 128);
00305
00306 if (last == 0)
00307 {
00308 if (run == 0 && level < 20 )
00309 {
00310 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab14[level-1].code,
00311 (LInt)coeff_RVLCtab14[level-1].len);
00312
00313 length = coeff_RVLCtab14[level-1].len;
00314 }
00315 else if (run == 1 && level < 11)
00316 {
00317 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab15[level-1].code,
00318 (LInt)coeff_RVLCtab15[level-1].len);
00319
00320 length = coeff_RVLCtab15[level-1].len;
00321 }
00322 else if (run > 1 && run < 4 && level < 8)
00323 {
00324 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab16[run-2][level-1].code,
00325 (LInt)coeff_RVLCtab16[run-2][level-1].len);
00326 length = coeff_RVLCtab16[run-2][level-1].len;
00327 }
00328 else if (run == 4 && level < 6)
00329 {
00330 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab17[level-1].code,
00331 (LInt)coeff_RVLCtab17[level-1].len);
00332
00333 length = coeff_RVLCtab17[level-1].len;
00334 }
00335 else if (run > 4 && run < 8 && level < 5)
00336 {
00337 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab18[run-5][level-1].code,
00338 (LInt)coeff_RVLCtab18[run-5][level-1].len);
00339
00340 length = coeff_RVLCtab18[run-5][level-1].len;
00341 }
00342 else if (run > 7 && run < 10 && level < 4)
00343 {
00344 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab19[run-8][level-1].code,
00345 (LInt)coeff_RVLCtab19[run-8][level-1].len);
00346
00347 length = coeff_RVLCtab19[run-8][level-1].len;
00348 }
00349 else if (run > 9 && run < 18 && level < 3)
00350 {
00351 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab20[run-10][level-1].code,
00352 (LInt)coeff_RVLCtab20[run-10][level-1].len);
00353
00354 length = coeff_RVLCtab20[run-10][level-1].len;
00355 }
00356 else if (run > 17 && run < 39 && level == 1)
00357 {
00358 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab21[run-18].code,
00359 (LInt)coeff_RVLCtab21[run-18].len);
00360
00361 length = coeff_RVLCtab21[run-18].len;
00362 }
00363 }
00364 else if (last == 1)
00365 {
00366 if (run >= 0 && run < 2 && level < 6)
00367 {
00368 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab22[run][level-1].code,
00369 (LInt)coeff_RVLCtab22[run][level-1].len);
00370
00371 length = coeff_RVLCtab22[run][level-1].len;
00372 }
00373 else if (run == 2 && level < 4)
00374 {
00375 BitstreamPutBits (bitstream, (LInt)coeff_RVLCtab23[level-1].code,
00376 (LInt)coeff_RVLCtab23[level-1].len);
00377
00378 length = coeff_RVLCtab23[level-1].len;
00379 }
00380 else if (run > 2 && run < 14 && level < 3)
00381 {
00382 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab24[run-3][level-1].code,
00383 (LInt)coeff_RVLCtab24[run-3][level-1].len);
00384
00385 length = coeff_RVLCtab24[run-3][level-1].len;
00386 }
00387 else if (run > 13 && run < 46 && level == 1)
00388 {
00389 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab25[run-14].code,
00390 (LInt)coeff_RVLCtab25[run-14].len);
00391
00392 length = coeff_RVLCtab25[run-14].len;
00393 }
00394 }
00395 return length;
00396 }
00397
00398
00399 Int
00400 PutCoeff_Intra_RVLC(Int run, Int level, Int last, Image *bitstream)
00401 {
00402 Int length = 0;
00403
00404 MOMCHECK (last >= 0 && last < 2);
00405 MOMCHECK (run >= 0 && run < 64);
00406 MOMCHECK (level > 0 && level < 128);
00407
00408 if (last == 0)
00409 {
00410 if (run == 0 && level < 28 )
00411 {
00412 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab1[level-1].code,
00413 (LInt)coeff_RVLCtab1[level-1].len);
00414
00415 length = coeff_RVLCtab1[level-1].len;
00416 }
00417 else if (run == 1 && level < 14)
00418 {
00419 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab2[level-1].code,
00420 (LInt)coeff_RVLCtab2[level-1].len);
00421
00422 length = coeff_RVLCtab2[level-1].len;
00423 }
00424 else if (run == 2 && level < 12)
00425 {
00426 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab3[level-1].code,
00427 (LInt)coeff_RVLCtab3[level-1].len);
00428
00429 length = coeff_RVLCtab3[level-1].len;
00430 }
00431 else if (run == 3 && level < 10)
00432 {
00433 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab4[level-1].code,
00434 (LInt)coeff_RVLCtab4[level-1].len);
00435
00436 length = coeff_RVLCtab4[level-1].len;
00437 }
00438 else if (run > 3 && run < 6 && level < 7)
00439 {
00440 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab5[run-4][level-1].code,
00441 (LInt)coeff_RVLCtab5[run-4][level-1].len);
00442
00443 length = coeff_RVLCtab5[run-4][level-1].len;
00444 }
00445 else if (run > 5 && run < 8 && level < 6)
00446 {
00447 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab6[run-6][level-1].code,
00448 (LInt)coeff_RVLCtab6[run-6][level-1].len);
00449
00450 length = coeff_RVLCtab6[run-6][level-1].len;
00451 }
00452 else if (run > 7 && run < 10 && level < 5)
00453 {
00454 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab7[run-8][level-1].code,
00455 (LInt)coeff_RVLCtab7[run-8][level-1].len);
00456
00457 length = coeff_RVLCtab7[run-8][level-1].len;
00458 }
00459 else if (run > 9 && run < 13 && level < 3)
00460 {
00461 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab8[run-10][level-1].code,
00462 (LInt)coeff_RVLCtab8[run-10][level-1].len);
00463
00464 length = coeff_RVLCtab8[run-10][level-1].len;
00465 }
00466 else if (run > 12 && run < 20 && level == 1)
00467 {
00468 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab9[run-13].code,
00469 (LInt)coeff_RVLCtab9[run-13].len);
00470
00471 length = coeff_RVLCtab9[run-13].len;
00472 }
00473 }
00474 else if (last == 1)
00475 {
00476 if (run >= 0 && run < 2 && level < 6)
00477 {
00478 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab10[run][level-1].code,
00479 (LInt)coeff_RVLCtab10[run][level-1].len);
00480
00481 length = coeff_RVLCtab10[run][level-1].len;
00482 }
00483 else if (run == 2 && level < 4)
00484 {
00485 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab11[level-1].code,
00486 (LInt)coeff_RVLCtab11[level-1].len);
00487
00488 length = coeff_RVLCtab11[level-1].len;
00489 }
00490 else if (run > 2 && run < 14 && level < 3)
00491 {
00492 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab12[run-3][level-1].code,
00493 (LInt)coeff_RVLCtab12[run-3][level-1].len);
00494
00495 length = coeff_RVLCtab12[run-3][level-1].len;
00496 }
00497 else if (run > 13 && run < 46 && level == 1)
00498 {
00499 BitstreamPutBits(bitstream, (LInt)coeff_RVLCtab13[run-14].code,
00500 (LInt)coeff_RVLCtab13[run-14].len);
00501
00502 length = coeff_RVLCtab13[run-14].len;
00503 }
00504 }
00505 return length;
00506 }
00507
00508
00509
00510
00511 Int
00512 PutRunCoeff_Inter(Int run, Int level, Int last, Image *bitstream)
00513 {
00514 Int length = 0;
00515
00516 MOMCHECK (last >= 0 && last < 2);
00517 MOMCHECK (run >= 0 && run < 64);
00518 MOMCHECK (level > 0 && level < 128);
00519
00520 if (last == 0)
00521 {
00522 if (run < 2 && level < 13 )
00523 {
00524 length = coeff_tab0[run][level-1].len;
00525 if (length != 0)
00526 {
00527
00528 BitstreamPutBits(bitstream, 3L, 7L);
00529
00530 BitstreamPutBits(bitstream, 2L, 2L);
00531 length += 9;
00532 BitstreamPutBits (bitstream, (LInt)coeff_tab0[run][level-1].code,
00533 (LInt)coeff_tab0[run][level-1].len);
00534 }
00535 }
00536 else if (run > 1 && run < 27 && level < 5)
00537 {
00538 length = coeff_tab1[run-2][level-1].len;
00539 if (length != 0)
00540 {
00541
00542 BitstreamPutBits(bitstream, 3L, 7L);
00543
00544 BitstreamPutBits(bitstream, 2L, 2L);
00545 length += 9;
00546 BitstreamPutBits (bitstream, (LInt)coeff_tab1[run-2][level-1].code,
00547 (LInt)coeff_tab1[run-2][level-1].len);
00548 }
00549 }
00550 }
00551 else if (last == 1)
00552 {
00553 if (run < 2 && level < 4)
00554 {
00555 length = coeff_tab2[run][level-1].len;
00556 if (length != 0)
00557 {
00558
00559 BitstreamPutBits(bitstream, 3L, 7L);
00560
00561 BitstreamPutBits(bitstream, 2L, 2L);
00562 length += 9;
00563 BitstreamPutBits (bitstream, (LInt)coeff_tab2[run][level-1].code,
00564 (LInt)coeff_tab2[run][level-1].len);
00565 }
00566 }
00567 else if (run > 1 && run < 42 && level == 1)
00568 {
00569 length = coeff_tab3[run-2].len;
00570 if (length != 0)
00571 {
00572
00573 BitstreamPutBits(bitstream, 3L, 7L);
00574
00575 BitstreamPutBits(bitstream, 2L, 2L);
00576 length += 9;
00577 BitstreamPutBits (bitstream, (LInt)coeff_tab3[run-2].code,
00578 (LInt)coeff_tab3[run-2].len);
00579 }
00580 }
00581 }
00582 return length;
00583 }
00584
00585
00586 Int
00587 PutRunCoeff_Intra(Int run, Int level, Int last, Image *bitstream)
00588 {
00589 Int length = 0;
00590
00591 MOMCHECK (last >= 0 && last < 2);
00592 MOMCHECK (run >= 0 && run < 64);
00593 MOMCHECK (level > 0 && level < 128);
00594
00595 if (last == 0)
00596 {
00597 if (run == 0 && level < 28 )
00598 {
00599 length = coeff_tab4[level-1].len;
00600 if (length != 0)
00601 {
00602
00603 BitstreamPutBits(bitstream, 3L, 7L);
00604
00605 BitstreamPutBits(bitstream, 2L, 2L);
00606 length += 9;
00607 BitstreamPutBits(bitstream, (LInt)coeff_tab4[level-1].code,
00608 (LInt)coeff_tab4[level-1].len);
00609 }
00610 }
00611 else if (run == 1 && level < 11)
00612 {
00613 length = coeff_tab5[level-1].len;
00614 if (length != 0)
00615 {
00616
00617 BitstreamPutBits(bitstream, 3L, 7L);
00618
00619 BitstreamPutBits(bitstream, 2L, 2L);
00620 length += 9;
00621 BitstreamPutBits(bitstream, (LInt)coeff_tab5[level-1].code,
00622 (LInt)coeff_tab5[level-1].len);
00623 }
00624 }
00625 else if (run > 1 && run < 10 && level < 6)
00626 {
00627 length = coeff_tab6[run-2][level-1].len;
00628 if (length != 0)
00629 {
00630
00631 BitstreamPutBits(bitstream, 3L, 7L);
00632
00633 BitstreamPutBits(bitstream, 2L, 2L);
00634 length += 9;
00635 BitstreamPutBits(bitstream, (LInt)coeff_tab6[run-2][level-1].code,
00636 (LInt)coeff_tab6[run-2][level-1].len);
00637 }
00638 }
00639 else if (run > 9 && run < 15 && level == 1)
00640 {
00641 length = coeff_tab7[run-10].len;
00642 if (length != 0)
00643 {
00644
00645 BitstreamPutBits(bitstream, 3L, 7L);
00646
00647 BitstreamPutBits(bitstream, 2L, 2L);
00648 length += 9;
00649 BitstreamPutBits(bitstream, (LInt)coeff_tab7[run-10].code,
00650 (LInt)coeff_tab7[run-10].len);
00651 }
00652 }
00653 }
00654 else if (last == 1)
00655 {
00656 if (run == 0 && level < 9)
00657 {
00658 length = coeff_tab8[level-1].len;
00659 if (length != 0)
00660 {
00661
00662 BitstreamPutBits(bitstream, 3L, 7L);
00663
00664 BitstreamPutBits(bitstream, 2L, 2L);
00665 length += 9;
00666 BitstreamPutBits(bitstream, (LInt)coeff_tab8[level-1].code,
00667 (LInt)coeff_tab8[level-1].len);
00668 }
00669 }
00670 else if (run > 0 && run < 7 && level < 4)
00671 {
00672 length = coeff_tab9[run-1][level-1].len;
00673 if (length != 0)
00674 {
00675
00676 BitstreamPutBits(bitstream, 3L, 7L);
00677
00678 BitstreamPutBits(bitstream, 2L, 2L);
00679 length += 9;
00680 BitstreamPutBits(bitstream, (LInt)coeff_tab9[run-1][level-1].code,
00681 (LInt)coeff_tab9[run-1][level-1].len);
00682 }
00683 }
00684 else if (run > 6 && run < 21 && level == 1)
00685 {
00686 length = coeff_tab10[run-7].len;
00687 if (length != 0)
00688 {
00689
00690 BitstreamPutBits(bitstream, 3L, 7L);
00691
00692 BitstreamPutBits(bitstream, 2L, 2L);
00693 length += 9;
00694 BitstreamPutBits(bitstream, (LInt)coeff_tab10[run-7].code,
00695 (LInt)coeff_tab10[run-7].len);
00696 }
00697 }
00698 }
00699 return length;
00700 }
00701
00702
00703 Int
00704 PutLevelCoeff_Inter(Int run, Int level, Int last, Image *bitstream)
00705 {
00706 Int length = 0;
00707
00708 MOMCHECK (last >= 0 && last < 2);
00709 MOMCHECK (run >= 0 && run < 64);
00710 MOMCHECK (level > 0 && level < 128);
00711
00712 if (last == 0)
00713 {
00714 if (run < 2 && level < 13 )
00715 {
00716 length = coeff_tab0[run][level-1].len;
00717 if (length != 0)
00718 {
00719 BitstreamPutBits(bitstream, 3L, 7L);
00720
00721 BitstreamPutBits(bitstream, 0L, 1L);
00722 length += 8;
00723 BitstreamPutBits (bitstream, (LInt)coeff_tab0[run][level-1].code,
00724 (LInt)coeff_tab0[run][level-1].len);
00725 }
00726 }
00727 else if (run > 1 && run < 27 && level < 5)
00728 {
00729 length = coeff_tab1[run-2][level-1].len;
00730 if (length != 0)
00731 {
00732 BitstreamPutBits(bitstream, 3L, 7L);
00733
00734 BitstreamPutBits(bitstream, 0L, 1L);
00735 length += 8;
00736 BitstreamPutBits (bitstream, (LInt)coeff_tab1[run-2][level-1].code,
00737 (LInt)coeff_tab1[run-2][level-1].len);
00738 }
00739 }
00740 }
00741 else if (last == 1)
00742 {
00743 if (run < 2 && level < 4)
00744 {
00745 length = coeff_tab2[run][level-1].len;
00746 if (length != 0)
00747 {
00748 BitstreamPutBits(bitstream, 3L, 7L);
00749
00750 BitstreamPutBits(bitstream, 0L, 1L);
00751 length += 8;
00752 BitstreamPutBits (bitstream, (LInt)coeff_tab2[run][level-1].code,
00753 (LInt)coeff_tab2[run][level-1].len);
00754 }
00755 }
00756 else if (run > 1 && run < 42 && level == 1)
00757 {
00758 length = coeff_tab3[run-2].len;
00759 if (length != 0)
00760 {
00761 BitstreamPutBits(bitstream, 3L, 7L);
00762
00763 BitstreamPutBits(bitstream, 0L, 1L);
00764 length += 8;
00765 BitstreamPutBits (bitstream, (LInt)coeff_tab3[run-2].code,
00766 (LInt)coeff_tab3[run-2].len);
00767 }
00768 }
00769 }
00770 return length;
00771 }
00772
00773
00774 Int
00775 PutLevelCoeff_Intra(Int run, Int level, Int last, Image *bitstream)
00776 {
00777 Int length = 0;
00778
00779 MOMCHECK (last >= 0 && last < 2);
00780 MOMCHECK (run >= 0 && run < 64);
00781 MOMCHECK (level > 0 && level < 128);
00782
00783 if (last == 0)
00784 {
00785 if (run == 0 && level < 28 )
00786 {
00787 length = coeff_tab4[level-1].len;
00788 if (length != 0)
00789 {
00790 BitstreamPutBits(bitstream, 3L, 7L);
00791
00792 BitstreamPutBits(bitstream, 0L, 1L);
00793 length += 8;
00794 BitstreamPutBits(bitstream, (LInt)coeff_tab4[level-1].code,
00795 (LInt)coeff_tab4[level-1].len);
00796 }
00797 }
00798 else if (run == 1 && level < 11)
00799 {
00800 length = coeff_tab5[level-1].len;
00801 if (length != 0)
00802 {
00803 BitstreamPutBits(bitstream, 3L, 7L);
00804
00805 BitstreamPutBits(bitstream, 0L, 1L);
00806 length += 8;
00807 BitstreamPutBits(bitstream, (LInt)coeff_tab5[level-1].code,
00808 (LInt)coeff_tab5[level-1].len);
00809 }
00810 }
00811 else if (run > 1 && run < 10 && level < 6)
00812 {
00813 length = coeff_tab6[run-2][level-1].len;
00814 if (length != 0)
00815 {
00816 BitstreamPutBits(bitstream, 3L, 7L);
00817
00818 BitstreamPutBits(bitstream, 0L, 1L);
00819 length += 8;
00820 BitstreamPutBits(bitstream, (LInt)coeff_tab6[run-2][level-1].code,
00821 (LInt)coeff_tab6[run-2][level-1].len);
00822 }
00823 }
00824 else if (run > 9 && run < 15 && level == 1)
00825 {
00826 length = coeff_tab7[run-10].len;
00827 if (length != 0)
00828 {
00829 BitstreamPutBits(bitstream, 3L, 7L);
00830
00831 BitstreamPutBits(bitstream, 0L, 1L);
00832 length += 8;
00833 BitstreamPutBits(bitstream, (LInt)coeff_tab7[run-10].code,
00834 (LInt)coeff_tab7[run-10].len);
00835 }
00836 }
00837 }
00838 else if (last == 1)
00839 {
00840 if (run == 0 && level < 9)
00841 {
00842 length = coeff_tab8[level-1].len;
00843 if (length != 0)
00844 {
00845 BitstreamPutBits(bitstream, 3L, 7L);
00846
00847 BitstreamPutBits(bitstream, 0L, 1L);
00848 length += 8;
00849 BitstreamPutBits(bitstream, (LInt)coeff_tab8[level-1].code,
00850 (LInt)coeff_tab8[level-1].len);
00851 }
00852 }
00853 else if (run > 0 && run < 7 && level < 4)
00854 {
00855 length = coeff_tab9[run-1][level-1].len;
00856 if (length != 0)
00857 {
00858 BitstreamPutBits(bitstream, 3L, 7L);
00859
00860 BitstreamPutBits(bitstream, 0L, 1L);
00861 length += 8;
00862 BitstreamPutBits(bitstream, (LInt)coeff_tab9[run-1][level-1].code,
00863 (LInt)coeff_tab9[run-1][level-1].len);
00864 }
00865 }
00866 else if (run > 6 && run < 21 && level == 1)
00867 {
00868 length = coeff_tab10[run-7].len;
00869 if (length != 0)
00870 {
00871 BitstreamPutBits(bitstream, 3L, 7L);
00872
00873 BitstreamPutBits(bitstream, 0L, 1L);
00874 length += 8;
00875 BitstreamPutBits(bitstream, (LInt)coeff_tab10[run-7].code,
00876 (LInt)coeff_tab10[run-7].len);
00877 }
00878 }
00879 }
00880 return length;
00881 }