Support to detect the RGB16 bitmap info, fix the iOS 11- decode issues (#87)
Support to detect the RGB 16 bits bitmap info Also, fallback when the libwebp don't support the target bitmap info, should not just return nil
This commit is contained in:
parent
b442fafefe
commit
d91987f623
|
@ -91,15 +91,21 @@ static inline CGContextRef _Nullable CreateWebPCanvas(BOOL hasAlpha, CGSize canv
|
||||||
WEBP_CSP_MODE ConvertCSPMode(CGBitmapInfo bitmapInfo) {
|
WEBP_CSP_MODE ConvertCSPMode(CGBitmapInfo bitmapInfo) {
|
||||||
// Get alpha info, byteOrder info
|
// Get alpha info, byteOrder info
|
||||||
CGImageAlphaInfo alphaInfo = bitmapInfo & kCGBitmapAlphaInfoMask;
|
CGImageAlphaInfo alphaInfo = bitmapInfo & kCGBitmapAlphaInfoMask;
|
||||||
CGBitmapInfo byteOrderInfo = bitmapInfo & kCGBitmapByteOrderMask;
|
CGImageByteOrderInfo byteOrderInfo = bitmapInfo & kCGBitmapByteOrderMask;
|
||||||
|
size_t bitsPerPixel = 8;
|
||||||
|
if (bitmapInfo & kCGBitmapFloatComponents) {
|
||||||
|
bitsPerPixel = 16; // 16-Bits, which don't support currently!
|
||||||
|
}
|
||||||
BOOL byteOrderNormal = NO;
|
BOOL byteOrderNormal = NO;
|
||||||
switch (byteOrderInfo) {
|
switch (byteOrderInfo) {
|
||||||
case kCGBitmapByteOrderDefault: {
|
case kCGImageByteOrderDefault: {
|
||||||
byteOrderNormal = YES;
|
byteOrderNormal = YES;
|
||||||
} break;
|
} break;
|
||||||
case kCGBitmapByteOrder32Little: {
|
case kCGImageByteOrder32Little:
|
||||||
|
case kCGImageByteOrder16Little: {
|
||||||
} break;
|
} break;
|
||||||
case kCGBitmapByteOrder32Big: {
|
case kCGImageByteOrder32Big:
|
||||||
|
case kCGImageByteOrder16Big: {
|
||||||
byteOrderNormal = YES;
|
byteOrderNormal = YES;
|
||||||
} break;
|
} break;
|
||||||
default: break;
|
default: break;
|
||||||
|
@ -161,7 +167,7 @@ WEBP_CSP_MODE ConvertCSPMode(CGBitmapInfo bitmapInfo) {
|
||||||
break;
|
break;
|
||||||
case kCGImageAlphaOnly: {
|
case kCGImageAlphaOnly: {
|
||||||
// A
|
// A
|
||||||
// Unsupported
|
// Unsupported!
|
||||||
return MODE_LAST;
|
return MODE_LAST;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -621,8 +627,13 @@ WEBP_CSP_MODE ConvertCSPMode(CGBitmapInfo bitmapInfo) {
|
||||||
CGBitmapInfo bitmapInfo = pixelFormat.bitmapInfo;
|
CGBitmapInfo bitmapInfo = pixelFormat.bitmapInfo;
|
||||||
WEBP_CSP_MODE mode = ConvertCSPMode(bitmapInfo);
|
WEBP_CSP_MODE mode = ConvertCSPMode(bitmapInfo);
|
||||||
if (mode == MODE_LAST) {
|
if (mode == MODE_LAST) {
|
||||||
NSAssert(NO, @"Unsupported libwebp preferred CGBitmapInfo: %d", bitmapInfo);
|
#if DEBUG
|
||||||
return nil;
|
NSLog(@"Unsupported libwebp preferred CGBitmapInfo: %d", bitmapInfo);
|
||||||
|
#endif
|
||||||
|
// Fallback to RGBA8888/RGB888 instead
|
||||||
|
mode = MODE_rgbA;
|
||||||
|
bitmapInfo = kCGBitmapByteOrderDefault;
|
||||||
|
bitmapInfo |= hasAlpha ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNoneSkipLast;
|
||||||
}
|
}
|
||||||
config.output.colorspace = mode;
|
config.output.colorspace = mode;
|
||||||
config.options.use_threads = 1;
|
config.options.use_threads = 1;
|
||||||
|
|
Loading…
Reference in New Issue