Merge pull request #936 from flexih/master
Decoding webp, depends on source image data alpha status.
This commit is contained in:
commit
c3c55784cb
|
@ -24,7 +24,11 @@ static void FreeImageData(void *info, const void *data, size_t size)
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
config.output.colorspace = MODE_rgbA;
|
if (WebPGetFeatures(data.bytes, data.length, &config.input) != VP8_STATUS_OK) {
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
config.output.colorspace = config.input.has_alpha ? MODE_rgbA : MODE_RGB;
|
||||||
config.options.use_threads = 1;
|
config.options.use_threads = 1;
|
||||||
|
|
||||||
// Decode the WebP image data into a RGBA value array.
|
// Decode the WebP image data into a RGBA value array.
|
||||||
|
@ -43,9 +47,10 @@ static void FreeImageData(void *info, const void *data, size_t size)
|
||||||
CGDataProviderRef provider =
|
CGDataProviderRef provider =
|
||||||
CGDataProviderCreateWithData(NULL, config.output.u.RGBA.rgba, config.output.u.RGBA.size, FreeImageData);
|
CGDataProviderCreateWithData(NULL, config.output.u.RGBA.rgba, config.output.u.RGBA.size, FreeImageData);
|
||||||
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
|
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
|
||||||
CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast;
|
CGBitmapInfo bitmapInfo = config.input.has_alpha ? kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast : 0;
|
||||||
|
size_t components = config.input.has_alpha ? 4 : 3;
|
||||||
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
|
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
|
||||||
CGImageRef imageRef = CGImageCreate(width, height, 8, 32, 4 * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
|
CGImageRef imageRef = CGImageCreate(width, height, 8, components * 8, components * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
|
||||||
|
|
||||||
CGColorSpaceRelease(colorSpaceRef);
|
CGColorSpaceRelease(colorSpaceRef);
|
||||||
CGDataProviderRelease(provider);
|
CGDataProviderRelease(provider);
|
||||||
|
|
Loading…
Reference in New Issue