putvlc.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:2k
- #include "Includesysdefs.h"
- #include "PlaycoreCaptureLogompeg_encvlc.h"
- #include "PlaycoreCaptureLogompeg_encputbits.h"
- #ifdef SUPPORT_CAPTURE_LOGO
- static void putDC (CONST sVLCtable *tab, int val);
- /* generate variable length code for luminance DC coefficient */
- void putDClum(int val)
- {
- putDC(DClumtab,val);
- }
- /* generate variable length code for chrominance DC coefficient */
- void putDCchrom(int val)
- {
- putDC(DCchromtab,val);
- }
- /* generate variable length code for DC coefficient (7.2.1) */
- static void putDC(CONST sVLCtable *tab,int val)
- {
- int absval, size;
- absval = (val<0) ? -val : val; /* abs(val) */
- /* compute dct_dc_size */
- size = 0;
- while (absval)
- {
- absval >>= 1;
- size++;
- }
- /* generate VLC for dct_dc_size (Table B-12 or B-13) */
- putbits(tab[size].code,tab[size].len);
- /* append fixed length code (dc_dct_differential) */
- if (size!=0)
- {
- if (val>=0)
- absval = val;
- else
- absval = val + (1<<size) - 1; /* val + (2 ^ size) - 1 */
- putbits(absval,size);
- }
- }
- /* generate variable length code for other DCT coefficients (7.2.2) */
- void putAC(int run,int signed_level)
- {
- int level, len;
- CONST VLCtable *ptab;
- level = (signed_level<0) ? -signed_level : signed_level; /* abs(signed_level) */
- len = 0;
- if (run<2 && level<41)
- {
- ptab = &dct_code_tab1[run][level-1];
- len = ptab->len;
- }
- else if (run<32 && level<6)
- {
- /* vlcformat selects either of Table B-14 / B-15 */
- ptab = &dct_code_tab2[run-2][level-1];
- len = ptab->len;
- }
- if (len!=0) /* a VLC code exists */
- {
- putbits(ptab->code,len);
- putbits(signed_level<0,1); /* sign */
- }
- else
- {
- /* no VLC for this (run, level) combination: use escape coding (7.2.2.3) */
- putbits(1l,6); /* Escape */
- putbits(run,6); /* 6 bit code for run */
- putbits(signed_level,12);
- }
- }
- /* generate variable length code for macroblock_type (6.3.16.1) */
- void putmbtype(MB_TYPE mb_type)
- {
- putbits(mbtypetab[mb_type].code,
- mbtypetab[mb_type].len);
- }
- #endif