2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
#ifndef __SWF_BITSTREAM_H__
|
|
|
|
#define __SWF_BITSTREAM_H__
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
class idSWFBitStream
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
public:
|
2012-11-28 15:47:07 +00:00
|
|
|
idSWFBitStream();
|
|
|
|
idSWFBitStream( const byte* data, uint32 len, bool copy )
|
|
|
|
{
|
|
|
|
free = false;
|
|
|
|
Load( data, len, copy );
|
|
|
|
}
|
|
|
|
~idSWFBitStream()
|
|
|
|
{
|
|
|
|
Free();
|
|
|
|
}
|
|
|
|
|
|
|
|
idSWFBitStream& operator=( idSWFBitStream& other );
|
|
|
|
|
|
|
|
void Load( const byte* data, uint32 len, bool copy );
|
2012-11-26 18:58:24 +00:00
|
|
|
void Free();
|
2012-11-28 15:47:07 +00:00
|
|
|
const byte* Ptr()
|
|
|
|
{
|
|
|
|
return startp;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 Length() const
|
|
|
|
{
|
|
|
|
return ( uint32 )( endp - startp );
|
|
|
|
}
|
|
|
|
uint32 Tell() const
|
|
|
|
{
|
|
|
|
return ( uint32 )( readp - startp );
|
|
|
|
}
|
|
|
|
void Seek( int32 offset )
|
|
|
|
{
|
|
|
|
readp += offset;
|
|
|
|
}
|
|
|
|
void Rewind()
|
|
|
|
{
|
|
|
|
readp = startp;
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
void ResetBits();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int ReadS( unsigned int numBits );
|
|
|
|
unsigned int ReadU( unsigned int numBits );
|
|
|
|
bool ReadBool();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
const byte* ReadData( int size );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
template< typename T >
|
2012-11-28 15:47:07 +00:00
|
|
|
void ReadLittle( T& val );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
uint8 ReadU8();
|
|
|
|
uint16 ReadU16();
|
|
|
|
uint32 ReadU32();
|
|
|
|
int16 ReadS16();
|
|
|
|
int32 ReadS32();
|
|
|
|
uint32 ReadEncodedU32();
|
|
|
|
float ReadFixed8();
|
|
|
|
float ReadFixed16();
|
|
|
|
float ReadFloat();
|
|
|
|
double ReadDouble();
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* ReadString();
|
|
|
|
|
|
|
|
void ReadRect( swfRect_t& rect );
|
|
|
|
void ReadMatrix( swfMatrix_t& matrix );
|
|
|
|
void ReadColorXFormRGBA( swfColorXform_t& cxf );
|
|
|
|
void ReadColorRGB( swfColorRGB_t& color );
|
|
|
|
void ReadColorRGBA( swfColorRGBA_t& color );
|
|
|
|
void ReadGradient( swfGradient_t& grad, bool rgba );
|
|
|
|
void ReadMorphGradient( swfGradient_t& grad );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
private:
|
|
|
|
bool free;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
const byte* startp;
|
|
|
|
const byte* endp;
|
|
|
|
const byte* readp;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
uint64 currentBit;
|
|
|
|
uint64 currentByte;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
int ReadInternalS( uint64& regCurrentBit, uint64& regCurrentByte, unsigned int numBits );
|
|
|
|
unsigned int ReadInternalU( uint64& regCurrentBit, uint64& regCurrentByte, unsigned int numBits );
|
2012-11-26 18:58:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSWFBitStream::ResetBits
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
ID_INLINE void idSWFBitStream::ResetBits()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
currentBit = 0;
|
|
|
|
currentByte = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
idSWFBitStream::ReadLittle
|
|
|
|
========================
|
|
|
|
*/
|
|
|
|
template< typename T >
|
2012-11-28 15:47:07 +00:00
|
|
|
void idSWFBitStream::ReadLittle( T& val )
|
|
|
|
{
|
|
|
|
val = *( T* )ReadData( sizeof( val ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
idSwap::Little( val );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
========================
|
|
|
|
Wrappers for the most basic types
|
|
|
|
========================
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
ID_INLINE bool idSWFBitStream::ReadBool()
|
|
|
|
{
|
|
|
|
return ( ReadU( 1 ) != 0 );
|
|
|
|
}
|
|
|
|
ID_INLINE uint8 idSWFBitStream::ReadU8()
|
|
|
|
{
|
|
|
|
ResetBits();
|
|
|
|
return *readp++;
|
|
|
|
}
|
|
|
|
ID_INLINE uint16 idSWFBitStream::ReadU16()
|
|
|
|
{
|
|
|
|
ResetBits();
|
|
|
|
readp += 2;
|
|
|
|
return ( readp[-2] | ( readp[-1] << 8 ) );
|
|
|
|
}
|
|
|
|
ID_INLINE uint32 idSWFBitStream::ReadU32()
|
|
|
|
{
|
|
|
|
ResetBits();
|
|
|
|
readp += 4;
|
|
|
|
return ( readp[-4] | ( readp[-3] << 8 ) | ( readp[-2] << 16 ) | ( readp[-1] << 24 ) );
|
|
|
|
}
|
|
|
|
ID_INLINE int16 idSWFBitStream::ReadS16()
|
|
|
|
{
|
|
|
|
ResetBits();
|
|
|
|
readp += 2;
|
|
|
|
return ( readp[-2] | ( readp[-1] << 8 ) );
|
|
|
|
}
|
|
|
|
ID_INLINE int32 idSWFBitStream::ReadS32()
|
|
|
|
{
|
|
|
|
ResetBits();
|
|
|
|
readp += 4;
|
|
|
|
return ( readp[-4] | ( readp[-3] << 8 ) | ( readp[-2] << 16 ) | ( readp[-1] << 24 ) );
|
|
|
|
}
|
|
|
|
ID_INLINE float idSWFBitStream::ReadFixed8()
|
|
|
|
{
|
|
|
|
ResetBits();
|
|
|
|
readp += 2;
|
|
|
|
return SWFFIXED8( ( readp[-2] | ( readp[-1] << 8 ) ) );
|
|
|
|
}
|
|
|
|
ID_INLINE float idSWFBitStream::ReadFixed16()
|
|
|
|
{
|
|
|
|
ResetBits();
|
|
|
|
readp += 4;
|
|
|
|
return SWFFIXED16( ( readp[-4] | ( readp[-3] << 8 ) | ( readp[-2] << 16 ) | ( readp[-1] << 24 ) ) );
|
|
|
|
}
|
|
|
|
ID_INLINE float idSWFBitStream::ReadFloat()
|
|
|
|
{
|
|
|
|
ResetBits();
|
|
|
|
readp += 4;
|
|
|
|
uint32 i = ( readp[-4] | ( readp[-3] << 8 ) | ( readp[-2] << 16 ) | ( readp[-1] << 24 ) );
|
|
|
|
return ( float& )i;
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
ID_INLINE double idSWFBitStream::ReadDouble()
|
|
|
|
{
|
|
|
|
const byte* swfIsRetarded = ReadData( 8 );
|
2012-11-26 18:58:24 +00:00
|
|
|
byte buffer[8];
|
|
|
|
buffer[0] = swfIsRetarded[4];
|
|
|
|
buffer[1] = swfIsRetarded[5];
|
|
|
|
buffer[2] = swfIsRetarded[6];
|
|
|
|
buffer[3] = swfIsRetarded[7];
|
|
|
|
buffer[4] = swfIsRetarded[0];
|
|
|
|
buffer[5] = swfIsRetarded[1];
|
|
|
|
buffer[6] = swfIsRetarded[2];
|
|
|
|
buffer[7] = swfIsRetarded[3];
|
2012-11-28 15:47:07 +00:00
|
|
|
double d = *( double* )buffer;
|
2012-11-26 18:58:24 +00:00
|
|
|
idSwap::Little( d );
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !__SWF_BITSTREAM_H__
|