Set a gray filter in Skia

281 views
Skip to first unread message

Heidi Kurz

unread,
Feb 10, 2021, 7:41:13 AM2/10/21
to skia-discuss
Hi, I'm upgrating our Skia version from a old branch to the newest Skia version.

Now I have the problem that we set a gray filter like here:

SkPaint skpaint;

... do anything

Old code
 const SkScalar grayscale[20] = {
        0.21f, 0.72f, 0.07f, 0.0f, 100.0f, // red
        0.21f, 0.72f, 0.07f, 0.0f, 100.0f, // green
        0.21f, 0.72f, 0.07f, 0.0f, 100.0f, // blue
        0.0f,  0.0f,  0.0f,  1.0f,  0.0f }; // alpha transparency

skpaint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(grayscale));


But the method 
SkColorFilter::MakeMatrixFilterRowMajor255(...)
is removed. 
So far I was not able to find any replacement.

Please could anybody give me any hint how I could this functionality replace?








Mike Klein

unread,
Feb 10, 2021, 8:41:54 AM2/10/21
to skia-discuss
There are a few SkColorFilters::Matrix() methods for this sort of color filter in SkColorFilter.h.

--
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/9bdb2338-50dd-4739-9538-e74385cbdafbn%40googlegroups.com.

Heidi Kurz

unread,
Feb 11, 2021, 2:11:39 AM2/11/21
to skia-discuss
I tried out this 
 const SkScalar rowMajorgrayScale[20] = {
        0.21f, 0.72f, 0.07f, 0.0f, 100.0f, // red
        0.21f, 0.72f, 0.07f, 0.0f, 100.0f, // green
        0.21f, 0.72f, 0.07f, 0.0f, 100.0f, // blue
        0.0f,  0.0f,  0.0f,  1.0f,  0.0f }; // alpha transparency

 sk_sp<SkColorFilter> cf = SkColorFilters::Matrix(rowMajorgrayScale);
 skpaint.setColorFilter(cf);

But it doesn't work!




Heidi Kurz

unread,
Feb 11, 2021, 3:54:25 AM2/11/21
to skia-discuss
I have played around a lot and found this solution 
 const SkScalar greyColorMatrix[20] = { 0.21f,  0.72f,  0.07f,    0.41f, 0, // red
                                     0.21f,  0.72f,  0.07f,    0.41f, 0,  // green
                                     0.21f,  0.72f,  0.07f,    0.41f, 0,  // blue
                                     0,    0,    0,    1.0f, 0 };

sk_sp<SkColorFilter> cf = SkColorFilters::Matrix(rowMajorgrayScale);
 skpaint.setColorFilter(cf);

That works.

Reply all
Reply to author
Forward
0 new messages