Fix the similiar case when input image is CMYK image, check color space model as well :)
This commit is contained in:
parent
6693ecb35a
commit
777065d638
|
@ -766,11 +766,14 @@ static CGSize SDCalculateThumbnailSize(CGSize fullSize, BOOL preserveAspectRatio
|
||||||
if (!dataRef) {
|
if (!dataRef) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
// Check colorSpace is RGB/RGBA
|
||||||
|
CGColorSpaceRef colorSpace = CGImageGetColorSpace(imageRef);
|
||||||
|
BOOL isRGB = CGColorSpaceGetModel(colorSpace) == kCGColorSpaceModelRGB;
|
||||||
|
|
||||||
uint8_t *rgba = NULL; // RGBA Buffer managed by CFData, don't call `free` on it, instead call `CFRelease` on `dataRef`
|
uint8_t *rgba = NULL; // RGBA Buffer managed by CFData, don't call `free` on it, instead call `CFRelease` on `dataRef`
|
||||||
// We could not assume that input CGImage's color mode is always RGB888/RGBA8888. Convert all other cases to target color mode using vImage
|
// We could not assume that input CGImage's color mode is always RGB888/RGBA8888. Convert all other cases to target color mode using vImage
|
||||||
BOOL isRGB888 = byteOrderNormal && alphaInfo == kCGImageAlphaNone && components == 3;
|
BOOL isRGB888 = isRGB && byteOrderNormal && alphaInfo == kCGImageAlphaNone && components == 3;
|
||||||
BOOL isRGBA8888 = byteOrderNormal && alphaInfo == kCGImageAlphaLast && components == 4;
|
BOOL isRGBA8888 = isRGB && byteOrderNormal && alphaInfo == kCGImageAlphaLast && components == 4;
|
||||||
if (isRGB888 || isRGBA8888) {
|
if (isRGB888 || isRGBA8888) {
|
||||||
// If the input CGImage is already RGB888/RGBA8888
|
// If the input CGImage is already RGB888/RGBA8888
|
||||||
rgba = (uint8_t *)CFDataGetBytePtr(dataRef);
|
rgba = (uint8_t *)CFDataGetBytePtr(dataRef);
|
||||||
|
@ -782,7 +785,7 @@ static CGSize SDCalculateThumbnailSize(CGSize fullSize, BOOL preserveAspectRatio
|
||||||
vImage_CGImageFormat srcFormat = {
|
vImage_CGImageFormat srcFormat = {
|
||||||
.bitsPerComponent = (uint32_t)bitsPerComponent,
|
.bitsPerComponent = (uint32_t)bitsPerComponent,
|
||||||
.bitsPerPixel = (uint32_t)bitsPerPixel,
|
.bitsPerPixel = (uint32_t)bitsPerPixel,
|
||||||
.colorSpace = CGImageGetColorSpace(imageRef),
|
.colorSpace = colorSpace,
|
||||||
.bitmapInfo = bitmapInfo
|
.bitmapInfo = bitmapInfo
|
||||||
};
|
};
|
||||||
vImage_CGImageFormat destFormat = {
|
vImage_CGImageFormat destFormat = {
|
||||||
|
|
Loading…
Reference in New Issue