Skip to content

Commit

Permalink
background images #1
Browse files Browse the repository at this point in the history
  • Loading branch information
zesinger committed Jun 4, 2023
1 parent 0b561e7 commit c35480d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
46 changes: 41 additions & 5 deletions src/serum-decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ UINT16 nframes;
UINT32 nocolors, nccolors;
UINT32 ncompmasks, nmovmasks;
UINT32 nsprites;
UINT16 nbackgrounds;
// data
UINT32* hashcodes = NULL;
UINT8* shapecompmode = NULL;
Expand All @@ -69,6 +70,9 @@ UINT32* spritedetdwords = NULL;
UINT16* spritedetdwordpos = NULL;
UINT32* triggerIDs = NULL;
UINT16* framespriteBB = NULL;
UINT8* backgroundframes = NULL;
UINT16* backgroundIDs = NULL;
UINT16* backgroundBB = NULL;

// variables
bool cromloaded = false; // is there a crom loaded?
Expand Down Expand Up @@ -219,6 +223,21 @@ void Serum_free(void)
free(triggerIDs);
triggerIDs = NULL;
}
if (backgroundframes)
{
free(backgroundframes);
backgroundframes = NULL;
}
if (backgroundIDs)
{
free(backgroundIDs);
backgroundIDs = NULL;
}
if (backgroundBB)
{
free(backgroundBB);
backgroundBB = NULL;
}
cromloaded = false;
}

Expand Down Expand Up @@ -386,6 +405,8 @@ SERUM_API(bool) Serum_LoadFile(const char* const filename, int* pwidth, int* phe
fread(&ncompmasks, 4, 1, pfile);
fread(&nmovmasks, 4, 1, pfile);
fread(&nsprites, 4, 1, pfile);
if (sizeheader >= 13 * sizeof(UINT)) fread(&nbackgrounds, 4, 1, pfile);
else nbackgrounds = 0;
// allocate memory for the serum format
hashcodes = (UINT32*)malloc(sizeof(UINT32) * nframes);
shapecompmode = (UINT8*)malloc(nframes);
Expand All @@ -407,10 +428,14 @@ SERUM_API(bool) Serum_LoadFile(const char* const filename, int* pwidth, int* phe
spritedetdwordpos = (UINT16*)malloc(nsprites * sizeof(UINT16) * MAX_SPRITE_DETECT_AREAS);
spritedetareas = (UINT16*)malloc(nsprites * sizeof(UINT16) * MAX_SPRITE_DETECT_AREAS * 4);
triggerIDs = (UINT32*)malloc(nframes * sizeof(UINT32));
backgroundframes = (UINT8*)malloc(nbackgrounds * fwidth * fheight);
backgroundIDs = (UINT16*)malloc(nframes * sizeof(UINT16));
backgroundBB = (UINT16*)malloc(nframes * 4 * sizeof(UINT16));
if (!hashcodes || !shapecompmode || !compmaskID || !movrctID || !cpal || !cframes || !dynamasks || !dyna4cols || !framesprites || !framespriteBB || !activeframes || !colorrotations || !triggerIDs ||
(!compmasks && ncompmasks > 0) ||
(!movrcts && nmovmasks > 0) ||
((nsprites > 0) && (!spritedescriptionso || !spritedescriptionsc || !spritedetdwords || !spritedetdwordpos || !spritedetareas)))
((nsprites > 0) && (!spritedescriptionso || !spritedescriptionsc || !spritedetdwords || !spritedetdwordpos || !spritedetareas)) ||
((nbackgrounds > 0) && (!backgroundframes || !backgroundIDs || !backgroundBB)))
{
Serum_free();
fclose(pfile);
Expand Down Expand Up @@ -455,6 +480,13 @@ SERUM_API(bool) Serum_LoadFile(const char* const filename, int* pwidth, int* phe
}
}
}
if (sizeheader >= 13 * sizeof(UINT))
{
fread(backgroundframes, fwidth * fheight, nbackgrounds, pfile);
fread(backgroundIDs, sizeof(UINT16), nframes, pfile);
fread(backgroundBB, 4 * sizeof(UINT16), nframes, pfile);
}
else memset(backgroundIDs, 0xFF, nframes * sizeof(UINT16));
fclose(pfile);
if (pntriggers)
{
Expand Down Expand Up @@ -692,11 +724,15 @@ void Colorize_Frame(UINT8* frame, int IDfound)
// Generate the colorized version of a frame once identified in the crom frames
for (ti = 0; ti < fwidth * fheight; ti++)
{
UINT8 dynacouche = dynamasks[IDfound * fwidth * fheight + ti];
if (dynacouche == 255)
frame[ti] = cframes[IDfound * fwidth * fheight + ti];
if ((backgroundIDs[IDfound] < nbackgrounds) && (frame[ti] == 0)) frame[ti] = backgroundframes[backgroundIDs[IDfound] * fwidth * fheight + ti];
else
frame[ti] = dyna4cols[IDfound * MAX_DYNA_4COLS_PER_FRAME * nocolors + dynacouche * nocolors + frame[ti]];
{
UINT8 dynacouche = dynamasks[IDfound * fwidth * fheight + ti];
if (dynacouche == 255)
frame[ti] = cframes[IDfound * fwidth * fheight + ti];
else
frame[ti] = dyna4cols[IDfound * MAX_DYNA_4COLS_PER_FRAME * nocolors + dynacouche * nocolors + frame[ti]];
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/serum-decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const int MAX_SPRITE_DETECT_AREAS = 4; // maximum number of areas to detect the
const int PALETTE_SIZE = 64 * 3; // size of a palette
const int ROTATION_SIZE = 3 * MAX_COLOR_ROTATIONS; // size of a color rotation block
const int MAX_SPRITE_TO_DETECT = 12; // max number of sprites detected in a frame
const int MAX_BACKGROUND_IMAGES = 255; // max number of background images

SERUM_API(bool) Serum_LoadFile(const char* const filename, int* pwidth, int* pheight, unsigned int* pnocolors, unsigned int* pntriggers);
SERUM_API(bool) Serum_Load(const char* const altcolorpath, const char* const romname, int* pwidth, int* pheight, unsigned int* pnocolors, unsigned int* pntriggers);
Expand Down
4 changes: 2 additions & 2 deletions src/serum-version.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#define SERUM_VERSION_MAJOR 1 // X Digits
#define SERUM_VERSION_MINOR 5 // Max 2 Digits
#define SERUM_VERSION_PATCH 1 // Max 2 Digits
#define SERUM_VERSION_MINOR 6 // Max 2 Digits
#define SERUM_VERSION_PATCH 0 // Max 2 Digits

#define _SERUM_STR(x) #x
#define SERUM_STR(x) _SERUM_STR(x)
Expand Down

0 comments on commit c35480d

Please sign in to comment.