Skip to content

Correct transparency when converting from RGB to LA or La - #10390

Open
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:convert_la
Open

radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:convert_la

Conversation

@radarhere

Copy link
Copy Markdown
Member

Resolves #10389

When converting with transparency, Pillow usually converts to RGB first, and then applies transparency.

It compares all channels when detecting transparent pixels, presuming that the fourth channel is 255.

rgbT2a(UINT8 *out, UINT8 *in, int xsize, int r, int g, int b, int premultiplied) {
#ifdef WORDS_BIGENDIAN
UINT32 trns = ((r & 0xff) << 24) | ((g & 0xff) << 16) | ((b & 0xff) << 8) | 0xff;
UINT32 repl = premultiplied ? 0 : (trns & 0xffffff00);
#else
UINT32 trns = (0xffU << 24) | ((b & 0xff) << 16) | ((g & 0xff) << 8) | (r & 0xff);

This is not necessarily the case though, as Image.new("RGB", (1, 1)) sets the fourth channel to 0.

a = (UINT8)(r >> 24);

So when checking the pixel value, let's treat the fourth channel as 255.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

convert("LA") with an RGB info["transparency"] stores the red value as L of transparent pixels and misses pixels whose padding byte is not 255

1 participant