From 20fbe78290c5e9bb8ae9a5d58f22137b69c7b513 Mon Sep 17 00:00:00 2001 From: Ville Sundell Date: Fri, 23 Jan 2026 22:24:36 +0200 Subject: [PATCH] Add gd_copy_frame_data() The gd_render_frame() copies the pixel-ready picture to the destination buffer, by converting the palette entries into three-byte colored pixels. However, this is not always desired. For example in applications which need to preserve the pixel - palette relationship for further processing. Hence the new gd_copy_frame_data() function, which copies only the raw data (pixels represent palette indexes, not colors per se). --- gifdec.c | 7 +++++++ gifdec.h | 1 + 2 files changed, 8 insertions(+) diff --git a/gifdec.c b/gifdec.c index 83c2d0f..9a97923 100644 --- a/gifdec.c +++ b/gifdec.c @@ -509,6 +509,13 @@ gd_render_frame(gd_GIF *gif, uint8_t *buffer) render_frame_rect(gif, buffer); } +/* Extract the raw frame data (pixels represent palette indexes) */ +void +gd_copy_frame_data(gd_GIF *gif, uint8_t *buffer) +{ + memcpy(buffer, gif->frame, gif->width * gif->height); +} + int gd_is_bgcolor(gd_GIF *gif, uint8_t color[3]) { diff --git a/gifdec.h b/gifdec.h index 2bbc9f5..92dea3b 100644 --- a/gifdec.h +++ b/gifdec.h @@ -45,6 +45,7 @@ typedef struct gd_GIF { gd_GIF *gd_open_gif(const char *fname); int gd_get_frame(gd_GIF *gif); void gd_render_frame(gd_GIF *gif, uint8_t *buffer); +void gd_copy_frame_data(gd_GIF *gif, uint8_t *buffer); int gd_is_bgcolor(gd_GIF *gif, uint8_t color[3]); void gd_rewind(gd_GIF *gif); void gd_close_gif(gd_GIF *gif);