cache the GIF data instead of the jpeg representation
This commit is contained in:
parent
3f98095704
commit
5bf37d5472
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#import "SDImageCache.h"
|
#import "SDImageCache.h"
|
||||||
#import "SDWebImageDecoder.h"
|
#import "SDWebImageDecoder.h"
|
||||||
|
#import "UIImage+GIF.h"
|
||||||
#import <CommonCrypto/CommonDigest.h>
|
#import <CommonCrypto/CommonDigest.h>
|
||||||
#import <mach/mach.h>
|
#import <mach/mach.h>
|
||||||
#import <mach/mach_host.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];
|
NSData *data = [NSData dataWithContentsOfFile:path];
|
||||||
if (data)
|
if (data)
|
||||||
{
|
{
|
||||||
|
if ([data isGIF]) {
|
||||||
|
return [UIImage animatedGIFWithData:data];
|
||||||
|
} else {
|
||||||
UIImage *image = [[UIImage alloc] initWithData:data];
|
UIImage *image = [[UIImage alloc] initWithData:data];
|
||||||
UIImage *scaledImage = [self scaledImageForKey:key image:image];
|
UIImage *scaledImage = [self scaledImageForKey:key image:image];
|
||||||
return [UIImage decodedImageWithImage:scaledImage];
|
return [UIImage decodedImageWithImage:scaledImage];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return nil;
|
return nil;
|
||||||
|
|
|
@ -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)
|
__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];
|
downloadedImage = [UIImage animatedGIFWithData:data];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +155,7 @@
|
||||||
{
|
{
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^
|
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(), ^
|
dispatch_async(dispatch_get_main_queue(), ^
|
||||||
{
|
{
|
||||||
|
@ -163,7 +164,8 @@
|
||||||
|
|
||||||
if (transformedImage && finished)
|
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];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue