Fix the test on macOS. Fix the issue when using rounded corner
This commit is contained in:
parent
d0df01bec1
commit
aea81791ec
|
@ -43,7 +43,7 @@ typedef NS_OPTIONS(NSUInteger, SDRectCorner) {
|
|||
/**
|
||||
Convenience way to create a bezier path with the specify rouunding corners on macOS. Same as the one on `UIBezierPath`.
|
||||
*/
|
||||
+ (instancetype)sd_bezierPathWithRoundedRect:(NSRect)rect byRoundingCorners:(SDRectCorner)corners cornerRadius:(CGFloat)cornerRadius;
|
||||
+ (nonnull instancetype)sd_bezierPathWithRoundedRect:(NSRect)rect byRoundingCorners:(SDRectCorner)corners cornerRadius:(CGFloat)cornerRadius;
|
||||
|
||||
@end
|
||||
#endif
|
||||
|
|
|
@ -81,29 +81,6 @@ static UIImage * SDGraphicsGetImageFromCurrentImageContext(void) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static SDRectCorner SDRectCornerConvertCounterClockwise(SDRectCorner corners) {
|
||||
#if SD_UIKIT || SD_WATCH
|
||||
if (corners != UIRectCornerAllCorners) {
|
||||
UIRectCorner tmp = 0;
|
||||
if (corners & UIRectCornerTopLeft) tmp |= UIRectCornerBottomLeft;
|
||||
if (corners & UIRectCornerTopRight) tmp |= UIRectCornerBottomRight;
|
||||
if (corners & UIRectCornerBottomLeft) tmp |= UIRectCornerTopLeft;
|
||||
if (corners & UIRectCornerBottomRight) tmp |= UIRectCornerTopRight;
|
||||
corners = tmp;
|
||||
}
|
||||
#else
|
||||
if (corners != SDRectCornerAllCorners) {
|
||||
SDRectCorner tmp = 0;
|
||||
if (corners & SDRectCornerTopLeft) tmp |= SDRectCornerBottomLeft;
|
||||
if (corners & SDRectCornerTopRight) tmp |= SDRectCornerBottomRight;
|
||||
if (corners & SDRectCornerBottomLeft) tmp |= SDRectCornerTopLeft;
|
||||
if (corners & SDRectCornerBottomRight) tmp |= SDRectCornerTopRight;
|
||||
corners = tmp;
|
||||
}
|
||||
#endif
|
||||
return corners;
|
||||
}
|
||||
|
||||
static CGRect SDCGRectFitWithScaleMode(CGRect rect, CGSize size, SDImageScaleMode scaleMode) {
|
||||
rect = CGRectStandardize(rect);
|
||||
size.width = size.width < 0 ? -size.width : size.width;
|
||||
|
@ -261,7 +238,6 @@ static CGRect SDCGRectFitWithScaleMode(CGRect rect, CGSize size, SDImageScaleMod
|
|||
|
||||
- (UIImage *)sd_roundedCornerImageWithRadius:(CGFloat)cornerRadius corners:(SDRectCorner)corners borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor {
|
||||
if (!self.CGImage) return nil;
|
||||
corners = SDRectCornerConvertCounterClockwise(corners);
|
||||
SDGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
|
||||
CGContextRef context = SDGraphicsGetCurrentContext();
|
||||
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
|
||||
|
@ -463,7 +439,8 @@ static CGRect SDCGRectFitWithScaleMode(CGRect rect, CGSize size, SDImageScaleMod
|
|||
default: break;
|
||||
}
|
||||
switch (alphaInfo) {
|
||||
case kCGImageAlphaPremultipliedFirst: {
|
||||
case kCGImageAlphaPremultipliedFirst:
|
||||
case kCGImageAlphaFirst: {
|
||||
if (byteOrderNormal) {
|
||||
// ARGB8888
|
||||
a = pixel[0] / 255.0;
|
||||
|
@ -479,7 +456,8 @@ static CGRect SDCGRectFitWithScaleMode(CGRect rect, CGSize size, SDImageScaleMod
|
|||
}
|
||||
}
|
||||
break;
|
||||
case kCGImageAlphaPremultipliedLast: {
|
||||
case kCGImageAlphaPremultipliedLast:
|
||||
case kCGImageAlphaLast: {
|
||||
if (byteOrderNormal) {
|
||||
// RGBA8888
|
||||
r = pixel[0] / 255.0;
|
||||
|
@ -537,7 +515,7 @@ static CGRect SDCGRectFitWithScaleMode(CGRect rect, CGSize size, SDImageScaleMod
|
|||
}
|
||||
}
|
||||
break;
|
||||
// iOS does not supports non-premultiplied alpha, so no these cases :)
|
||||
case kCGImageAlphaOnly:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#import <SDWebImage/UIImage+GIF.h>
|
||||
#import <SDWebImage/UIImage+WebP.h>
|
||||
#import <SDWebImage/UIImage+Transform.h>
|
||||
#import <CoreImage/CoreImage.h>
|
||||
|
||||
@interface SDCategoriesTests : SDTestCase
|
||||
|
||||
|
@ -85,7 +86,11 @@
|
|||
|
||||
- (void)test07UIImageTransformRoundedCorner {
|
||||
CGFloat radius = 50;
|
||||
UIRectCorner corners = UIRectCornerAllCorners;
|
||||
#if SD_UIKIT
|
||||
SDRectCorner corners = UIRectCornerAllCorners;
|
||||
#else
|
||||
SDRectCorner corners = SDRectCornerAllCorners;
|
||||
#endif
|
||||
CGFloat borderWidth = 1;
|
||||
UIColor *borderCoder = [UIColor blackColor];
|
||||
UIImage *roundedCornerImage = [self.testImage sd_roundedCornerImageWithRadius:radius corners:corners borderWidth:borderWidth borderColor:borderCoder];
|
||||
|
@ -155,7 +160,7 @@
|
|||
|
||||
- (UIImage *)testImage {
|
||||
if (!_testImage) {
|
||||
_testImage = [UIImage imageWithContentsOfFile:[self testPNGPath]];
|
||||
_testImage = [[UIImage alloc] initWithContentsOfFile:[self testPNGPath]];
|
||||
}
|
||||
return _testImage;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue