diff options
Diffstat (limited to 'libsgl/images/SkImageDecoder_libgif.cpp')
-rw-r--r-- | libsgl/images/SkImageDecoder_libgif.cpp | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/libsgl/images/SkImageDecoder_libgif.cpp b/libsgl/images/SkImageDecoder_libgif.cpp index 9353c37..519366a 100644 --- a/libsgl/images/SkImageDecoder_libgif.cpp +++ b/libsgl/images/SkImageDecoder_libgif.cpp @@ -114,9 +114,9 @@ void CheckFreeExtension(SavedImage* Image) { // return NULL on failure static const ColorMapObject* find_colormap(const GifFileType* gif) { - const ColorMapObject* cmap = gif->SColorMap; + const ColorMapObject* cmap = gif->Image.ColorMap; if (NULL == cmap) { - cmap = gif->Image.ColorMap; + cmap = gif->SColorMap; } // some sanity checks if ((unsigned)cmap->ColorCount > 256 || @@ -145,11 +145,20 @@ static int find_transpIndex(const SavedImage& image, int colorCount) { return transpIndex; } +static bool error_return(GifFileType* gif, const SkBitmap& bm, + const char msg[]) { +#if 0 + SkDebugf("libgif error <%s> bitmap [%d %d] pixels %p colortable %p\n", + msg, bm.width(), bm.height(), bm.getPixels(), bm.getColorTable()); +#endif + return false; +} + bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, SkBitmap::Config prefConfig, Mode mode) { GifFileType* gif = DGifOpen(sk_stream, DecodeCallBackProc); if (NULL == gif) { - return false; + return error_return(gif, *bm, "DGifOpen"); } SkAutoTCallIProc<GifFileType, DGifCloseFile> acp(gif); @@ -165,17 +174,17 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, do { if (DGifGetRecordType(gif, &recType) == GIF_ERROR) { - return false; + return error_return(gif, *bm, "DGifGetRecordType"); } switch (recType) { case IMAGE_DESC_RECORD_TYPE: { if (DGifGetImageDesc(gif) == GIF_ERROR) { - return false; + return error_return(gif, *bm, "IMAGE_DESC_RECORD_TYPE"); } if (gif->ImageCount < 1) { // sanity check - return false; + return error_return(gif, *bm, "ImageCount < 1"); } width = gif->SWidth; @@ -183,7 +192,7 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, if (width <= 0 || height <= 0 || !this->chooseFromOneChoice(SkBitmap::kIndex8_Config, width, height)) { - return false; + return error_return(gif, *bm, "chooseFromOneChoice"); } bm->setConfig(SkBitmap::kIndex8_Config, width, height); @@ -197,7 +206,7 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, if ( (desc.Top | desc.Left) < 0 || desc.Left + desc.Width > width || desc.Top + desc.Height > height) { - return false; + return error_return(gif, *bm, "TopLeft"); } // now we decode the colortable @@ -205,7 +214,7 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, { const ColorMapObject* cmap = find_colormap(gif); if (NULL == cmap) { - return false; + return error_return(gif, *bm, "null cmap"); } colorCount = cmap->ColorCount; @@ -226,7 +235,7 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, SkAutoUnref aurts(ctable); if (!this->allocPixelRef(bm, ctable)) { - return false; + return error_return(gif, *bm, "allocPixelRef"); } } @@ -241,7 +250,7 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, // abort if either inner dimension is <= 0 if (innerWidth <= 0 || innerHeight <= 0) { - return false; + return error_return(gif, *bm, "non-pos inner width/height"); } // are we only a subset of the total bounds? @@ -266,7 +275,7 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, { uint8_t* row = scanline + iter.currY() * rowBytes; if (DGifGetLine(gif, row, innerWidth) == GIF_ERROR) { - return false; + return error_return(gif, *bm, "interlace DGifGetLine"); } iter.next(); } @@ -276,7 +285,7 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, // easy, non-interlace case for (int y = 0; y < innerHeight; y++) { if (DGifGetLine(gif, scanline, innerWidth) == GIF_ERROR) { - return false; + return error_return(gif, *bm, "DGifGetLine"); } scanline += rowBytes; } @@ -287,17 +296,17 @@ bool SkGIFImageDecoder::onDecode(SkStream* sk_stream, SkBitmap* bm, case EXTENSION_RECORD_TYPE: if (DGifGetExtension(gif, &temp_save.Function, &extData) == GIF_ERROR) { - return false; + return error_return(gif, *bm, "DGifGetExtension"); } while (extData != NULL) { /* Create an extension block with our data */ if (AddExtensionBlock(&temp_save, extData[0], &extData[1]) == GIF_ERROR) { - return false; + return error_return(gif, *bm, "AddExtensionBlock"); } if (DGifGetExtensionNext(gif, &extData) == GIF_ERROR) { - return false; + return error_return(gif, *bm, "DGifGetExtensionNext"); } temp_save.Function = 0; } |