diff --git a/include/ace/utils/palette.h b/include/ace/utils/palette.h index 1e6059b9..1690c968 100644 --- a/include/ace/utils/palette.h +++ b/include/ace/utils/palette.h @@ -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. diff --git a/src/ace/utils/palette.c b/src/ace/utils/palette.c index db3b5d8d..3f2fb4b9 100644 --- a/src/ace/utils/palette.c +++ b/src/ace/utils/palette.c @@ -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()"); +}