Merge branch 'master' of https://github.com/rs/SDWebImage into 5.x
# Conflicts: # SDWebImage/SDWebImageImageIOCoder.m
This commit is contained in:
commit
d515a36337
|
@ -221,21 +221,6 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|||
return colorSpace;
|
||||
}
|
||||
|
||||
+ (CGColorSpaceRef)imageRefGetColorSpace:(CGImageRef)imageRef {
|
||||
// current
|
||||
CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef));
|
||||
CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef);
|
||||
|
||||
BOOL unsupportedColorSpace = (imageColorSpaceModel == kCGColorSpaceModelUnknown ||
|
||||
imageColorSpaceModel == kCGColorSpaceModelMonochrome ||
|
||||
imageColorSpaceModel == kCGColorSpaceModelCMYK ||
|
||||
imageColorSpaceModel == kCGColorSpaceModelIndexed);
|
||||
if (unsupportedColorSpace) {
|
||||
colorspaceRef = [self colorSpaceGetDeviceRGB];
|
||||
}
|
||||
return colorspaceRef;
|
||||
}
|
||||
|
||||
+ (BOOL)CGImageContainsAlpha:(CGImageRef)cgImage {
|
||||
if (!cgImage) {
|
||||
return NO;
|
||||
|
@ -353,8 +338,12 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|||
destResolution.width = (int)(sourceResolution.width*imageScale);
|
||||
destResolution.height = (int)(sourceResolution.height*imageScale);
|
||||
|
||||
// current color space
|
||||
CGColorSpaceRef colorspaceRef = [self imageRefGetColorSpace:sourceImageRef];
|
||||
// device color space
|
||||
CGColorSpaceRef colorspaceRef = [self colorSpaceGetDeviceRGB];
|
||||
BOOL hasAlpha = [self CGImageContainsAlpha:sourceImageRef];
|
||||
// iOS display alpha info (BGRA8888/BGRX8888)
|
||||
CGBitmapInfo bitmapInfo = kCGBitmapByteOrder32Host;
|
||||
bitmapInfo |= hasAlpha ? kCGImageAlphaPremultipliedFirst : kCGImageAlphaNoneSkipFirst;
|
||||
|
||||
// kCGImageAlphaNone is not supported in CGBitmapContextCreate.
|
||||
// Since the original image here has no alpha info, use kCGImageAlphaNoneSkipFirst
|
||||
|
@ -365,7 +354,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|||
kBitsPerComponent,
|
||||
0,
|
||||
colorspaceRef,
|
||||
kCGBitmapByteOrder32Host|kCGImageAlphaNoneSkipFirst);
|
||||
bitmapInfo);
|
||||
|
||||
if (destContext == NULL) {
|
||||
return image;
|
||||
|
@ -528,12 +517,6 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|||
if (image.images != nil) {
|
||||
return NO;
|
||||
}
|
||||
CGImageRef imageRef = image.CGImage;
|
||||
BOOL hasAlpha = [self CGImageContainsAlpha:imageRef];
|
||||
// do not decode images with alpha
|
||||
if (hasAlpha) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
|
|
@ -49,12 +49,12 @@
|
|||
expect(decodedImage).to.equal(animatedImage);
|
||||
}
|
||||
|
||||
- (void)test04ThatDecodedImageWithImageDoesNotDecodeImagesWithAlpha {
|
||||
- (void)test04ThatDecodedImageWithImageWorksWithAlphaImages {
|
||||
NSString * testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"png"];
|
||||
UIImage *image = [[UIImage alloc] initWithContentsOfFile:testImagePath];
|
||||
UIImage *decodedImage = [UIImage sd_decodedImageWithImage:image];
|
||||
expect(decodedImage).toNot.beNil();
|
||||
expect(decodedImage).to.equal(image);
|
||||
expect(decodedImage).toNot.equal(image);
|
||||
}
|
||||
|
||||
- (void)test05ThatDecodedImageWithImageWorksEvenWithMonochromeImage {
|
||||
|
|
Loading…
Reference in New Issue