From 4f588e9400eb82efac9c8c9fa6844419c2caa101 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sun, 8 May 2022 16:18:35 +0100 Subject: API: Add function to get a frame's local palette. --- src/gif.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src') diff --git a/src/gif.c b/src/gif.c index 7f960d1..09bacdc 100644 --- a/src/gif.c +++ b/src/gif.c @@ -1950,6 +1950,31 @@ void nsgif_global_palette( *entries = gif->colour_table_size; } +/* exported function documented in nsgif.h */ +bool nsgif_local_palette( + const nsgif_t *gif, + uint32_t frame, + uint32_t table[NSGIF_MAX_COLOURS], + size_t *entries) +{ + const nsgif_frame *f; + + if (frame >= gif->frame_count_partial) { + return false; + } + + f = &gif->frames[frame]; + if (f->info.colour_table == false) { + return false; + } + + *entries = 2 << (f->flags & NSGIF_COLOUR_TABLE_SIZE_MASK); + nsgif__colour_table_decode(table, &gif->colour_layout, + *entries, gif->buf + f->colour_table_offset); + + return true; +} + /* exported function documented in nsgif.h */ const char *nsgif_strerror(nsgif_error err) { -- cgit v1.2.1