diff --git a/SDWebImage/Core/UIImage+Transform.m b/SDWebImage/Core/UIImage+Transform.m index c40e4cfb..a4d72f23 100644 --- a/SDWebImage/Core/UIImage+Transform.m +++ b/SDWebImage/Core/UIImage+Transform.m @@ -659,7 +659,9 @@ static NSString * _Nullable SDGetCIFilterNameFromBlendMode(CGBlendMode blendMode } else { clearColor = [[CIColor alloc] initWithColor:UIColor.clearColor]; } - ciImage = [CIImage imageWithColor:clearColor]; + colorImage = [CIImage imageWithColor:clearColor]; + colorImage = [colorImage imageByCroppingToRect:ciImage.extent]; + ciImage = colorImage; } else if (blendMode == kCGBlendModeCopy) { // R = S ciImage = colorImage; @@ -675,12 +677,14 @@ static NSString * _Nullable SDGetCIFilterNameFromBlendMode(CGBlendMode blendMode } else if (blendMode == kCGBlendModePlusDarker) { // R = MAX(0, (1 - D) + (1 - S)) // (1 - D) - CIFilter *filter1 = [CIFilter filterWithName:@"CIColorInvert"]; + CIFilter *filter1 = [CIFilter filterWithName:@"CIColorControls"]; [filter1 setValue:ciImage forKey:kCIInputImageKey]; + [filter1 setValue:@(-0.5) forKey:kCIInputBrightnessKey]; ciImage = filter1.outputImage; // (1 - S) - CIFilter *filter2 = [CIFilter filterWithName:@"CIColorInvert"]; + CIFilter *filter2 = [CIFilter filterWithName:@"CIColorControls"]; [filter2 setValue:colorImage forKey:kCIInputImageKey]; + [filter2 setValue:@(-0.5) forKey:kCIInputBrightnessKey]; colorImage = filter2.outputImage; // + CIFilter *filter = [CIFilter filterWithName:@"CIAdditionCompositing"]; diff --git a/Tests/Tests/SDImageTransformerTests.m b/Tests/Tests/SDImageTransformerTests.m index 1559d4d2..b099fb7e 100644 --- a/Tests/Tests/SDImageTransformerTests.m +++ b/Tests/Tests/SDImageTransformerTests.m @@ -243,7 +243,7 @@ static void SDAssertCGImageFirstComponentWhite(CGImageRef image, OSType pixelTyp UIColor *topCenterColor = [tintedImage sd_colorAtPoint:CGPointMake(150, 20)]; expect([topCenterColor.sd_hexString isEqualToString:[UIColor blackColor].sd_hexString]).beTruthy(); - UIImage *tintedSourceInImage = [testImage sd_tintedImageWithColor:tintColor blendMode:kCGBlendModeSourceOut]; + UIImage *tintedSourceInImage = [testImage sd_tintedImageWithColor:tintColor blendMode:kCGBlendModeSourceIn]; centerColor = [tintedSourceInImage sd_colorAtPoint:CGPointMake(150, 150)]; expect([centerColor.sd_hexString isEqualToString:[UIColor blackColor].sd_hexString]).beTruthy(); }