putbits.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:2k
- #include "Includesysdefs.h"
- #include "PlaycoreCaptureLogompeg_encenc_io.h"
- #include "PlaycoreCaptureLogompeg_encmpeg_defs.h"
- #include "PlaycoreCaptureLogompeg_encputbits.h"
- #include "PlaycoreCaptureLogompeg_encenc.h"
- #ifdef SUPPORT_CAPTURE_LOGO
- void putsyshdr(void)
- {
- putbits(PACK_START_CODE,32);
- putbits(0x44000404L,32);
- putbits(0x94AD0189L,32);
- putbits(0xC3F80000L,32);
- putbits(0x01E007ECL,32);
- putbits(0x81C10D31L,32);
- putbits(0x0001AEE9L,32);
- putbits(0x11000192L,32);
- putbits(0xC91E60E8L,32);
- }
- /* initialize buffer, call once before first putbits or alignbits */
- void initbits(void)
- {
- pLogoCapture->outcnt = 16;
- pLogoCapture->bytecnt = 0;
- pLogoCapture->sectors_cnt = 0;
- }
- /* write rightmost n (0<=n<=32) bits of val to outfile */
- int putbits(long val,int n)
- {
- int i;
- unsigned long mask;
- mask = 1UL << (n-1); /* selects first (leftmost) bit */
- for (i=0; i<n; i++)
- {
- pLogoCapture->outbfr <<= 1;
- if (val & mask)
- pLogoCapture->outbfr|= 1;
- mask >>= 1; /* select next bit */
- pLogoCapture->outcnt--;
- if (pLogoCapture->outcnt==0) /* 8 bit buffer full */
- {
- output(pLogoCapture->outbfr);
- pLogoCapture->outcnt = 16;
- pLogoCapture->bytecnt++;
- if( !(pLogoCapture->bytecnt % 1024) )
- {
- pLogoCapture->bytecnt=0;
- pLogoCapture->sectors_cnt ++;
- putsyshdr();
- }
- }
- }
- return 1;
- }
- /* zero bit stuffing to next byte boundary (5.2.3, 6.2.1) */
- void alignbits(void)
- {
- if (pLogoCapture->outcnt!=8 && pLogoCapture->outcnt!=16)
- {
- putbits(0,pLogoCapture->outcnt&0x7);
- }
- }
- /* return total number of generated bits */
- int bitcount(void)
- {
- return 16*pLogoCapture->bytecnt + (16-pLogoCapture->outcnt);
- }
- int alignsector(void)
- {
- int i;
- alignbits();
- if(pLogoCapture->bytecnt!=0)
- {
- for(i=pLogoCapture->bytecnt;i<1024;i++)
- {
- output(0);
- }
- pLogoCapture->sectors_cnt ++;
- }
- return pLogoCapture->sectors_cnt;
- }
- #endif