Authored by Sebastian Vieira
Committed by Olivier Poitrey

Adding the ability to render retina display images based on the file to which the url is pointing at

... ... @@ -169,13 +169,25 @@ static SDImageCache *instance;
}
}
}
- (UIImage *) imageForFile:(NSString*)fileKey {
NSString *file = [self cachePathForKey:fileKey];
NSData *imageData = [NSData dataWithContentsOfFile:file];
if (imageData) {
UIImage *image = [[[UIImage alloc] initWithData:imageData ] autorelease];
CGFloat scale = 1.0;
if ([fileKey hasSuffix:@"@2x.png"] || [fileKey hasSuffix:@"@2x.jpg"]) {
scale = 2.0;
}
return [[[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp] autorelease];
}
return nil;
}
- (void)queryDiskCacheOperation:(NSDictionary *)arguments
{
NSString *key = [arguments objectForKey:@"key"];
NSMutableDictionary *mutableArguments = [[arguments mutableCopy] autorelease];
UIImage *image = [[[UIImage alloc] initWithContentsOfFile:[self cachePathForKey:key]] autorelease];
UIImage *image = [self imageForFile:key];
if (image)
{
#ifdef ENABLE_SDWEBIMAGE_DECODER
... ... @@ -247,7 +259,7 @@ static SDImageCache *instance;
if (!image && fromDisk)
{
image = [[[UIImage alloc] initWithContentsOfFile:[self cachePathForKey:key]] autorelease];
UIImage *image = [self imageForFile:key];
if (image)
{
[memCache setObject:image forKey:key];
... ...
... ... @@ -125,7 +125,14 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot
if ([delegate respondsToSelector:@selector(imageDownloader:didFinishWithImage:)])
{
UIImage *image = [[UIImage alloc] initWithData:imageData];
CGFloat scale = 1.0;
NSString *lastPathComponent = url.lastPathComponent;
if ([lastPathComponent hasSuffix:@"@2x.png"] || [lastPathComponent hasSuffix:@"@2x.jpg"]) {
scale = 2.0;
}
UIImage *image = [[[UIImage alloc] initWithData:imageData ] autorelease];
image = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp];
#ifdef ENABLE_SDWEBIMAGE_DECODER
[[SDWebImageDecoder sharedImageDecoder] decodeImage:image withDelegate:self userInfo:nil];
... ...