From fba9213c9cee4bdd1056b84e827b55a949ba820e Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 30 Jul 2015 18:46:56 -0300 Subject: [PATCH] Fix bug saving invalid .gif files when we use an indexed image with more than 256 colors --- src/app/file/gif_format.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/app/file/gif_format.cpp b/src/app/file/gif_format.cpp index b543417c9..e0ef8da15 100644 --- a/src/app/file/gif_format.cpp +++ b/src/app/file/gif_format.cpp @@ -46,6 +46,9 @@ #define GifBitSize BitSize #endif +// GifBitSize can return 9 (it's a bug in giflib) +#define GifBitSizeLimited(v) (MIN(GifBitSize(v), 8)) + namespace app { using namespace base; @@ -682,7 +685,7 @@ public: if (m_sprite->pixelFormat() == IMAGE_INDEXED) { for (Palette* palette : m_sprite->getPalettes()) { - int bpp = GifBitSize(palette->size()); + int bpp = GifBitSizeLimited(palette->size()); m_bitsPerPixel = MAX(m_bitsPerPixel, bpp); } } @@ -964,7 +967,7 @@ private: } int usedNColors = usedColors.picks(); - int localColorCount = (1 << GifBitSize(usedNColors)); + int localColorCount = (1 << GifBitSizeLimited(usedNColors)); Remap remap(256); for (int i=0; isize()); + int n = 1 << GifBitSizeLimited(palette->size()); ColorMapObject* colormap = GifMakeMapObject(n, nullptr); for (int i=0; i