diff options
author | az6667 <az6667@gmail.com> | 2021-03-03 18:17:51 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-03 02:17:51 -0500 |
commit | fc38677e8005c24db891b84d3e84df7a199c979c (patch) | |
tree | 4c9d48e75eed62e4e47c700e5db3bdd272c2e572 /src/gd_gif_in.c | |
parent | a9a5b459832af3f524c23dc5e795f9593d9b4fe4 (diff) | |
download | libgd-fc38677e8005c24db891b84d3e84df7a199c979c.tar.gz |
Allow GIFs missing both Global and Local Colormaps to still decode (#494)
Ensure that a GIF without any Global or Local color tables is still
decoded by libgd.
GIF89a spec indicates conforming image files need not have
Global or Local color tables at all.
Spec recommends creating custom color map in that situation, and
that at least Black+White as first two entries, to ensure B&W images
are decoded.
Some commonly used single-pixel GIFs found around the web are
undecoded by libgd otherwise. Test case has been included.
References:
https://www.w3.org/Graphics/GIF/spec-gif89a.txt
http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever
Diffstat (limited to 'src/gd_gif_in.c')
-rw-r--r-- | src/gd_gif_in.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/gd_gif_in.c b/src/gd_gif_in.c index 1ae0e32..2b6b34e 100644 --- a/src/gd_gif_in.c +++ b/src/gd_gif_in.c @@ -315,8 +315,10 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromGifCtx(gdIOCtxPtr fd) ReadImage(im, fd, width, height, localColorMap, BitSet(buf[8], INTERLACE), &ZeroDataBlock); } else { if(!haveGlobalColormap) { - gdImageDestroy(im); - return 0; + // Still a valid gif, apply simple default palette as per spec + ColorMap[CM_RED][1] = 0xff; + ColorMap[CM_GREEN][1] = 0xff; + ColorMap[CM_BLUE][1] = 0xff; } ReadImage(im, fd, width, height, ColorMap, BitSet(buf[8], INTERLACE), &ZeroDataBlock); |