From 8966288ad6f9fecf92fb77e794d5c2cb6abddc18 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 8 May 2022 16:20:02 +0100 Subject: Test: Allow local palettes to be saved as an image. --- test/nsgif.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/nsgif.c b/test/nsgif.c index 17fb596..7f1cc55 100644 --- a/test/nsgif.c +++ b/test/nsgif.c @@ -235,6 +235,22 @@ static bool save_global_palette(const nsgif_t *gif) table, entries); } +static bool save_local_palette(const nsgif_t *gif, uint32_t frame) +{ + static uint32_t table[NSGIF_MAX_COLOURS]; + char filename[64]; + size_t entries; + + snprintf(filename, sizeof(filename), "local-palette-%"PRIu32".ppm", + frame); + + if (!nsgif_local_palette(gif, frame, table, &entries)) { + return false; + } + + return save_palette(nsgif_options.file, filename, table, entries); +} + static void decode(FILE* ppm, const char *name, nsgif_t *gif) { nsgif_error err; @@ -291,6 +307,9 @@ static void decode(FILE* ppm, const char *name, nsgif_t *gif) print_gif_frame_info(f_info, frame_new); } } + if (nsgif_options.palette == true) { + save_local_palette(gif, frame_new); + } err = nsgif_frame_decode(gif, frame_new, &bitmap); if (err != NSGIF_OK) { -- cgit v1.2.1