Added the blend mode to transformer API as well
Update unit tests
This commit is contained in:
parent
099371823e
commit
3c89a092cd
|
@ -223,11 +223,14 @@ FOUNDATION_EXPORT NSString * _Nullable SDThumbnailedKeyForKey(NSString * _Nullab
|
|||
The tint color.
|
||||
*/
|
||||
@property (nonatomic, strong, readonly, nonnull) UIColor *tintColor;
|
||||
/// The blend mode, defaults to `sourceAtop` if you use the old initializer
|
||||
@property (nonatomic, assign, readonly) CGBlendMode blendMode;
|
||||
|
||||
- (nonnull instancetype)init NS_UNAVAILABLE;
|
||||
+ (nonnull instancetype)new NS_UNAVAILABLE;
|
||||
|
||||
+ (nonnull instancetype)transformerWithColor:(nonnull UIColor *)tintColor;
|
||||
+ (nonnull instancetype)transformerWithColor:(nonnull UIColor *)tintColor blendMode:(CGBlendMode)blendMode;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -245,20 +245,26 @@ NSString * _Nullable SDThumbnailedKeyForKey(NSString * _Nullable key, CGSize thu
|
|||
@interface SDImageTintTransformer ()
|
||||
|
||||
@property (nonatomic, strong, nonnull) UIColor *tintColor;
|
||||
@property (nonatomic, assign) CGBlendMode blendMode;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SDImageTintTransformer
|
||||
|
||||
+ (instancetype)transformerWithColor:(UIColor *)tintColor {
|
||||
return [self transformerWithColor:tintColor blendMode:kCGBlendModeSourceAtop];
|
||||
}
|
||||
|
||||
+ (instancetype)transformerWithColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode {
|
||||
SDImageTintTransformer *transformer = [SDImageTintTransformer new];
|
||||
transformer.tintColor = tintColor;
|
||||
transformer.blendMode = blendMode;
|
||||
|
||||
return transformer;
|
||||
}
|
||||
|
||||
- (NSString *)transformerKey {
|
||||
return [NSString stringWithFormat:@"SDImageTintTransformer(%@)", self.tintColor.sd_hexString];
|
||||
return [NSString stringWithFormat:@"SDImageTintTransformer(%@,%d)", self.tintColor.sd_hexString, self.blendMode];
|
||||
}
|
||||
|
||||
- (UIImage *)transformedImageWithImage:(UIImage *)image forKey:(NSString *)key {
|
||||
|
|
|
@ -242,6 +242,10 @@ static void SDAssertCGImageFirstComponentWhite(CGImageRef image, OSType pixelTyp
|
|||
// Check rounded corner operation not inversion the image
|
||||
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];
|
||||
centerColor = [tintedSourceInImage sd_colorAtPoint:CGPointMake(150, 150)];
|
||||
expect([centerColor.sd_hexString isEqualToString:[UIColor blackColor].sd_hexString]).beTruthy();
|
||||
}
|
||||
|
||||
- (void)test07UIImageTransformBlurCG {
|
||||
|
@ -353,7 +357,7 @@ static void SDAssertCGImageFirstComponentWhite(CGImageRef image, OSType pixelTyp
|
|||
@"SDImageRoundCornerTransformer(50.000000,18446744073709551615,1.000000,#ff000000)",
|
||||
@"SDImageFlippingTransformer(1,1)",
|
||||
@"SDImageCroppingTransformer({0.000000,0.000000,50.000000,50.000000})",
|
||||
@"SDImageTintTransformer(#00000000)",
|
||||
@"SDImageTintTransformer(#00000000,20)",
|
||||
@"SDImageBlurTransformer(5.000000)",
|
||||
@"SDImageFilterTransformer(CIColorInvert)"
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue