Fix some CIFilter implementation

This commit is contained in:
DreamPiggy 2024-09-03 18:56:03 +08:00
parent 3c89a092cd
commit 7892f4ca20
2 changed files with 8 additions and 4 deletions

View File

@ -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"];

View File

@ -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();
}