Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions source/c2_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
28 changes: 17 additions & 11 deletions source/gsla_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{

}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -306,7 +306,7 @@ void GSLAFile::UnpackAnimation(GSLA_ANIM* pANIM, GSLA_Header* pHeader)
//
void GSLAFile::AddImages( const std::vector<unsigned char*>& 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 );
Expand All @@ -318,7 +318,7 @@ void GSLAFile::AddImages( const std::vector<unsigned char*>& 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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion source/gsla_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class GSLAFile
// Creation
GSLAFile(int iWidthPixels, int iHeightPixels, int iFrameSizeBytes);
void AddImages( const std::vector<unsigned char*>& pFrameBytes );
void SaveToFile(const char* pFilenamePath);
void SaveToFile(const char* pFilenamePath, bool bVerbose = false);

// Retrieval
void LoadFromFile(const char* pFilePath);
Expand Down
14 changes: 7 additions & 7 deletions source/lzb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
// }
//}

//------------------------------------------------------------------------------
//
Expand Down
112 changes: 91 additions & 21 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] <input_file> <outfile>\n");
printf("\n\n There are no [options] yet\n");
printf("Converts from C2 to GSLA\n");
printf("\n");
printf("gsla [options] <input_file> <outfile>\n");
printf("-f<fps> | 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);
}
Expand Down Expand Up @@ -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

Expand All @@ -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)
{
Expand Down Expand Up @@ -117,31 +152,66 @@ int main(int argc, char* argv[])

if (pOutfilePath)
{
const std::vector<unsigned char*>& c1Datas = c2data.GetPixelMaps();
int frameCountMultiplier = 60 / encodingFps;

if (encodingFps)
{
const std::vector<unsigned char*>& c1DataOriginal = c2data.GetPixelMaps();
std::vector<unsigned char*> 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<unsigned char *> &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<unsigned char *> &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
}
}

Expand Down
8 changes: 4 additions & 4 deletions vcxproj/gsla.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down