SWF shapes export

This commit is contained in:
Robert Beckebans 2013-11-13 13:59:58 +01:00
parent 038f798f88
commit dd056c4ecc
4 changed files with 38 additions and 33 deletions

View file

@ -46,11 +46,11 @@ idFile_SWF::~idFile_SWF()
int idFile_SWF::BitCountS( const int value )
{
//int nBits = idMath::BitCount( value );
int count = 0;
#if 1
count = idMath::BitCount( value );
#else
int v = value;
while( v > 0 )
{
@ -59,10 +59,11 @@ int idFile_SWF::BitCountS( const int value )
// lower bit is set
count++;
}
// shift bits, remove lower bit
v >>= 1;
}
#endif
return count;
}
@ -110,6 +111,8 @@ int idFile_SWF::EnlargeBitCountU( const int value, int numBits )
int idFile_SWF::Write( const void* buffer, int len )
{
ByteAlign();
return file->Write( buffer, len );
}
@ -169,18 +172,25 @@ void idFile_SWF::WriteU32( uint32 value )
void idFile_SWF::WriteRect( const swfRect_t& rect )
{
int nBits = rect.BitCount();
int tl_x = FLOAT2SWFTWIP( rect.tl.x );
int br_x = FLOAT2SWFTWIP( rect.br.x );
int tl_y = FLOAT2SWFTWIP( rect.tl.y );
int br_y = FLOAT2SWFTWIP( rect.br.y );
int nBits = 0;
nBits = EnlargeBitCountS( tl_x, nBits );
nBits = EnlargeBitCountS( br_x, nBits );
nBits = EnlargeBitCountS( tl_y, nBits );
nBits = EnlargeBitCountS( br_y, nBits );
WriteUBits( nBits, 5 );
WriteSBits( tl_x, nBits );
WriteSBits( br_x, nBits );
WriteSBits( tl_y, nBits );
WriteSBits( br_y, nBits );
ByteAlign();
}
void idFile_SWF::WriteMatrix( const swfMatrix_t& matrix )
@ -239,6 +249,8 @@ void idFile_SWF::WriteMatrix( const swfMatrix_t& matrix )
void idFile_SWF::WriteColorRGB( const swfColorRGB_t& color )
{
ByteAlign();
WriteByte( color.r );
WriteByte( color.g );
WriteByte( color.b );
@ -246,6 +258,8 @@ void idFile_SWF::WriteColorRGB( const swfColorRGB_t& color )
void idFile_SWF::WriteColorRGBA( const swfColorRGBA_t& color )
{
ByteAlign();
WriteByte( color.r );
WriteByte( color.g );
WriteByte( color.b );

View file

@ -269,7 +269,7 @@ void idSWF::WriteSWF( const char* swfFilename, const byte* atlasImageRGBA, int a
{
idSWFShapeDrawFill& fillDraw = shape->fillDraws[d];
if( fillDraw.style.type == 0 )
if( fillDraw.style.type == 0 /* || fillDraw.style.type == 4 */ )
{
numFillDraws++;
}
@ -286,8 +286,15 @@ void idSWF::WriteSWF( const char* swfFilename, const byte* atlasImageRGBA, int a
tag.WriteU16( i ); // characterID
tag.WriteRect( shape->startBounds );
tag.WriteU8( 0xFF );
tag.WriteU16( numFillDraws );
if( numFillDraws >= 0xFF )
{
tag.WriteU8( 0xFF );
tag.WriteU16( numFillDraws );
}
else
{
tag.WriteU8( numFillDraws );
}
for( int d = 0; d < shape->fillDraws.Num(); d++ )
{
@ -296,22 +303,23 @@ void idSWF::WriteSWF( const char* swfFilename, const byte* atlasImageRGBA, int a
if( fillDraw.style.type == 0 )
{
// solid
tag.WriteU8( 0x00 );
tag.WriteColorRGBA( fillDraw.style.startColor );
}
/*
else
if( fillDraw.style.type == 4 )
if( fillDraw.style.type == 4 )
{
//uint8 styleType = ( ( int ) fillDraw.style.type << 4 );
// bitmap
tag.WriteU8( 0x40 );
// bitmap
tag.WriteU16( fillDraw.style.bitmapID );
tag.WriteMatrix( fillDraw.style.startMatrix );
}
*/
// type: 0 = solid, 1 = gradient, 4 = bitmap
//if( fillDraw.style.type == 0 )
@ -340,8 +348,8 @@ void idSWF::WriteSWF( const char* swfFilename, const byte* atlasImageRGBA, int a
}
// TODO
tag.WriteU8( 0xFF );
tag.WriteU16( 0 );
tag.WriteU8( 0 ); // no lines
tag.WriteU8( 1 ); // no shapes
/*
file->WriteBig( shape->lineDraws.Num() );
@ -361,7 +369,7 @@ void idSWF::WriteSWF( const char* swfFilename, const byte* atlasImageRGBA, int a
}
*/
file.WriteTagHeader( Tag_DefineShape3, tag->Length() );
file.WriteTagHeader( Tag_DefineShape3, tagMem->Length() );
file.Write( tagMem->GetDataPtr(), tagMem->Length() );
break;
}

View file

@ -46,20 +46,7 @@ bool idSWF::isMouseInClientArea = false;
extern idCVar in_useJoystick;
// RB begin
int swfRect_t::BitCount() const
{
int num = 0;
num = idFile_SWF::EnlargeBitCountS( FLOAT2SWFTWIP( tl.x ), num );
num = idFile_SWF::EnlargeBitCountS( FLOAT2SWFTWIP( tl.y ), num );
num = idFile_SWF::EnlargeBitCountS( FLOAT2SWFTWIP( br.x ), num );
num = idFile_SWF::EnlargeBitCountS( FLOAT2SWFTWIP( br.x ), num );
return num;
}
// RB end
/*
===================

View file

@ -67,10 +67,6 @@ struct swfRect_t
swfRect_t();
idVec2 tl;
idVec2 br;
// RB begin
int BitCount() const;
// RB end
};
struct swfMatrix_t
{