dslinux/user/pixil/packages/dvdview/dvdview/oldlibgfx/libvideogfx/utility/bitstream .cvsignore Makefile.am bitbuffer.cc bitbuffer.hh fastbitbuf.hh fastbitbuf.icc membitsread.cc membitsread.hh membitsread.icc
amadeus
dslinux_amadeus at user.in-berlin.de
Tue Oct 3 13:25:56 CEST 2006
Update of /cvsroot/dslinux/dslinux/user/pixil/packages/dvdview/dvdview/oldlibgfx/libvideogfx/utility/bitstream
In directory antilope:/tmp/cvs-serv11916/packages/dvdview/dvdview/oldlibgfx/libvideogfx/utility/bitstream
Added Files:
.cvsignore Makefile.am bitbuffer.cc bitbuffer.hh fastbitbuf.hh
fastbitbuf.icc membitsread.cc membitsread.hh membitsread.icc
Log Message:
adding pristine copy of pixil to HEAD so I can branch from it
--- NEW FILE: .cvsignore ---
Makefile
Makefile.in
*.lo
_libs
.libs
.deps
libvideogfx-utility-bitstream.la
--- NEW FILE: Makefile.am ---
## Makefile.am for libvideogfx/utility/bitstream
libvideogfx_utility_bitstream_includedir = \
$(includedir)/libvideogfx/utility/bitstream
noinst_LTLIBRARIES = libvideogfx-utility-bitstream.la
libvideogfx_utility_bitstream_la_SOURCES = \
fastbitbuf.hh \
fastbitbuf.icc \
bitbuffer.hh \
bitbuffer.cc \
membitsread.cc \
membitsread.hh \
membitsread.icc
libvideogfx_utility_bitstream_include_HEADERS = \
bitbuffer.hh
INCLUDES = \
-I$(top_srcdir)
.PHONY: files
files:
@files=`ls $(DISTFILES) 2> /dev/null`; for p in $$files; do \
echo $$p; \
done
--- NEW FILE: membitsread.cc ---
/********************************************************************************
Copyright (C) 1999 Dirk Farin
This program is distributed under GNU Public License (GPL) as
outlined in the COPYING file that comes with the source distribution.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
********************************************************************************/
#include "config.h"
#include <iostream.h>
#include "libvideogfx/types.hh"
#include "membitsread.hh"
MemBitstreamReader::MemBitstreamReader(const uint8* buffer,uint32 len)
: d_buffer(0),
d_bitsleft(0),
d_ptr(buffer),
d_endptr(buffer+len)
{
}
--- NEW FILE: fastbitbuf.icc ---
/********************************************************************************
Copyright (C) 1999 Dirk Farin
This program is distributed under GNU Public License (GPL) as
outlined in the COPYING file that comes with the source distribution.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
********************************************************************************/
#include "config.h"
#include <assert.h>
#include <iostream.h>
inline uint32 MemBitstreamReader::GetBits (int n)
{
if (n>d_bitsleft)
Refill();
uint32 val = d_buffer>>(64-n);
d_buffer <<= n;
d_bitsleft -= n;
return val;
}
inline uint32 MemBitstreamReader::PeekBits(int n)
{
if (n>d_bitsleft)
Refill();
uint32 val = d_buffer>>(64-n);
return val;
}
inline void MemBitstreamReader::SkipBits(int nbits)
{
if (nbits>d_bitsleft)
Refill();
d_buffer<<=nbits;
d_bitsleft-=nbits;
}
inline void MemBitstreamReader::SkipBitsFast(int nbits)
{
d_buffer<<=nbits;
d_bitsleft-=nbits;
}
inline bool MemBitstreamReader::eof() const
{
return d_ptr >= d_endptr;
}
inline uint32 MemBitstreamReader::AskBitsLeft() const
{
return ((d_endptr-d_ptr)<<3) + d_bitsleft;
}
inline void MemBitstreamReader::Refill()
{
#if WORDS_BIGENDIAN
uint32 val = *((uint32*)d_ptr)++;
uint64 val64 = val;
val64 <<= 64-32-d_bitsleft;
d_buffer |= val64;
d_bitsleft += 32;
#else
#if CPU_x86
uint32 val = *((uint32*)d_ptr);
d_ptr+=4;
__asm__("bswap %0" : "=r" (val) : "0" (val));
uint64 val64 = val;
val64 <<= 64-32-d_bitsleft;
d_buffer |= val64;
d_bitsleft += 32;
#else
int shiftval = 64-8-d_bitsleft;
while (shiftval>=0)
{
uint64 newval = *d_ptr++;
newval <<= shiftval;
d_buffer |= newval;
shiftval -=8;
}
d_bitsleft = 64-8 -shiftval;
#endif
#endif
}
--- NEW FILE: membitsread.hh ---
/********************************************************************************
libvideogfx/utility/bitstream/membitsread.hh
purpose:
Implements bit-access to an externally provided memory buffer.
notes:
to do:
author(s):
- Dirk Farin, farin at ti.uni-mannheim.de
modifications:
03/Jul/2000 - Dirk Farin
- new method: SkipBitsFast()
20/Jun/2000 - Dirk Farin
- completely new implementation
30/Sep/1999 - Dirk Farin
- integrated from old DVDview into ULib
26/Dec/1998 - Dirk Farin
- made most methods inline
- new method: "AskBitsLeft()"
23/Dec/1998 - Dirk Farin
- first implementation, not working yet
********************************************************************************
Copyright (C) 1999 Dirk Farin
This program is distributed under GNU Public License (GPL) as
outlined in the COPYING file that comes with the source distribution.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
********************************************************************************/
#ifndef LIBVIDEOGFX_UTILITY_BITSTREAM_MEMBITSREAD_HH
#define LIBVIDEOGFX_UTILITY_BITSTREAM_MEMBITSREAD_HH
class MemBitstreamReader
{
public:
MemBitstreamReader(const uint8* buffer,uint32 len);
inline uint32 GetBits (int nbits);
inline uint32 PeekBits(int nbits);
inline void SkipBits(int nbits);
inline void SkipBitsFast(int nbits); /* Use ONLY when you called PeekBits() with at
least as many bits before! */
inline uint32 AskBitsLeft() const; // Return number of bits that have still not been read.
inline bool eof() const; // True iff current cursor position at or behind file end
private:
uint64 d_buffer;
uint32 d_bitsleft;
const uint8* d_ptr;
const uint8* d_endptr;
void Refill();
};
#include "membitsread.icc"
#endif
--- NEW FILE: bitbuffer.hh ---
/********************************************************************************
$Header: /cvsroot/dslinux/dslinux/user/pixil/packages/dvdview/dvdview/oldlibgfx/libvideogfx/utility/bitstream/bitbuffer.hh,v 1.1 2006-10-03 11:25:54 dslinux_amadeus Exp $
Memory buffer that can be filled with bit-strings.
+-------------------------------------------------------------------------------
| $Log: bitbuffer.hh,v $
| Revision 1.1 2006-10-03 11:25:54 dslinux_amadeus
| adding pristine copy of pixil to HEAD so I can branch from it
|
| Revision 1.1.1.1 2003/09/10 19:53:45 jasonk
|
|
| Revision 1.1.1.1 2003/09/10 19:36:16 jasonk
| Initial import of dvdview 1.1.0d
|
| Revision 1.2 2001/02/01 17:19:09 farin
| added WriteBool() method for convenience
|
| Revision 1.1 2000/12/14 18:13:46 farin
| new BitBuffer class for bit-oriented output
|
********************************************************************************
Copyright (C) 2000 Dirk Farin (see the README for complete list of authors)
This program is distributed under GNU Public License (GPL) as
outlined in the COPYING file that comes with the source distribution.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
********************************************************************************/
#ifndef LIBVIDEOGFX_UTILITY_BITSTREAM_BITBUFFER_HH
#define LIBVIDEOGFX_UTILITY_BITSTREAM_BITBUFFER_HH
#include "libvideogfx/types.hh"
class BitBuffer
{
public:
BitBuffer();
~BitBuffer();
void WriteBits(uint32 bits,int nBits); // input has to be right aligned
void WriteBool(bool b) { WriteBits(b ? 1 : 0 , 1); }
void WriteBitsMasked(uint32 bits,int nBits);
void AlignToByte0(); // Fill 0-bits until a byte boundary is reached. 0-7 bits are inserted.
void Flush(); // Fill 0-bits to next byte boundary and make all data available at the output buffer.
uint8* AskBuffer() const { return d_buffer; }
int AskBufferSize() const { return d_bufferidx; }
private:
uint8* d_buffer;
int d_bufferidx;
int d_buffersize;
uint32 d_tmpbuf;
int d_freebits;
void TmpToBuffer();
void EnlargeIfFull();
};
#endif
--- NEW FILE: fastbitbuf.hh ---
/********************************************************************************
libvideogfx/utility/bitstream/fastbitbuf.hh
purpose:
Implements very fast bit-access to an externally provided memory buffer.
notes:
to do:
author(s):
- Dirk Farin, farin at ti.uni-mannheim.de
modifications:
27/Sep/2000 - Dirk Farin
- first implementation, based on ideas seen in "mpeg2dec"
********************************************************************************
Copyright (C) 1999 Dirk Farin
This program is distributed under GNU Public License (GPL) as
outlined in the COPYING file that comes with the source distribution.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
********************************************************************************/
#ifndef LIBVIDEOGFX_UTILITY_BITSTREAM_FASTBITBUF_HH
#define LIBVIDEOGFX_UTILITY_BITSTREAM_FASTBITBUF_HH
#include "libvideogfx/types.hh"
#include <iostream.h>
void ShowBits(uint32 bits,int nbits)
{
for (int i=nbits-1;i>=0;i--)
{
if ((1<<i) & bits) cout << '1'; else cout << '0';
}
}
#define NEEDBITS(bit_buf,bits) bs.LocalFill16Bits(bit_buf,bits)
// remove num valid bits from bit_buf
#define DUMPBITS(bit_buf,bits,num) \
do { \
bit_buf <<= (num); \
bits += (num); \
} while (0)
// take num bits from the high part of bit_buf and zero extend them
#define UBITS(bit_buf,num) (((uint32)(bit_buf)) >> (32 - (num)))
// take num bits from the high part of bit_buf and sign extend them
#define SBITS(bit_buf,num) (((int32)(bit_buf)) >> (32 - (num)))
class FastBitBuf
{
public:
FastBitBuf(const uint8* buffer,uint32 len)
: d_ptr(buffer), d_endptr(buffer+len),
d_buffer(0), d_freebits(16)
{
Fill16Bits();
}
inline void MakeLocalCopy(uint32& buf,int& bits) { buf=d_buffer; bits=d_freebits; }
inline void RestoreFromLocal(uint32 buf,int bits) { d_buffer=buf; d_freebits=bits; }
inline void LocalFill16Bits(uint32& buf,int& bits)
{
if (bits >= 0)
{
buf |= ((((int)d_ptr[0])<<8)|d_ptr[1])<<bits;
d_ptr+=2;
bits-=16;
}
}
inline uint32 GetNextWord()
{
uint32 val = (((int)d_ptr[0])<<8) | d_ptr[1];
d_ptr+=2;
return val;
}
inline uint32 Peek16BitsMSB()
{
return d_buffer;
}
inline uint32 PeekBitsFast(int nbits)
{
return UBITS(d_buffer,nbits);
}
inline void SkipBitsFast(int nbits)
{
Assert(nbits<=16);
Assert(16-d_freebits >= nbits);
DUMPBITS(d_buffer,d_freebits,nbits);
}
inline void Fill16Bits()
{
if (d_freebits >= 0)
{
d_buffer |= ((((int)d_ptr[0])<<8)|d_ptr[1])<<d_freebits;
d_ptr+=2;
d_freebits-=16;
}
}
// ---------------- Slow methods for compatibility and non-time critical parts ---------------
inline uint32 PeekBits(int nbits)
{
if(nbits>16)
{
uint32 copy_buffer = d_buffer;
int copy_freebits = d_freebits;
const uint8 * copy_ptr = d_ptr;
uint32 bits = GetBits(16)<<(nbits-16);
bits |= PeekBits(nbits-16);
d_buffer=copy_buffer;
d_freebits = copy_freebits;
d_ptr = copy_ptr;
return bits;
}
Fill16Bits();
uint32 bits = d_buffer>>(32-nbits);
return bits;
}
inline uint32 GetBits(int nbits)
{
if (nbits>16)
{
uint32 bits = GetBits(16)<<(nbits-16);
bits |= GetBits(nbits-16);
return bits;
}
uint32 bits = PeekBits(nbits);
SkipBits(nbits);
return bits;
}
inline void SkipBits(int nbits)
{
if (nbits>16)
{
SkipBits(16);
SkipBits(nbits-16);
return;
}
Fill16Bits();
d_buffer<<=nbits;
d_freebits += nbits;
}
inline uint32 AskBitsLeft() const // Return number of bits that have still not been read.
{
return ((d_endptr-d_ptr)<<3) + 16-d_freebits;
}
inline bool eof() const // True iff current cursor position at or behind file end
{
return d_ptr >= d_endptr;
}
public:
uint32 d_buffer;
int d_freebits; // number of invalid bits in top 16 bits of buffer
private:
const uint8* d_ptr;
const uint8* d_endptr;
};
#endif
--- NEW FILE: bitbuffer.cc ---
#include "libvideogfx/utility/bitstream/bitbuffer.hh"
#include <assert.h>
const int InitialBufferSize = 1000; // has to be an integer multiple of d_tmpbuf size.
const int BitsPerEntry = 32;
const int BytesPerEntry = BitsPerEntry/8;
BitBuffer::BitBuffer()
{
d_buffer = new uint8[InitialBufferSize];
d_buffersize = InitialBufferSize;
d_bufferidx = 0;
d_freebits = BitsPerEntry;
d_tmpbuf = 0;
assert(BitsPerEntry%8 == 0);
assert(sizeof(d_tmpbuf)*8==BitsPerEntry);
assert(InitialBufferSize%sizeof(d_tmpbuf)==0);
}
BitBuffer::~BitBuffer()
{
delete[] d_buffer;
}
void BitBuffer::WriteBitsMasked(uint32 bits,int nBits)
{
uint32 mask=1;
mask<<=nBits;
mask--;
WriteBits(bits & mask,nBits);
}
void BitBuffer::WriteBits(uint32 bits,int nBits)
{
/*
+------+----------------------+
|XXXXXX|0000000000000000000000|
+------+----------------------+
d_freebits
+----+------------------------+
|0000|XXXXXXXXXXXXXXXXXXXXXXXX|
+----+------------------------+
nBits
*/
if (d_freebits>=nBits)
{
// Neue Bits passen komplett in das aktuelle Feld hinein.
uint32 aligned = bits;
int nShiftLeft = d_freebits - nBits;
if (nShiftLeft>0)
{
aligned <<= nShiftLeft;
d_tmpbuf |= aligned;
d_freebits = nShiftLeft;
}
else
{
d_tmpbuf |= aligned;
TmpToBuffer();
d_tmpbuf = 0;
d_freebits = BitsPerEntry;
}
}
else
{
// Neue Bits passen nicht mehr komplett in das aktuelle Feld.
// Sie werden folglich in zwei Teile geteilt.
uint32 rightpart = bits; // Der Teil, der noch in das aktuelle Feld passt.
uint32 leftpart = bits; // Der Rest, der in ein neues Feld kommt.
int nShiftRight = nBits - d_freebits;
if (nShiftRight != 0) rightpart >>= nShiftRight;
d_tmpbuf |= rightpart;
TmpToBuffer();
int nShiftLeft = BitsPerEntry-nShiftRight;
leftpart <<= nShiftLeft;
d_tmpbuf = leftpart;
d_freebits = nShiftLeft;
}
}
void BitBuffer::AlignToByte0()
{
d_freebits -= d_freebits%8;
if (d_freebits==0)
{
TmpToBuffer();
d_tmpbuf = 0;
d_freebits = BitsPerEntry;
}
}
void BitBuffer::Flush()
{
AlignToByte0();
EnlargeIfFull();
assert(d_bufferidx+4 <= d_buffersize);
while (d_freebits<BitsPerEntry)
{
d_buffer[d_bufferidx++] = (d_tmpbuf>>(BitsPerEntry-8));
d_tmpbuf<<=8;
d_freebits+=8;
}
assert(d_freebits == BitsPerEntry);
}
void BitBuffer::TmpToBuffer()
{
EnlargeIfFull();
assert(d_bufferidx+4 <= d_buffersize);
#ifdef WORDS_BIGENDIAN
unsigned char* p = (unsigned char*)(&d_tmpbuf);
for (int j=0;j<BytesPerEntry;j++)
d_buffer[d_bufferidx++] = p[j];
#else
unsigned char* p = (unsigned char*)(&d_tmpbuf);
for (int j=BytesPerEntry-1;j>=0;j--)
d_buffer[d_bufferidx++] = p[j];
#endif
}
void BitBuffer::EnlargeIfFull()
{
if (d_bufferidx == d_buffersize)
{
uint8* newbuf = new uint8[d_buffersize*2];
for (int i=0;i<d_buffersize;i++)
newbuf[i]=d_buffer[i];
d_buffersize *= 2;
delete[] d_buffer;
d_buffer = newbuf;
}
}
--- NEW FILE: membitsread.icc ---
/********************************************************************************
Copyright (C) 1999 Dirk Farin
This program is distributed under GNU Public License (GPL) as
outlined in the COPYING file that comes with the source distribution.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
********************************************************************************/
#include "config.h"
#include <assert.h>
#include <iostream.h>
inline uint32 MemBitstreamReader::GetBits (int n)
{
if (n>d_bitsleft)
Refill();
uint32 val = d_buffer>>(64-n);
d_buffer <<= n;
d_bitsleft -= n;
return val;
}
inline uint32 MemBitstreamReader::PeekBits(int n)
{
if (n>d_bitsleft)
Refill();
uint32 val = d_buffer>>(64-n);
return val;
}
inline void MemBitstreamReader::SkipBits(int nbits)
{
if (nbits>d_bitsleft)
Refill();
d_buffer<<=nbits;
d_bitsleft-=nbits;
}
inline void MemBitstreamReader::SkipBitsFast(int nbits)
{
d_buffer<<=nbits;
d_bitsleft-=nbits;
}
inline bool MemBitstreamReader::eof() const
{
return d_ptr >= d_endptr;
}
inline uint32 MemBitstreamReader::AskBitsLeft() const
{
return ((d_endptr-d_ptr)<<3) + d_bitsleft;
}
inline void MemBitstreamReader::Refill()
{
#if WORDS_BIGENDIAN
uint32 val = *((uint32*)d_ptr)++;
uint64 val64 = val;
val64 <<= 64-32-d_bitsleft;
d_buffer |= val64;
d_bitsleft += 32;
#else
#if CPU_x86
uint32 val = *((uint32*)d_ptr);
d_ptr+=4;
__asm__("bswap %0" : "=r" (val) : "0" (val));
uint64 val64 = val;
val64 <<= 64-32-d_bitsleft;
d_buffer |= val64;
d_bitsleft += 32;
#else
int shiftval = 64-8-d_bitsleft;
while (shiftval>=0)
{
uint64 newval = *d_ptr++;
newval <<= shiftval;
d_buffer |= newval;
shiftval -=8;
}
d_bitsleft = 64-8 -shiftval;
#endif
#endif
}
More information about the dslinux-commit
mailing list