~ubuntu-branches/ubuntu/gutsy/vtk/gutsy

« back to all changes in this revision

Viewing changes to Utilities/vtkmpeg2encode/putbits.c

  • Committer: Bazaar Package Importer
  • Author(s): Michele Angrisano
  • Date: 2007-06-30 22:39:48 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20070630223948-6dqehsrip8yk05zb
Tags: upstream-5.0.3
ImportĀ upstreamĀ versionĀ 5.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* putbits.c, bit-level output                                              */
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
 
#include "mpeg2enc_config.h"
32
 
#include "mpeg2enc_global.h"
33
 
 
34
 
/* private data */
35
 
static unsigned char outbfr;
36
 
static int outcnt;
37
 
static int bytecnt;
38
 
 
39
 
/* initialize buffer, call once before first putbits or alignbits */
40
 
VTK_MPEG2ENC_EXPORT void MPEG2_initbits()
41
 
{
42
 
  outcnt = 8;
43
 
  bytecnt = 0;
44
 
}
45
 
 
46
 
/* write rightmost n (0<=n<=32) bits of val to outfile */
47
 
void MPEG2_putbits(val,n,mpeg2_struct)
48
 
int val;
49
 
int n;
50
 
struct MPEG2_structure *mpeg2_struct;
51
 
{
52
 
  int i;
53
 
  unsigned int mask;
54
 
 
55
 
  mask = 1 << (n-1); /* selects first (leftmost) bit */
56
 
 
57
 
  for (i=0; i<n; i++)
58
 
  {
59
 
    outbfr <<= 1;
60
 
 
61
 
    if (val & mask)
62
 
      outbfr|= 1;
63
 
 
64
 
    mask >>= 1; /* select next bit */
65
 
    outcnt--;
66
 
 
67
 
    if (outcnt==0) /* 8 bit buffer full */
68
 
    {
69
 
      putc(outbfr,mpeg2_struct->outfile);
70
 
      outcnt = 8;
71
 
      bytecnt++;
72
 
    }
73
 
  }
74
 
}
75
 
 
76
 
/* zero bit stuffing to next byte boundary (5.2.3, 6.2.1) */
77
 
void MPEG2_alignbits(mpeg2_struct)
78
 
struct MPEG2_structure *mpeg2_struct;
79
 
{
80
 
  if (outcnt!=8)
81
 
    MPEG2_putbits(0,outcnt,mpeg2_struct);
82
 
}
83
 
 
84
 
/* return total number of generated bits */
85
 
int MPEG2_bitcount()
86
 
{
87
 
  return 8*bytecnt + (8-outcnt);
88
 
}