Add animation decode verification code, to make sure things seems to work (hint, they do not work yet)

This commit is contained in:
JASON-6700K\jandersen 2020-07-19 17:58:59 -04:00
parent 1c0f4d5ae3
commit c768f34156
3 changed files with 33 additions and 7 deletions

View File

@ -265,9 +265,9 @@ void GSLAFile::LoadFromFile(const char* pFilePath)
//
void GSLAFile::UnpackInitialFrame(GSLA_INIT* pINIT, GSLA_Header* pHeader)
{
unsigned char *pData = ((unsigned char*)pINIT) + sizeof(GSLA_INIT);
unsigned char* pData = ((unsigned char*)pINIT) + sizeof(GSLA_INIT);
unsigned char *pTargetBuffer = m_pC1PixelMaps[ 0 ]; // Data needs to be pre allocated
unsigned char* pTargetBuffer = m_pC1PixelMaps[ 0 ]; // Data needs to be pre allocated
DecompressFrame(pTargetBuffer, pData, (unsigned char*)pHeader);
}
@ -278,11 +278,21 @@ void GSLAFile::UnpackInitialFrame(GSLA_INIT* pINIT, GSLA_Header* pHeader)
//
void GSLAFile::UnpackAnimation(GSLA_ANIM* pANIM, GSLA_Header* pHeader)
{
unsigned char *pData = ((unsigned char*)pANIM) + sizeof(GSLA_ANIM);
unsigned char* pData = ((unsigned char*)pANIM) + sizeof(GSLA_ANIM);
unsigned char *pTargetBuffer = m_pC1PixelMaps[ 0 ]; // Data needs to be pre allocated
unsigned char *pCanvas = new unsigned char[m_frameSize];
//DecompressAnim(pTargetBuffer, pData);
// Initialize the Canvas with the first frame
memcpy(pCanvas, m_pC1PixelMaps[0], m_frameSize);
for (int idx = 1; idx < m_pC1PixelMaps.size(); ++idx)
{
// Apply Changes to the Canvas
pData += DecompressFrame(pCanvas, pData, (unsigned char*) pHeader);
// Capture the Canvas
memcpy(m_pC1PixelMaps[idx], pCanvas, m_frameSize);
}
}
//------------------------------------------------------------------------------
@ -318,7 +328,7 @@ void GSLAFile::SaveToFile(const char* pFilenamePath)
// Add the header
bytes.resize( bytes.size() + sizeof(GSLA_Header) );
//$$JGA Rememeber, you have to set the pointer, before every access
//$$JGA Remember, you have to set the pointer, before every access
//$$JGA to the header data, because vector is going to change out
//$$JGA memory addresses from underneath you
GSLA_Header* pHeader = (GSLA_Header*)&bytes[0];
@ -567,7 +577,7 @@ int GSLAFile::DecompressFrame(unsigned char* pTarget, unsigned char* pData, unsi
bDoWork = false;
break;
case 2: // End of Animation
case 3: // End of Animation
// Intentionally, leave cursor alone here
bDoWork = false;
break;

View File

@ -124,6 +124,7 @@ public:
int GetFrameCount() { return (int)m_pC1PixelMaps.size(); }
int GetWidth() { return m_widthPixels; }
int GetHeight() { return m_heightPixels; }
int GetFrameSize() { return m_frameSize; }
const std::vector<unsigned char*>& GetPixelMaps() { return m_pC1PixelMaps; }

View File

@ -127,6 +127,21 @@ int main(int argc, char* argv[])
anim.SaveToFile(pOutfilePath);
#if 1
{
// Verify the conversion is good
// Load the file back in
GSLAFile verify(pOutfilePath);
const std::vector<unsigned char *> &frames = verify.GetPixelMaps();
for (int idx = 0; idx < frames.size(); ++idx)
{
int result = memcmp(c1Datas[idx % c1Datas.size()], frames[idx], verify.GetFrameSize());
printf("Verify Frame %d - %s\n", idx, result ? "Failed" : "Good");
}
}
#endif
}
}