forked from mwaterfall/MWPhotoBrowser
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,075 additions
and
817 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
MWPhotoBrowser/Libraries/SDWebImage/SDWebImage/MKAnnotationView+WebCache.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
69 changes: 69 additions & 0 deletions
69
MWPhotoBrowser/Libraries/SDWebImage/SDWebImage/MKAnnotationView+WebCache.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
10 changes: 10 additions & 0 deletions
10
MWPhotoBrowser/Libraries/SDWebImage/SDWebImage/NSData+ImageContentType.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
40 changes: 40 additions & 0 deletions
40
MWPhotoBrowser/Libraries/SDWebImage/SDWebImage/NSData+ImageContentType.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.