From bdb312737d57497db67dda2543c7ea8b62315d0a Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Sat, 7 May 2022 14:23:32 +0100 Subject: API: Store presence of global/local colour table in GIF/frame info. --- include/nsgif.h | 4 ++++ src/gif.c | 15 +++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/include/nsgif.h b/include/nsgif.h index 0ea792b..bd0fd58 100644 --- a/include/nsgif.h +++ b/include/nsgif.h @@ -360,6 +360,8 @@ typedef struct nsgif_info { int loop_max; /** background colour in same pixel format as \ref nsgif_bitmap_t. */ uint32_t background; + /** whether the GIF has a global colour table */ + bool colour_table; } nsgif_info_t; /** @@ -392,6 +394,8 @@ typedef struct nsgif_frame_info { bool display; /** whether the frame may have transparency */ bool transparency; + /** whether the frame has a local colour table */ + bool colour_table; /** Disposal method for previous frame; affects plotting */ uint8_t disposal; diff --git a/src/gif.c b/src/gif.c index 435d0d9..038ebf9 100644 --- a/src/gif.c +++ b/src/gif.c @@ -103,11 +103,9 @@ struct nsgif { uint32_t bg_index; /** image aspect ratio (ignored) */ uint32_t aspect_ratio; - /** size of colour table (in entries) */ + /** size of global colour table (in entries) */ uint32_t colour_table_size; - /** whether the GIF has a global colour table */ - bool global_colours; /** current colour table */ uint32_t *colour_table; /** Client's colour component order. */ @@ -1117,6 +1115,10 @@ static nsgif_error nsgif__parse_colour_table( return NSGIF_OK; } + if (decode == false) { + frame->info.colour_table = true; + } + ret = nsgif__colour_table_extract(gif, gif->local_colour_table, &gif->colour_layout, 2 << (frame->flags & NSGIF_COLOUR_TABLE_SIZE_MASK), @@ -1234,6 +1236,7 @@ static struct nsgif_frame *nsgif__get_frame( frame->transparency_index = NSGIF_NO_TRANSPARENCY; frame->frame_pointer = gif->buf_pos; + frame->info.colour_table = false; frame->info.transparency = false; frame->redraw_required = false; frame->info.display = false; @@ -1546,7 +1549,7 @@ static nsgif_error nsgif__parse_logical_screen_descriptor( gif->info.width = data[0] | (data[1] << 8); gif->info.height = data[2] | (data[3] << 8); - gif->global_colours = data[4] & NSGIF_COLOUR_TABLE_MASK; + gif->info.colour_table = data[4] & NSGIF_COLOUR_TABLE_MASK; gif->colour_table_size = 2 << (data[4] & NSGIF_COLOUR_TABLE_SIZE_MASK); gif->bg_index = data[5]; gif->aspect_ratio = data[6]; @@ -1640,7 +1643,7 @@ nsgif_error nsgif_data_scan( */ if (gif->global_colour_table[0] == NSGIF_PROCESS_COLOURS) { /* Check for a global colour map signified by bit 7 */ - if (gif->global_colours) { + if (gif->info.colour_table) { ret = nsgif__colour_table_extract(gif, gif->global_colour_table, &gif->colour_layout, @@ -1671,7 +1674,7 @@ nsgif_error nsgif_data_scan( entry[gif->colour_layout.a] = 0xFF; } - if (gif->global_colours && + if (gif->info.colour_table && gif->bg_index < gif->colour_table_size) { size_t bg_idx = gif->bg_index; gif->info.background = gif->global_colour_table[bg_idx]; -- cgit v1.2.1