Mercurial > hg > dmlib
changeset 2209:7a0af15fbe97
Add support for 'raw' 768 byte palette files.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 14 Jun 2019 05:32:58 +0300 |
parents | 90ec1ec89c56 |
children | fa5e74384d87 |
files | tools/libgfx.c tools/libgfx.h |
diffstat | 2 files changed, 48 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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, }, };