From 66d294dbec3cc69d093b5c288c094804c0212a9b Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 3 Apr 2019 12:24:41 +0800 Subject: [PATCH 1/2] Fix tint image bug which leads to image upside down --- SDWebImage/UIImage+Transform.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDWebImage/UIImage+Transform.m b/SDWebImage/UIImage+Transform.m index acf86fb1..85b1e271 100644 --- a/SDWebImage/UIImage+Transform.m +++ b/SDWebImage/UIImage+Transform.m @@ -349,7 +349,7 @@ static inline UIColor * SDGetColorFromPixel(Pixel_8888 pixel, CGBitmapInfo bitma SDGraphicsBeginImageContextWithOptions(size, NO, scale); CGContextRef context = SDGraphicsGetCurrentContext(); - CGContextDrawImage(context, rect, self.CGImage); + [self drawInRect:rect]; CGContextSetBlendMode(context, blendMode); CGContextSetFillColorWithColor(context, tintColor.CGColor); CGContextFillRect(context, rect); From 3a5a3874858a6df67146021861d1dcad16d491c7 Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 3 Apr 2019 14:14:15 +0800 Subject: [PATCH 2/2] Add tests for inversion check --- Tests/Tests/SDImageTransformerTests.m | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Tests/Tests/SDImageTransformerTests.m b/Tests/Tests/SDImageTransformerTests.m index 57a19589..6ef957ff 100644 --- a/Tests/Tests/SDImageTransformerTests.m +++ b/Tests/Tests/SDImageTransformerTests.m @@ -35,14 +35,20 @@ CGSize scaleUpSize = CGSizeMake(2000, 1000); UIImage *scaledUpImage = [self.testImage sd_resizedImageWithSize:scaleUpSize scaleMode:SDImageScaleModeAspectFit]; expect(CGSizeEqualToSize(scaledUpImage.size, scaleUpSize)).beTruthy(); + // Check image not inversion + UIColor *topCenterColor = [scaledUpImage sd_colorAtPoint:CGPointMake(1000, 50)]; + expect([topCenterColor.sd_hexString isEqualToString:[UIColor blackColor].sd_hexString]).beTruthy(); } - (void)test02UIImageTransformCrop { - CGRect rect = CGRectMake(50, 50, 200, 200); + CGRect rect = CGRectMake(50, 10, 200, 200); UIImage *croppedImage = [self.testImage sd_croppedImageWithRect:rect]; expect(CGSizeEqualToSize(croppedImage.size, CGSizeMake(200, 200))).beTruthy(); UIColor *startColor = [croppedImage sd_colorAtPoint:CGPointZero]; expect([startColor.sd_hexString isEqualToString:[UIColor clearColor].sd_hexString]).beTruthy(); + // Check image not inversion + UIColor *topCenterColor = [croppedImage sd_colorAtPoint:CGPointMake(100, 10)]; + expect([topCenterColor.sd_hexString isEqualToString:[UIColor blackColor].sd_hexString]).beTruthy(); } - (void)test03UIImageTransformRoundedCorner { @@ -72,6 +78,9 @@ rotatedImage = [self.testImage sd_rotatedImageWithAngle:angle fitSize:YES]; CGSize rotatedSize = CGSizeMake(floor(300 * 1.414), floor(300 * 1.414)); // 45ยบ, square length * sqrt(2) expect(CGSizeEqualToSize(rotatedImage.size, rotatedSize)).beTruthy(); + // Check image not inversion + UIColor *leftCenterColor = [rotatedImage sd_colorAtPoint:CGPointMake(60, 175)]; + expect([leftCenterColor.sd_hexString isEqualToString:[UIColor blackColor].sd_hexString]).beTruthy(); } - (void)test05UIImageTransformFlip { @@ -87,6 +96,9 @@ for (UIColor *color in checkColors) { expect([color isEqual:checkColor]).to.beTruthy(); } + // Check image not inversion + UIColor *bottomCenterColor = [flippedImage sd_colorAtPoint:CGPointMake(150, 285)]; + expect([bottomCenterColor.sd_hexString isEqualToString:[UIColor blackColor].sd_hexString]).beTruthy(); } - (void)test06UIImageTransformTint { @@ -99,6 +111,9 @@ // Check left color, should be tinted UIColor *leftColor = [tintedImage sd_colorAtPoint:CGPointMake(80, 150)]; expect([leftColor.sd_hexString isEqualToString:tintColor.sd_hexString]); + // 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(); } - (void)test07UIImageTransformBlur { @@ -110,6 +125,9 @@ // Hard-code from the output UIColor *expectedColor = [UIColor colorWithRed:0.431373 green:0.101961 blue:0.0901961 alpha:0.729412]; expect([leftColor.sd_hexString isEqualToString:expectedColor.sd_hexString]); + // Check rounded corner operation not inversion the image + UIColor *topCenterColor = [blurredImage sd_colorAtPoint:CGPointMake(150, 20)]; + expect([topCenterColor.sd_hexString isEqualToString:@"#9a430d06"]).beTruthy(); } - (void)test08UIImageTransformFilter { @@ -122,6 +140,9 @@ // Hard-code from the output UIColor *expectedColor = [UIColor colorWithRed:0.85098 green:0.992157 blue:0.992157 alpha:1]; expect([leftColor.sd_hexString isEqualToString:expectedColor.sd_hexString]); + // Check rounded corner operation not inversion the image + UIColor *topCenterColor = [filteredImage sd_colorAtPoint:CGPointMake(150, 20)]; + expect([topCenterColor.sd_hexString isEqualToString:[UIColor whiteColor].sd_hexString]).beTruthy(); } #pragma mark - SDImageTransformer