Authored by DreamPiggy
Committed by GitHub

Merge pull request #2348 from dreampiggy/fix_webp_decoding_iOS_12

Fix that WebP (including Animated WebP) decoding issue on iOS 12.
@@ -73,9 +73,12 @@ @@ -73,9 +73,12 @@
73 int canvasWidth = WebPDemuxGetI(demuxer, WEBP_FF_CANVAS_WIDTH); 73 int canvasWidth = WebPDemuxGetI(demuxer, WEBP_FF_CANVAS_WIDTH);
74 int canvasHeight = WebPDemuxGetI(demuxer, WEBP_FF_CANVAS_HEIGHT); 74 int canvasHeight = WebPDemuxGetI(demuxer, WEBP_FF_CANVAS_HEIGHT);
75 CGBitmapInfo bitmapInfo; 75 CGBitmapInfo bitmapInfo;
  76 + // `CGBitmapContextCreate` does not support RGB888 on iOS. Where `CGImageCreate` supports.
76 if (!(flags & ALPHA_FLAG)) { 77 if (!(flags & ALPHA_FLAG)) {
  78 + // RGBX8888
77 bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipLast; 79 bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipLast;
78 } else { 80 } else {
  81 + // RGBA8888
79 bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast; 82 bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast;
80 } 83 }
81 CGContextRef canvas = CGBitmapContextCreate(NULL, canvasWidth, canvasHeight, 8, 0, SDCGColorSpaceGetDeviceRGB(), bitmapInfo); 84 CGContextRef canvas = CGBitmapContextCreate(NULL, canvasWidth, canvasHeight, 8, 0, SDCGColorSpaceGetDeviceRGB(), bitmapInfo);
@@ -298,7 +301,15 @@ @@ -298,7 +301,15 @@
298 CGDataProviderRef provider = 301 CGDataProviderRef provider =
299 CGDataProviderCreateWithData(NULL, config.output.u.RGBA.rgba, config.output.u.RGBA.size, FreeImageData); 302 CGDataProviderCreateWithData(NULL, config.output.u.RGBA.rgba, config.output.u.RGBA.size, FreeImageData);
300 CGColorSpaceRef colorSpaceRef = SDCGColorSpaceGetDeviceRGB(); 303 CGColorSpaceRef colorSpaceRef = SDCGColorSpaceGetDeviceRGB();
301 - CGBitmapInfo bitmapInfo = config.input.has_alpha ? kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast : kCGBitmapByteOrder32Big | kCGImageAlphaNoneSkipLast; 304 + CGBitmapInfo bitmapInfo;
  305 + // `CGBitmapContextCreate` does not support RGB888 on iOS. Where `CGImageCreate` supports.
  306 + if (!config.input.has_alpha) {
  307 + // RGB888
  308 + bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaNone;
  309 + } else {
  310 + // RGBA8888
  311 + bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast;
  312 + }
302 size_t components = config.input.has_alpha ? 4 : 3; 313 size_t components = config.input.has_alpha ? 4 : 3;
303 CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; 314 CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
304 CGImageRef imageRef = CGImageCreate(width, height, 8, components * 8, components * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent); 315 CGImageRef imageRef = CGImageCreate(width, height, 8, components * 8, components * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);