From d1ef49edcc40aeeba050a7212b8e7c3ffc034421 Mon Sep 17 00:00:00 2001 From: KaiN Date: Tue, 16 Apr 2024 17:39:42 +0200 Subject: [PATCH] add paletteSave() --- include/ace/utils/palette.h | 8 ++++++++ src/ace/utils/palette.c | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) 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..bf5944fa 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')", + szFileName, pPalette, ubMaxLength + ); + + 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()"); +}