...
|
...
|
@@ -26,7 +26,9 @@ |
|
|
|
|
|
@autoreleasepool{
|
|
|
// do not decode animated images
|
|
|
if (image.images) { return image; }
|
|
|
if (image.images != nil) {
|
|
|
return image;
|
|
|
}
|
|
|
|
|
|
CGImageRef imageRef = image.CGImage;
|
|
|
|
...
|
...
|
@@ -35,16 +37,21 @@ |
|
|
alpha == kCGImageAlphaLast ||
|
|
|
alpha == kCGImageAlphaPremultipliedFirst ||
|
|
|
alpha == kCGImageAlphaPremultipliedLast);
|
|
|
|
|
|
if (anyAlpha) { return image; }
|
|
|
if (anyAlpha) {
|
|
|
return image;
|
|
|
}
|
|
|
|
|
|
// current
|
|
|
CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef));
|
|
|
CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef);
|
|
|
|
|
|
bool unsupportedColorSpace = (imageColorSpaceModel == 0 || imageColorSpaceModel == -1 || imageColorSpaceModel == kCGColorSpaceModelCMYK || imageColorSpaceModel == kCGColorSpaceModelIndexed);
|
|
|
if (unsupportedColorSpace)
|
|
|
BOOL unsupportedColorSpace = (imageColorSpaceModel == kCGColorSpaceModelUnknown ||
|
|
|
imageColorSpaceModel == kCGColorSpaceModelMonochrome ||
|
|
|
imageColorSpaceModel == kCGColorSpaceModelCMYK ||
|
|
|
imageColorSpaceModel == kCGColorSpaceModelIndexed);
|
|
|
if (unsupportedColorSpace) {
|
|
|
colorspaceRef = CGColorSpaceCreateDeviceRGB();
|
|
|
}
|
|
|
|
|
|
size_t width = CGImageGetWidth(imageRef);
|
|
|
size_t height = CGImageGetHeight(imageRef);
|
...
|
...
|
@@ -52,26 +59,33 @@ |
|
|
NSUInteger bytesPerRow = bytesPerPixel * width;
|
|
|
NSUInteger bitsPerComponent = 8;
|
|
|
|
|
|
|
|
|
// kCGImageAlphaNone is not supported in CGBitmapContextCreate.
|
|
|
// Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast
|
|
|
// to create bitmap graphics contexts without alpha info.
|
|
|
CGContextRef context = CGBitmapContextCreate(NULL,
|
|
|
width,
|
|
|
height,
|
|
|
bitsPerComponent,
|
|
|
bytesPerRow,
|
|
|
colorspaceRef,
|
|
|
kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
|
|
|
kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast);
|
|
|
|
|
|
// Draw the image into the context and retrieve the new image, which will now have an alpha layer
|
|
|
// Draw the image into the context and retrieve the new bitmap image without alpha
|
|
|
CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
|
|
|
CGImageRef imageRefWithAlpha = CGBitmapContextCreateImage(context);
|
|
|
UIImage *imageWithAlpha = [UIImage imageWithCGImage:imageRefWithAlpha scale:image.scale orientation:image.imageOrientation];
|
|
|
CGImageRef imageRefWithoutAlpha = CGBitmapContextCreateImage(context);
|
|
|
UIImage *imageWithoutAlpha = [UIImage imageWithCGImage:imageRefWithoutAlpha
|
|
|
scale:image.scale
|
|
|
orientation:image.imageOrientation];
|
|
|
|
|
|
if (unsupportedColorSpace)
|
|
|
if (unsupportedColorSpace) {
|
|
|
CGColorSpaceRelease(colorspaceRef);
|
|
|
}
|
|
|
|
|
|
CGContextRelease(context);
|
|
|
CGImageRelease(imageRefWithAlpha);
|
|
|
CGImageRelease(imageRefWithoutAlpha);
|
|
|
|
|
|
return imageWithAlpha;
|
|
|
return imageWithoutAlpha;
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|