Skip to content

Commit

Permalink
Updated SDWebImage to version 3.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjinkun committed Mar 10, 2014
1 parent b5f1c0e commit e1ddd8e
Show file tree
Hide file tree
Showing 27 changed files with 1,075 additions and 817 deletions.
2 changes: 1 addition & 1 deletion MWPhotoBrowser.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Pod::Spec.new do |s|
s.resources = 'MWPhotoBrowser/MWPhotoBrowser.bundle'
s.requires_arc = true
s.frameworks = 'MessageUI', 'ImageIO', 'QuartzCore', 'AssetsLibrary'
s.dependency 'SDWebImage', '~> 3.5'
s.dependency 'SDWebImage', '~> 3.5.4'
s.dependency 'MBProgressHUD'
s.dependency 'DACircularProgress'
s.dependency 'PSTCollectionView', '~> 1.2'
Expand Down
2 changes: 1 addition & 1 deletion MWPhotoBrowser/Classes/MWPhoto.m
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ - (void)performLoadUnderlyingImageAndNotify {
SDWebImageManager *manager = [SDWebImageManager sharedManager];
_webImageOperation = [manager downloadWithURL:_photoURL
options:0
progress:^(NSUInteger receivedSize, long long expectedSize) {
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
if (expectedSize > 0) {
float progress = receivedSize / (float)expectedSize;
NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
Expand Down
9 changes: 5 additions & 4 deletions MWPhotoBrowser/Libraries/SDWebImage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ It provides:
- A guarantee that main thread will never be blocked
- Performances!
- Use GCD and ARC
- Arm64 support

NOTE: The version 3.0 of SDWebImage isn't fully backward compatible with 2.0 and requires iOS 5.0
NOTE: The version 3.0 of SDWebImage isn't fully backward compatible with 2.0 and requires iOS 5.1.1
minimum deployement version. If you need iOS < 5.0 support, please use the last [2.0 version](https://github.com/rs/SDWebImage/tree/2.0-compat).

[How is SDWebImage better than X?](https://github.com/rs/SDWebImage/wiki/How-is-SDWebImage-better-than-X%3F)

Who Use It
----------

Find out [who use SDWebImage](https://github.com/rs/SDWebImage/wiki/Who-Use-SDWebImage) and add your app to the list.
Find out [who uses SDWebImage](https://github.com/rs/SDWebImage/wiki/Who-Uses-SDWebImage) and add your app to the list.

How To Use
----------
Expand Down Expand Up @@ -94,7 +95,7 @@ SDWebImageManager *manager = [SDWebImageManager sharedManager];
{
// progression tracking code
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
{
if (image)
{
Expand Down Expand Up @@ -138,7 +139,7 @@ key is an application unique identifier for the image to cache. It is generally
the image.
```objective-c
SDImageCache *imageCache = [SDImageCache.alloc initWithNamespace:@"myNamespace"];
SDImageCache *imageCache = [[SDImageCache alloc] initWithNamespace:@"myNamespace"];
[imageCache queryDiskCacheForKey:myCacheKey done:^(UIImage *image)
{
// image is not nil if image was found
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// MKAnnotationView+WebCache.h
// SDWebImage
//
// Created by Olivier Poitrey on 14/03/12.
// Copyright (c) 2012 Dailymotion. All rights reserved.
//

#import "MapKit/MapKit.h"
#import "SDWebImageManager.h"

/**
* Integrates SDWebImage async downloading and caching of remote images with MKAnnotationView.
*/
@interface MKAnnotationView (WebCache)

/**
* Set the imageView `image` with an `url`.
*
* The downloand is asynchronous and cached.
*
* @param url The url for the image.
*/
- (void)setImageWithURL:(NSURL *)url;

/**
* Set the imageView `image` with an `url` and a placeholder.
*
* The downloand is asynchronous and cached.
*
* @param url The url for the image.
* @param placeholder The image to be set initially, until the image request finishes.
* @see setImageWithURL:placeholderImage:options:
*/
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder;

/**
* Set the imageView `image` with an `url`, placeholder and custom options.
*
* The downloand is asynchronous and cached.
*
* @param url The url for the image.
* @param placeholder The image to be set initially, until the image request finishes.
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
*/
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options;

/**
* Set the imageView `image` with an `url`.
*
* The downloand is asynchronous and cached.
*
* @param url The url for the image.
* @param completedBlock A block called when operation has been completed. This block as no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrived from the local cache of from the network.
*/
- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock;

/**
* Set the imageView `image` with an `url`, placeholder.
*
* The downloand is asynchronous and cached.
*
* @param url The url for the image.
* @param placeholder The image to be set initially, until the image request finishes.
* @param completedBlock A block called when operation has been completed. This block as no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrived from the local cache of from the network.
*/
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock;

/**
* Set the imageView `image` with an `url`, placeholder and custom options.
*
* The downloand is asynchronous and cached.
*
* @param url The url for the image.
* @param placeholder The image to be set initially, until the image request finishes.
* @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
* @param completedBlock A block called when operation has been completed. This block as no return value
* and takes the requested UIImage as first parameter. In case of error the image parameter
* is nil and the second parameter may contain an NSError. The third parameter is a Boolean
* indicating if the image was retrived from the local cache of from the network.
*/
- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock;

/**
* Cancel the current download
*/
- (void)cancelCurrentImageLoad;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// MKAnnotationView+WebCache.m
// SDWebImage
//
// Created by Olivier Poitrey on 14/03/12.
// Copyright (c) 2012 Dailymotion. All rights reserved.
//

#import "MKAnnotationView+WebCache.h"
#import "objc/runtime.h"

static char operationKey;

@implementation MKAnnotationView (WebCache)

- (void)setImageWithURL:(NSURL *)url {
[self setImageWithURL:url placeholderImage:nil options:0 completed:nil];
}

- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder {
[self setImageWithURL:url placeholderImage:placeholder options:0 completed:nil];
}

- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options {
[self setImageWithURL:url placeholderImage:placeholder options:options completed:nil];
}

- (void)setImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
[self setImageWithURL:url placeholderImage:nil options:0 completed:completedBlock];
}

- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder completed:(SDWebImageCompletedBlock)completedBlock {
[self setImageWithURL:url placeholderImage:placeholder options:0 completed:completedBlock];
}

- (void)setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
[self cancelCurrentImageLoad];

self.image = placeholder;

if (url) {
__weak MKAnnotationView *wself = self;
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
if (!wself) return;
dispatch_main_sync_safe(^{
__strong MKAnnotationView *sself = wself;
if (!sself) return;
if (image) {
sself.image = image;
}
if (completedBlock && finished) {
completedBlock(image, error, cacheType);
}
});
}];
objc_setAssociatedObject(self, &operationKey, operation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
}

- (void)cancelCurrentImageLoad {
// Cancel in progress downloader from queue
id <SDWebImageOperation> operation = objc_getAssociatedObject(self, &operationKey);
if (operation) {
[operation cancel];
objc_setAssociatedObject(self, &operationKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Created by Fabrice Aneche on 06/01/14.
// Copyright (c) 2014 Dailymotion. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSData (ImageContentType)
+ (NSString *)contentTypeForImageData:(NSData *)data;
@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Created by Fabrice Aneche on 06/01/14.
// Copyright (c) 2014 Dailymotion. All rights reserved.
//

#import "NSData+ImageContentType.h"


@implementation NSData (ImageContentType)

+ (NSString *)contentTypeForImageData:(NSData *)data {
uint8_t c;
[data getBytes:&c length:1];
switch (c) {
case 0xFF:
return @"image/jpeg";
case 0x89:
return @"image/png";
case 0x47:
return @"image/gif";
case 0x49:
case 0x4D:
return @"image/tiff";
case 0x52:
// R as RIFF for WEBP
if ([data length] < 12) {
return nil;
}

NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
return @"image/webp";
}

return nil;
}
return nil;
}

@end
27 changes: 16 additions & 11 deletions MWPhotoBrowser/Libraries/SDWebImage/SDWebImage/SDImageCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,32 @@
#import <Foundation/Foundation.h>
#import "SDWebImageCompat.h"

enum SDImageCacheType
{
typedef NS_ENUM(NSInteger, SDImageCacheType) {
/**
* The image wasn't available the SDWebImage caches, but was downloaded from the web.
*/
SDImageCacheTypeNone = 0,
SDImageCacheTypeNone,
/**
* The image was obtained from the disk cache.
*/
SDImageCacheTypeDisk,
SDImageCacheTypeDisk,
/**
* The image was obtained from the memory cache.
*/
SDImageCacheTypeMemory
SDImageCacheTypeMemory
};
typedef enum SDImageCacheType SDImageCacheType;

/**
* SDImageCache maintains a memory cache and an optional disk cache. Disk cache write operations are performed
* asynchronous so it doesn’t add unnecessary latency to the UI.
*/
@interface SDImageCache : NSObject

/**
* The maximum "total cost" of the in-memory image cache. The cost function is the number of pixels held in memory.
*/
@property (assign, nonatomic) NSUInteger maxMemoryCost;

/**
* The maximum length of time to keep an image in the cache, in seconds
*/
Expand All @@ -40,7 +43,7 @@ typedef enum SDImageCacheType SDImageCacheType;
/**
* The maximum size of the cache, in bytes.
*/
@property (assign, nonatomic) unsigned long long maxCacheSize;
@property (assign, nonatomic) NSUInteger maxCacheSize;

/**
* Returns global shared cache instance
Expand Down Expand Up @@ -85,13 +88,14 @@ typedef enum SDImageCacheType SDImageCacheType;
* Store an image into memory and optionally disk cache at the given key.
*
* @param image The image to store
* @param data The image data as returned by the server, this representation will be used for disk storage
* @param recalculate BOOL indicates if imageData can be used or a new data should be constructed from the UIImage
* @param imageData The image data as returned by the server, this representation will be used for disk storage
* instead of converting the given image object into a storable/compressed image format in order
* to save quality and CPU
* @param key The unique image cache key, usually it's image absolute URL
* @param toDisk Store the image to disk cache if YES
*/
- (void)storeImage:(UIImage *)image imageData:(NSData *)data forKey:(NSString *)key toDisk:(BOOL)toDisk;
- (void)storeImage:(UIImage *)image recalculateFromImage:(BOOL)recalculate imageData:(NSData *)imageData forKey:(NSString *)key toDisk:(BOOL)toDisk;

/**
* Query the disk cache asynchronously.
Expand Down Expand Up @@ -138,6 +142,7 @@ typedef enum SDImageCacheType SDImageCacheType;
* Clear all disk cached images
*/
- (void)clearDisk;
- (void)clearDiskOnCompletion:(void (^)())completion;

/**
* Remove all expired cached image from disk
Expand All @@ -147,7 +152,7 @@ typedef enum SDImageCacheType SDImageCacheType;
/**
* Get the size used by the disk cache
*/
- (unsigned long long)getSize;
- (NSUInteger)getSize;

/**
* Get the number of images in the disk cache
Expand All @@ -157,7 +162,7 @@ typedef enum SDImageCacheType SDImageCacheType;
/**
* Asynchronously calculate the disk cache's size.
*/
- (void)calculateSizeWithCompletionBlock:(void (^)(NSUInteger fileCount, unsigned long long totalSize))completionBlock;
- (void)calculateSizeWithCompletionBlock:(void (^)(NSUInteger fileCount, NSUInteger totalSize))completionBlock;

/**
* Check if image exists in cache already
Expand Down
Loading

0 comments on commit e1ddd8e

Please sign in to comment.