Skip to content

Commit

Permalink
Type fixes (#34)
Browse files Browse the repository at this point in the history
fix wrong types
  • Loading branch information
mkalkbrenner authored May 22, 2023
1 parent 40fb09c commit 30b3aec
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/serum-decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const int IDENTIFY_NO_FRAME = -1;
// header
char rname[64];
UINT32 fwidth, fheight;
UINT32 nframes;
UINT16 nframes;
UINT32 nocolors, nccolors;
UINT32 ncompmasks, nmovmasks;
UINT32 nsprites;
Expand Down Expand Up @@ -72,7 +72,7 @@ UINT16* framespriteBB = NULL;

// variables
bool cromloaded = false; // is there a crom loaded?
UINT32 lastfound = 0; // last frame ID identified
UINT16 lastfound = 0; // last frame ID identified
UINT8* lastframe = NULL; // last frame content identified
UINT32 lastframe_found = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
UINT32 lastframe_full_crc = 0;
Expand Down Expand Up @@ -370,7 +370,10 @@ SERUM_API(bool) Serum_LoadFile(const char* const filename, int* pwidth, int* phe
fread(&sizeheader, 4, 1, pfile);
fread(&fwidth, 4, 1, pfile);
fread(&fheight, 4, 1, pfile);
fread(&nframes, 4, 1, pfile);
// The serum file stored the number of frames as UINT32, but in fact, the number of frames will never exceed the size of UINT16 (65535)
UINT32 nframes32;
fread(&nframes32, 4, 1, pfile);
nframes = (UINT16) nframes32;
fread(&nocolors, 4, 1, pfile);
fread(&nccolors, 4, 1, pfile);
if ((fwidth == 0) || (fheight == 0) || (nframes == 0) || (nocolors == 0) || (nccolors == 0))
Expand Down Expand Up @@ -516,15 +519,15 @@ SERUM_API(void) Serum_Dispose(void)
Serum_free();
}

int Identify_Frame(UINT8* frame)
int32_t Identify_Frame(UINT8* frame)
{
// Usually the first frame has the ID 0, but lastfound is also initialized with 0. So we ned a helper to be able to detect frame 0 as new.
static bool first_match = true;

if (!cromloaded) return -1;
if (!cromloaded) return IDENTIFY_NO_FRAME;
UINT8* pmask;
memset(framechecked, false, nframes);
UINT32 tj = lastfound; // we start from the frame we last found
UINT16 tj = lastfound; // we start from the frame we last found
UINT pixels = fwidth * fheight;
do
{
Expand All @@ -541,7 +544,7 @@ int Identify_Frame(UINT8* frame)
}
else Hashc = crc32_fast(frame, pixels, Shape);
// now we can compare with all the crom frames that share these same mask and shapemode
UINT32 ti = tj;
UINT16 ti = tj;
do
{
if (!framechecked[ti])
Expand Down Expand Up @@ -685,7 +688,7 @@ bool Check_Sprites(UINT8* Frame, int quelleframe, UINT8* pquelsprites, UINT8* ns

void Colorize_Frame(UINT8* frame, int IDfound)
{
UINT32 ti;
UINT16 ti;
// Generate the colorized version of a frame once identified in the crom frames
for (ti = 0; ti < fwidth * fheight; ti++)
{
Expand All @@ -699,9 +702,9 @@ void Colorize_Frame(UINT8* frame, int IDfound)

void Colorize_Sprite(UINT8* frame, UINT8 nosprite, UINT16 frx, UINT16 fry, UINT16 spx, UINT16 spy, UINT16 wid, UINT16 hei)
{
for (UINT tj = 0; tj < hei; tj++)
for (UINT16 tj = 0; tj < hei; tj++)
{
for (UINT ti = 0; ti < wid; ti++)
for (UINT16 ti = 0; ti < wid; ti++)
{
if (spritedescriptionso[(nosprite * MAX_SPRITE_SIZE + tj + spy) * MAX_SPRITE_SIZE + ti + spx] < 255)
{
Expand Down Expand Up @@ -737,7 +740,7 @@ SERUM_API(void) Serum_SetStandardPalette(const UINT8* palette, const int bitDept
}
}

SERUM_API(bool) Serum_ColorizeWithMetadata(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID, UINT32* hashcode, int* frameID)
SERUM_API(bool) Serum_ColorizeWithMetadata(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID, UINT32* hashcode, int32_t* frameID)
{
if (triggerID)
{
Expand Down Expand Up @@ -841,7 +844,7 @@ SERUM_API(bool) Serum_ColorizeWithMetadata(UINT8* frame, int width, int height,
SERUM_API(bool) Serum_Colorize(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32 *triggerID)
{
UINT32 hashcode;
int frameID;
int32_t frameID;
return Serum_ColorizeWithMetadata(frame, width, height, palette, rotations, triggerID, &hashcode, &frameID);
}

Expand Down Expand Up @@ -873,7 +876,7 @@ SERUM_API(bool) Serum_ApplyRotations(UINT8* palette, UINT8* rotations)
return isrotation;
}

SERUM_API(bool) Serum_ColorizeWithMetadataOrApplyRotations(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID, UINT32* hashcode, int* frameID)
SERUM_API(bool) Serum_ColorizeWithMetadataOrApplyRotations(UINT8* frame, int width, int height, UINT8* palette, UINT8* rotations, UINT32* triggerID, UINT32* hashcode, int32_t* frameID)
{
bool new_frame = Serum_ColorizeWithMetadata(frame, width, height, palette, rotations, triggerID, hashcode, frameID);
if (!new_frame) {
Expand All @@ -884,11 +887,12 @@ SERUM_API(bool) Serum_ColorizeWithMetadataOrApplyRotations(UINT8* frame, int wid

SERUM_API(bool) Serum_ColorizeOrApplyRotations(UINT8* frame, int width, int height, UINT8* palette, UINT32 *triggerID)
{
static UINT8 rotations[24];
if (frame)
{
static UINT8 rotations[24] = { 255 };
memset(rotations, 255, 24);
UINT32 hashcode;
int frameID;
int32_t frameID;
bool new_frame = Serum_ColorizeWithMetadataOrApplyRotations(frame, width, height, palette, rotations, triggerID, &hashcode, &frameID);
if (new_frame)
{
Expand Down

0 comments on commit 30b3aec

Please sign in to comment.