r1026: Videoscope layout tweaks.
[cinelerra_cv/ct.git] / quicktime / encore50 / text_bits.c
blob1a72eca622fa69138c8015526bec05572cc69204
2 /**************************************************************************
3 * *
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. *
13 * *
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. *
18 * *
19 * The complete Open DivX license can be found at *
20 * http://www.projectmayo.com/opendivx/license.php . *
21 * *
22 **************************************************************************/
24 /**************************************************************************
26 * text_bits.c
28 * Copyright (C) 2001 Project Mayo
30 * Adam Li
32 * DivX Advance Research Center <darc@projectmayo.com>
34 **************************************************************************/
36 /* This file contains some utility functions to write to bitstreams for */
37 /* texture part of the coding. */
38 /* Some codes of this project come from MoMuSys MPEG-4 implementation. */
39 /* Please see seperate acknowledgement file for a list of contributors. */
41 #include "momusys.h"
42 #include "text_defs.h"
43 #include "bitstream.h"
44 #include "text_bits.h"
45 #include "putvlc.h"
46 #include "zigzag.h" /* added, 14-NOV-1996 MW */
47 #include "max_level.h" /* 3-mode esc */
49 Int IntraDC_dpcm (Int val, Int lum, Image *bitstream);
50 Int CodeCoeff (Int j_start, Int Mode, Int qcoeff[],
51 Int block, Int ncoeffs, Image *bitstream);
52 Int CodeCoeff_RVLC (Int j_start, Int Mode, Int qcoeff[],
53 Int block, Int ncoeffs, Image *bitstream);
55 /***********************************************************CommentBegin******
57 * -- MB_CodeCoeff -- Codes coefficients, does DC/AC prediction
59 * Purpose :
60 * Codes coefficients, does DC/AC prediction
62 * Arguments in :
63 * Int *qcoeff : quantized dct-coefficients
64 * Int Mode : encoding mode
65 * Int CBP : coded block pattern
66 * Int ncoeffs : number of coefficients per block
67 * Int x_pos : the horizontal position of the macroblock in the vop
68 * Int intra_dcpred_disable : disable the intradc prediction
69 * Int transp_pattern[]: Describes which blocks are transparent
71 * Arguments out :
72 * Bits *bits : struct to count the number of texture bits
73 * Image *bitstream : output bitstream
75 * Description :
76 * The intradc prediction can be switched off by setting the variable
77 * intradc_pred_disable to '1'.
79 ***********************************************************CommentEnd********/
80 Void MB_CodeCoeff(Bits* bits, Int *qcoeff,
81 Int Mode, Int CBP, Int ncoeffs,
82 Int intra_dcpred_disable,
83 Image *DCbitstream,
84 Image *bitstream,
85 Int transp_pattern[], Int direction[],
86 Int error_res_disable,
87 Int reverse_vlc,
88 Int switched,
89 Int alternate_scan)
91 Int i, m, coeff[64];
92 Int *zz = alternate_scan ? zigzag_v : zigzag;
94 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
96 if (intra_dcpred_disable == 0)
98 for (i = 0; i < 6; i++)
100 // if (i>3 || transp_pattern[i]!=1) /* Not transparent */
102 if (!alternate_scan)
104 switch (direction[i])
106 case 1: zz = zigzag_v; break;
107 case 2: zz = zigzag_h; break;
108 case 0: break;
109 default: fprintf(stderr, "MB_CodeCoeff(): Error in zigzag direction\n");
110 exit(-1);
113 /* Do the zigzag scanning of coefficients */
114 for (m = 0; m < 64; m++)
116 *(coeff + zz[m]) = qcoeff[i*ncoeffs+m];
119 if (switched==0)
121 if (error_res_disable)
123 if (i < 4)
124 bits->Y += IntraDC_dpcm(coeff[0],1,bitstream);
125 else
126 bits->C += IntraDC_dpcm(coeff[0],0,bitstream);
128 else
130 if (i < 4)
131 bits->Y += IntraDC_dpcm(coeff[0],1,DCbitstream);
132 else
133 bits->C += IntraDC_dpcm(coeff[0],0,DCbitstream);
137 /* Code AC coeffs. dep. on block pattern MW 15-NOV-1996 */
138 if ((i==0 && CBP&32) ||
139 (i==1 && CBP&16) ||
140 (i==2 && CBP&8) ||
141 (i==3 && CBP&4) ||
142 (i==4 && CBP&2) ||
143 (i==5 && CBP&1))
145 if (error_res_disable || ((!error_res_disable) && (!reverse_vlc)))
147 if (i < 4)
148 bits->Y += CodeCoeff(1-switched,Mode, coeff,i,ncoeffs,bitstream);
149 else
150 bits->C += CodeCoeff(1-switched,Mode, coeff,i,ncoeffs,
151 bitstream);
153 else
155 if (i < 4)
156 bits->Y += CodeCoeff_RVLC(1-switched,Mode, coeff, i,
157 ncoeffs, bitstream);
158 else
159 bits->C += CodeCoeff_RVLC(1-switched,Mode, coeff, i,
160 ncoeffs, bitstream);
166 else /* Without ACDC prediction */
168 for (i = 0; i < 6; i++)
170 // if (i>3 || transp_pattern[i]!=1) /* Not transparent */
172 /* Do the zigzag scanning of coefficients */
173 for (m = 0; m < 64; m++)
174 *(coeff + zz[m]) = qcoeff[i*ncoeffs+m];
176 if (switched==0)
178 if (error_res_disable)
180 if (coeff[0] != 128)
181 BitstreamPutBits(bitstream,(long)(coeff[0]),8L);
182 else
183 BitstreamPutBits(bitstream, 255L, 8L);
185 else
187 if (coeff[0] != 128)
188 BitstreamPutBits(DCbitstream,(long)(coeff[0]),8L);
189 else
190 BitstreamPutBits(DCbitstream,255L, 8L);
193 if (i < 4)
194 bits->Y += 8;
195 else
196 bits->C += 8;
199 if ((i==0 && CBP&32) || (i==1 && CBP&16) ||
200 (i==2 && CBP&8) || (i==3 && CBP&4) ||
201 (i==4 && CBP&2) || (i==5 && CBP&1))
203 /* send coeff, not qcoeff !!! MW 07-11-96 */
205 if (error_res_disable || ((!error_res_disable) && (!reverse_vlc)))
207 if (i < 4)
208 bits->Y += CodeCoeff(1-switched,Mode, coeff,i,ncoeffs,
209 bitstream);
210 else
211 bits->C += CodeCoeff(1-switched,Mode, coeff,i,ncoeffs,
212 bitstream);
214 else
216 if (i < 4)
217 bits->Y += CodeCoeff_RVLC(1-switched,Mode, coeff, i,
218 ncoeffs, bitstream);
219 else
220 bits->C += CodeCoeff_RVLC(1-switched,Mode, coeff, i,
221 ncoeffs, bitstream);
229 else /* inter block encoding */
231 for (i = 0; i < 6; i++)
233 /* Do the zigzag scanning of coefficients */
234 for (m = 0; m < 64; m++)
235 *(coeff + zz[m]) = qcoeff[i*ncoeffs+m];
236 if ((i==0 && CBP&32) ||
237 (i==1 && CBP&16) ||
238 (i==2 && CBP&8) ||
239 (i==3 && CBP&4) ||
240 (i==4 && CBP&2) ||
241 (i==5 && CBP&1))
243 if (error_res_disable || ((!error_res_disable) && (!reverse_vlc)))
245 if (i < 4)
246 bits->Y += CodeCoeff(0,Mode, coeff, i, ncoeffs, bitstream);
247 else
248 bits->C += CodeCoeff(0,Mode, coeff, i, ncoeffs, bitstream);
250 else
252 if (i < 4)
253 bits->Y += CodeCoeff_RVLC(0,Mode, coeff, i, ncoeffs,
254 bitstream);
255 else
256 bits->C += CodeCoeff_RVLC(0,Mode, coeff, i, ncoeffs,
257 bitstream);
266 /***********************************************************CommentBegin******
268 * -- IntraDC_dpcm -- DPCM Encoding of INTRADC in case of Intra macroblocks
270 * Purpose :
271 * DPCM Encoding of INTRADC in case of Intra macroblocks
273 * Arguments in :
274 * Int val : the difference value with respect to the previous
275 * INTRADC value
276 * Int lum : indicates whether the block is a luminance block (lum=1) or
277 * a chrominance block ( lum = 0)
279 * Arguments out :
280 * Image* bitstream : a pointer to the output bitstream
282 ***********************************************************CommentEnd********/
285 IntraDC_dpcm(Int val, Int lum, Image *bitstream)
287 Int n_bits;
288 Int absval, size = 0;
290 absval = ( val <0)?-val:val; /* abs(val) */
292 /* compute dct_dc_size */
294 size = 0;
295 while(absval)
297 absval>>=1;
298 size++;
301 if (lum)
302 { /* luminance */
303 n_bits = PutDCsize_lum (size, bitstream);
305 else
306 { /* chrominance */
307 n_bits = PutDCsize_chrom (size, bitstream);
310 if ( size != 0 )
312 if (val>=0)
316 else
318 absval = -val; /* set to "-val" MW 14-NOV-1996 */
319 val = (absval ^( (int)pow(2.0,(double)size)-1) );
321 BitstreamPutBits(bitstream, (long)(val), (long)(size));
322 n_bits += size;
324 if (size > 8)
325 BitstreamPutBits(bitstream, (long)1, (long)1);
328 return n_bits; /* # bits for intra_dc dpcm */
333 /***********************************************************CommentBegin******
335 * -- CodeCoeff -- VLC encoding of quantized DCT coefficients
337 * Purpose :
338 * VLC encoding of quantized DCT coefficients, except for
339 * INTRADC in case of Intra macroblocks
340 * Used by Bits_CountCoeff
342 * Arguments in :
343 * Int Mode : encoding mode
344 * Int *qcoeff: pointer to quantized dct coefficients
345 * Int block : number of the block in the macroblock (0-5)
346 * Int ncoeffs : the number of coefficients per block
348 * Arguments out :
349 * Image *bitstream : pointer to the output bitstream
351 * Return values :
352 * Int bits : number of bits added to the bitstream (?)
354 ***********************************************************CommentEnd********/
356 Int CodeCoeff(Int j_start, Int Mode, Int qcoeff[], Int block, Int ncoeffs, Image *bitstream)
358 Int j, bits;
359 Int prev_run, run, prev_level, level, first;
360 Int prev_ind, ind, prev_s, s, length;
362 run = bits = 0;
363 first = 1;
364 prev_run = prev_level = prev_ind = level = s = prev_s = ind = 0;
366 for (j = j_start; j< ncoeffs; j++)
368 /* The INTRADC encoding for INTRA Macroblocks is done in
369 Bits_CountCoeff */
372 /* do not enter this part for INTRADC coding for INTRA macro-
373 blocks */
375 /* encode AC coeff */
377 s = 0;
379 /* Increment run if coeff is zero */
381 if ((level = qcoeff[j]) == 0)
383 run++;
385 else
387 /* code run & level and count bits */
389 if (level < 0)
391 s = 1;
392 level = -level;
395 ind = level | run<<4;
396 ind = ind | 0<<12; /* Not last coeff */
398 if (!first)
400 /* Encode the previous ind */
402 if ((prev_run < 64) &&
403 (((prev_level < 13) && (Mode != MODE_INTRA &&
404 Mode != MODE_INTRA_Q))
405 || ((prev_level < 28) && (Mode == MODE_INTRA ||
406 Mode == MODE_INTRA_Q))))
408 /* Separate tables for Intra luminance blocks */
409 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
411 length = PutCoeff_Intra(prev_run, prev_level,
412 0, bitstream);
414 else
416 length = PutCoeff_Inter(prev_run, prev_level,
417 0, bitstream);
420 else
421 length = 0;
423 /* First escape mode. Level offset */
424 if (length == 0)
427 if ( prev_run < 64 )
430 /* subtraction of Max level, last = 0 */
431 int level_minus_max;
433 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
434 level_minus_max = prev_level -
435 intra_max_level[0][prev_run];
436 else
437 level_minus_max = prev_level -
438 inter_max_level[0][prev_run];
440 if ( ( (level_minus_max < 13) && (Mode != MODE_INTRA && Mode != MODE_INTRA_Q) ) ||
441 ( (level_minus_max < 28) && (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) ) )
443 /* Separate tables for Intra luminance blocks */
444 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
446 length = PutLevelCoeff_Intra(prev_run, level_minus_max, 0, bitstream);
448 else
450 length = PutLevelCoeff_Inter(prev_run, level_minus_max, 0, bitstream);
452 } else
453 length = 0;
455 else length = 0;
458 /* Second escape mode. Run offset */
459 if (length == 0)
461 if ( ((prev_level < 13) && (Mode != MODE_INTRA && Mode != MODE_INTRA_Q)) ||
462 ((prev_level < 28) && (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)) )
465 /* subtraction of Max Run, last = 0 */
466 int run_minus_max;
468 if (prev_level == 0)
470 fprintf (stdout, "ERROR(CodeCoeff-second esc): level is %d\n", prev_level);
471 exit(-1);
474 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
475 run_minus_max = prev_run - (intra_max_run0[prev_level]+1);
476 else
477 run_minus_max = prev_run - (inter_max_run0[prev_level]+1);
479 /* boon 120697 */
480 if (run_minus_max < 64)
482 /* Separate tables for Intra luminance blocks */
483 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
485 length = PutRunCoeff_Intra(run_minus_max, prev_level, 0, bitstream);
487 else
489 length = PutRunCoeff_Inter(run_minus_max, prev_level, 0, bitstream);
491 } else
492 length = 0;
494 else length = 0;
497 /* Third escape mode. FLC */
498 if (length == 0)
499 { /* Escape coding */
501 if (prev_s == 1)
503 /* Modified due to N2171 Cl. 2.2.14 MW 25-MAR-1998 */
504 /* prev_level = (prev_level^0xff)+1; */
505 prev_level = (prev_level^0xfff)+1;
507 BitstreamPutBits(bitstream, 3L, 7L);
508 /* boon */
509 BitstreamPutBits(bitstream, 3L, 2L);
511 /* last */
512 BitstreamPutBits(bitstream, 0L, 1L);
513 /* run */
514 BitstreamPutBits(bitstream, (long)(prev_run), 6L);
516 /* 11.08.98 Sven Brandau: "insert marker_bit" due to N2339, Clause 2.1.21 */
517 BitstreamPutBits(bitstream, MARKER_BIT, 1);
519 /* Modified due to N2171 Cl. 2.2.14 MW 25-MAR-1998 */
520 /* BitstreamPutBits(bitstream, (long)(prev_level), 8L); */
521 /* bits += 24; */
522 /* level */
523 BitstreamPutBits(bitstream, (long)(prev_level), 12L);
525 /* 11.08.98 Sven Brandau: "insert marker_bit" due to N2339, Clause 2.1.21 */
526 BitstreamPutBits(bitstream, MARKER_BIT, 1);
528 /*bits += 28;*/
529 bits += 30;
531 else
533 BitstreamPutBits(bitstream, (long)(prev_s), 1L);
534 bits += length + 1;
538 prev_run = run; prev_s = s;
539 prev_level = level; prev_ind = ind;
541 run = first = 0;
546 /* Encode the last coeff */
548 if (!first)
550 prev_ind = prev_ind | 1<<12; /* last coeff */
552 if ((prev_run < 64) &&
553 (((prev_level < 4) && (Mode != MODE_INTRA &&
554 Mode != MODE_INTRA_Q))
555 || ((prev_level < 9) && ((Mode == MODE_INTRA) ||
556 (Mode == MODE_INTRA_Q)))))
558 /* Separate tables for Intra luminance blocks */
559 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
561 length = PutCoeff_Intra(prev_run, prev_level, 1,
562 bitstream);
564 else
566 length = PutCoeff_Inter(prev_run, prev_level, 1,
567 bitstream);
570 else
571 length = 0;
573 /* First escape mode. Level offset */
574 if (length == 0)
576 if ( prev_run < 64 )
579 /* subtraction of Max level, last = 0 */
580 int level_minus_max;
582 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
583 level_minus_max = prev_level - intra_max_level[1][prev_run];
584 else
585 level_minus_max = prev_level - inter_max_level[1][prev_run];
587 if ( ( (level_minus_max < 4) && (Mode != MODE_INTRA && Mode != MODE_INTRA_Q) ) ||
588 ( (level_minus_max < 9) && (Mode == MODE_INTRA || Mode == MODE_INTRA_Q) ) )
590 /* Separate tables for Intra luminance blocks */
591 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
593 length = PutLevelCoeff_Intra(prev_run, level_minus_max, 1, bitstream);
595 else
597 length = PutLevelCoeff_Inter(prev_run, level_minus_max, 1, bitstream);
599 } else
600 length = 0;
602 else length = 0;
605 /* Second escape mode. Run offset */
606 if (length == 0)
608 if (((prev_level < 4) && (Mode != MODE_INTRA && Mode != MODE_INTRA_Q))||
609 ((prev_level < 9) && (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)) )
612 /* subtraction of Max Run, last = 1 */
613 int run_minus_max;
615 if (prev_level == 0)
617 fprintf (stdout, "ERROR(CodeCoeff-second esc): level is %d\n", prev_level);
618 exit(-1);
621 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
622 run_minus_max = prev_run - (intra_max_run1[prev_level]+1);
623 else
624 run_minus_max = prev_run - (inter_max_run1[prev_level]+1);
626 if (run_minus_max < 64) /* boon 120697 */
628 /* Separate tables for Intra luminance blocks */
629 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
631 length = PutRunCoeff_Intra(run_minus_max, prev_level, 1, bitstream);
633 else
635 length = PutRunCoeff_Inter(run_minus_max, prev_level, 1, bitstream);
637 } else
638 length = 0;
640 else length = 0;
643 /* Third escape mode. FLC */
644 if (length == 0)
645 { /* Escape coding */
647 if (prev_s == 1)
649 /* Modified due to N2171 Cl. 2.2.14 MW 25-MAR-1998 */
650 /* prev_level = (prev_level^0xff)+1; */
651 prev_level = (prev_level^0xfff)+1;
653 BitstreamPutBits(bitstream, 3L, 7L);
654 BitstreamPutBits(bitstream, 3L, 2L); /* boon */
656 BitstreamPutBits(bitstream, 1L, 1L); /* last */
657 BitstreamPutBits(bitstream, (long)(prev_run), 6L);
659 /* 11.08.98 Sven Brandau: "insert marker_bit" due to N2339, Clause 2.1.21 */
660 BitstreamPutBits(bitstream, MARKER_BIT, 1);
662 /* Modified due to N2171 Cl. 2.2.14 MW 25-MAR-1998 */
663 /* BitstreamPutBits(bitstream, (long)(prev_level), 8L); */
664 /* bits += 24; */
665 /* level */
666 BitstreamPutBits(bitstream, (long)(prev_level), 12L);
668 /* 11.08.98 Sven Brandau: "insert marker_bit" due to N2339, Clause 2.1.21 */
669 BitstreamPutBits(bitstream, MARKER_BIT, 1);
671 /*bits += 28;*/
672 bits += 30;
675 else
677 BitstreamPutBits(bitstream, (long)(prev_s), 1L);
678 bits += length + 1;
682 return bits;
686 /***********************************************************CommentBegin******
688 * -- CodeCoeff_RVLC -- RVLC encoding of quantized DCT coefficients
690 * Purpose :
691 * RVLC encoding of quantized DCT coefficients, except for
692 * INTRADC in case of Intra macroblocks
694 * Arguments in :
695 * Int Mode : encoding mode
696 * Int *qcoeff: pointer to quantized dct coefficients
697 * Int block : number of the block in the macroblock (0-5)
698 * Int ncoeffs : the number of coefficients per block
700 * Arguments out :
701 * Image *bitstream : pointer to the output bitstream
703 * Return values :
704 * Int bits : number of bits added to the bitstream (?)
706 ***********************************************************CommentEnd********/
708 Int CodeCoeff_RVLC(Int j_start, Int Mode, Int qcoeff[], Int block, Int ncoeffs, Image *bitstream)
710 Int j, bits;
711 Int prev_run, run, prev_level, level, first;
712 Int prev_ind, ind, prev_s, s, length;
714 run = bits = 0;
715 first = 1;
716 prev_run = prev_level = prev_ind = level = s = prev_s = ind = 0;
718 for (j = j_start; j< ncoeffs; j++)
720 /* The INTRADC encoding for INTRA Macroblocks is done in
721 Bits_CountCoeff */
724 /* do not enter this part for INTRADC coding for INTRA macro-
725 blocks */
727 /* encode AC coeff */
729 s = 0;
731 /* Increment run if coeff is zero */
733 if ((level = qcoeff[j]) == 0)
735 run++;
737 else
739 /* code run & level and count bits */
741 if (level < 0)
743 s = 1;
744 level = -level;
747 ind = level | run<<4;
748 ind = ind | 0<<12; /* Not last coeff */
749 if (!first)
751 /* Encode the previous ind */
753 if (prev_level < 28 && prev_run < 39)
754 /* Separate tables for Intra luminance blocks */
755 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
757 length = PutCoeff_Intra_RVLC(prev_run, prev_level, 0,
758 bitstream);
760 else
762 length = PutCoeff_Inter_RVLC(prev_run, prev_level, 0,
763 bitstream);
765 else
766 length = 0;
768 if (length == 0)
769 { /* Escape coding */
771 /* ESCAPE */
772 BitstreamPutBits(bitstream, 1L, 5L);
774 /* LAST */
775 BitstreamPutBits(bitstream, 0L, 1L);
777 BitstreamPutBits(bitstream,
778 (long)(prev_run), 6L);/* RUN */
780 /* 11.08.98 Sven Brandau: "changed length for LEVEL (11 bit)" due to N2339, Clause 2.1.21 */
781 /* 11.08.98 Sven Brandau: "insert marker_bit befor and after LEVEL" due to N2339, Clause 2.1.21 */
782 /* BitstreamPutBits(bitstream,
783 (long)(prev_level), 7L);*/
784 /* LEVEL */
785 BitstreamPutBits( bitstream, MARKER_BIT, 1 );
786 /* LEVEL */
787 BitstreamPutBits( bitstream, (long)(prev_level), 11L);
788 BitstreamPutBits( bitstream, MARKER_BIT, 1 );
790 /* ESCAPE */
791 BitstreamPutBits(bitstream, 0L, 4L);
793 /* ESCAPE's */
794 BitstreamPutBits(bitstream,
795 (long)(prev_s),1L);
797 bits += 5 + 1 + 6 + 1 + 11 + 1 + 4 + 1;
798 /* bits += 24; */
800 else
802 BitstreamPutBits(bitstream,
803 (long)(prev_s), 1L);
804 bits += length + 1;
808 prev_run = run; prev_s = s;
809 prev_level = level; prev_ind = ind;
811 run = first = 0;
816 /* Encode the last coeff */
818 if (!first)
820 prev_ind = prev_ind | 1<<12; /* last coeff */
822 if (prev_level < 5 && prev_run < 45)
823 /* Separate tables for Intra luminance blocks */
824 if (Mode == MODE_INTRA || Mode == MODE_INTRA_Q)
826 length = PutCoeff_Intra_RVLC(prev_run, prev_level, 1,
827 bitstream);
829 else
831 length = PutCoeff_Inter_RVLC(prev_run, prev_level, 1,
832 bitstream);
834 else
835 length = 0;
837 if (length == 0)
838 { /* Escape coding */
840 BitstreamPutBits(bitstream, 1L, 5L); /* ESCAPE */
842 BitstreamPutBits(bitstream, 1L, 1L); /* LAST */
844 /* RUN */
845 BitstreamPutBits(bitstream, (long)(prev_run), 6L);
847 /* 11.08.98 Sven Brandau: "changed length for LEVEL (11 bit)" due to N2339, Clause 2.1.21 */
848 /* 11.08.98 Sven Brandau: "insert marker_bit befor and after LEVEL" due to N2339, Clause 2.1.21 */
849 /* BitstreamPutBits(bitstream, (long)(prev_level), 7L);*/
850 BitstreamPutBits( bitstream, MARKER_BIT, 1 );
851 /* LEVEL */
852 BitstreamPutBits( bitstream, (long)(prev_level), 11L);
853 BitstreamPutBits( bitstream, MARKER_BIT, 1 );
855 BitstreamPutBits(bitstream, 0L, 4L); /* ESCAPE */
857 /* ESCAPE's */
858 BitstreamPutBits(bitstream, (long)(prev_s), 1L);
860 bits += 24;
863 else
865 BitstreamPutBits(bitstream, (long)(prev_s), 1L);
866 bits += length + 1;
870 return bits;
874 /***********************************************************CommentBegin******
876 * -- Bits_Reset -- To reset the structure bits
878 * Purpose :
879 * To reset the structure bits, used for counting the number
880 * of texture bits
882 * Arguments in :
883 * Bits* bits : a pointer to the struct Bits
885 ***********************************************************CommentEnd********/
887 void
888 Bits_Reset (Bits *bits)
890 memset(bits, 0, sizeof(Bits));