Fix the compile issue on watchOS

This commit is contained in:
DreamPiggy 2019-12-30 17:41:08 +08:00
parent 40957da785
commit 2163691d11
1 changed files with 30 additions and 21 deletions

View File

@ -164,7 +164,9 @@ static inline UIColor * SDGetColorFromPixel(Pixel_8888 pixel, CGBitmapInfo bitma
return [UIColor colorWithRed:r green:g blue:b alpha:a]; return [UIColor colorWithRed:r green:g blue:b alpha:a];
} }
static inline CIColor *SDCIColorConvertFromUIColor(UIColor * _Nonnull color) { #if SD_UIKIT || SD_MAC
// Core Image Support
static inline CIColor *SDCIColorFromUIColor(UIColor * _Nonnull color) {
CGFloat red, green, blue, alpha; CGFloat red, green, blue, alpha;
#if SD_UIKIT #if SD_UIKIT
if (![color getRed:&red green:&green blue:&blue alpha:&alpha]) { if (![color getRed:&red green:&green blue:&blue alpha:&alpha]) {
@ -186,6 +188,19 @@ static inline CIColor *SDCIColorConvertFromUIColor(UIColor * _Nonnull color) {
return ciColor; return ciColor;
} }
static inline CGImageRef _Nullable SDCGImageFromCIImage(CIImage * _Nonnull ciImage) {
CGImageRef imageRef = NULL;
if (@available(iOS 10, macOS 10.12, tvOS 10, *)) {
imageRef = ciImage.CGImage;
}
if (!imageRef) {
CIContext *context = [CIContext context];
imageRef = [context createCGImage:ciImage fromRect:ciImage.extent];
}
return imageRef;
}
#endif
@implementation UIImage (Transform) @implementation UIImage (Transform)
- (void)sd_drawInRect:(CGRect)rect context:(CGContextRef)context scaleMode:(SDImageScaleMode)scaleMode clipsToBounds:(BOOL)clips { - (void)sd_drawInRect:(CGRect)rect context:(CGContextRef)context scaleMode:(SDImageScaleMode)scaleMode clipsToBounds:(BOOL)clips {
@ -400,7 +415,7 @@ static inline CIColor *SDCIColorConvertFromUIColor(UIColor * _Nonnull color) {
// CIImage shortcut // CIImage shortcut
if (self.CIImage) { if (self.CIImage) {
CIImage *ciImage = self.CIImage; CIImage *ciImage = self.CIImage;
CIImage *colorImage = [CIImage imageWithColor:SDCIColorConvertFromUIColor(tintColor)]; CIImage *colorImage = [CIImage imageWithColor:SDCIColorFromUIColor(tintColor)];
colorImage = [colorImage imageByCroppingToRect:ciImage.extent]; colorImage = [colorImage imageByCroppingToRect:ciImage.extent];
CIFilter *filter = [CIFilter filterWithName:@"CISourceAtopCompositing"]; CIFilter *filter = [CIFilter filterWithName:@"CISourceAtopCompositing"];
[filter setValue:colorImage forKey:kCIInputImageKey]; [filter setValue:colorImage forKey:kCIInputImageKey];
@ -435,19 +450,16 @@ static inline CIColor *SDCIColorConvertFromUIColor(UIColor * _Nonnull color) {
} }
- (nullable UIColor *)sd_colorAtPoint:(CGPoint)point { - (nullable UIColor *)sd_colorAtPoint:(CGPoint)point {
CGImageRef imageRef; CGImageRef imageRef = NULL;
// CIImage compatible // CIImage compatible
#if SD_UIKIT || SD_MAC
if (self.CIImage) { if (self.CIImage) {
CIImage *ciImage = self.CIImage; imageRef = SDCGImageFromCIImage(self.CIImage);
imageRef = ciImage.CGImage;
if (!imageRef) {
CIContext *context = [CIContext context];
imageRef = [context createCGImage:ciImage fromRect:ciImage.extent];
} }
} else { #endif
if (!imageRef) {
imageRef = self.CGImage; imageRef = self.CGImage;
} }
if (!imageRef) { if (!imageRef) {
return nil; return nil;
} }
@ -488,19 +500,16 @@ static inline CIColor *SDCIColorConvertFromUIColor(UIColor * _Nonnull color) {
} }
- (nullable NSArray<UIColor *> *)sd_colorsWithRect:(CGRect)rect { - (nullable NSArray<UIColor *> *)sd_colorsWithRect:(CGRect)rect {
CGImageRef imageRef; CGImageRef imageRef = NULL;
// CIImage shortcut // CIImage compatible
#if SD_UIKIT || SD_MAC
if (self.CIImage) { if (self.CIImage) {
CIImage *ciImage = self.CIImage; imageRef = SDCGImageFromCIImage(self.CIImage);
imageRef = ciImage.CGImage;
if (!imageRef) {
CIContext *context = [CIContext context];
imageRef = [context createCGImage:ciImage fromRect:ciImage.extent];
} }
} else { #endif
if (!imageRef) {
imageRef = self.CGImage; imageRef = self.CGImage;
} }
if (!imageRef) { if (!imageRef) {
return nil; return nil;
} }