Fix the colorspace of hardware supported on macOS

Should use device RGB, like Color LCD
This commit is contained in:
DreamPiggy 2023-07-13 15:07:22 +08:00
parent cc89e14fdd
commit 67da434e79
1 changed files with 28 additions and 12 deletions

View File

@ -20,7 +20,7 @@
#import "SDDeviceHelper.h"
#import <Accelerate/Accelerate.h>
#define kCGColorSpaceDeviceRGB @"kCGColorSpaceDeviceRGB"
#define kCGColorSpaceDeviceRGB CFSTR("kCGColorSpaceDeviceRGB")
#if SD_UIKIT
static inline UIImage *SDImageDecodeUIKit(UIImage *image) {
@ -293,7 +293,17 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
static CGColorSpaceRef colorSpace;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
#if SD_MAC
NSScreen *mainScreen = nil;
if (@available(macOS 10.12, *)) {
mainScreen = [NSScreen mainScreen];
} else {
mainScreen = [NSScreen screens].firstObject;
}
colorSpace = mainScreen.colorSpace.CGColorSpace;
#else
colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
#endif
});
return colorSpace;
}
@ -328,11 +338,16 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
if (!supported) return supported;
// 2. Check color space
CGColorSpaceRef colorSpace = CGImageGetColorSpace(cgImage);
CGColorSpaceRef perferredColorSpace = [self colorSpaceGetDeviceRGB];
if (colorSpace == perferredColorSpace) {
return supported;
} else {
if (@available(iOS 10.0, tvOS 10.0, macOS 10.6, watchOS 3.0, *)) {
CGColorSpaceRef colorspace = CGImageGetColorSpace(cgImage);
NSString *colorspaceName = (__bridge_transfer NSString *)CGColorSpaceCopyName(colorspace);
NSString *colorspaceName = (__bridge_transfer NSString *)CGColorSpaceCopyName(colorSpace);
// Seems sRGB/deviceRGB always supported, P3 not always
if ([colorspaceName isEqualToString:(__bridge NSString *)kCGColorSpaceSRGB] || [colorspaceName isEqualToString:kCGColorSpaceDeviceRGB]) {
if ([colorspaceName isEqualToString:(__bridge NSString *)kCGColorSpaceDeviceRGB]
|| [colorspaceName isEqualToString:(__bridge NSString *)kCGColorSpaceSRGB]) {
supported &= YES;
} else {
supported &= NO;
@ -343,6 +358,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
return supported;
}
}
}
+ (BOOL)CGImageContainsAlpha:(CGImageRef)cgImage {
if (!cgImage) {