Authored by Bogdan Poplauschi

Fixed build due to latest animated WebP support that was not properly adapted fo…

…r OSX. For OSX, this will not work because the `animatedImageWithImages:duration:` API does not have an equivalent there.
... ... @@ -29,7 +29,7 @@
// Do any additional setup after loading the view.
[self.imageView1 sd_setImageWithURL:[NSURL URLWithString:@"http://assets.sbnation.com/assets/2512203/dogflops.gif"]];
[self.imageView2 sd_setImageWithURL:[NSURL URLWithString:@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp"]];
[self.imageView3 sd_setImageWithURL:[NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage000.jpg"]];
[self.imageView3 sd_setImageWithURL:[NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"]];
[self.imageView4 sd_setImageWithURL:[NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage001.jpg"]];
}
... ...
... ... @@ -14,6 +14,7 @@
@interface NSImage (WebCache)
- (CGImageRef)CGImage;
- (NSArray<NSImage *> *)images;
- (BOOL)isGIF;
... ...
... ... @@ -12,6 +12,12 @@
@implementation NSImage (WebCache)
- (CGImageRef)CGImage {
NSRect imageRect = NSMakeRect(0, 0, self.size.width, self.size.height);
CGImageRef cgImage = [self CGImageForProposedRect:&imageRect context:NULL hints:nil];
return cgImage;
}
- (NSArray<NSImage *> *)images {
return nil;
}
... ...
... ... @@ -12,6 +12,7 @@
#import "webp/decode.h"
#import "webp/mux_types.h"
#import "webp/demux.h"
#import "NSImage+WebCache.h"
// Callback for CGDataProviderRelease
static void FreeImageData(void *info, const void *data, size_t size) {
... ... @@ -71,8 +72,16 @@ static void FreeImageData(void *info, const void *data, size_t size) {
WebPDemuxReleaseIterator(&iter);
WebPDemuxDelete(demuxer);
UIImage *animateImage = [UIImage animatedImageWithImages:images duration:duration];
return animateImage;
UIImage *finalImage = nil;
#if SD_UIKIT || SD_WATCH
finalImage = [UIImage animatedImageWithImages:images duration:duration];
#elif SD_MAC
if ([images count] > 0) {
finalImage = images[0];
}
#endif
return finalImage;
}
... ... @@ -98,7 +107,11 @@ static void FreeImageData(void *info, const void *data, size_t size) {
CGContextDrawImage(blendCanvas, imageRect, image.CGImage);
CGImageRef newImageRef = CGBitmapContextCreateImage(blendCanvas);
#if SD_UIKIT || SD_WATCH
image = [UIImage imageWithCGImage:newImageRef];
#elif SD_MAC
image = [[UIImage alloc] initWithCGImage:newImageRef size:NSZeroSize];
#endif
CGImageRelease(newImageRef);
CGContextRelease(blendCanvas);
... ...
... ... @@ -99,11 +99,16 @@ static char TAG_ACTIVITY_SHOW;
setImageBlock(image, imageData);
return;
}
#if SD_UIKIT
#if SD_UIKIT || SD_MAC
if ([self isKindOfClass:[UIImageView class]]) {
UIImageView *imageView = (UIImageView *)self;
imageView.image = image;
} else if ([self isKindOfClass:[UIButton class]]) {
}
#endif
#if SD_UIKIT
if ([self isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)self;
[button setImage:image forState:UIControlStateNormal];
}
... ...