2 /**************************************************************************
4 * This code is developed by Adam Li. This software is an *
5 * implementation of a part of one or more MPEG-4 Video tools as *
6 * specified in ISO/IEC 14496-2 standard. Those intending to use this *
7 * software module in hardware or software products are advised that its *
8 * use may infringe existing patents or copyrights, and any such use *
9 * would be at such party's own risk. The original developer of this *
10 * software module and his/her company, and subsequent editors and their *
11 * companies (including Project Mayo), will have no liability for use of *
12 * this software or modifications or derivatives thereof. *
14 * Project Mayo gives users of the Codec a license to this software *
15 * module or modifications thereof for use in hardware or software *
16 * products claiming conformance to the MPEG-4 Video Standard as *
17 * described in the Open DivX license. *
19 * The complete Open DivX license can be found at *
20 * http://www.projectmayo.com/opendivx/license.php . *
22 **************************************************************************/
24 /**************************************************************************
28 * Copyright (C) 2001 Project Mayo
32 * DivX Advance Research Center <darc@projectmayo.com>
34 **************************************************************************/
36 /* This file contains some functions to code the RVLC code for bitstream. */
37 /* Some codes of this project come from MoMuSys MPEG-4 implementation. */
38 /* Please see seperate acknowledgement file for a list of contributors. */
43 #include "bitstream.h"
45 /***********************************************************CommentBegin******
47 * -- Putxxx -- Write bits from huffman tables to file
49 * Int PutCoeff_Inter(Int run, Int level, Int last, Image *bitstream)
50 * Int PutCoeff_Intra(Int run, Int level, Int last, Image *bitstream)
51 * Int PutCBPY (Int cbpy, Int *MB_transp_pattren,Image *bitstream)
52 * Int PutMCBPC_Inter (Int cbpc, Int mode, Image *bitstream)
53 * Int PutMCBPC_Sprite (Int cbpc, Int mode, Image *bitstream)
54 * Int PutMCBPC_Intra (Int cbpc, Int mode, Image *bitstream)
55 * Int PutMV (Int mvint, Image *bitstream)
56 * Int PutDCsize_chrom (Int size, Image *bitstream)
57 * Int PutDCsize_lum (Int size, Image *bitstream)
58 * Int PutDCsize_lum (Int size, Image *bitstream)
59 * Int PutCoeff_Inter_RVLC (Int run, Int level, Int last, Image *bitstream)
60 * Int PutCoeff_Intra_RVLC (Int run, Int level, Int last, Image *bitstream)
61 * Int PutRunCoeff_Inter (Int run, Int level, Int last, Image *bitstream)
62 * Int PutRunCoeff_Intra (Int run, Int level, Int last, Image *bitstream)
63 * Int PutLevelCoeff_Inter (Int run, Int level, Int last, Image *bitstream)
64 * Int PutLevelCoeff_Intra (Int run, Int level, Int last, Image *bitstream)
67 * Writes bits from huffman tables to bitstream
70 * various, see prototypes above
73 * Number of bits written
75 ***********************************************************CommentEnd********/
78 PutDCsize_lum (Int size
, Image
*bitstream
)
80 MOMCHECK(size
>= 0 && size
< 13);
82 BitstreamPutBits (bitstream
, DCtab_lum
[size
].code
, DCtab_lum
[size
].len
);
84 return DCtab_lum
[size
].len
;
89 PutDCsize_chrom (Int size
, Image
*bitstream
)
91 MOMCHECK (size
>= 0 && size
< 13);
93 BitstreamPutBits (bitstream
, DCtab_chrom
[size
].code
, DCtab_chrom
[size
].len
);
95 return DCtab_chrom
[size
].len
;
100 PutMV (Int mvint
, Image
*bitstream
)
113 BitstreamPutBits (bitstream
, mvtab
[absmv
].code
, mvtab
[absmv
].len
);
117 BitstreamPutBits (bitstream
, sign
, 1);
118 return mvtab
[absmv
].len
+ 1;
121 return mvtab
[absmv
].len
;
126 PutMCBPC_Intra (Int cbpc
, Int mode
, Image
*bitstream
)
130 ind
= ((mode
>> 1) & 3) | ((cbpc
& 3) << 2);
132 BitstreamPutBits (bitstream
, mcbpc_intra_tab
[ind
].code
, mcbpc_intra_tab
[ind
].len
);
134 return mcbpc_intra_tab
[ind
].len
;
139 PutMCBPC_Inter (Int cbpc
, Int mode
, Image
*bitstream
)
143 ind
= (mode
& 7) | ((cbpc
& 3) << 3);
145 BitstreamPutBits (bitstream
, mcbpc_inter_tab
[ind
].code
,
146 mcbpc_inter_tab
[ind
].len
);
148 return mcbpc_inter_tab
[ind
].len
;
153 PutMCBPC_Sprite (Int cbpc
, Int mode
, Image
*bitstream
)
157 ind
= (mode
& 7) | ((cbpc
& 3) << 3);
159 BitstreamPutBits (bitstream
, mcbpc_sprite_tab
[ind
].code
,
160 mcbpc_sprite_tab
[ind
].len
);
162 return mcbpc_sprite_tab
[ind
].len
;
167 PutCBPY (Int cbpy
, Char intra
, Int
*MB_transp_pattern
, Image
*bitstream
)
172 /* Changed due to bug report from Yoshinori Suzuki; MW 11-JUN-1998 */
173 /* if ((intra==0)&&(index!=3)) cbpy = 15 - cbpy; */
174 if (intra
== 0) cbpy
= 15 - cbpy
;
177 BitstreamPutBits (bitstream
, cbpy_tab
[ind
].code
, cbpy_tab
[ind
].len
);
178 return cbpy_tab
[ind
].len
;
183 PutCoeff_Inter(Int run
, Int level
, Int last
, Image
*bitstream
)
187 MOMCHECK (last
>= 0 && last
< 2);
188 MOMCHECK (run
>= 0 && run
< 64);
189 MOMCHECK (level
> 0 && level
< 128);
193 if (run
< 2 && level
< 13 )
195 BitstreamPutBits (bitstream
, (LInt
)coeff_tab0
[run
][level
-1].code
,
196 (LInt
)coeff_tab0
[run
][level
-1].len
);
198 length
= coeff_tab0
[run
][level
-1].len
;
200 else if (run
> 1 && run
< 27 && level
< 5)
202 BitstreamPutBits (bitstream
, (LInt
)coeff_tab1
[run
-2][level
-1].code
,
203 (LInt
)coeff_tab1
[run
-2][level
-1].len
);
205 length
= coeff_tab1
[run
-2][level
-1].len
;
210 if (run
< 2 && level
< 4)
212 BitstreamPutBits (bitstream
, (LInt
)coeff_tab2
[run
][level
-1].code
,
213 (LInt
)coeff_tab2
[run
][level
-1].len
);
215 length
= coeff_tab2
[run
][level
-1].len
;
217 else if (run
> 1 && run
< 42 && level
== 1)
219 BitstreamPutBits (bitstream
, (LInt
)coeff_tab3
[run
-2].code
,
220 (LInt
)coeff_tab3
[run
-2].len
);
222 length
= coeff_tab3
[run
-2].len
;
230 PutCoeff_Intra(Int run
, Int level
, Int last
, Image
*bitstream
)
234 MOMCHECK (last
>= 0 && last
< 2);
235 MOMCHECK (run
>= 0 && run
< 64);
236 MOMCHECK (level
> 0 && level
< 128);
240 if (run
== 0 && level
< 28 )
242 BitstreamPutBits(bitstream
, (LInt
)coeff_tab4
[level
-1].code
,
243 (LInt
)coeff_tab4
[level
-1].len
);
245 length
= coeff_tab4
[level
-1].len
;
247 else if (run
== 1 && level
< 11)
249 BitstreamPutBits(bitstream
, (LInt
)coeff_tab5
[level
-1].code
,
250 (LInt
)coeff_tab5
[level
-1].len
);
252 length
= coeff_tab5
[level
-1].len
;
254 else if (run
> 1 && run
< 10 && level
< 6)
256 BitstreamPutBits(bitstream
, (LInt
)coeff_tab6
[run
-2][level
-1].code
,
257 (LInt
)coeff_tab6
[run
-2][level
-1].len
);
259 length
= coeff_tab6
[run
-2][level
-1].len
;
261 else if (run
> 9 && run
< 15 && level
== 1)
263 BitstreamPutBits(bitstream
, (LInt
)coeff_tab7
[run
-10].code
,
264 (LInt
)coeff_tab7
[run
-10].len
);
266 length
= coeff_tab7
[run
-10].len
;
271 if (run
== 0 && level
< 9)
273 BitstreamPutBits(bitstream
, (LInt
)coeff_tab8
[level
-1].code
,
274 (LInt
)coeff_tab8
[level
-1].len
);
276 length
= coeff_tab8
[level
-1].len
;
278 else if (run
> 0 && run
< 7 && level
< 4)
280 BitstreamPutBits(bitstream
, (LInt
)coeff_tab9
[run
-1][level
-1].code
,
281 (LInt
)coeff_tab9
[run
-1][level
-1].len
);
283 length
= coeff_tab9
[run
-1][level
-1].len
;
285 else if (run
> 6 && run
< 21 && level
== 1)
287 BitstreamPutBits(bitstream
, (LInt
)coeff_tab10
[run
-7].code
,
288 (LInt
)coeff_tab10
[run
-7].len
);
290 length
= coeff_tab10
[run
-7].len
;
298 PutCoeff_Inter_RVLC(Int run
, Int level
, Int last
, Image
*bitstream
)
302 MOMCHECK (last
>= 0 && last
< 2);
303 MOMCHECK (run
>= 0 && run
< 64);
304 MOMCHECK (level
> 0 && level
< 128);
308 if (run
== 0 && level
< 20 )
310 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab14
[level
-1].code
,
311 (LInt
)coeff_RVLCtab14
[level
-1].len
);
313 length
= coeff_RVLCtab14
[level
-1].len
;
315 else if (run
== 1 && level
< 11)
317 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab15
[level
-1].code
,
318 (LInt
)coeff_RVLCtab15
[level
-1].len
);
320 length
= coeff_RVLCtab15
[level
-1].len
;
322 else if (run
> 1 && run
< 4 && level
< 8)
324 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab16
[run
-2][level
-1].code
,
325 (LInt
)coeff_RVLCtab16
[run
-2][level
-1].len
);
326 length
= coeff_RVLCtab16
[run
-2][level
-1].len
;
328 else if (run
== 4 && level
< 6)
330 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab17
[level
-1].code
,
331 (LInt
)coeff_RVLCtab17
[level
-1].len
);
333 length
= coeff_RVLCtab17
[level
-1].len
;
335 else if (run
> 4 && run
< 8 && level
< 5)
337 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab18
[run
-5][level
-1].code
,
338 (LInt
)coeff_RVLCtab18
[run
-5][level
-1].len
);
340 length
= coeff_RVLCtab18
[run
-5][level
-1].len
;
342 else if (run
> 7 && run
< 10 && level
< 4)
344 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab19
[run
-8][level
-1].code
,
345 (LInt
)coeff_RVLCtab19
[run
-8][level
-1].len
);
347 length
= coeff_RVLCtab19
[run
-8][level
-1].len
;
349 else if (run
> 9 && run
< 18 && level
< 3)
351 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab20
[run
-10][level
-1].code
,
352 (LInt
)coeff_RVLCtab20
[run
-10][level
-1].len
);
354 length
= coeff_RVLCtab20
[run
-10][level
-1].len
;
356 else if (run
> 17 && run
< 39 && level
== 1)
358 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab21
[run
-18].code
,
359 (LInt
)coeff_RVLCtab21
[run
-18].len
);
361 length
= coeff_RVLCtab21
[run
-18].len
;
366 if (run
>= 0 && run
< 2 && level
< 6)
368 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab22
[run
][level
-1].code
,
369 (LInt
)coeff_RVLCtab22
[run
][level
-1].len
);
371 length
= coeff_RVLCtab22
[run
][level
-1].len
;
373 else if (run
== 2 && level
< 4)
375 BitstreamPutBits (bitstream
, (LInt
)coeff_RVLCtab23
[level
-1].code
,
376 (LInt
)coeff_RVLCtab23
[level
-1].len
);
378 length
= coeff_RVLCtab23
[level
-1].len
;
380 else if (run
> 2 && run
< 14 && level
< 3)
382 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab24
[run
-3][level
-1].code
,
383 (LInt
)coeff_RVLCtab24
[run
-3][level
-1].len
);
385 length
= coeff_RVLCtab24
[run
-3][level
-1].len
;
387 else if (run
> 13 && run
< 46 && level
== 1)
389 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab25
[run
-14].code
,
390 (LInt
)coeff_RVLCtab25
[run
-14].len
);
392 length
= coeff_RVLCtab25
[run
-14].len
;
400 PutCoeff_Intra_RVLC(Int run
, Int level
, Int last
, Image
*bitstream
)
404 MOMCHECK (last
>= 0 && last
< 2);
405 MOMCHECK (run
>= 0 && run
< 64);
406 MOMCHECK (level
> 0 && level
< 128);
410 if (run
== 0 && level
< 28 )
412 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab1
[level
-1].code
,
413 (LInt
)coeff_RVLCtab1
[level
-1].len
);
415 length
= coeff_RVLCtab1
[level
-1].len
;
417 else if (run
== 1 && level
< 14)
419 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab2
[level
-1].code
,
420 (LInt
)coeff_RVLCtab2
[level
-1].len
);
422 length
= coeff_RVLCtab2
[level
-1].len
;
424 else if (run
== 2 && level
< 12)
426 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab3
[level
-1].code
,
427 (LInt
)coeff_RVLCtab3
[level
-1].len
);
429 length
= coeff_RVLCtab3
[level
-1].len
;
431 else if (run
== 3 && level
< 10)
433 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab4
[level
-1].code
,
434 (LInt
)coeff_RVLCtab4
[level
-1].len
);
436 length
= coeff_RVLCtab4
[level
-1].len
;
438 else if (run
> 3 && run
< 6 && level
< 7)
440 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab5
[run
-4][level
-1].code
,
441 (LInt
)coeff_RVLCtab5
[run
-4][level
-1].len
);
443 length
= coeff_RVLCtab5
[run
-4][level
-1].len
;
445 else if (run
> 5 && run
< 8 && level
< 6)
447 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab6
[run
-6][level
-1].code
,
448 (LInt
)coeff_RVLCtab6
[run
-6][level
-1].len
);
450 length
= coeff_RVLCtab6
[run
-6][level
-1].len
;
452 else if (run
> 7 && run
< 10 && level
< 5)
454 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab7
[run
-8][level
-1].code
,
455 (LInt
)coeff_RVLCtab7
[run
-8][level
-1].len
);
457 length
= coeff_RVLCtab7
[run
-8][level
-1].len
;
459 else if (run
> 9 && run
< 13 && level
< 3)
461 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab8
[run
-10][level
-1].code
,
462 (LInt
)coeff_RVLCtab8
[run
-10][level
-1].len
);
464 length
= coeff_RVLCtab8
[run
-10][level
-1].len
;
466 else if (run
> 12 && run
< 20 && level
== 1)
468 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab9
[run
-13].code
,
469 (LInt
)coeff_RVLCtab9
[run
-13].len
);
471 length
= coeff_RVLCtab9
[run
-13].len
;
476 if (run
>= 0 && run
< 2 && level
< 6)
478 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab10
[run
][level
-1].code
,
479 (LInt
)coeff_RVLCtab10
[run
][level
-1].len
);
481 length
= coeff_RVLCtab10
[run
][level
-1].len
;
483 else if (run
== 2 && level
< 4)
485 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab11
[level
-1].code
,
486 (LInt
)coeff_RVLCtab11
[level
-1].len
);
488 length
= coeff_RVLCtab11
[level
-1].len
;
490 else if (run
> 2 && run
< 14 && level
< 3)
492 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab12
[run
-3][level
-1].code
,
493 (LInt
)coeff_RVLCtab12
[run
-3][level
-1].len
);
495 length
= coeff_RVLCtab12
[run
-3][level
-1].len
;
497 else if (run
> 13 && run
< 46 && level
== 1)
499 BitstreamPutBits(bitstream
, (LInt
)coeff_RVLCtab13
[run
-14].code
,
500 (LInt
)coeff_RVLCtab13
[run
-14].len
);
502 length
= coeff_RVLCtab13
[run
-14].len
;
509 /* The following is for 3-mode VLC */
512 PutRunCoeff_Inter(Int run
, Int level
, Int last
, Image
*bitstream
)
516 MOMCHECK (last
>= 0 && last
< 2);
517 MOMCHECK (run
>= 0 && run
< 64);
518 MOMCHECK (level
> 0 && level
< 128);
522 if (run
< 2 && level
< 13 )
524 length
= coeff_tab0
[run
][level
-1].len
;
528 BitstreamPutBits(bitstream
, 3L, 7L);
530 BitstreamPutBits(bitstream
, 2L, 2L);
531 length
+= 9; /* boon */
532 BitstreamPutBits (bitstream
, (LInt
)coeff_tab0
[run
][level
-1].code
,
533 (LInt
)coeff_tab0
[run
][level
-1].len
);
536 else if (run
> 1 && run
< 27 && level
< 5)
538 length
= coeff_tab1
[run
-2][level
-1].len
;
542 BitstreamPutBits(bitstream
, 3L, 7L);
544 BitstreamPutBits(bitstream
, 2L, 2L);
545 length
+= 9; /* boon */
546 BitstreamPutBits (bitstream
, (LInt
)coeff_tab1
[run
-2][level
-1].code
,
547 (LInt
)coeff_tab1
[run
-2][level
-1].len
);
553 if (run
< 2 && level
< 4)
555 length
= coeff_tab2
[run
][level
-1].len
;
559 BitstreamPutBits(bitstream
, 3L, 7L);
561 BitstreamPutBits(bitstream
, 2L, 2L);
562 length
+= 9; /* boon */
563 BitstreamPutBits (bitstream
, (LInt
)coeff_tab2
[run
][level
-1].code
,
564 (LInt
)coeff_tab2
[run
][level
-1].len
);
567 else if (run
> 1 && run
< 42 && level
== 1)
569 length
= coeff_tab3
[run
-2].len
;
573 BitstreamPutBits(bitstream
, 3L, 7L);
575 BitstreamPutBits(bitstream
, 2L, 2L);
576 length
+= 9; /* boon */
577 BitstreamPutBits (bitstream
, (LInt
)coeff_tab3
[run
-2].code
,
578 (LInt
)coeff_tab3
[run
-2].len
);
587 PutRunCoeff_Intra(Int run
, Int level
, Int last
, Image
*bitstream
)
591 MOMCHECK (last
>= 0 && last
< 2);
592 MOMCHECK (run
>= 0 && run
< 64);
593 MOMCHECK (level
> 0 && level
< 128);
597 if (run
== 0 && level
< 28 )
599 length
= coeff_tab4
[level
-1].len
;
603 BitstreamPutBits(bitstream
, 3L, 7L);
605 BitstreamPutBits(bitstream
, 2L, 2L);
606 length
+= 9; /* boon */
607 BitstreamPutBits(bitstream
, (LInt
)coeff_tab4
[level
-1].code
,
608 (LInt
)coeff_tab4
[level
-1].len
);
611 else if (run
== 1 && level
< 11)
613 length
= coeff_tab5
[level
-1].len
;
617 BitstreamPutBits(bitstream
, 3L, 7L);
619 BitstreamPutBits(bitstream
, 2L, 2L);
620 length
+= 9; /* boon */
621 BitstreamPutBits(bitstream
, (LInt
)coeff_tab5
[level
-1].code
,
622 (LInt
)coeff_tab5
[level
-1].len
);
625 else if (run
> 1 && run
< 10 && level
< 6)
627 length
= coeff_tab6
[run
-2][level
-1].len
;
631 BitstreamPutBits(bitstream
, 3L, 7L);
633 BitstreamPutBits(bitstream
, 2L, 2L);
634 length
+= 9; /* boon */
635 BitstreamPutBits(bitstream
, (LInt
)coeff_tab6
[run
-2][level
-1].code
,
636 (LInt
)coeff_tab6
[run
-2][level
-1].len
);
639 else if (run
> 9 && run
< 15 && level
== 1)
641 length
= coeff_tab7
[run
-10].len
;
645 BitstreamPutBits(bitstream
, 3L, 7L);
647 BitstreamPutBits(bitstream
, 2L, 2L);
648 length
+= 9; /* boon */
649 BitstreamPutBits(bitstream
, (LInt
)coeff_tab7
[run
-10].code
,
650 (LInt
)coeff_tab7
[run
-10].len
);
656 if (run
== 0 && level
< 9)
658 length
= coeff_tab8
[level
-1].len
;
662 BitstreamPutBits(bitstream
, 3L, 7L);
664 BitstreamPutBits(bitstream
, 2L, 2L);
665 length
+= 9; /* boon */
666 BitstreamPutBits(bitstream
, (LInt
)coeff_tab8
[level
-1].code
,
667 (LInt
)coeff_tab8
[level
-1].len
);
670 else if (run
> 0 && run
< 7 && level
< 4)
672 length
= coeff_tab9
[run
-1][level
-1].len
;
676 BitstreamPutBits(bitstream
, 3L, 7L);
678 BitstreamPutBits(bitstream
, 2L, 2L);
679 length
+= 9; /* boon */
680 BitstreamPutBits(bitstream
, (LInt
)coeff_tab9
[run
-1][level
-1].code
,
681 (LInt
)coeff_tab9
[run
-1][level
-1].len
);
684 else if (run
> 6 && run
< 21 && level
== 1)
686 length
= coeff_tab10
[run
-7].len
;
690 BitstreamPutBits(bitstream
, 3L, 7L);
692 BitstreamPutBits(bitstream
, 2L, 2L);
693 length
+= 9; /* boon */
694 BitstreamPutBits(bitstream
, (LInt
)coeff_tab10
[run
-7].code
,
695 (LInt
)coeff_tab10
[run
-7].len
);
704 PutLevelCoeff_Inter(Int run
, Int level
, Int last
, Image
*bitstream
)
708 MOMCHECK (last
>= 0 && last
< 2);
709 MOMCHECK (run
>= 0 && run
< 64);
710 MOMCHECK (level
> 0 && level
< 128);
714 if (run
< 2 && level
< 13 )
716 length
= coeff_tab0
[run
][level
-1].len
;
719 BitstreamPutBits(bitstream
, 3L, 7L);
721 BitstreamPutBits(bitstream
, 0L, 1L);
722 length
+= 8; /* boon */
723 BitstreamPutBits (bitstream
, (LInt
)coeff_tab0
[run
][level
-1].code
,
724 (LInt
)coeff_tab0
[run
][level
-1].len
);
727 else if (run
> 1 && run
< 27 && level
< 5)
729 length
= coeff_tab1
[run
-2][level
-1].len
;
732 BitstreamPutBits(bitstream
, 3L, 7L);
734 BitstreamPutBits(bitstream
, 0L, 1L);
735 length
+= 8; /* boon */
736 BitstreamPutBits (bitstream
, (LInt
)coeff_tab1
[run
-2][level
-1].code
,
737 (LInt
)coeff_tab1
[run
-2][level
-1].len
);
743 if (run
< 2 && level
< 4)
745 length
= coeff_tab2
[run
][level
-1].len
;
748 BitstreamPutBits(bitstream
, 3L, 7L);
750 BitstreamPutBits(bitstream
, 0L, 1L);
751 length
+= 8; /* boon */
752 BitstreamPutBits (bitstream
, (LInt
)coeff_tab2
[run
][level
-1].code
,
753 (LInt
)coeff_tab2
[run
][level
-1].len
);
756 else if (run
> 1 && run
< 42 && level
== 1)
758 length
= coeff_tab3
[run
-2].len
;
761 BitstreamPutBits(bitstream
, 3L, 7L);
763 BitstreamPutBits(bitstream
, 0L, 1L);
764 length
+= 8; /* boon */
765 BitstreamPutBits (bitstream
, (LInt
)coeff_tab3
[run
-2].code
,
766 (LInt
)coeff_tab3
[run
-2].len
);
775 PutLevelCoeff_Intra(Int run
, Int level
, Int last
, Image
*bitstream
)
779 MOMCHECK (last
>= 0 && last
< 2);
780 MOMCHECK (run
>= 0 && run
< 64);
781 MOMCHECK (level
> 0 && level
< 128);
785 if (run
== 0 && level
< 28 )
787 length
= coeff_tab4
[level
-1].len
;
790 BitstreamPutBits(bitstream
, 3L, 7L);
792 BitstreamPutBits(bitstream
, 0L, 1L);
793 length
+= 8; /* boon */
794 BitstreamPutBits(bitstream
, (LInt
)coeff_tab4
[level
-1].code
,
795 (LInt
)coeff_tab4
[level
-1].len
);
798 else if (run
== 1 && level
< 11)
800 length
= coeff_tab5
[level
-1].len
;
803 BitstreamPutBits(bitstream
, 3L, 7L);
805 BitstreamPutBits(bitstream
, 0L, 1L);
806 length
+= 8; /* boon */
807 BitstreamPutBits(bitstream
, (LInt
)coeff_tab5
[level
-1].code
,
808 (LInt
)coeff_tab5
[level
-1].len
);
811 else if (run
> 1 && run
< 10 && level
< 6)
813 length
= coeff_tab6
[run
-2][level
-1].len
;
816 BitstreamPutBits(bitstream
, 3L, 7L);
818 BitstreamPutBits(bitstream
, 0L, 1L);
819 length
+= 8; /* boon */
820 BitstreamPutBits(bitstream
, (LInt
)coeff_tab6
[run
-2][level
-1].code
,
821 (LInt
)coeff_tab6
[run
-2][level
-1].len
);
824 else if (run
> 9 && run
< 15 && level
== 1)
826 length
= coeff_tab7
[run
-10].len
;
829 BitstreamPutBits(bitstream
, 3L, 7L);
831 BitstreamPutBits(bitstream
, 0L, 1L);
832 length
+= 8; /* boon */
833 BitstreamPutBits(bitstream
, (LInt
)coeff_tab7
[run
-10].code
,
834 (LInt
)coeff_tab7
[run
-10].len
);
840 if (run
== 0 && level
< 9)
842 length
= coeff_tab8
[level
-1].len
;
845 BitstreamPutBits(bitstream
, 3L, 7L);
847 BitstreamPutBits(bitstream
, 0L, 1L);
848 length
+= 8; /* boon */
849 BitstreamPutBits(bitstream
, (LInt
)coeff_tab8
[level
-1].code
,
850 (LInt
)coeff_tab8
[level
-1].len
);
853 else if (run
> 0 && run
< 7 && level
< 4)
855 length
= coeff_tab9
[run
-1][level
-1].len
;
858 BitstreamPutBits(bitstream
, 3L, 7L);
860 BitstreamPutBits(bitstream
, 0L, 1L);
861 length
+= 8; /* boon */
862 BitstreamPutBits(bitstream
, (LInt
)coeff_tab9
[run
-1][level
-1].code
,
863 (LInt
)coeff_tab9
[run
-1][level
-1].len
);
866 else if (run
> 6 && run
< 21 && level
== 1)
868 length
= coeff_tab10
[run
-7].len
;
871 BitstreamPutBits(bitstream
, 3L, 7L);
873 BitstreamPutBits(bitstream
, 0L, 1L);
874 length
+= 8; /* boon */
875 BitstreamPutBits(bitstream
, (LInt
)coeff_tab10
[run
-7].code
,
876 (LInt
)coeff_tab10
[run
-7].len
);