@@ -24,7 +24,11 @@ + (UIImage *)sd_imageWithWebPData:(NSData *)data {
2424 return nil ;
2525 }
2626
27- config.output .colorspace = MODE_rgbA;
27+ if (WebPGetFeatures (data.bytes , data.length , &config.input ) != VP8_STATUS_OK) {
28+ return nil ;
29+ }
30+
31+ config.output .colorspace = config.input .has_alpha ? MODE_rgbA : MODE_RGB;
2832 config.options .use_threads = 1 ;
2933
3034 // Decode the WebP image data into a RGBA value array.
@@ -43,9 +47,10 @@ + (UIImage *)sd_imageWithWebPData:(NSData *)data {
4347 CGDataProviderRef provider =
4448 CGDataProviderCreateWithData (NULL , config.output .u .RGBA .rgba , config.output .u .RGBA .size , FreeImageData);
4549 CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB ();
46- CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast ;
50+ CGBitmapInfo bitmapInfo = config.input .has_alpha ? kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast : 0 ;
51+ size_t components = config.input .has_alpha ? 4 : 3 ;
4752 CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault ;
48- CGImageRef imageRef = CGImageCreate (width, height, 8 , 32 , 4 * width, colorSpaceRef, bitmapInfo, provider, NULL , NO , renderingIntent);
53+ CGImageRef imageRef = CGImageCreate (width, height, 8 , components * 8 , components * width, colorSpaceRef, bitmapInfo, provider, NULL , NO , renderingIntent);
4954
5055 CGColorSpaceRelease (colorSpaceRef);
5156 CGDataProviderRelease (provider);
0 commit comments