Alpha value doesn't work while using SkTableColorFilter

40 views
Skip to first unread message

Levin Le

unread,
May 18, 2021, 12:01:41 AM5/18/21
to skia-discuss
Hi,

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? 

Thanks. 


Greg Daniel

unread,
May 18, 2021, 7:41:33 AM5/18/21
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 skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/c4e44ed4-153b-47ca-ab6f-634fca76383bn%40googlegroups.com.

Levin Le

unread,
May 18, 2021, 7:37:17 PM5/18/21
to skia-discuss
Hi,

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));
paint.setColorFilter(composedFilter);
bitmap.installPixels(...);
canvas->drawImage(bitmap.asImage(), x, y, SkSamplingOptions{}, &paint);

Thanks much,
Levin


Reply all
Reply to author
Forward
0 new messages