Grayscale Alpha Mask

159 views
Skip to first unread message

corey....@gmail.com

unread,
Oct 25, 2022, 8:20:19 AM10/25/22
to skia-discuss
What is the most efficient way in Skia to treat an opaque grayscale RGBA image as an alpha mask suitable for use with clipShader ? e.g. Where the whitest portion of the image implies my masked layer contents is most visible and the darkest the least visible.

e.g. Do I need to construct a new kAlpha_8 image from one of the image channels, or is there a convenience method or automatic mechanism to do this for me?


Brian Osman

unread,
Oct 25, 2022, 8:54:12 AM10/25/22
to skia-d...@googlegroups.com
The first thing that comes to mind:
Turn your image into an SkShader (image->makeShader). Then use imageShader->makeWithColorFilter(SkColorFilters::Matrix(...)). That will give you a shader that is the result of running the original image through a matrix color filter. You can construct the color matrix to populate alpha from a single channel, or from the average of the three RGB channels, etc...


On Tue, Oct 25, 2022 at 8:20 AM corey....@gmail.com <corey....@gmail.com> wrote:
What is the most efficient way in Skia to treat an opaque grayscale RGBA image as an alpha mask suitable for use with clipShader ? e.g. Where the whitest portion of the image implies my masked layer contents is most visible and the darkest the least visible.

e.g. Do I need to construct a new kAlpha_8 image from one of the image channels, or is there a convenience method or automatic mechanism to do this for me?


--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/cd5af7ed-f4a0-47be-9e73-1374e2282da3n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages