81 lines
2.1 KiB
Objective-C
81 lines
2.1 KiB
Objective-C
/*
|
|
* This file is part of the SDWebImage package.
|
|
* (c) Olivier Poitrey <rs@dailymotion.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
#import "UIImage+WebCache.h"
|
|
|
|
#if SD_UIKIT
|
|
|
|
#import "objc/runtime.h"
|
|
|
|
@implementation UIImage (WebCache)
|
|
|
|
- (NSUInteger)sd_imageLoopCount {
|
|
NSUInteger imageLoopCount = 0;
|
|
NSNumber *value = objc_getAssociatedObject(self, @selector(sd_imageLoopCount));
|
|
if ([value isKindOfClass:[NSNumber class]]) {
|
|
imageLoopCount = value.unsignedIntegerValue;
|
|
}
|
|
return imageLoopCount;
|
|
}
|
|
|
|
- (void)setSd_imageLoopCount:(NSUInteger)sd_imageLoopCount {
|
|
NSNumber *value = @(sd_imageLoopCount);
|
|
objc_setAssociatedObject(self, @selector(sd_imageLoopCount), value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
}
|
|
|
|
- (BOOL)sd_isAnimated {
|
|
return (self.images != nil);
|
|
}
|
|
|
|
@end
|
|
|
|
#endif
|
|
|
|
#if SD_MAC
|
|
|
|
@implementation NSImage (WebCache)
|
|
|
|
- (NSUInteger)sd_imageLoopCount {
|
|
NSUInteger imageLoopCount = 0;
|
|
for (NSImageRep *rep in self.representations) {
|
|
if ([rep isKindOfClass:[NSBitmapImageRep class]]) {
|
|
NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)rep;
|
|
imageLoopCount = [[bitmapRep valueForProperty:NSImageLoopCount] unsignedIntegerValue];
|
|
break;
|
|
}
|
|
}
|
|
return imageLoopCount;
|
|
}
|
|
|
|
- (void)setSd_imageLoopCount:(NSUInteger)sd_imageLoopCount {
|
|
for (NSImageRep *rep in self.representations) {
|
|
if ([rep isKindOfClass:[NSBitmapImageRep class]]) {
|
|
NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)rep;
|
|
[bitmapRep setProperty:NSImageLoopCount withValue:@(sd_imageLoopCount)];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
- (BOOL)sd_isAnimated {
|
|
BOOL isGIF = NO;
|
|
for (NSImageRep *rep in self.representations) {
|
|
if ([rep isKindOfClass:[NSBitmapImageRep class]]) {
|
|
NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)rep;
|
|
NSUInteger frameCount = [[bitmapRep valueForProperty:NSImageFrameCount] unsignedIntegerValue];
|
|
isGIF = frameCount > 1 ? YES : NO;
|
|
break;
|
|
}
|
|
}
|
|
return isGIF;
|
|
}
|
|
|
|
@end
|
|
|
|
#endif
|