diff --git a/source/c2_file.cpp b/source/c2_file.cpp index 789c08e..038a430 100644 --- a/source/c2_file.cpp +++ b/source/c2_file.cpp @@ -35,7 +35,7 @@ C2File::C2File(const char *pFilePath) C2File::~C2File() { // Free Up the memory - for (int idx = 0; idx < m_pC1PixelMaps.size(); ++idx) + for (unsigned int idx = 0; idx < m_pC1PixelMaps.size(); ++idx) { delete[] m_pC1PixelMaps[idx]; m_pC1PixelMaps[ idx ] = nullptr; @@ -47,7 +47,7 @@ C2File::~C2File() void C2File::LoadFromFile(const char* pFilePath) { // Free Up the memory - for (int idx = 0; idx < m_pC1PixelMaps.size(); ++idx) + for (unsigned int idx = 0; idx < m_pC1PixelMaps.size(); ++idx) { delete[] m_pC1PixelMaps[idx]; m_pC1PixelMaps[ idx ] = nullptr; @@ -62,7 +62,7 @@ void C2File::LoadFromFile(const char* pFilePath) // Read the file into memory FILE* pFile = nullptr; #ifdef _WIN32 - errno_t err = fopen_s(&pFile, pFilePath, "wb"); + errno_t err = fopen_s(&pFile, pFilePath, "rb"); #else pFile = fopen(pFilePath, "rb"); errno_t err = (pFile == nullptr) ? errno : 0; diff --git a/source/gsla_file.cpp b/source/gsla_file.cpp index fe55649..489d7ca 100644 --- a/source/gsla_file.cpp +++ b/source/gsla_file.cpp @@ -151,9 +151,9 @@ GSLAFile::GSLAFile(const char *pFilePath) //------------------------------------------------------------------------------ GSLAFile::GSLAFile(int iWidthPixels, int iHeightPixels, int iFrameSizeBytes ) - : m_widthPixels(iWidthPixels) + : m_frameSize( iFrameSizeBytes ) + , m_widthPixels(iWidthPixels) , m_heightPixels(iHeightPixels) - , m_frameSize( iFrameSizeBytes ) { } @@ -163,7 +163,7 @@ GSLAFile::GSLAFile(int iWidthPixels, int iHeightPixels, int iFrameSizeBytes ) GSLAFile::~GSLAFile() { // Free Up the memory - for (int idx = 0; idx < m_pC1PixelMaps.size(); ++idx) + for (unsigned int idx = 0; idx < m_pC1PixelMaps.size(); ++idx) { delete[] m_pC1PixelMaps[idx]; m_pC1PixelMaps[ idx ] = nullptr; @@ -175,7 +175,7 @@ GSLAFile::~GSLAFile() void GSLAFile::LoadFromFile(const char* pFilePath) { // Free Up the memory - for (int idx = 0; idx < m_pC1PixelMaps.size(); ++idx) + for (unsigned int idx = 0; idx < m_pC1PixelMaps.size(); ++idx) { delete[] m_pC1PixelMaps[idx]; m_pC1PixelMaps[ idx ] = nullptr; @@ -190,7 +190,7 @@ void GSLAFile::LoadFromFile(const char* pFilePath) // Read the file into memory FILE* pFile = nullptr; #ifdef _WIN32 - errno_t err = fopen_s(&pFile, pFilePath, "wb"); + errno_t err = fopen_s(&pFile, pFilePath, "rb"); #else pFile = fopen(pFilePath, "rb"); errno_t err = (pFile == nullptr) ? errno : 0; @@ -290,7 +290,7 @@ void GSLAFile::UnpackAnimation(GSLA_ANIM* pANIM, GSLA_Header* pHeader) // Initialize the Canvas with the first frame memcpy(pCanvas, m_pC1PixelMaps[0], m_frameSize); - for (int idx = 1; idx < m_pC1PixelMaps.size(); ++idx) + for (unsigned int idx = 1; idx < m_pC1PixelMaps.size(); ++idx) { // Apply Changes to the Canvas pData += DecompressFrame(pCanvas, pData, (unsigned char*) pHeader); @@ -306,7 +306,7 @@ void GSLAFile::UnpackAnimation(GSLA_ANIM* pANIM, GSLA_Header* pHeader) // void GSLAFile::AddImages( const std::vector& pFrameBytes ) { - for (int idx = 0; idx < pFrameBytes.size(); ++idx) + for (unsigned int idx = 0; idx < pFrameBytes.size(); ++idx) { unsigned char* pPixels = new unsigned char[ m_frameSize ]; memcpy(pPixels, pFrameBytes[ idx ], m_frameSize ); @@ -318,7 +318,7 @@ void GSLAFile::AddImages( const std::vector& pFrameBytes ) // // Compress / Serialize a new GSLA File // -void GSLAFile::SaveToFile(const char* pFilenamePath) +void GSLAFile::SaveToFile(const char* pFilenamePath, bool bVerbose) { // We're not going to even try encoding an empty file if (m_pC1PixelMaps.size() < 1) @@ -416,9 +416,12 @@ void GSLAFile::SaveToFile(const char* pFilenamePath) memcpy(pCanvas, m_pC1PixelMaps[0], m_frameSize); // Let's encode some frames buddy - for (int frameIndex = 1; frameIndex < m_pC1PixelMaps.size(); ++frameIndex) + for (unsigned int frameIndex = 1; frameIndex < m_pC1PixelMaps.size(); ++frameIndex) { - printf("Save Frame %d\n", frameIndex+1); + if (bVerbose) + { + printf("Save Frame %d\n", frameIndex + 1); + } // I don't want random data in the bank gaps, so initialize this // buffer with zero @@ -433,7 +436,10 @@ void GSLAFile::SaveToFile(const char* pFilenamePath) //{ // printf("Canvas is not correct - %d\n", canvasDiff); //} - printf("frameSize = %d\n", frameSize); + if (bVerbose) + { + printf("frameSize = %d\n", frameSize); + } for (int frameIndex = 0; frameIndex < frameSize; ++frameIndex) diff --git a/source/gsla_file.h b/source/gsla_file.h index d51e345..cfd2dd2 100644 --- a/source/gsla_file.h +++ b/source/gsla_file.h @@ -117,7 +117,7 @@ class GSLAFile // Creation GSLAFile(int iWidthPixels, int iHeightPixels, int iFrameSizeBytes); void AddImages( const std::vector& pFrameBytes ); - void SaveToFile(const char* pFilenamePath); + void SaveToFile(const char* pFilenamePath, bool bVerbose = false); // Retrieval void LoadFromFile(const char* pFilePath); diff --git a/source/lzb.cpp b/source/lzb.cpp index 4ce97cf..1ee2e49 100644 --- a/source/lzb.cpp +++ b/source/lzb.cpp @@ -703,13 +703,13 @@ static int EmitReference(unsigned char *pDest, int dictionaryOffset, DataString& // Std C memcpy seems to be stopping the copy from happening, when I overlap // the buffer to get a pattern run copy (overlapped buffers) // -static void my_memcpy(u8* pDest, u8* pSrc, int length) -{ - while (length-- > 0) - { - *pDest++ = *pSrc++; - } -} +//static void my_memcpy(u8* pDest, u8* pSrc, int length) +//{ +// while (length-- > 0) +// { +// *pDest++ = *pSrc++; +// } +//} //------------------------------------------------------------------------------ // diff --git a/source/main.cpp b/source/main.cpp index e780553..77b97af 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -14,13 +14,15 @@ //------------------------------------------------------------------------------ static void helpText() { - printf("GSLA - v1.0\n"); + printf("GSLA - v1.01\n"); printf("--------------\n"); printf("GS Lzb Animation Creation Tool\n"); - printf("\n"); - printf("\ngsla [options] \n"); - printf("\n\n There are no [options] yet\n"); printf("Converts from C2 to GSLA\n"); + printf("\n"); + printf("gsla [options] \n"); + printf("-f | Set the intended fps [*60,30,20,15,12,10,6,5,1]\n"); + printf("-v | Verbose\n"); + printf("* indicates default setting\n"); exit(-1); } @@ -60,7 +62,8 @@ int main(int argc, char* argv[]) { char* pInfilePath = nullptr; char* pOutfilePath = nullptr; - + int encodingFps = 60; + bool bVerbose = false; // index 0 is the executable name @@ -74,6 +77,38 @@ int main(int argc, char* argv[]) { // Parse as an option // Currently I have no options, so I'll just skip + switch (arg[1]) + { + case 'f': + case 'F': // set fps + { + #ifdef _WIN32 + sscanf_s(&arg[2], "%d", &encodingFps); + #else + sscanf(&arg[2], "%d", &encodingFps); + #endif + + if ((encodingFps < 1) || (encodingFps > 60)) + { + printf("Invalide Encoding FPS: %d\n", encodingFps); + helpText(); + } + + printf("Requested Encoding Speed = %dFPS\n", encodingFps); + + } + break; + + case 'v': + case 'V': // verbose + bVerbose = true; + break; + + default: + printf("Unknown Option: %s\n", arg); + helpText(); + break; + } } else if (nullptr == pInfilePath) { @@ -117,31 +152,66 @@ int main(int argc, char* argv[]) if (pOutfilePath) { - const std::vector& c1Datas = c2data.GetPixelMaps(); + int frameCountMultiplier = 60 / encodingFps; + + if (encodingFps) + { + const std::vector& c1DataOriginal = c2data.GetPixelMaps(); + std::vector c1Datas; + + if (frameCountMultiplier > 1) + { + printf("Encoding Speed %dFPS / FrameCount Multiplier = %d\n", encodingFps, frameCountMultiplier); + printf("C2 with %d frames becomes %d frames\n", c2data.GetFrameCount(), c2data.GetFrameCount() * frameCountMultiplier); + } + + // quick copy the c1Data, add extra frames to compensate for requested framerate + for (unsigned int frameIndex = 0; frameIndex < c1DataOriginal.size(); ++frameIndex) + { + for (int multiplier = 0; multiplier < frameCountMultiplier; ++multiplier) + { + c1Datas.push_back(c1DataOriginal[frameIndex]); + } + } - printf("Saving %s with %d frames\n", pOutfilePath, (int)c1Datas.size()); - GSLAFile anim(320,200, 0x8000); + printf("Saving %s with %d frames\n", pOutfilePath, (int)c1Datas.size()); - anim.AddImages(c1Datas); - - anim.SaveToFile(pOutfilePath); + GSLAFile anim(320,200, 0x8000); - #if 1 - { - // Verify the conversion is good - // Load the file back in - GSLAFile verify(pOutfilePath); + anim.AddImages(c1Datas); - const std::vector &frames = verify.GetPixelMaps(); + anim.SaveToFile(pOutfilePath, bVerbose); - for (int idx = 0; idx < frames.size(); ++idx) + bool bSuccess = true; { - int result = memcmp(c1Datas[idx % c1Datas.size()], frames[idx], verify.GetFrameSize()); - printf("Verify Frame %d - %s\n", idx, result ? "Failed" : "Good"); + // Verify the conversion is good + // Load the file back in + GSLAFile verify(pOutfilePath); + + const std::vector &frames = verify.GetPixelMaps(); + + for (unsigned int idx = 0; idx < frames.size(); ++idx) + { + int result = memcmp(c1Datas[idx % c1Datas.size()], frames[idx], verify.GetFrameSize()); + if (bVerbose) + { + printf("Verify Frame %d - %s\n", idx, result ? "Failed" : "Good"); + } + else if (result) + { + printf("Verify Frame %d - Failed\n", idx); + } + + if (result) + { + bSuccess = false; + } + } } + + printf("%s\n", bSuccess ? "Success" : "Failed"); } - #endif } } diff --git a/vcxproj/gsla.vcxproj b/vcxproj/gsla.vcxproj index 24ac719..3912a6f 100644 --- a/vcxproj/gsla.vcxproj +++ b/vcxproj/gsla.vcxproj @@ -29,26 +29,26 @@ Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode