Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to detect the RGB16 bitmap info, fix the iOS 11- decode issues #87

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions SDWebImageWebPCoder/Classes/SDImageWebPCoder.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,21 @@ static inline CGContextRef _Nullable CreateWebPCanvas(BOOL hasAlpha, CGSize canv
WEBP_CSP_MODE ConvertCSPMode(CGBitmapInfo bitmapInfo) {
// Get alpha info, byteOrder info
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;
switch (byteOrderInfo) {
case kCGBitmapByteOrderDefault: {
case kCGImageByteOrderDefault: {
byteOrderNormal = YES;
} break;
case kCGBitmapByteOrder32Little: {
case kCGImageByteOrder32Little:
case kCGImageByteOrder16Little: {
} break;
case kCGBitmapByteOrder32Big: {
case kCGImageByteOrder32Big:
case kCGImageByteOrder16Big: {
byteOrderNormal = YES;
} break;
default: break;
Expand Down Expand Up @@ -161,7 +167,7 @@ WEBP_CSP_MODE ConvertCSPMode(CGBitmapInfo bitmapInfo) {
break;
case kCGImageAlphaOnly: {
// A
// Unsupported
// Unsupported!
return MODE_LAST;
}
break;
Expand Down Expand Up @@ -621,8 +627,13 @@ - (nullable CGImageRef)sd_createWebpImageWithData:(WebPData)webpData colorSpace:
CGBitmapInfo bitmapInfo = pixelFormat.bitmapInfo;
WEBP_CSP_MODE mode = ConvertCSPMode(bitmapInfo);
if (mode == MODE_LAST) {
NSAssert(NO, @"Unsupported libwebp preferred CGBitmapInfo: %d", bitmapInfo);
return nil;
#if DEBUG
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.options.use_threads = 1;
Expand Down
Loading