Skip to content

Commit

Permalink
add paletteSave()
Browse files Browse the repository at this point in the history
  • Loading branch information
tehKaiN committed Apr 16, 2024
1 parent 7b7d47f commit f30b8fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/ace/utils/palette.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ extern "C" {
*/
void paletteLoad(const char *szFileName, UWORD *pPalette, UBYTE ubMaxLength);

/**
* @brief Saves given palette into .plt file.
* @param pPalette Palette to save.
* @param ubColorCnt Number of colors in palette.
* @param szPath Destination path.
*/
void paletteSave(UWORD *pPalette, UBYTE ubColorCnt, char *szPath);

/**
* @brief Loads palette from supplied .plt stored in memory to given address.
* @param pData Palette source pointer.
Expand Down
24 changes: 24 additions & 0 deletions src/ace/utils/palette.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,27 @@ void paletteDump(UWORD *pPalette, UBYTE ubColorCnt, char *szPath) {
bitmapSaveBmp(pBm, pPalette, szPath);
bitmapDestroy(pBm);
}

void paletteSave(UWORD *pPalette, UBYTE ubColorCnt, char *szPath) {
tFile *pFile;
UBYTE ubPaletteLength;

logBlockBegin(
"paletteSave(pPalette: %p, ubColorCnt: %hu, szPath: '%s')",
pPalette, ubColorCnt, szPath
);

pFile = fileOpen(szPath, "wb");
if(!pFile) {
logWrite("ERR: Can't write file!\n");
logBlockEnd("paletteSave()");
return;
}
else {
fileWrite(pFile, &ubColorCnt, sizeof(UBYTE));
fileWrite(pFile, pPalette, sizeof(UWORD) * ubColorCnt);
fileClose(pFile);
}

logBlockEnd("paletteSave()");
}

0 comments on commit f30b8fe

Please sign in to comment.