# HG changeset patch # User Matti Hamalainen # Date 1560479578 -10800 # Node ID 7a0af15fbe9781093e7e287e6fdb975c2da0239e # Parent 90ec1ec89c565c821476c789f030edeb0a6e089d Add support for 'raw' 768 byte palette files. diff -r 90ec1ec89c56 -r 7a0af15fbe97 tools/libgfx.c --- a/tools/libgfx.c Fri Jun 14 05:01:12 2019 +0300 +++ b/tools/libgfx.c Fri Jun 14 05:32:58 2019 +0300 @@ -331,7 +331,7 @@ } -static int fmtProbeACT(const Uint8 *buf, const size_t len) +static int fmtProbeACTPalette(const Uint8 *buf, const size_t len) { if (len == 0x304 && buf[0x300] == 0) @@ -394,6 +394,45 @@ } +static int fmtProbeRAWPalette(const Uint8 *buf, const size_t len) +{ + if (len == 0x300) + return DM_PROBE_SCORE_MAX; + + return DM_PROBE_SCORE_FALSE; +} + + +int dmReadRAWPalette(DMResource *fp, DMPalette **pdst) +{ + int res; + + if ((res = dmPaletteAlloc(pdst, 256, -1)) != DMERR_OK) + return res; + + if ((res = dmPaletteReadData(fp, *pdst, 256)) != DMERR_OK) + goto error; + + return res; + +error: + dmPaletteFree(*pdst); + *pdst = NULL; + return res; +} + + +int dmWriteRAWPalette(DMResource *fp, const DMPalette *ppal) +{ + int res; + + if ((res = dmPaletteWriteData(fp, ppal, ppal->ncolors, 256)) != DMERR_OK) + return res; + + return DMERR_OK; +} + + int dmWriteImageData(const DMImage *img, void *cbdata, int (*writeRowCB)(void *, const Uint8 *, const size_t), const DMImageWriteSpec *spec) @@ -3031,9 +3070,14 @@ const DMPaletteFormat dmPaletteFormatList[] = { { - "act", "ACT Palette", + "act", "Adobe Color Table palette", DM_PALFMT_ACT, DM_FMT_RDWR, - fmtProbeACT, dmReadACTPalette, dmWriteACTPalette, + fmtProbeACTPalette, dmReadACTPalette, dmWriteACTPalette, + }, + { + "rpl", "RAW binary palette (RGB, 768 bytes)", + DM_PALFMT_RAW, DM_FMT_RDWR, + fmtProbeRAWPalette, dmReadRAWPalette, dmWriteRAWPalette, }, }; diff -r 90ec1ec89c56 -r 7a0af15fbe97 tools/libgfx.h --- a/tools/libgfx.h Fri Jun 14 05:01:12 2019 +0300 +++ b/tools/libgfx.h Fri Jun 14 05:32:58 2019 +0300 @@ -36,6 +36,7 @@ enum { DM_PALFMT_ACT, + DM_PALFMT_RAW, };