cache the GIF data instead of the jpeg representation

This commit is contained in:
Andy LaVoy 2013-04-28 14:37:47 -07:00
parent 3f98095704
commit 5bf37d5472
2 changed files with 13 additions and 6 deletions

View File

@ -8,6 +8,7 @@
#import "SDImageCache.h"
#import "SDWebImageDecoder.h"
#import "UIImage+GIF.h"
#import <CommonCrypto/CommonDigest.h>
#import <mach/mach.h>
#import <mach/mach_host.h>
@ -180,10 +181,14 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
NSData *data = [NSData dataWithContentsOfFile:path];
if (data)
{
if ([data isGIF]) {
return [UIImage animatedGIFWithData:data];
} else {
UIImage *image = [[UIImage alloc] initWithData:data];
UIImage *scaledImage = [self scaledImageForKey:key image:image];
return [UIImage decodedImageWithImage:scaledImage];
}
}
else
{
return nil;

View File

@ -122,7 +122,8 @@
}
__block id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished)
{
if ([data isGIF]) {
BOOL imageIsGIF = [data isGIF];
if (imageIsGIF) {
downloadedImage = [UIImage animatedGIFWithData:data];
}
@ -154,7 +155,7 @@
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^
{
UIImage *transformedImage = [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url];
UIImage *transformedImage = imageIsGIF ? downloadedImage : [self.delegate imageManager:self transformDownloadedImage:downloadedImage withURL:url];
dispatch_async(dispatch_get_main_queue(), ^
{
@ -163,7 +164,8 @@
if (transformedImage && finished)
{
[self.imageCache storeImage:transformedImage imageData:nil forKey:key toDisk:cacheOnDisk];
NSData *dataToStore = imageIsGIF ? data : nil;
[self.imageCache storeImage:transformedImage imageData:dataToStore forKey:key toDisk:cacheOnDisk];
}
});
}