From 76cc3a8ae804d398816ab9454731948f0ecb4c70 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 7 May 2022 20:23:51 +0100 Subject: API: Add function to get global colour table. --- include/nsgif.h | 20 ++++++++++++++++++++ src/gif.c | 17 ++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/include/nsgif.h b/include/nsgif.h index bd0fd58..9eec0f8 100644 --- a/include/nsgif.h +++ b/include/nsgif.h @@ -23,6 +23,9 @@ /** Representation of infinity. */ #define NSGIF_INFINITE (UINT32_MAX) +/** Maximum colour table size */ +#define NSGIF_MAX_COLOURS 256 + /** * Opaque type used by LibNSGIF to represent a GIF object in memory. */ @@ -427,6 +430,23 @@ const nsgif_frame_info_t *nsgif_get_frame_info( const nsgif_t *gif, uint32_t frame); +/** + * Get the global colour palette. + * + * If the GIF has no global colour table, this will return the default + * colour palette. + * + * Colours in same pixel format as \ref nsgif_bitmap_t. + * + * \param[in] gif The \ref nsgif_t object. + * \param[out] table Client buffer to hold the colour table. + * \param[out] entries The number of used entries in the colour table. + */ +void nsgif_global_palette( + const nsgif_t *gif, + uint32_t table[NSGIF_MAX_COLOURS], + size_t *entries); + /** * Configure handling of small frame delays. * diff --git a/src/gif.c b/src/gif.c index 038ebf9..34b4e58 100644 --- a/src/gif.c +++ b/src/gif.c @@ -17,9 +17,6 @@ #include "lzw.h" #include "nsgif.h" -/** Maximum colour table size */ -#define NSGIF_MAX_COLOURS 256 - /** Default minimum allowable frame delay in cs. */ #define NSGIF_FRAME_DELAY_MIN 2 @@ -1672,6 +1669,8 @@ nsgif_error nsgif_data_scan( entry[gif->colour_layout.g] = 0xFF; entry[gif->colour_layout.b] = 0xFF; entry[gif->colour_layout.a] = 0xFF; + + gif->colour_table_size = 2; } if (gif->info.colour_table && @@ -1908,6 +1907,18 @@ const nsgif_frame_info_t *nsgif_get_frame_info( return &gif->frames[frame].info; } +/* exported function documented in nsgif.h */ +void nsgif_global_palette( + const nsgif_t *gif, + uint32_t table[NSGIF_MAX_COLOURS], + size_t *entries) +{ + size_t len = sizeof(*table) * NSGIF_MAX_COLOURS; + + memcpy(table, gif->global_colour_table, len); + *entries = gif->colour_table_size; +} + /* exported function documented in nsgif.h */ const char *nsgif_strerror(nsgif_error err) { -- cgit v1.2.1