-
Notifications
You must be signed in to change notification settings - Fork 806
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for CGImageCreateWithMask. #1555
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -525,13 +525,34 @@ CGImageRef CGImageCreateCopyWithColorSpace(CGImageRef ref, CGColorSpaceRef color | |
} | ||
|
||
/** | ||
@Status Stub | ||
@Status Interoperable | ||
@Notes This function does not defer the composition of its mask. | ||
This function supports non-grayscale alpha masks, unlike the reference platform. | ||
*/ | ||
CGImageRef CGImageCreateWithMask(CGImageRef image, CGImageRef mask) { | ||
// TODO #1425 - masks are applied during rendering via D2D. | ||
RETURN_NULL_IF(!image); | ||
UNIMPLEMENTED(); | ||
return StubReturn(); | ||
RETURN_NULL_IF(!mask); | ||
RETURN_NULL_IF(CGImageIsMask(image)); | ||
|
||
size_t width = CGImageGetWidth(image); | ||
size_t height = CGImageGetHeight(image); | ||
|
||
woc::unique_cf<CGContextRef> context{ CGBitmapContextCreate(nullptr, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
for some unforeseen reason check if bitmapcontextcreate failed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea. this will return a cascading null, but it's better to be safe. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I'm thinking if someone decides to change the bitmap info (without realizing we don't support all of it due to D2D restrictions) In reply to: 92708281 [](ancestors = 92708281) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They can't change the bitmap info. Do you mean some internal consumer? |
||
width, | ||
height, | ||
8, | ||
width * 4, | ||
CGImageGetColorSpace(image), | ||
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) }; | ||
RETURN_NULL_IF(!context); | ||
|
||
CGRect rect{ | ||
CGPointZero, { width, height }, | ||
}; | ||
CGContextClipToMask(context.get(), rect, mask); | ||
CGContextDrawImage(context.get(), rect, image); | ||
|
||
return CGBitmapContextCreateImage(context.get()); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return null if it's not a mask?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
image
is the input image, it is contractually disallowed from being a mask.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops, LOL I was thinking it was mask.
Can you add a check to see if the mask is really as mask?
In reply to: 92708221 [](ancestors = 92708221)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some how my comment won't appear:
Ops, LOL I was thinking it was mask.
Can you add a check to see if the mask is really as mask?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See notes above; the reference platform requires a mask (black/white image). We add support for an alpha clip (alpha image), but an alpha image is not a mask.