Using SkTableColorFilter::MakeARGB to respect the original alpha channel

47 views
Skip to first unread message

Kirill Grouchnikov

unread,
Aug 26, 2021, 4:52:57 PM8/26/21
to skia-discuss
Not using Skia directly in C / C++ code, but rather in Compose for Desktop via Skija bindings.

SkColorFilter::Blend accepts a single color and a blend mode. That can be used to colorize monochrome icons (like Material, for example) with SrcIn that respects the original alpha channel. But not all icon sets are monochrome.

Which lead me to try SkTableColorFilter::MakeARGB, constructing a set of 256 colors to colorize a multi-color icon, like the ones from Tango iconset.

Here is how it looks like:
Screen Shot 2021-08-26 at 4.51.01 PM.png
The colors are applied correctly on the main "content" of the icon, but also to all the partially or fully translucent pixels as well. 

Is there a way to construct an SkColorFilter from a palette of colors and to respect the original alpha channel of the source image pixels?

Brian Osman

unread,
Aug 26, 2021, 4:59:23 PM8/26/21
to skia-d...@googlegroups.com
What are you passing for the alpha-table in MakeARGB? If you leave that as nullptr, it should leave alpha values unchanged, so I'd expect the resulting colors to be fully transparent if they were transparent in the source data. As long as you then draw them using a blend mode that respects source-alpha (eg kSrcOver), those pixels should remain transparent?

--
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/717cf458-0da4-4a49-8c04-d77055f43d93n%40googlegroups.com.

Kirill Grouchnikov

unread,
Aug 26, 2021, 5:02:33 PM8/26/21
to skia-discuss
Thanks, I was just reading this documentation that mentioned passing null alpha array.

Screen Shot 2021-08-26 at 5.01.08 PM.png

Looks good now on the alpha channel! Need to tweak the contrast of colors, of course, in some cases, but that's on my side.

Reply all
Reply to author
Forward
0 new messages