Merge pull request #379 from lavoy/master
Moved scaling to earlier in the process
Showing
2 changed files
with
22 additions
and
11 deletions
@@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
8 | 8 | ||
9 | #import "SDWebImageDownloaderOperation.h" | 9 | #import "SDWebImageDownloaderOperation.h" |
10 | #import "SDWebImageDecoder.h" | 10 | #import "SDWebImageDecoder.h" |
11 | +#import "UIImage+GIF.h" | ||
11 | #import <ImageIO/ImageIO.h> | 12 | #import <ImageIO/ImageIO.h> |
12 | 13 | ||
13 | @interface SDWebImageDownloaderOperation () | 14 | @interface SDWebImageDownloaderOperation () |
@@ -274,9 +275,24 @@ | @@ -274,9 +275,24 @@ | ||
274 | } | 275 | } |
275 | else | 276 | else |
276 | { | 277 | { |
277 | - UIImage *image = [[UIImage alloc] initWithData:self.imageData]; | ||
278 | - UIImage *scaledImage = [self scaledImageForKey:self.request.URL.absoluteString image:image]; | ||
279 | - image = [UIImage decodedImageWithImage:scaledImage]; | 278 | + BOOL isImageGIF = [self.imageData isGIF]; |
279 | + | ||
280 | + UIImage *image; | ||
281 | + if (isImageGIF) | ||
282 | + { | ||
283 | + image = [UIImage animatedGIFWithData:self.imageData]; | ||
284 | + } | ||
285 | + else | ||
286 | + { | ||
287 | + image = [[UIImage alloc] initWithData:self.imageData]; | ||
288 | + } | ||
289 | + | ||
290 | + image = [self scaledImageForKey:self.request.URL.absoluteString image:image]; | ||
291 | + | ||
292 | + if (!isImageGIF) { | ||
293 | + image = [UIImage decodedImageWithImage:image]; | ||
294 | + } | ||
295 | + | ||
280 | if (CGSizeEqualToSize(image.size, CGSizeZero)) | 296 | if (CGSizeEqualToSize(image.size, CGSizeZero)) |
281 | { | 297 | { |
282 | completionBlock(nil, nil, [NSError errorWithDomain:@"SDWebImageErrorDomain" code:0 userInfo:@{NSLocalizedDescriptionKey: @"Downloaded image has 0 pixels"}], YES); | 298 | completionBlock(nil, nil, [NSError errorWithDomain:@"SDWebImageErrorDomain" code:0 userInfo:@{NSLocalizedDescriptionKey: @"Downloaded image has 0 pixels"}], YES); |
@@ -121,13 +121,7 @@ | @@ -121,13 +121,7 @@ | ||
121 | downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse; | 121 | downloaderOptions |= SDWebImageDownloaderIgnoreCachedResponse; |
122 | } | 122 | } |
123 | __block id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) | 123 | __block id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished) |
124 | - { | ||
125 | - BOOL isImageGIF = [data isGIF]; | ||
126 | - if (isImageGIF) | ||
127 | - { | ||
128 | - downloadedImage = [UIImage animatedGIFWithData:data]; | ||
129 | - } | ||
130 | - | 124 | + { |
131 | if (weakOperation.cancelled) | 125 | if (weakOperation.cancelled) |
132 | { | 126 | { |
133 | completedBlock(nil, nil, SDImageCacheTypeNone, finished); | 127 | completedBlock(nil, nil, SDImageCacheTypeNone, finished); |
@@ -155,7 +149,8 @@ | @@ -155,7 +149,8 @@ | ||
155 | else if (downloadedImage && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) | 149 | else if (downloadedImage && [self.delegate respondsToSelector:@selector(imageManager:transformDownloadedImage:withURL:)]) |
156 | { | 150 | { |
157 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ | 151 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ |
158 | - { | 152 | + { |
153 | + BOOL isImageGIF = [data isGIF]; | ||
159 | UIImage *transformedImage = isImageGIF ? downloadedImage : [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url]; | 154 | UIImage *transformedImage = isImageGIF ? downloadedImage : [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url]; |
160 | 155 | ||
161 | dispatch_async(dispatch_get_main_queue(), ^ | 156 | dispatch_async(dispatch_get_main_queue(), ^ |
-
Please register or login to post a comment