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.
Showing
5 changed files
with
30 additions
and
5 deletions
@@ -29,7 +29,7 @@ | @@ -29,7 +29,7 @@ | ||
29 | // Do any additional setup after loading the view. | 29 | // Do any additional setup after loading the view. |
30 | [self.imageView1 sd_setImageWithURL:[NSURL URLWithString:@"http://assets.sbnation.com/assets/2512203/dogflops.gif"]]; | 30 | [self.imageView1 sd_setImageWithURL:[NSURL URLWithString:@"http://assets.sbnation.com/assets/2512203/dogflops.gif"]]; |
31 | [self.imageView2 sd_setImageWithURL:[NSURL URLWithString:@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp"]]; | 31 | [self.imageView2 sd_setImageWithURL:[NSURL URLWithString:@"http://www.ioncannon.net/wp-content/uploads/2011/06/test2.webp"]]; |
32 | - [self.imageView3 sd_setImageWithURL:[NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage000.jpg"]]; | 32 | + [self.imageView3 sd_setImageWithURL:[NSURL URLWithString:@"http://littlesvr.ca/apng/images/SteamEngine.webp"]]; |
33 | [self.imageView4 sd_setImageWithURL:[NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage001.jpg"]]; | 33 | [self.imageView4 sd_setImageWithURL:[NSURL URLWithString:@"http://s3.amazonaws.com/fast-image-cache/demo-images/FICDDemoImage001.jpg"]]; |
34 | } | 34 | } |
35 | 35 |
@@ -12,6 +12,12 @@ | @@ -12,6 +12,12 @@ | ||
12 | 12 | ||
13 | @implementation NSImage (WebCache) | 13 | @implementation NSImage (WebCache) |
14 | 14 | ||
15 | +- (CGImageRef)CGImage { | ||
16 | + NSRect imageRect = NSMakeRect(0, 0, self.size.width, self.size.height); | ||
17 | + CGImageRef cgImage = [self CGImageForProposedRect:&imageRect context:NULL hints:nil]; | ||
18 | + return cgImage; | ||
19 | +} | ||
20 | + | ||
15 | - (NSArray<NSImage *> *)images { | 21 | - (NSArray<NSImage *> *)images { |
16 | return nil; | 22 | return nil; |
17 | } | 23 | } |
@@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
12 | #import "webp/decode.h" | 12 | #import "webp/decode.h" |
13 | #import "webp/mux_types.h" | 13 | #import "webp/mux_types.h" |
14 | #import "webp/demux.h" | 14 | #import "webp/demux.h" |
15 | +#import "NSImage+WebCache.h" | ||
15 | 16 | ||
16 | // Callback for CGDataProviderRelease | 17 | // Callback for CGDataProviderRelease |
17 | static void FreeImageData(void *info, const void *data, size_t size) { | 18 | 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) { | @@ -71,8 +72,16 @@ static void FreeImageData(void *info, const void *data, size_t size) { | ||
71 | 72 | ||
72 | WebPDemuxReleaseIterator(&iter); | 73 | WebPDemuxReleaseIterator(&iter); |
73 | WebPDemuxDelete(demuxer); | 74 | WebPDemuxDelete(demuxer); |
74 | - UIImage *animateImage = [UIImage animatedImageWithImages:images duration:duration]; | ||
75 | - return animateImage; | 75 | + |
76 | + UIImage *finalImage = nil; | ||
77 | +#if SD_UIKIT || SD_WATCH | ||
78 | + finalImage = [UIImage animatedImageWithImages:images duration:duration]; | ||
79 | +#elif SD_MAC | ||
80 | + if ([images count] > 0) { | ||
81 | + finalImage = images[0]; | ||
82 | + } | ||
83 | +#endif | ||
84 | + return finalImage; | ||
76 | } | 85 | } |
77 | 86 | ||
78 | 87 | ||
@@ -98,7 +107,11 @@ static void FreeImageData(void *info, const void *data, size_t size) { | @@ -98,7 +107,11 @@ static void FreeImageData(void *info, const void *data, size_t size) { | ||
98 | CGContextDrawImage(blendCanvas, imageRect, image.CGImage); | 107 | CGContextDrawImage(blendCanvas, imageRect, image.CGImage); |
99 | CGImageRef newImageRef = CGBitmapContextCreateImage(blendCanvas); | 108 | CGImageRef newImageRef = CGBitmapContextCreateImage(blendCanvas); |
100 | 109 | ||
110 | +#if SD_UIKIT || SD_WATCH | ||
101 | image = [UIImage imageWithCGImage:newImageRef]; | 111 | image = [UIImage imageWithCGImage:newImageRef]; |
112 | +#elif SD_MAC | ||
113 | + image = [[UIImage alloc] initWithCGImage:newImageRef size:NSZeroSize]; | ||
114 | +#endif | ||
102 | 115 | ||
103 | CGImageRelease(newImageRef); | 116 | CGImageRelease(newImageRef); |
104 | CGContextRelease(blendCanvas); | 117 | CGContextRelease(blendCanvas); |
@@ -99,11 +99,16 @@ static char TAG_ACTIVITY_SHOW; | @@ -99,11 +99,16 @@ static char TAG_ACTIVITY_SHOW; | ||
99 | setImageBlock(image, imageData); | 99 | setImageBlock(image, imageData); |
100 | return; | 100 | return; |
101 | } | 101 | } |
102 | -#if SD_UIKIT | 102 | + |
103 | +#if SD_UIKIT || SD_MAC | ||
103 | if ([self isKindOfClass:[UIImageView class]]) { | 104 | if ([self isKindOfClass:[UIImageView class]]) { |
104 | UIImageView *imageView = (UIImageView *)self; | 105 | UIImageView *imageView = (UIImageView *)self; |
105 | imageView.image = image; | 106 | imageView.image = image; |
106 | - } else if ([self isKindOfClass:[UIButton class]]) { | 107 | + } |
108 | +#endif | ||
109 | + | ||
110 | +#if SD_UIKIT | ||
111 | + if ([self isKindOfClass:[UIButton class]]) { | ||
107 | UIButton *button = (UIButton *)self; | 112 | UIButton *button = (UIButton *)self; |
108 | [button setImage:image forState:UIControlStateNormal]; | 113 | [button setImage:image forState:UIControlStateNormal]; |
109 | } | 114 | } |
-
Please register or login to post a comment