|
|
@@ -149,7 +149,7 @@ static inline UIColor * SDGetColorFromGrayscale(Pixel_88 pixel, CGBitmapInfo bit
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-static inline UIColor * SDGetColorFromRGBA(Pixel_8888 pixel, CGBitmapInfo bitmapInfo, CGColorSpaceRef cgColorSpace) {
|
|
|
+static inline UIColor * SDGetColorFromRGBA8(Pixel_8888 pixel, CGBitmapInfo bitmapInfo, CGColorSpaceRef cgColorSpace) {
|
|
|
// Get alpha info, byteOrder info
|
|
|
CGImageAlphaInfo alphaInfo = bitmapInfo & kCGBitmapAlphaInfoMask;
|
|
|
CGBitmapInfo byteOrderInfo = bitmapInfo & kCGBitmapByteOrderMask;
|
|
|
@@ -752,6 +752,19 @@ static NSString * _Nullable SDGetCIFilterNameFromBlendMode(CGBlendMode blendMode
|
|
|
return nil;
|
|
|
}
|
|
|
|
|
|
+ // Check pixel format
|
|
|
+ CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
|
|
|
+ size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
|
|
|
+ if (@available(iOS 12.0, tvOS 12.0, macOS 10.14, watchOS 5.0, *)) {
|
|
|
+ CGImagePixelFormatInfo pixelFormat = (bitmapInfo & kCGImagePixelFormatMask);
|
|
|
+ if (pixelFormat != kCGImagePixelFormatPacked || bitsPerComponent > 8) {
|
|
|
+ // like RGBA1010102, need bitwise to extract pixel from single uint32_t, we don't support currently
|
|
|
+ SD_LOG("Unsupported pixel format: %u, bpc: %zu for CGImage: %@", pixelFormat, bitsPerComponent, imageRef);
|
|
|
+ CGImageRelease(imageRef);
|
|
|
+ return nil;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Get pixels
|
|
|
CGDataProviderRef provider = CGImageGetDataProvider(imageRef);
|
|
|
if (!provider) {
|
|
|
@@ -766,8 +779,7 @@ static NSString * _Nullable SDGetCIFilterNameFromBlendMode(CGBlendMode blendMode
|
|
|
|
|
|
// Get pixel at point
|
|
|
size_t bytesPerRow = CGImageGetBytesPerRow(imageRef);
|
|
|
- size_t components = CGImageGetBitsPerPixel(imageRef) / CGImageGetBitsPerComponent(imageRef);
|
|
|
- CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
|
|
|
+ size_t components = CGImageGetBitsPerPixel(imageRef) / bitsPerComponent;
|
|
|
|
|
|
CFRange range = CFRangeMake(bytesPerRow * y + components * x, components);
|
|
|
if (CFDataGetLength(data) < range.location + range.length) {
|
|
|
@@ -793,7 +805,7 @@ static NSString * _Nullable SDGetCIFilterNameFromBlendMode(CGBlendMode blendMode
|
|
|
CFRelease(data);
|
|
|
CGImageRelease(imageRef);
|
|
|
// Convert to color
|
|
|
- return SDGetColorFromRGBA(pixel, bitmapInfo, colorSpace);
|
|
|
+ return SDGetColorFromRGBA8(pixel, bitmapInfo, colorSpace);
|
|
|
} else {
|
|
|
SD_LOG("Unsupported components: %zu", components);
|
|
|
CFRelease(data);
|
|
|
@@ -826,6 +838,19 @@ static NSString * _Nullable SDGetCIFilterNameFromBlendMode(CGBlendMode blendMode
|
|
|
return nil;
|
|
|
}
|
|
|
|
|
|
+ // Check pixel format
|
|
|
+ CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
|
|
|
+ size_t bitsPerComponent = CGImageGetBitsPerComponent(imageRef);
|
|
|
+ if (@available(iOS 12.0, tvOS 12.0, macOS 10.14, watchOS 5.0, *)) {
|
|
|
+ CGImagePixelFormatInfo pixelFormat = (bitmapInfo & kCGImagePixelFormatMask);
|
|
|
+ if (pixelFormat != kCGImagePixelFormatPacked || bitsPerComponent > 8) {
|
|
|
+ // like RGBA1010102, need bitwise to extract pixel from single uint32_t, we don't support currently
|
|
|
+ SD_LOG("Unsupported pixel format: %u, bpc: %zu for CGImage: %@", pixelFormat, bitsPerComponent, imageRef);
|
|
|
+ CGImageRelease(imageRef);
|
|
|
+ return nil;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Get pixels
|
|
|
CGDataProviderRef provider = CGImageGetDataProvider(imageRef);
|
|
|
if (!provider) {
|
|
|
@@ -840,7 +865,7 @@ static NSString * _Nullable SDGetCIFilterNameFromBlendMode(CGBlendMode blendMode
|
|
|
|
|
|
// Get pixels with rect
|
|
|
size_t bytesPerRow = CGImageGetBytesPerRow(imageRef);
|
|
|
- size_t components = CGImageGetBitsPerPixel(imageRef) / CGImageGetBitsPerComponent(imageRef);
|
|
|
+ size_t components = CGImageGetBitsPerPixel(imageRef) / bitsPerComponent;
|
|
|
|
|
|
size_t start = bytesPerRow * CGRectGetMinY(rect) + components * CGRectGetMinX(rect);
|
|
|
size_t end = bytesPerRow * (CGRectGetMaxY(rect) - 1) + components * CGRectGetMaxX(rect);
|
|
|
@@ -855,7 +880,6 @@ static NSString * _Nullable SDGetCIFilterNameFromBlendMode(CGBlendMode blendMode
|
|
|
size_t col = CGRectGetMaxX(rect);
|
|
|
|
|
|
// Convert to color
|
|
|
- CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
|
|
|
NSMutableArray<UIColor *> *colors = [NSMutableArray arrayWithCapacity:CGRectGetWidth(rect) * CGRectGetHeight(rect)];
|
|
|
// ColorSpace
|
|
|
CGColorSpaceRef colorSpace = CGImageGetColorSpace(imageRef);
|
|
|
@@ -874,12 +898,12 @@ static NSString * _Nullable SDGetCIFilterNameFromBlendMode(CGBlendMode blendMode
|
|
|
} else {
|
|
|
if (components == 3) {
|
|
|
Pixel_8888 pixel = {pixels[index], pixels[index+1], pixels[index+2], 0};
|
|
|
- color = SDGetColorFromRGBA(pixel, bitmapInfo, colorSpace);
|
|
|
+ color = SDGetColorFromRGBA8(pixel, bitmapInfo, colorSpace);
|
|
|
} else if (components == 4) {
|
|
|
Pixel_8888 pixel = {pixels[index], pixels[index+1], pixels[index+2], pixels[index+3]};
|
|
|
- color = SDGetColorFromRGBA(pixel, bitmapInfo, colorSpace);
|
|
|
+ color = SDGetColorFromRGBA8(pixel, bitmapInfo, colorSpace);
|
|
|
} else {
|
|
|
- SD_LOG("Unsupported components: %zu", components);
|
|
|
+ SD_LOG("Unsupported components: %zu for CGImage: %@", components, imageRef);
|
|
|
}
|
|
|
}
|
|
|
if (color) {
|