From f58c2ebb43129337ffd6135cadc06bc9ad9804eb Mon Sep 17 00:00:00 2001 From: Andy LaVoy Date: Sun, 28 Apr 2013 20:10:36 -0700 Subject: [PATCH] moved scaling up the process --- SDWebImage/SDWebImageDownloaderOperation.m | 22 +++++++++++++++++++--- SDWebImage/SDWebImageManager.m | 11 +++-------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index a194966a..b1717d35 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -8,6 +8,7 @@ #import "SDWebImageDownloaderOperation.h" #import "SDWebImageDecoder.h" +#import "UIImage+GIF.h" #import @interface SDWebImageDownloaderOperation () @@ -274,9 +275,24 @@ } else { - UIImage *image = [[UIImage alloc] initWithData:self.imageData]; - UIImage *scaledImage = [self scaledImageForKey:self.request.URL.absoluteString image:image]; - image = [UIImage decodedImageWithImage:scaledImage]; + BOOL isImageGIF = [self.imageData isGIF]; + + UIImage *image; + if (isImageGIF) + { + image = [UIImage animatedGIFWithData:self.imageData]; + } + else + { + image = [[UIImage alloc] initWithData:self.imageData]; + } + + image = [self scaledImageForKey:self.request.URL.absoluteString image:image]; + + if (!isImageGIF) { + image = [UIImage decodedImageWithImage:image]; + } + if (CGSizeEqualToSize(image.size, CGSizeZero)) { completionBlock(nil, nil, [NSError errorWithDomain:@"SDWebImageErrorDomain" code:0 userInfo:@{NSLocalizedDescriptionKey: @"Downloaded image has 0 pixels"}], YES); diff --git a/SDWebImage/SDWebImageManager.m b/SDWebImage/SDWebImageManager.m index 3c83301d..825f7476 100644 --- a/SDWebImage/SDWebImageManager.m +++ b/SDWebImage/SDWebImageManager.m @@ -121,13 +121,7 @@ downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse; } __block id subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) - { - BOOL isImageGIF = [data isGIF]; - if (isImageGIF) - { - downloadedImage = [UIImage animatedGIFWithData:data]; - } - + { if (weakOperation.cancelled) { completedBlock(nil, nil, SDImageCacheTypeNone, finished); @@ -155,7 +149,8 @@ else if (downloadedImage && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ - { + { + BOOL isImageGIF = [data isGIF]; UIImage *transformedImage = isImageGIF ? downloadedImage : [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url]; dispatch_async(dispatch_get_main_queue(), ^