Skip to content

Commit d1ef49e

Browse files
committed
add paletteSave()
1 parent 7b7d47f commit d1ef49e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

include/ace/utils/palette.h

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ extern "C" {
2424
*/
2525
void paletteLoad(const char *szFileName, UWORD *pPalette, UBYTE ubMaxLength);
2626

27+
/**
28+
* @brief Saves given palette into .plt file.
29+
* @param pPalette Palette to save.
30+
* @param ubColorCnt Number of colors in palette.
31+
* @param szPath Destination path.
32+
*/
33+
void paletteSave(UWORD *pPalette, UBYTE ubColorCnt, char *szPath);
34+
2735
/**
2836
* @brief Loads palette from supplied .plt stored in memory to given address.
2937
* @param pData Palette source pointer.

src/ace/utils/palette.c

+24
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,27 @@ void paletteDump(UWORD *pPalette, UBYTE ubColorCnt, char *szPath) {
107107
bitmapSaveBmp(pBm, pPalette, szPath);
108108
bitmapDestroy(pBm);
109109
}
110+
111+
void paletteSave(UWORD *pPalette, UBYTE ubColorCnt, char *szPath) {
112+
tFile *pFile;
113+
UBYTE ubPaletteLength;
114+
115+
logBlockBegin(
116+
"paletteSave(pPalette: %p, ubColorCnt: %hu, szPath: '%s')",
117+
szFileName, pPalette, ubMaxLength
118+
);
119+
120+
pFile = fileOpen(szPath, "wb");
121+
if(!pFile) {
122+
logWrite("ERR: Can't write file!\n");
123+
logBlockEnd("paletteSave()");
124+
return;
125+
}
126+
else {
127+
fileWrite(pFile, &ubColorCnt, sizeof(UBYTE));
128+
fileWrite(pFile, pPalette, sizeof(UWORD) * ubColorCnt);
129+
fileClose(pFile);
130+
}
131+
132+
logBlockEnd("paletteSave()");
133+
}

0 commit comments

Comments
 (0)