Mercurial > hg > dmlib
changeset 2131:781b1d63109a
Free previously allocated palette in the image palette allocation functions if it
is not a constpal.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 28 May 2019 07:25:20 +0300 |
parents | 3b5be00759ed |
children | 6528a1398e8e |
files | tools/lib64gfx.c |
diffstat | 1 files changed, 17 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/lib64gfx.c Mon May 27 12:22:08 2019 +0300 +++ b/tools/lib64gfx.c Tue May 28 07:25:20 2019 +0300 @@ -118,6 +118,14 @@ int dmSetDefaultC64Palette(DMImage *img) { int res; + + // Free previous palette + if (!img->constpal) + dmPaletteFree(img->pal); + + img->constpal = FALSE; + + // Allocate new if ((res = dmPaletteAlloc(&(img->pal), D64_NCOLORS, 255)) != DMERR_OK) return res; @@ -130,11 +138,18 @@ int dmSetMixedColorC64Palette(DMImage *img) { int res; + + // Free previous palette + if (!img->constpal) + dmPaletteFree(img->pal); + + img->constpal = FALSE; + + // Allocate new if ((res = dmPaletteAlloc(&(img->pal), D64_NCOLORS * D64_NCOLORS, -1)) != DMERR_OK) return res; - int n = 0; - for (int n1 = 0; n1 < D64_NCOLORS; n1++) + for (int n1 = 0, n = 0; n1 < D64_NCOLORS; n1++) { const DMColor *col1 = &dmDefaultC64Palette[n1]; for (int n2 = 0; n2 < D64_NCOLORS; n2++)