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; @@ -169,13 +169,25 @@ static SDImageCache *instance;
169 } 169 }
170 } 170 }
171 } 171 }
172 - 172 +- (UIImage *) imageForFile:(NSString*)fileKey {
  173 + NSString *file = [self cachePathForKey:fileKey];
  174 + NSData *imageData = [NSData dataWithContentsOfFile:file];
  175 + if (imageData) {
  176 + UIImage *image = [[[UIImage alloc] initWithData:imageData ] autorelease];
  177 + CGFloat scale = 1.0;
  178 + if ([fileKey hasSuffix:@"@2x.png"] || [fileKey hasSuffix:@"@2x.jpg"]) {
  179 + scale = 2.0;
  180 + }
  181 + return [[[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp] autorelease];
  182 + }
  183 + return nil;
  184 +}
173 - (void)queryDiskCacheOperation:(NSDictionary *)arguments 185 - (void)queryDiskCacheOperation:(NSDictionary *)arguments
174 { 186 {
175 NSString *key = [arguments objectForKey:@"key"]; 187 NSString *key = [arguments objectForKey:@"key"];
176 NSMutableDictionary *mutableArguments = [[arguments mutableCopy] autorelease]; 188 NSMutableDictionary *mutableArguments = [[arguments mutableCopy] autorelease];
177 -  
178 - UIImage *image = [[[UIImage alloc] initWithContentsOfFile:[self cachePathForKey:key]] autorelease]; 189 +
  190 + UIImage *image = [self imageForFile:key];
179 if (image) 191 if (image)
180 { 192 {
181 #ifdef ENABLE_SDWEBIMAGE_DECODER 193 #ifdef ENABLE_SDWEBIMAGE_DECODER
@@ -247,7 +259,7 @@ static SDImageCache *instance; @@ -247,7 +259,7 @@ static SDImageCache *instance;
247 259
248 if (!image && fromDisk) 260 if (!image && fromDisk)
249 { 261 {
250 - image = [[[UIImage alloc] initWithContentsOfFile:[self cachePathForKey:key]] autorelease]; 262 + UIImage *image = [self imageForFile:key];
251 if (image) 263 if (image)
252 { 264 {
253 [memCache setObject:image forKey:key]; 265 [memCache setObject:image forKey:key];
@@ -125,7 +125,14 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot @@ -125,7 +125,14 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot
125 125
126 if ([delegate respondsToSelector:@selector(imageDownloader:didFinishWithImage:)]) 126 if ([delegate respondsToSelector:@selector(imageDownloader:didFinishWithImage:)])
127 { 127 {
128 - UIImage *image = [[UIImage alloc] initWithData:imageData]; 128 + CGFloat scale = 1.0;
  129 + NSString *lastPathComponent = url.lastPathComponent;
  130 + if ([lastPathComponent hasSuffix:@"@2x.png"] || [lastPathComponent hasSuffix:@"@2x.jpg"]) {
  131 + scale = 2.0;
  132 + }
  133 +
  134 + UIImage *image = [[[UIImage alloc] initWithData:imageData ] autorelease];
  135 + image = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp];
129 136
130 #ifdef ENABLE_SDWEBIMAGE_DECODER 137 #ifdef ENABLE_SDWEBIMAGE_DECODER
131 [[SDWebImageDecoder sharedImageDecoder] decodeImage:image withDelegate:self userInfo:nil]; 138 [[SDWebImageDecoder sharedImageDecoder] decodeImage:image withDelegate:self userInfo:nil];