mirror of
https://github.com/dwsJason/gsla.git
synced 2024-11-21 21:31:39 +00:00
GSLA: WIP
This commit is contained in:
parent
7712398e0c
commit
bb916c15e2
@ -289,7 +289,7 @@ void GSLAFile::UnpackAnimation(GSLA_ANIM* pANIM, GSLA_Header* pHeader)
|
|||||||
//
|
//
|
||||||
// Append a copy of raw image data into the class
|
// Append a copy of raw image data into the class
|
||||||
//
|
//
|
||||||
void GSLA::AddImages( const std::vector<unsigned char*>& pFrameBytes )
|
void GSLAFile::AddImages( const std::vector<unsigned char*>& pFrameBytes )
|
||||||
{
|
{
|
||||||
for (int idx = 0; idx < pFrameBytes.size(); ++idx)
|
for (int idx = 0; idx < pFrameBytes.size(); ++idx)
|
||||||
{
|
{
|
||||||
@ -303,7 +303,7 @@ void GSLA::AddImages( const std::vector<unsigned char*>& pFrameBytes )
|
|||||||
//
|
//
|
||||||
// Compress / Serialize a new GSLA File
|
// Compress / Serialize a new GSLA File
|
||||||
//
|
//
|
||||||
void GSLA::SaveToFile(const char* pFilenamePath)
|
void GSLAFile::SaveToFile(const char* pFilenamePath)
|
||||||
{
|
{
|
||||||
// We're not going to even try encoding an empty file
|
// We're not going to even try encoding an empty file
|
||||||
if (m_pC1PixelMaps.size() < 1)
|
if (m_pC1PixelMaps.size() < 1)
|
||||||
@ -330,11 +330,11 @@ void GSLA::SaveToFile(const char* pFilenamePath)
|
|||||||
pHeader->version = 0x8000; // Version 0, with a Ring/Loop Frame at the end
|
pHeader->version = 0x8000; // Version 0, with a Ring/Loop Frame at the end
|
||||||
|
|
||||||
pHeader->width = m_widthPixels >> 1;
|
pHeader->width = m_widthPixels >> 1;
|
||||||
pHeader->height = m_widthHeight;
|
pHeader->height = m_heightPixels;
|
||||||
|
|
||||||
pHeader->frame_size = m_frameSize;
|
pHeader->frame_size = m_frameSize;
|
||||||
|
|
||||||
pHeader->frame_count = m_pC1PixelMaps.size() + 1; // + 1 for the ring frame
|
pHeader->frame_count = (unsigned int)m_pC1PixelMaps.size() + 1; // + 1 for the ring frame
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
// Add the INITial frame chunk
|
// Add the INITial frame chunk
|
||||||
@ -387,7 +387,7 @@ void GSLA::SaveToFile(const char* pFilenamePath)
|
|||||||
size_t anim_offset = bytes.size();
|
size_t anim_offset = bytes.size();
|
||||||
|
|
||||||
// Add Space for the ANIM Header
|
// Add Space for the ANIM Header
|
||||||
bytes.resize( bytes.size() + sizeof(GLSA_ANIM) );
|
bytes.resize( bytes.size() + sizeof(GSLA_ANIM) );
|
||||||
GSLA_ANIM* pANIM = (GSLA_ANIM*) &bytes[ anim_offset ];
|
GSLA_ANIM* pANIM = (GSLA_ANIM*) &bytes[ anim_offset ];
|
||||||
|
|
||||||
pANIM->A = 'A'; pANIM->N = 'N'; pANIM->I ='I'; pANIM->M = 'M';
|
pANIM->A = 'A'; pANIM->N = 'N'; pANIM->I ='I'; pANIM->M = 'M';
|
||||||
@ -435,11 +435,11 @@ void GSLA::SaveToFile(const char* pFilenamePath)
|
|||||||
bytes.push_back( 0x00 );
|
bytes.push_back( 0x00 );
|
||||||
|
|
||||||
// Update the chunk length
|
// Update the chunk length
|
||||||
pFRAM = (FanFile_FRAM*)&bytes[ fram_offset ];
|
pANIM = (GSLA_ANIM*)&bytes[ anim_offset ];
|
||||||
pFRAM->chunk_length = (unsigned int) (bytes.size() - fram_offset);
|
pANIM->chunk_length = (unsigned int) (bytes.size() - anim_offset);
|
||||||
|
|
||||||
// Update the header
|
// Update the header
|
||||||
pHeader = (FanFile_Header*)&bytes[0]; // Required
|
pHeader = (GSLA_Header*)&bytes[0]; // Required
|
||||||
pHeader->file_length = (unsigned int)bytes.size(); // get some valid data in there
|
pHeader->file_length = (unsigned int)bytes.size(); // get some valid data in there
|
||||||
|
|
||||||
// Try not to leak memory, even though we probably do
|
// Try not to leak memory, even though we probably do
|
||||||
|
@ -575,18 +575,72 @@ void LZB_Decompress(unsigned char* pDest, unsigned char* pSource, int destSize)
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// Encode a Frame in GSLA LZB Format
|
// Compress a Frame in the GSLA LZB Format
|
||||||
//
|
//
|
||||||
int LZBA_Compress(unsigned char* pDest, unsigned char* pSource, int sourceSize, unsigned char* pDataStart, int dictionarySize)
|
int LZBA_Compress(unsigned char* pDest, unsigned char* pSource, int sourceSize,
|
||||||
|
unsigned char* pDataStart, unsigned char* pDictionary,
|
||||||
|
int dictionarySize)
|
||||||
{
|
{
|
||||||
}
|
// printf("LZBA Compress %d bytes\n", sourceSize);
|
||||||
|
|
||||||
|
unsigned char *pOriginalDest = pDest;
|
||||||
|
|
||||||
|
DataString sourceData;
|
||||||
|
DataString dictionaryData;
|
||||||
|
DataString candidateData;
|
||||||
|
|
||||||
|
// Source Data Stream - will compress until the size is zero
|
||||||
|
sourceData.pData = pSource;
|
||||||
|
sourceData.size = sourceSize;
|
||||||
|
|
||||||
|
// Dictionary is the Frame Buffer
|
||||||
|
dictionaryData.pData = pDictionary;
|
||||||
|
dictionaryData.size = dictionarySize;
|
||||||
|
|
||||||
|
// dumb last emit is a literal stuff
|
||||||
|
bool bLastEmitIsLiteral = false;
|
||||||
|
unsigned char* pLastLiteralDest = nullptr;
|
||||||
|
|
||||||
|
while (sourceData.size > 0)
|
||||||
|
{
|
||||||
|
candidateData = LongestMatch(sourceData, dictionaryData);
|
||||||
|
|
||||||
|
// If no match, or the match is too small, then take the next byte
|
||||||
|
// and emit as literal
|
||||||
|
if ((0 == candidateData.size)) // || (candidateData.size < 4))
|
||||||
|
{
|
||||||
|
candidateData.size = 1;
|
||||||
|
candidateData.pData = sourceData.pData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adjust source stream
|
||||||
|
sourceData.pData += candidateData.size;
|
||||||
|
sourceData.size -= candidateData.size;
|
||||||
|
|
||||||
|
dictionaryData.size = AddDictionary(candidateData, dictionaryData.size);
|
||||||
|
|
||||||
|
if (candidateData.size > 3)
|
||||||
|
{
|
||||||
|
// Emit a dictionary reference
|
||||||
|
pDest += (int)EmitReference(pDest, (int)(candidateData.pData - dictionaryData.pData), candidateData);
|
||||||
|
bLastEmitIsLiteral = false;
|
||||||
|
}
|
||||||
|
else if (bLastEmitIsLiteral)
|
||||||
|
{
|
||||||
|
// Concatenate this literal onto the previous literal
|
||||||
|
pDest += ConcatLiteral(pLastLiteralDest, candidateData);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Emit a new literal
|
||||||
|
pLastLiteralDest = pDest;
|
||||||
|
bLastEmitIsLiteral = true;
|
||||||
|
pDest += EmitLiteral(pDest, candidateData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int)(pDest - pOriginalDest);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Decompress a Frame in the GSLA LZB Format
|
|
||||||
//
|
|
||||||
int LZBA_Decompress(unsigned char* pDest, unsigned char* pSource, unsigned char* pDataStart)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
@ -14,7 +14,9 @@ void LZB_Decompress(unsigned char* pDest, unsigned char* pSource, int destSize);
|
|||||||
//
|
//
|
||||||
// LZB Compressor that uses GSLA Opcodes while encoding
|
// LZB Compressor that uses GSLA Opcodes while encoding
|
||||||
//
|
//
|
||||||
int LZBA_Compress(unsigned char* pDest, unsigned char* pSource, int sourceSize, unsigned char* pDataStart, unsigned char* pDictionary, int dictionarySize=0);
|
int LZBA_Compress(unsigned char* pDest, unsigned char* pSource, int sourceSize,
|
||||||
|
unsigned char* pDataStart, unsigned char* pDictionary,
|
||||||
|
int dictionarySize=0);
|
||||||
int LZBA_Decompress(unsigned char* pDest, unsigned char* pSource, unsigned char* pDataStart);
|
int LZBA_Decompress(unsigned char* pDest, unsigned char* pSource, unsigned char* pDataStart);
|
||||||
|
|
||||||
#endif // LZB_H
|
#endif // LZB_H
|
||||||
|
Loading…
Reference in New Issue
Block a user