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.
|
The tint color.
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, strong, readonly, nonnull) UIColor *tintColor;
|
@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)init NS_UNAVAILABLE;
|
||||||
+ (nonnull instancetype)new NS_UNAVAILABLE;
|
+ (nonnull instancetype)new NS_UNAVAILABLE;
|
||||||
|
|
||||||
+ (nonnull instancetype)transformerWithColor:(nonnull UIColor *)tintColor;
|
+ (nonnull instancetype)transformerWithColor:(nonnull UIColor *)tintColor;
|
||||||
|
+ (nonnull instancetype)transformerWithColor:(nonnull UIColor *)tintColor blendMode:(CGBlendMode)blendMode;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -245,20 +245,26 @@ NSString * _Nullable SDThumbnailedKeyForKey(NSString * _Nullable key, CGSize thu
|
||||||
@interface SDImageTintTransformer ()
|
@interface SDImageTintTransformer ()
|
||||||
|
|
||||||
@property (nonatomic, strong, nonnull) UIColor *tintColor;
|
@property (nonatomic, strong, nonnull) UIColor *tintColor;
|
||||||
|
@property (nonatomic, assign) CGBlendMode blendMode;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation SDImageTintTransformer
|
@implementation SDImageTintTransformer
|
||||||
|
|
||||||
+ (instancetype)transformerWithColor:(UIColor *)tintColor {
|
+ (instancetype)transformerWithColor:(UIColor *)tintColor {
|
||||||
|
return [self transformerWithColor:tintColor blendMode:kCGBlendModeSourceAtop];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (instancetype)transformerWithColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode {
|
||||||
SDImageTintTransformer *transformer = [SDImageTintTransformer new];
|
SDImageTintTransformer *transformer = [SDImageTintTransformer new];
|
||||||
transformer.tintColor = tintColor;
|
transformer.tintColor = tintColor;
|
||||||
|
transformer.blendMode = blendMode;
|
||||||
|
|
||||||
return transformer;
|
return transformer;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)transformerKey {
|
- (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 {
|
- (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
|
// Check rounded corner operation not inversion the image
|
||||||
UIColor *topCenterColor = [tintedImage sd_colorAtPoint:CGPointMake(150, 20)];
|
UIColor *topCenterColor = [tintedImage sd_colorAtPoint:CGPointMake(150, 20)];
|
||||||
expect([topCenterColor.sd_hexString isEqualToString:[UIColor blackColor].sd_hexString]).beTruthy();
|
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 {
|
- (void)test07UIImageTransformBlurCG {
|
||||||
|
@ -353,7 +357,7 @@ static void SDAssertCGImageFirstComponentWhite(CGImageRef image, OSType pixelTyp
|
||||||
@"SDImageRoundCornerTransformer(50.000000,18446744073709551615,1.000000,#ff000000)",
|
@"SDImageRoundCornerTransformer(50.000000,18446744073709551615,1.000000,#ff000000)",
|
||||||
@"SDImageFlippingTransformer(1,1)",
|
@"SDImageFlippingTransformer(1,1)",
|
||||||
@"SDImageCroppingTransformer({0.000000,0.000000,50.000000,50.000000})",
|
@"SDImageCroppingTransformer({0.000000,0.000000,50.000000,50.000000})",
|
||||||
@"SDImageTintTransformer(#00000000)",
|
@"SDImageTintTransformer(#00000000,20)",
|
||||||
@"SDImageBlurTransformer(5.000000)",
|
@"SDImageBlurTransformer(5.000000)",
|
||||||
@"SDImageFilterTransformer(CIColorInvert)"
|
@"SDImageFilterTransformer(CIColorInvert)"
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue