Add image decoder and retina support to partial images when progressive download is used
This commit is contained in:
parent
ea819b2a45
commit
6574083a95
|
@ -32,7 +32,6 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot
|
||||||
|
|
||||||
+ (id)downloaderWithURL:(NSURL *)url delegate:(id<SDWebImageDownloaderDelegate>)delegate userInfo:(id)userInfo
|
+ (id)downloaderWithURL:(NSURL *)url delegate:(id<SDWebImageDownloaderDelegate>)delegate userInfo:(id)userInfo
|
||||||
{
|
{
|
||||||
|
|
||||||
return [self downloaderWithURL:url delegate:delegate userInfo:userInfo lowPriority:NO];
|
return [self downloaderWithURL:url delegate:delegate userInfo:userInfo lowPriority:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +154,7 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot
|
||||||
// The following code is from http://www.cocoaintheshell.com/2011/05/progressive-images-download-imageio/
|
// The following code is from http://www.cocoaintheshell.com/2011/05/progressive-images-download-imageio/
|
||||||
// Thanks to the author @Nyx0uf
|
// Thanks to the author @Nyx0uf
|
||||||
|
|
||||||
/// Get the total bytes downloaded
|
// Get the total bytes downloaded
|
||||||
const NSUInteger totalSize = [imageData length];
|
const NSUInteger totalSize = [imageData length];
|
||||||
|
|
||||||
// Update the data source, we must pass ALL the data, not just the new bytes
|
// Update the data source, we must pass ALL the data, not just the new bytes
|
||||||
|
@ -177,7 +176,7 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot
|
||||||
|
|
||||||
if (width + height > 0 && totalSize < expectedSize)
|
if (width + height > 0 && totalSize < expectedSize)
|
||||||
{
|
{
|
||||||
/// Create the image
|
// Create the image
|
||||||
CGImageRef partialImageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
|
CGImageRef partialImageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
|
||||||
|
|
||||||
#ifdef TARGET_OS_IPHONE
|
#ifdef TARGET_OS_IPHONE
|
||||||
|
@ -205,8 +204,11 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot
|
||||||
|
|
||||||
if (partialImageRef)
|
if (partialImageRef)
|
||||||
{
|
{
|
||||||
UIImage *image = [[UIImage alloc] initWithCGImage:partialImageRef];
|
UIImage *image = SDScaledImageForPath(url.absoluteString, [UIImage imageWithCGImage:partialImageRef]);
|
||||||
[delegate imageDownloader:self didUpdatePartialImage:image];
|
[[SDWebImageDecoder sharedImageDecoder] decodeImage:image
|
||||||
|
withDelegate:self
|
||||||
|
userInfo:[NSDictionary dictionaryWithObject:@"partial" forKey:@"type"]];
|
||||||
|
|
||||||
SDWIRelease(image);
|
SDWIRelease(image);
|
||||||
|
|
||||||
CGImageRelease(partialImageRef);
|
CGImageRelease(partialImageRef);
|
||||||
|
@ -251,9 +253,16 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot
|
||||||
|
|
||||||
#pragma mark SDWebImageDecoderDelegate
|
#pragma mark SDWebImageDecoderDelegate
|
||||||
|
|
||||||
- (void)imageDecoder:(SDWebImageDecoder *)decoder didFinishDecodingImage:(UIImage *)image userInfo:(NSDictionary *)userInfo
|
- (void)imageDecoder:(SDWebImageDecoder *)decoder didFinishDecodingImage:(UIImage *)image userInfo:(NSDictionary *)aUserInfo
|
||||||
{
|
{
|
||||||
[delegate performSelector:@selector(imageDownloader:didFinishWithImage:) withObject:self withObject:image];
|
if ([[aUserInfo valueForKey:@"type"] isEqualToString:@"partial"])
|
||||||
|
{
|
||||||
|
[delegate imageDownloader:self didUpdatePartialImage:image];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[delegate performSelector:@selector(imageDownloader:didFinishWithImage:) withObject:self withObject:image];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark NSObject
|
#pragma mark NSObject
|
||||||
|
|
Loading…
Reference in New Issue