[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];
}
}
};