#include <libsswf.h>
Public Member Functions | |
void | Align (void) |
Align the buffer position to the next byte. | |
void | Append (const Data &append) |
Append another Data buffer. | |
unsigned long | ByteSize (void) const |
Returns the size of the buffer in bytes. | |
Data (void) | |
Initialize a Data buffer. | |
void | Empty (void) |
Reset the size. | |
unsigned long | GetSize (void) const |
Returns the current size of the buffer. | |
void | Overwrite (size_t offset, const void *ptr, size_t size) |
Overwrite data at the specified offset. | |
void | OverwriteByte (size_t offset, char c) |
Overwrite data at the specified offset. | |
void | OverwriteLong (size_t offset, long l) |
Overwrite data at the specified offset. | |
void | OverwriteShort (size_t offset, short s) |
Overwrite data at the specified offset. | |
void | PutByte (char c) |
Save one byte. | |
void | PutDLong (int64_t ll) |
Save one 64 bits long. | |
void | PutDoubleFloat (double f) |
Save one 64 bits floating point in IEEE format. | |
void | PutLong (long l) |
Save one 32 bits long. | |
void | PutLongFloat (float f) |
Save one 32 bits floating point in IEEE format. | |
void | PutShort (short s) |
Save one short. | |
void | PutShortFloat (float f) |
Save one 16 bits floating point in IEEE format. | |
void | PutString (const char *string) |
Save one string. | |
void | Read (void *&ptr, size_t &size) |
Read the data buffer information. | |
void | SetSize (unsigned long size) |
Set the size in bits. | |
void | Write (const void *ptr, size_t size) |
Write data at the end of the buffer. | |
void | WriteBits (long value, size_t bits) |
Write bits at the end of the buffer. | |
~Data () | |
Cleanup a Data buffer. | |
Private Member Functions | |
void | AdjustSize (size_t size) |
Make sure that the buffer is at least of that size. | |
Private Attributes | |
char * | f_data |
unsigned long | f_pos |
unsigned long | f_size |
It grows as required and has functions specific to SWF such as Align() and WriteBits().
Data::Data | ( | void | ) |
Data::~Data | ( | ) |
This function does nothing since the memory used by the Data buffer is managed by the memory manager directly.
void Data::AdjustSize | ( | size_t | size | ) | [private] |
This function ensures that the output buffer is at least of the specified number of bits (notice: BITS, bot BYTES.)
This is used to create a buffer for a tag that can later be modified with the Overwrite functions.
[in] | size | The new buffer size in bits |
References f_data, f_pos, f_size, and sswf::MemoryManager::MemRealloc().
Referenced by Append(), Write(), and WriteBits().
void Data::Align | ( | void | ) |
Whenever writing an SWF movie, it is most often compressed on bytes and quite often on bits. Whenever bits are used to save one structure (such as a rectangle), the following data which are aligned on a byte need to appear on a byte.
This function ensures that this is indeed the case.
This function can safely be called multiple times in a raw. The position will be adjusted only the first time and only if necessary.
References f_pos.
Referenced by Append(), sswf::TagFont::PreSave2ndPass(), Read(), sswf::Matrix::Save(), sswf::ColorTransform::Save(), sswf::TagText::Save(), sswf::TagShape::Save(), sswf::TagHeader::Save(), sswf::TagFont::Save(), sswf::TagEditText::Save(), sswf::Style::Save(), and Write().
void Data::Append | ( | const Data & | data | ) |
This function appends a Data buffer to this Data buffer.
The source Data buffer is not modified.
The destination is first aligned with a call to Align(). The buffer is grown as required, then the source is copied at the end of the destination.
[in] | data | The source Data buffer |
References AdjustSize(), Align(), f_data, and f_pos.
Referenced by sswf::TagScalingGrid::GridSave(), sswf::TagText::Save(), sswf::TagSprite::Save(), sswf::TagSound::Save(), sswf::TagStartSound::Save(), sswf::TagShape::Save(), sswf::TagPlace::Save(), sswf::TagImport::Save(), sswf::TagImage::Save(), sswf::TagHeader::Save(), sswf::TagFont::Save(), sswf::TagExport::Save(), sswf::TagEditText::Save(), sswf::TagDoAction::Save(), sswf::TagButton::Save(), sswf::Action::Save(), sswf::ActionTry::SaveData(), and sswf::TagShape::SaveWithoutStyles().
sswf::Data::ByteSize | ( | void | ) | const [inline] |
Returns the size of the buffer in bytes. The exact size of the buffer is in bits. The byte size is the bit size rounded up.
References f_pos.
Referenced by sswf::TagScalingGrid::GridSave(), sswf::TagFont::PreSave2ndPass(), sswf::TagText::Save(), sswf::TagSprite::Save(), sswf::TagSound::Save(), sswf::TagStartSound::Save(), sswf::TagShape::Save(), sswf::TagPlace::Save(), sswf::TagImport::Save(), sswf::TagImage::Save(), sswf::TagHeader::Save(), sswf::TagFont::Save(), sswf::TagExport::Save(), sswf::TagEditText::Save(), sswf::TagDoAction::Save(), sswf::TagButton::Save(), sswf::Action::Save(), sswf::ActionWith::SaveData(), sswf::ActionTry::SaveData(), sswf::ActionFunction::SaveData(), and sswf::Action::SaveList().
sswf::Data::Empty | ( | void | ) | [inline] |
This function marks the Data buffer as empty.
All the data previously saved in this buffer is lost.
References f_pos.
Referenced by sswf::TagFont::PreSave2ndPass(), sswf::TagPlace::Save(), sswf::TagFont::Save(), and sswf::TagButton::Save().
sswf::Data::GetSize | ( | void | ) | const [inline] |
Returns the size of the buffer in bits. This is the exact position in the buffer.
In general, one needs to call ByteSize() instead.
References f_pos.
Referenced by sswf::Action::Save(), and sswf::ActionTry::SaveData().
void Data::Overwrite | ( | size_t | offset, | |
const void * | ptr, | |||
size_t | size | |||
) |
This function is used to overwrite data at offset on size bytes with the data pointed by ptr. This function will not enlarge the Data buffer and thus is must be used to overwrite only.
References sswf::assert(), f_data, and f_pos.
void Data::OverwriteByte | ( | size_t | offset, | |
char | c | |||
) |
This function is used to overwrite one byte at the specified offset. This function will not enlarge the Data buffer and thus is must be used to overwrite only.
References sswf::assert(), f_data, and f_pos.
void Data::OverwriteLong | ( | size_t | offset, | |
long | l | |||
) |
This function is used to overwrite one long at the specified offset (i.e. 4 bytes). This function will not enlarge the Data buffer and thus is must be used to overwrite only.
The long value is saved in little endian (least significant byte first.)
References sswf::assert(), f_data, and f_pos.
void Data::OverwriteShort | ( | size_t | offset, | |
short | s | |||
) |
This function is used to overwrite one short at the specified offset. This function will not enlarge the Data buffer and thus is must be used to overwrite only.
The short value is saved in little endian (least significant byte first.)
References sswf::assert(), f_data, and f_pos.
Referenced by sswf::TagSprite::Save(), and sswf::ActionBranch::Save2ndPass().
void Data::PutByte | ( | char | c | ) |
This is a convenient function used to save one byte in the Data buffer.
This function implicitly calls Align().
[in] | c | The byte to save |
References Write().
Referenced by PutDLong(), PutLong(), PutShort(), PutString(), sswf::Color::Save(), sswf::TagText::Save(), sswf::SoundInfo::Save(), sswf::TagShape::Save(), sswf::TagSetBackgroundColor::Save(), sswf::TagPlace::Save(), sswf::TagProductInfo::Save(), sswf::TagImport::Save(), sswf::TagImage::Save(), sswf::TagHeader::Save(), sswf::TagFrameLabel::Save(), sswf::TagFont::Save(), sswf::TagEditText::Save(), sswf::TagButton::Save(), sswf::State::Save(), sswf::Style::Save(), sswf::BlendMode::Save(), sswf::Action::Save(), sswf::TagCSMTextSettings::SaveCSMTextSettings(), sswf::ActionWaitForFrame::SaveData(), sswf::ActionURL::SaveData(), sswf::ActionTry::SaveData(), sswf::ActionStrictMode::SaveData(), sswf::ActionStoreRegister::SaveData(), sswf::ActionPushData::SaveData(), sswf::ActionFunction::SaveData(), sswf::TagHeader::SaveEncodedString(), sswf::Action::SaveList(), sswf::TagShape::SaveStyles(), sswf::TagShape::SaveStylesCount(), sswf::TagShape::SaveWithoutStyles(), and sswfWriteData().
void Data::PutDLong | ( | int64_t | ll | ) |
This is a convenient function used to save one 64 bits long in the Data buffer.
The long least significant byte is saved first.
This function implicitly calls Align().
[in] | ll | The 64 bits long to save |
References PutByte().
Referenced by PutDoubleFloat(), and sswf::TagProductInfo::Save().
void Data::PutDoubleFloat | ( | double | d | ) |
This is a convenient function used to save a 64 bits floating point.
[in] | d | The floating point to save |
References PutDLong().
void Data::PutLong | ( | long | l | ) |
This is a convenient function used to save one long in the Data buffer.
The long least significant byte is saved first.
This function implicitly calls Align().
[in] | l | The long to save |
References PutByte().
Referenced by PutLongFloat(), sswf::TagSound::Save(), sswf::SoundInfo::Save(), sswf::Envelope::Save(), sswf::TagShape::Save(), sswf::TagPlace::Save(), sswf::TagInfo::Save(), sswf::TagProductInfo::Save(), sswf::TagImage::Save(), sswf::TagHeader::Save(), sswf::TagBinaryData::Save(), sswf::ActionPushData::SaveData(), and sswf::TagBase::SaveTag().
void Data::PutLongFloat | ( | float | f | ) |
This is a convenient function used to save a 32 bits floating point.
[in] | f | The floating point to save |
References PutLong().
Referenced by sswf::TagCSMTextSettings::SaveCSMTextSettings().
void Data::PutShort | ( | short | s | ) |
This is a convenient function used to save one short in the Data buffer.
The short least significant byte is saved first.
This function implicitly calls Align().
[in] | s | The short to save |
References PutByte().
Referenced by sswf::TagScalingGrid::GridSave(), PutShortFloat(), sswf::TagText::Save(), sswf::TagSprite::Save(), sswf::TagSound::Save(), sswf::SoundInfo::Save(), sswf::Envelope::Save(), sswf::TagSetTabIndex::Save(), sswf::TagScriptLimits::Save(), sswf::TagRemove::Save(), sswf::TagProtect::Save(), sswf::TagPlace::Save(), sswf::TagImport::Save(), sswf::TagImage::Save(), sswf::TagHeader::Save(), sswf::TagFont::Save(), sswf::TagExport::Save(), sswf::TagEditText::Save(), sswf::TagDoAction::Save(), sswf::TagButton::Save(), sswf::State::Save(), sswf::Style::Save(), sswf::Action::Save(), sswf::ActionWith::SaveData(), sswf::ActionWaitForFrame::SaveData(), sswf::ActionTry::SaveData(), sswf::ActionPushData::SaveData(), sswf::ActionGoto::SaveData(), sswf::ActionFunction::SaveData(), sswf::ActionDictionary::SaveData(), sswf::ActionBranch::SaveData(), sswf::TagBaseID::SaveID(), sswf::TagShape::SaveStylesCount(), and sswf::TagBase::SaveTag().
void Data::PutShortFloat | ( | float | f | ) |
This is a convenient function used to save a floating point on 16 bits. This is not a fixed point value, it really is a floating point defined as:
[in] | f | The floating point to convert and save |
References PutShort().
Referenced by sswf::TagShape::SaveAlignZone().
void Data::PutString | ( | const char * | string | ) |
This is a convenient function used to save a string in the Data buffer.
It is valid to call the function with a NULL pointer. It is considered to be an empty string and just one zero byte is written.
Otherwise, strlen(string) + 1 bytes are saved (i.e. the string characters and the nul terminator.)
This function implicitly calls Align().
[in] | string | The string to save |
References PutByte(), and Write().
Referenced by sswf::TagHeader::SaveEncodedString().
void Data::Read | ( | void *& | ptr, | |
size_t & | size | |||
) |
This function can be used to get access to the internal buffer pointer and size.
In general, this function is used at the end to save the Data buffer in a file.
This function implicitly calls Align().
[out] | ptr | Receives the Data buffer pointer |
[out] | size | Receives the size in bytes of the buffer pointer |
References Align(), f_data, and f_pos.
Referenced by sswf::TagHeader::Save().
void Data::SetSize | ( | unsigned long | size | ) |
This function can be used to shrink the buffer.
This is used after an AdjustSize() with a size which was too large.
In general, because the resulting size is determined after compression.
[in] | size | The new bit size of the buffer |
References sswf::assert(), and f_pos.
Referenced by sswf::Action::Save(), and sswf::ActionTry::SaveData().
void Data::Write | ( | const void * | ptr, | |
size_t | size | |||
) |
This function writes size bytes from ptr at the end of the buffer. It automatically calls Align() to make sure that the alignment is correct.
[in] | ptr | The pointer to the data to append |
[in] | size | The number of bytes to append |
References AdjustSize(), Align(), f_data, and f_pos.
Referenced by PutByte(), PutString(), sswf::TagSound::Save(), sswf::TagSceneFrameData::Save(), sswf::TagProtect::Save(), sswf::TagMetadata::Save(), sswf::TagImage::Save(), sswf::TagHeader::Save(), sswf::TagFont::Save(), sswf::TagBinaryData::Save(), and sswfWriteData().
void Data::WriteBits | ( | long | value, | |
size_t | bits | |||
) |
This function writes the specified number of bits from the specified value.
The least significant bits of value are used. Thus, a 1 bit value is defined as 0 or 1. A 2 bits value is defined as 0, 1, 2 or 3. And so on...
It is valid to save up to 31 bits with this function. In debug mode, the function asserts if it looks like the parameters are invalid.
[in] | value | The value of which bits are saved |
[in] | bits | The number of bits to be saved |
References AdjustSize(), sswf::assert(), f_data, and f_pos.
Referenced by sswf::Matrix::Save(), sswf::ColorTransform::Save(), sswf::SRectangle::Save(), sswf::TagText::Save(), sswf::TagSound::Save(), sswf::SoundInfo::Save(), sswf::TagShape::Save(), sswf::TagPlace::Save(), sswf::TagHeader::Save(), sswf::TagFont::Save(), sswf::TagEditText::Save(), sswf::Style::Save(), sswf::TagCSMTextSettings::SaveCSMTextSettings(), sswf::ActionTry::SaveData(), sswf::Edges::SaveEdge(), sswf::TagShape::SaveSetup(), sswf::TagShape::SaveShape(), and sswf::TagShape::SaveWithoutStyles().
char* sswf::Data::f_data [private] |
Referenced by AdjustSize(), Append(), Data(), Overwrite(), OverwriteByte(), OverwriteLong(), OverwriteShort(), Read(), Write(), and WriteBits().
unsigned long sswf::Data::f_pos [private] |
Referenced by AdjustSize(), Align(), Append(), ByteSize(), Data(), Empty(), GetSize(), Overwrite(), OverwriteByte(), OverwriteLong(), OverwriteShort(), Read(), SetSize(), Write(), and WriteBits().
unsigned long sswf::Data::f_size [private] |
Referenced by AdjustSize(), and Data().