gif

read/write GIFs
git clone git://bvnf.space/gm.git
Log | Files | Refs | README

commit 52677c1a0e6a91a995c9387fe7d0ea75544200af
parent c9dfbfd24f852142ef3298cff9d8598e336fd36f
Author: phoebos <ben@bvnf.space>
Date:   Wed,  1 Sep 2021 23:24:15 +0100

move colortable scanning to a separate function

Diffstat:
Mgif.c | 24++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/gif.c b/gif.c @@ -51,6 +51,16 @@ struct Image { }; void +scan_colortable(struct Color_table *ct, unsigned char *buf) { + /* TODO: gif87a.txt L 336? */ + int i; + for (i = 0; i < ct->len; i += 1) { + rgb c = {*buf++, *buf++, *buf++}; + memcpy(ct->table[i], c, sizeof(rgb)); + } +} + +void print_colortable(struct Color_table *c) { for (int i = 0; i < c->len; i++) { printf("%d: \033[48;2;%d;%d;%dm(%02x;%02x;%02x)\033[0m\n", i, @@ -94,7 +104,12 @@ gif_decode_image(struct Image *img, struct Color_table *gct, if (img->flags && 0x80) { /* local color table follows */ - fprintf(stderr, "using LCT(%d), ", img->flags && 7); + fprintf(stderr, "using LCT(%d)\n", img->flags && 7); + scan_colortable(img->lct, buf); + buf += 3 * img->lct->len; + print_colortable(img->lct); + + ct = img->lct; } else { /* use GCT */ fprintf(stderr, "using GCT, "); @@ -157,11 +172,8 @@ gif_decode(unsigned char *buf, size_t len) { /* if GCT... */ if (g.flags & 0x80) { - /* TODO: gif87a.txt L 336? */ - for (int i = 0; i < g.gct->len; i += 1) { - rgb c = {*buf++, *buf++, *buf++}; - memcpy(g.gct->table[i], c, sizeof(rgb)); - } + scan_colortable(g.gct, buf); + buf += 3 * g.gct->len; } print_colortable(g.gct);