From 756e59a995901d4130ce093af5d8487d706782fe Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 9 Oct 2017 11:47:02 +0800 Subject: [PATCH] Static WebP decoding a little enhancement. Do not need create WebP iterator for static images. --- SDWebImage/UIImage+WebP.m | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/SDWebImage/UIImage+WebP.m b/SDWebImage/UIImage+WebP.m index b84af518..97612bcc 100644 --- a/SDWebImage/UIImage+WebP.m +++ b/SDWebImage/UIImage+WebP.m @@ -50,15 +50,7 @@ static void FreeImageData(void *info, const void *data, size_t size) { return nil; } - WebPIterator iter; - if (!WebPDemuxGetFrame(demuxer, 1, &iter)) { - WebPDemuxReleaseIterator(&iter); - WebPDemuxDelete(demuxer); - return nil; - } - uint32_t flags = WebPDemuxGetI(demuxer, WEBP_FF_FORMAT_FLAGS); - #if SD_UIKIT || SD_WATCH int loopCount = WebPDemuxGetI(demuxer, WEBP_FF_LOOP_COUNT); int frameCount = WebPDemuxGetI(demuxer, WEBP_FF_FRAME_COUNT); @@ -73,7 +65,6 @@ static void FreeImageData(void *info, const void *data, size_t size) { } CGContextRef canvas = CGBitmapContextCreate(NULL, canvasWidth, canvasHeight, 8, 0, SDCGColorSpaceGetDeviceRGB(), bitmapInfo); if (!canvas) { - WebPDemuxReleaseIterator(&iter); WebPDemuxDelete(demuxer); return nil; } @@ -95,13 +86,20 @@ static void FreeImageData(void *info, const void *data, size_t size) { #endif CGImageRelease(newImageRef); } - WebPDemuxReleaseIterator(&iter); WebPDemuxDelete(demuxer); CGContextRelease(canvas); return staticImage; } // for animated webp image + WebPIterator iter; + if (!WebPDemuxGetFrame(demuxer, 1, &iter)) { + WebPDemuxReleaseIterator(&iter); + WebPDemuxDelete(demuxer); + CGContextRelease(canvas); + return nil; + } + NSMutableArray *images = [NSMutableArray array]; #if SD_UIKIT || SD_WATCH NSTimeInterval totalDuration = 0;