[ASDisplayNode] Use kCGBlendModeCopy in a Couple More Places (#2250)

* Use blend mode copy in a couple more places

* Add some tests
This commit is contained in:
Adlai Holler
2016-09-15 11:56:46 -07:00
committed by GitHub
parent 88d588d590
commit 1e86dcdbe2
5 changed files with 32 additions and 3 deletions

View File

@@ -677,7 +677,7 @@ extern asimagenode_modification_block_t ASImageNodeRoundBorderModificationBlock(
[roundOutline addClip];
// Draw the original image
[originalImage drawAtPoint:CGPointZero];
[originalImage drawAtPoint:CGPointZero blendMode:kCGBlendModeCopy alpha:1];
// Draw a border on top.
if (borderWidth > 0.0) {
@@ -700,7 +700,7 @@ extern asimagenode_modification_block_t ASImageNodeTintColorModificationBlock(UI
// Set color and render template
[color setFill];
UIImage *templateImage = [originalImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[templateImage drawAtPoint:CGPointZero];
[templateImage drawAtPoint:CGPointZero blendMode:kCGBlendModeCopy alpha:1];
UIImage *modifiedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

View File

@@ -14,6 +14,7 @@
#import "ASAssert.h"
#import "ASDisplayNodeInternal.h"
#import "ASDisplayNode+FrameworkPrivate.h"
#import "ASInternalHelpers.h"
@interface ASDisplayNode () <_ASDisplayLayerDelegate>
@end
@@ -113,7 +114,9 @@
if (displayBlock) {
UIImage *image = (UIImage *)displayBlock();
if (image) {
[image drawInRect:bounds];
BOOL opaque = ASImageAlphaInfoIsOpaque(CGImageGetAlphaInfo(image.CGImage));
CGBlendMode blendMode = opaque ? kCGBlendModeCopy : kCGBlendModeNormal;
[image drawInRect:bounds blendMode:blendMode alpha:1];
}
}
};

View File

@@ -58,4 +58,30 @@
@"Contents should be 100 x 100 by contents scale.");
}
- (void)testTintColorBlock
{
UIImage *test = [self testImage];
UIImage *tinted = ASImageNodeTintColorModificationBlock([UIColor redColor])(test);
ASImageNode *node = [[ASImageNode alloc] init];
node.image = tinted;
[node layoutThatFits:ASSizeRangeMake(test.size)];
ASSnapshotVerifyNode(node, nil);
}
- (void)testRoundedCornerBlock
{
UIGraphicsBeginImageContext(CGSizeMake(100, 100));
[[UIColor blueColor] setFill];
UIRectFill(CGRectMake(0, 0, 100, 100));
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage *rounded = ASImageNodeRoundBorderModificationBlock(2, [UIColor redColor])(result);
ASImageNode *node = [[ASImageNode alloc] init];
node.image = rounded;
[node layoutThatFits:ASSizeRangeMake(rounded.size)];
ASSnapshotVerifyNode(node, nil);
}
@end

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 354 KiB