home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2004 March / PCWELT_3_2004.ISO / pcwsoft / flaskmpeg_078_39_src.z.exe / flaskmpeg / Video / getvlc.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-28  |  16.5 KB  |  829 lines

  1. /* getvlc.c, variable length decoding                                       */
  2.  
  3. /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
  4.  
  5. /*
  6.  * Disclaimer of Warranty
  7.  *
  8.  * These software programs are available to the user without any license fee or
  9.  * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
  10.  * any and all warranties, whether express, implied, or statuary, including any
  11.  * implied warranties or merchantability or of fitness for a particular
  12.  * purpose.  In no event shall the copyright-holder be liable for any
  13.  * incidental, punitive, or consequential damages of any kind whatsoever
  14.  * arising from the use of these programs.
  15.  *
  16.  * This disclaimer of warranty extends to the user of these programs and user's
  17.  * customers, employees, agents, transferees, successors, and assigns.
  18.  *
  19.  * The MPEG Software Simulation Group does not represent or warrant that the
  20.  * programs furnished hereunder are free of infringement of any third-party
  21.  * patents.
  22.  *
  23.  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
  24.  * are subject to royalty fees to patent holders.  Many of these patents are
  25.  * general enough such that they are unavoidable regardless of implementation
  26.  * design.
  27.  *
  28.  */
  29.  
  30. #include <stdio.h>
  31.  
  32. #include "config.h"
  33. #include "global.h"
  34. //#include "getbits.h"
  35. #include "getvlc.h" 
  36.  
  37. // private prototypes 
  38. // generic picture macroblock type processing functions 
  39. __inline static int Get_I_macroblock_type _ANSI_ARGS_((void));
  40. __inline static int Get_P_macroblock_type _ANSI_ARGS_((void));
  41. __inline static int Get_B_macroblock_type _ANSI_ARGS_((void));
  42. __inline static int Get_D_macroblock_type _ANSI_ARGS_((void));
  43.  
  44. // spatial picture macroblock type processing functions 
  45. //snr static int Get_I_Spatial_macroblock_type _ANSI_ARGS_((void));
  46. //snr static int Get_P_Spatial_macroblock_type _ANSI_ARGS_((void));
  47. //snr static int Get_B_Spatial_macroblock_type _ANSI_ARGS_((void));
  48. //snr static int Get_SNR_macroblock_type _ANSI_ARGS_((void));
  49.  
  50. #define Show_Bits(N) ( ld->Bfr >> (32-N) )
  51. #define Get_Bits1() (Get_Bits(1))
  52.  
  53. int Get_macroblock_type()
  54. {
  55.   int macroblock_type = 0;
  56.  
  57. /* //snr
  58.   if (ld->scalable_mode==SC_SNR)
  59.     macroblock_type = Get_SNR_macroblock_type();
  60.   else
  61.   {
  62.     switch (picture_coding_type)
  63.     {
  64.     case I_TYPE:
  65.       macroblock_type = ld->pict_scal ? Get_I_Spatial_macroblock_type() : Get_I_macroblock_type();
  66.       break;
  67.     case P_TYPE:
  68.       macroblock_type = ld->pict_scal ? Get_P_Spatial_macroblock_type() : Get_P_macroblock_type();
  69.       break;
  70.     case B_TYPE:
  71.       macroblock_type = ld->pict_scal ? Get_B_Spatial_macroblock_type() : Get_B_macroblock_type();
  72.       break;
  73.     case D_TYPE:
  74.       macroblock_type = Get_D_macroblock_type();
  75.       break;
  76.     default:
  77.       printf("Get_macroblock_type(): unrecognized picture coding type\n");
  78.       break;
  79.     }
  80.   }*/
  81.  
  82.   // v0.16B22 removed scalable-support
  83.     switch (picture_coding_type)
  84.     {
  85.     case I_TYPE:
  86.       macroblock_type = Get_I_macroblock_type();
  87.       break;
  88.     case P_TYPE:
  89.       macroblock_type = Get_P_macroblock_type();
  90.       break;
  91.     case B_TYPE:
  92.       macroblock_type = Get_B_macroblock_type();
  93.       break;
  94.     case D_TYPE:
  95.       macroblock_type = Get_D_macroblock_type();
  96.       break;
  97.     default:
  98.       printf("Get_macroblock_type(): unrecognized picture coding type\n");
  99.       break;
  100.     }
  101.  
  102.   return macroblock_type;
  103. }
  104.  
  105. static int Get_I_macroblock_type()
  106. {
  107. #ifdef TRACE
  108.   if (Trace_Flag)
  109.     printf("macroblock_type(I) ");
  110. #endif // TRACE 
  111.  
  112.   if (Get_Bits1())
  113.   {
  114. #ifdef TRACE
  115.     if (Trace_Flag)
  116.       printf("(1): Intra (1)\n");
  117. #endif // TRACE 
  118.     return 1;
  119.   }
  120.  
  121.   if (!Get_Bits1())
  122.   {
  123.     if (!Quiet_Flag)
  124.       printf("Invalid macroblock_type code\n");
  125.     Fault_Flag = 1;
  126.   }
  127.  
  128. #ifdef TRACE
  129.   if (Trace_Flag)
  130.     printf("(01): Intra, Quant (17)\n");
  131. #endif // TRACE 
  132.  
  133.   return 17;
  134. }
  135.  
  136. static char *MBdescr[]={
  137.   "",                  "Intra",        "No MC, Coded",         "",
  138.   "Bwd, Not Coded",    "",             "Bwd, Coded",           "",
  139.   "Fwd, Not Coded",    "",             "Fwd, Coded",           "",
  140.   "Interp, Not Coded", "",             "Interp, Coded",        "",
  141.   "",                  "Intra, Quant", "No MC, Coded, Quant",  "",
  142.   "",                  "",             "Bwd, Coded, Quant",    "",
  143.   "",                  "",             "Fwd, Coded, Quant",    "",
  144.   "",                  "",             "Interp, Coded, Quant", ""
  145. };
  146.  
  147. static int Get_P_macroblock_type()
  148. {
  149.   int code;
  150.  
  151. #ifdef TRACE
  152.   if (Trace_Flag)
  153.     printf("macroblock_type(P) (");
  154. #endif // TRACE 
  155.  
  156.   if ((code = Show_Bits(6))>=8)
  157.   {
  158.     code >>= 3;
  159.     Flush_Buffer(PMBtab0[code].len);
  160. #ifdef TRACE
  161.     if (Trace_Flag)
  162.     {
  163.       Print_Bits(code,3,PMBtab0[code].len);
  164.       printf("): %s (%d)\n",MBdescr[(int)PMBtab0[code].val],PMBtab0[code].val);
  165.     }
  166. #endif // TRACE 
  167.     return PMBtab0[code].val;
  168.   }
  169.  
  170.   if (code==0)
  171.   {
  172.     if (!Quiet_Flag)
  173.       printf("Invalid macroblock_type code\n");
  174.     Fault_Flag = 1;
  175.     return 0;
  176.   }
  177.  
  178.   Flush_Buffer(PMBtab1[code].len);
  179.  
  180. #ifdef TRACE
  181.   if (Trace_Flag)
  182.   {
  183.     Print_Bits(code,6,PMBtab1[code].len);
  184.     printf("): %s (%d)\n",MBdescr[(int)PMBtab1[code].val],PMBtab1[code].val);
  185.   }
  186. #endif // TRACE 
  187.  
  188.   return PMBtab1[code].val;
  189. }
  190.  
  191. static int Get_B_macroblock_type()
  192. {
  193.   int code;
  194.  
  195. #ifdef TRACE
  196.   if (Trace_Flag)
  197.     printf("macroblock_type(B) (");
  198. #endif // TRACE 
  199.  
  200.   if ((code = Show_Bits(6))>=8)
  201.   {
  202.     code >>= 2;
  203.     Flush_Buffer(BMBtab0[code].len);
  204.  
  205. #ifdef TRACE
  206.     if (Trace_Flag)
  207.     {
  208.       Print_Bits(code,4,BMBtab0[code].len);
  209.       printf("): %s (%d)\n",MBdescr[(int)BMBtab0[code].val],BMBtab0[code].val);
  210.     }
  211. #endif // TRACE 
  212.  
  213.     return BMBtab0[code].val;
  214.   }
  215.  
  216.   if (code==0)
  217.   {
  218.     if (!Quiet_Flag)
  219.       printf("Invalid macroblock_type code\n");
  220.     Fault_Flag = 1;
  221.     return 0;
  222.   }
  223.  
  224.   Flush_Buffer(BMBtab1[code].len);
  225.  
  226. #ifdef TRACE
  227.   if (Trace_Flag)
  228.   {
  229.     Print_Bits(code,6,BMBtab1[code].len);
  230.     printf("): %s (%d)\n",MBdescr[(int)BMBtab1[code].val],BMBtab1[code].val);
  231.   }
  232. #endif // TRACE 
  233.  
  234.   return BMBtab1[code].val;
  235. }
  236.  
  237. static int Get_D_macroblock_type()
  238. {
  239.   if (!Get_Bits1())
  240.   {
  241.     if (!Quiet_Flag)
  242.       printf("Invalid macroblock_type code\n");
  243.     Fault_Flag=1;
  244.   }
  245.  
  246.   return 1;
  247. }
  248.  
  249. // macroblock_type for pictures with spatial scalability 
  250.  
  251. /* v0.16B33 removed spatial macroblock junk 
  252. static int Get_I_Spatial_macroblock_type()
  253. {
  254.   int code;
  255.  
  256. #ifdef TRACE
  257.   if (Trace_Flag)
  258.     printf("macroblock_type(I,spat) (");
  259. #endif // TRACE 
  260.  
  261.   code = Show_Bits(4);
  262.  
  263.   if (code==0)
  264.   {
  265.     if (!Quiet_Flag)
  266.       printf("Invalid macroblock_type code\n");
  267.     Fault_Flag = 1;
  268.     return 0;
  269.   }
  270.  
  271. #ifdef TRACE
  272.   if (Trace_Flag)
  273.   {
  274.     Print_Bits(code,4,spIMBtab[code].len);
  275.     printf("): %02x\n",spIMBtab[code].val);
  276.   }
  277. #endif // TRACE 
  278.  
  279.   Flush_Buffer(spIMBtab[code].len);
  280.   return spIMBtab[code].val;
  281. }
  282.  
  283. static int Get_P_Spatial_macroblock_type()
  284. {
  285.   int code;
  286.  
  287. #ifdef TRACE
  288.   if (Trace_Flag)
  289.     printf("macroblock_type(P,spat) (");
  290. #endif // TRACE 
  291.  
  292.   code = Show_Bits(7);
  293.  
  294.   if (code<2)
  295.   {
  296.     if (!Quiet_Flag)
  297.       printf("Invalid macroblock_type code\n");
  298.     Fault_Flag = 1;
  299.     return 0;
  300.   }
  301.  
  302.   if (code>=16)
  303.   {
  304.     code >>= 3;
  305.     Flush_Buffer(spPMBtab0[code].len);
  306.  
  307. #ifdef TRACE
  308.     if (Trace_Flag)
  309.     {
  310.       Print_Bits(code,4,spPMBtab0[code].len);
  311.       printf("): %02x\n",spPMBtab0[code].val);
  312.     }
  313. #endif // TRACE 
  314.  
  315.     return spPMBtab0[code].val;
  316.   }
  317.  
  318.   Flush_Buffer(spPMBtab1[code].len);
  319.  
  320. #ifdef TRACE
  321.   if (Trace_Flag)
  322.   {
  323.     Print_Bits(code,7,spPMBtab1[code].len);
  324.     printf("): %02x\n",spPMBtab1[code].val);
  325.   }
  326. #endif // TRACE 
  327.  
  328.   return spPMBtab1[code].val;
  329. }
  330.  
  331. static int Get_B_Spatial_macroblock_type()
  332. {
  333.   int code;
  334.   VLCtab *p;
  335.  
  336. #ifdef TRACE
  337.   if (Trace_Flag)
  338.     printf("macroblock_type(B,spat) (");
  339. #endif // TRACE 
  340.  
  341.   code = Show_Bits(9);
  342.  
  343.   if (code>=64)
  344.     p = &spBMBtab0[(code>>5)-2];
  345.   else if (code>=16)
  346.     p = &spBMBtab1[(code>>2)-4];
  347.   else if (code>=8)
  348.     p = &spBMBtab2[code-8];
  349.   else
  350.   {
  351.     if (!Quiet_Flag)
  352.       printf("Invalid macroblock_type code\n");
  353.     Fault_Flag = 1;
  354.     return 0;
  355.   }
  356.  
  357.   Flush_Buffer(p->len);
  358.  
  359. #ifdef TRACE
  360.   if (Trace_Flag)
  361.   {
  362.     Print_Bits(code,9,p->len);
  363.     printf("): %02x\n",p->val);
  364.   }
  365. #endif // TRACE 
  366.  
  367.   return p->val;
  368. }
  369.  
  370. static int Get_SNR_macroblock_type()
  371. {
  372.   int code;
  373.  
  374. #ifdef TRACE            // *CH* 
  375.   if (Trace_Flag)
  376.     printf("macroblock_type(SNR) (");
  377. #endif TRACE
  378.  
  379.   code = Show_Bits(3);
  380.  
  381.   if (code==0)
  382.   {
  383.     if (!Quiet_Flag)
  384.       printf("Invalid macroblock_type code\n");
  385.     Fault_Flag = 1;
  386.     return 0;
  387.   }
  388.  
  389.   Flush_Buffer(SNRMBtab[code].len);
  390.  
  391. #ifdef TRACE            // *CH* 
  392.   if (Trace_Flag)
  393.   {
  394.     Print_Bits(code,3,SNRMBtab[code].len);
  395.     printf("): %s (%d)\n",MBdescr[(int)SNRMBtab[code].val],SNRMBtab[code].val);
  396.   }
  397. #endif TRACE
  398.  
  399.  
  400.   return SNRMBtab[code].val;
  401. }
  402. */
  403. int Get_motion_code()
  404. {
  405.   int code;
  406.  
  407. #ifdef TRACE
  408.   if (Trace_Flag)
  409.     printf("motion_code (");
  410. #endif // TRACE 
  411.  
  412.   if (Get_Bits1())
  413.   {
  414. #ifdef TRACE
  415.     if (Trace_Flag)
  416.       printf("0): 0\n");
  417. #endif // TRACE 
  418.     return 0;
  419.   }
  420.  
  421.   if ((code = Show_Bits(9))>=64)
  422.   {
  423.     code >>= 6;
  424.     Flush_Buffer(MVtab0[code].len);
  425.  
  426. #ifdef TRACE
  427.     if (Trace_Flag)
  428.     {
  429.       Print_Bits(code,3,MVtab0[code].len);
  430.       printf("%d): %d\n",
  431.         Show_Bits(1),Show_Bits(1)?-MVtab0[code].val:MVtab0[code].val);
  432.     }
  433. #endif // TRACE 
  434.  
  435.     return Get_Bits1()?-MVtab0[code].val:MVtab0[code].val;
  436.   }
  437.  
  438.   if (code>=24)
  439.   {
  440.     code >>= 3;
  441.     Flush_Buffer(MVtab1[code].len);
  442.  
  443. #ifdef TRACE
  444.     if (Trace_Flag)
  445.     {
  446.       Print_Bits(code,6,MVtab1[code].len);
  447.       printf("%d): %d\n",
  448.         Show_Bits(1),Show_Bits(1)?-MVtab1[code].val:MVtab1[code].val);
  449.     }
  450. #endif // TRACE 
  451.  
  452.     return Get_Bits1()?-MVtab1[code].val:MVtab1[code].val;
  453.   }
  454.  
  455.   if ((code-=12)<0)
  456.   {
  457.     if (!Quiet_Flag)
  458. // HACK 
  459.       printf("Invalid motion_vector code (MBA %d, pic %d)\n", global_MBA, global_pic);
  460.     Fault_Flag=1;
  461.     return 0;
  462.   }
  463.  
  464.   Flush_Buffer(MVtab2[code].len);
  465.  
  466. #ifdef TRACE
  467.   if (Trace_Flag)
  468.   {
  469.     Print_Bits(code+12,9,MVtab2[code].len);
  470.     printf("%d): %d\n",
  471.       Show_Bits(1),Show_Bits(1)?-MVtab2[code].val:MVtab2[code].val);
  472.   }
  473. #endif // TRACE 
  474.  
  475.   return Get_Bits1() ? -MVtab2[code].val : MVtab2[code].val;
  476. }
  477.  
  478.  
  479. // get differential motion vector (for dual prime prediction) 
  480. int Get_dmvector()
  481. {
  482. #ifdef TRACE
  483.   if (Trace_Flag)
  484.     printf("dmvector (");
  485. #endif // TRACE 
  486.  
  487.   if (Get_Bits(1))
  488.   {
  489. #ifdef TRACE
  490.     if (Trace_Flag)
  491.       printf(Show_Bits(1) ? "11): -1\n" : "10): 1\n");
  492. #endif // TRACE 
  493.     return Get_Bits(1) ? -1 : 1;
  494.   }
  495.   else
  496.   {
  497. #ifdef TRACE
  498.     if (Trace_Flag)
  499.       printf("0): 0\n");
  500. #endif // TRACE 
  501.     return 0;
  502.   }
  503. }
  504.  
  505. int Get_coded_block_pattern()
  506. {
  507.   int code;
  508.  
  509. #ifdef TRACE
  510.   if (Trace_Flag)
  511.     printf("coded_block_pattern_420 (");
  512. #endif // TRACE 
  513.  
  514.   if ((code = Show_Bits(9))>=128)
  515.   {
  516.     code >>= 4;
  517.     Flush_Buffer(CBPtab0[code].len);
  518.  
  519. #ifdef TRACE
  520.     if (Trace_Flag)
  521.     {
  522.       Print_Bits(code,5,CBPtab0[code].len);
  523.       printf("): ");
  524.       Print_Bits(CBPtab0[code].val,6,6);
  525.       printf(" (%d)\n",CBPtab0[code].val);
  526.     }
  527. #endif // TRACE 
  528.  
  529.     return CBPtab0[code].val;
  530.   }
  531.  
  532.   if (code>=8)
  533.   {
  534.     code >>= 1;
  535.     Flush_Buffer(CBPtab1[code].len);
  536.  
  537. #ifdef TRACE
  538.     if (Trace_Flag)
  539.     {
  540.       Print_Bits(code,8,CBPtab1[code].len);
  541.       printf("): ");
  542.       Print_Bits(CBPtab1[code].val,6,6);
  543.       printf(" (%d)\n",CBPtab1[code].val);
  544.     }
  545. #endif // TRACE 
  546.  
  547.     return CBPtab1[code].val;
  548.   }
  549.  
  550.   if (code<1)
  551.   {
  552.     if (!Quiet_Flag)
  553.       printf("Invalid coded_block_pattern code\n");
  554.     Fault_Flag = 1;
  555.     return 0;
  556.   }
  557.  
  558.   Flush_Buffer(CBPtab2[code].len);
  559.  
  560. #ifdef TRACE
  561.   if (Trace_Flag)
  562.   {
  563.     Print_Bits(code,9,CBPtab2[code].len);
  564.     printf("): ");
  565.     Print_Bits(CBPtab2[code].val,6,6);
  566.     printf(" (%d)\n",CBPtab2[code].val);
  567.   }
  568. #endif // TRACE 
  569.  
  570.   return CBPtab2[code].val;
  571. }
  572.  
  573. int Get_macroblock_address_increment()
  574. {
  575.   int code, val;
  576.  
  577. #ifdef TRACE
  578.   if (Trace_Flag)
  579.     printf("macroblock_address_increment (");
  580. #endif // TRACE 
  581.  
  582.   val = 0;
  583.  
  584.   while ((code = Show_Bits(11))<24)
  585.   {
  586.     if (code!=15) // if not macroblock_stuffing 
  587.     {
  588.       if (code==8) // if macroblock_escape 
  589.       {
  590. #ifdef TRACE
  591.         if (Trace_Flag)
  592.           printf("00000001000 ");
  593. #endif // TRACE 
  594.  
  595.         val+= 33;
  596.       }
  597.       else
  598.       {
  599.         if (!Quiet_Flag)
  600.           printf("Invalid macroblock_address_increment code\n");
  601.  
  602.         Fault_Flag = 1;
  603.         return 1;
  604.       }
  605.     }
  606.     else // macroblock suffing 
  607.     {
  608. #ifdef TRACE
  609.       if (Trace_Flag)
  610.         printf("00000001111 ");
  611. #endif // TRACE 
  612.     }
  613.  
  614.     Flush_Buffer(11);
  615.   }
  616.  
  617.   // macroblock_address_increment == 1 
  618.   // ('1' is in the MSB position of the lookahead) 
  619.   if (code>=1024)
  620.   {
  621.     Flush_Buffer(1);
  622. #ifdef TRACE
  623.     if (Trace_Flag)
  624.       printf("1): %d\n",val+1);
  625. #endif // TRACE 
  626.     return val + 1;
  627.   }
  628.  
  629.   // codes 00010 ... 011xx 
  630.   if (code>=128)
  631.   {
  632.     // remove leading zeros 
  633.     code >>= 6;
  634.     Flush_Buffer(MBAtab1[code].len);
  635.  
  636. #ifdef TRACE
  637.     if (Trace_Flag)
  638.     {
  639.       Print_Bits(code,5,MBAtab1[code].len);
  640.       printf("): %d\n",val+MBAtab1[code].val);
  641.     }
  642. #endif // TRACE 
  643.  
  644.     
  645.     return val + MBAtab1[code].val;
  646.   }
  647.   
  648.   // codes 00000011000 ... 0000111xxxx 
  649.   code-= 24; // remove common base 
  650.   Flush_Buffer(MBAtab2[code].len);
  651.  
  652. #ifdef TRACE
  653.   if (Trace_Flag)
  654.   {
  655.     Print_Bits(code+24,11,MBAtab2[code].len);
  656.     printf("): %d\n",val+MBAtab2[code].val);
  657.   }
  658. #endif // TRACE 
  659.  
  660.   return val + MBAtab2[code].val;
  661. }
  662.  
  663. // combined MPEG-1 and MPEG-2 stage. parse VLC and 
  664. // perform dct_diff arithmetic.
  665. //
  666. //   MPEG-1:  ISO/IEC 11172-2 section
  667. //   MPEG-2:  ISO/IEC 13818-2 section 7.2.1 
  668. //   
  669. //   Note: the arithmetic here is presented more elegantly than
  670. //   the spec, yet the results, dct_diff, are the same.
  671.  
  672.  
  673. int Get_Luma_DC_dct_diff()
  674. {
  675.   int code, size, dct_diff;
  676.  
  677. #ifdef TRACE
  678. //
  679.   if (Trace_Flag)
  680.     printf("dct_dc_size_luminance: (");
  681.  
  682. #endif // TRACE 
  683.  
  684.   // decode length 
  685.   code = Show_Bits(5);
  686.  
  687.   if (code<31)
  688.   {
  689.     size = DClumtab0[code].val;
  690.     Flush_Buffer(DClumtab0[code].len);
  691. #ifdef TRACE
  692. //
  693.     if (Trace_Flag)
  694.     {
  695.       Print_Bits(code,5,DClumtab0[code].len);
  696.       printf("): %d",size);
  697.     }
  698.  
  699. #endif // TRACE 
  700.   }
  701.   else
  702.   {
  703.     code = Show_Bits(9) - 0x1f0;
  704.     size = DClumtab1[code].val;
  705.     Flush_Buffer(DClumtab1[code].len);
  706.  
  707. #ifdef TRACE
  708. //
  709.     if (Trace_Flag)
  710.     {
  711.       Print_Bits(code+0x1f0,9,DClumtab1[code].len);
  712.       printf("): %d",size);
  713.     }
  714.  
  715. #endif // TRACE 
  716.   }
  717.  
  718. #ifdef TRACE
  719. //
  720.   if (Trace_Flag)
  721.     printf(", dct_dc_differential (");
  722.  
  723. #endif // TRACE 
  724.  
  725.   if (size==0)
  726.     dct_diff = 0;
  727.   else
  728.   {
  729.     dct_diff = Get_Bits(size);
  730. #ifdef TRACE
  731. //
  732.     if (Trace_Flag)
  733.       Print_Bits(dct_diff,size,size);
  734.  
  735. #endif // TRACE 
  736.     if ((dct_diff & (1<<(size-1)))==0)
  737.       dct_diff-= (1<<size) - 1;
  738.   }
  739.  
  740. #ifdef TRACE
  741. //
  742.   if (Trace_Flag)
  743.     printf("): %d\n",dct_diff);
  744.  
  745. #endif // TRACE 
  746.  
  747.   return dct_diff;
  748. }
  749.  
  750.  
  751. int Get_Chroma_DC_dct_diff()
  752. {
  753.   int code, size, dct_diff;
  754.  
  755. #ifdef TRACE
  756. //
  757.   if (Trace_Flag)
  758.     printf("dct_dc_size_chrominance: (");
  759.  
  760. #endif // TRACE 
  761.  
  762.   // decode length 
  763.   code = Show_Bits(5);
  764.  
  765.   if (code<31)
  766.   {
  767.     size = DCchromtab0[code].val;
  768.     Flush_Buffer(DCchromtab0[code].len);
  769.  
  770. #ifdef TRACE
  771. //
  772.     if (Trace_Flag)
  773.     {
  774.       Print_Bits(code,5,DCchromtab0[code].len);
  775.       printf("): %d",size);
  776.     }
  777.  
  778. #endif // TRACE 
  779.   }
  780.   else
  781.   {
  782.     code = Show_Bits(10) - 0x3e0;
  783.     size = DCchromtab1[code].val;
  784.     Flush_Buffer(DCchromtab1[code].len);
  785.  
  786. #ifdef TRACE
  787. //
  788.     if (Trace_Flag)
  789.     {
  790.       Print_Bits(code+0x3e0,10,DCchromtab1[code].len);
  791.       printf("): %d",size);
  792.     }
  793.  
  794. #endif // TRACE 
  795.   }
  796.  
  797. #ifdef TRACE
  798. // 
  799.   if (Trace_Flag)
  800.     printf(", dct_dc_differential (");
  801.  
  802. #endif // TRACE 
  803.  
  804.   if (size==0)
  805.     dct_diff = 0;
  806.   else
  807.   {
  808.     dct_diff = Get_Bits(size);
  809. #ifdef TRACE
  810. //
  811.     if (Trace_Flag)
  812.       Print_Bits(dct_diff,size,size);
  813.  
  814. #endif // TRACE 
  815.     if ((dct_diff & (1<<(size-1)))==0)
  816.       dct_diff-= (1<<size) - 1;
  817.   }
  818.  
  819. #ifdef TRACE
  820. //
  821.   if (Trace_Flag)
  822.     printf("): %d\n",dct_diff);
  823.  
  824. #endif // TRACE 
  825.  
  826.   return dct_diff;
  827. }
  828.  
  829.