Alpha value doesn't work while using SkTableColorFilter

Skip to first unread message

Levin Le

May 18, 2021, 12:01:41 AMMay 18
to skia-discuss

I am applying a custom color filter on an 8-bit grey image by using SkTableColorFilter::MakeARGB(tableA, tableR, tableG, tableB), the image color works as we expected, however, the transparency of each pixel doesn't work individually

For example, I set tableA[0~254] = 255, tableA[255] = 0 as I want some pixels are transparent and other pixel are opaque. However, in my testing, I found the alpha value of the last item in the table. i.e  tableA[255] was applied to every pixel. 

Is it a bug or intended behaviour? is it another way to control the alpha of each color/pixel? 


Greg Daniel

May 18, 2021, 7:41:33 AMMay 18
to skia-discuss
So are you using the gray 8 SkColorType? If so this color format does not have alpha stored in it. Logically when this format is expanded out into RGBA it would look something like (g, g, g, 1) where g is your grey value at a pixel. When storing back into the gray format it uses the luminous of RGB to calculate the gray value.

Hope this helps.

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
To view this discussion on the web visit

Levin Le

May 18, 2021, 7:37:17 PMMay 18
to skia-discuss

Thanks for the quick feedback. Yes. we used the kGray_8_SkColorType.

Now, I just swap to kAlpha_8_SkColorType and compose the existing same colour filter with another filter created by "SkColorFilters::Blend(SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF), SkBlendMode::kSrcIn)", 
then both color and transparency for each pixel works as we expected but I can't understand why need to compose another special filter. would you please help to clarify my workaround?

Here is sample code,
auto imageInfo = SkImageInfo::Make(pixelMemory->Width(), pixelMemory->Height(), kAlpha_8_SkColorType, kPremul_SkAlphaType);  
auto composedFilter = SkColorFilters::Compose(filter, SkColorFilters::Blend(SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF), SkBlendMode::kSrcIn));
canvas->drawImage(bitmap.asImage(), x, y, SkSamplingOptions{}, &paint);

Thanks much,

Reply all
Reply to author
0 new messages