Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treating alpha like RGB #45

Closed
matthewlai opened this issue Dec 29, 2020 · 3 comments
Closed

Treating alpha like RGB #45

matthewlai opened this issue Dec 29, 2020 · 3 comments

Comments

@matthewlai
Copy link

matthewlai commented Dec 29, 2020

Hello!

I am using libimagequant to optimize PNGs to be used as textures in a game, and it mostly works very well - thanks!

But there are some textures where the alpha channel means something else entirely, and I see that in regions that would be transparent if alpha was interpreted as transparency, the RGB values are very wrong. That makes sense if those pixels were actually transparent of course, but not in this case.

Is there a way to make the library treat alpha as just another colour channel?

Thanks!

@matthewlai
Copy link
Author

It looks like that's a special case for alpha = 0? I have been able to workaround that by forcing alpha to be at least 1, but would still prefer a cleaner solution!

@kornelski
Copy link
Member

kornelski commented Dec 29, 2020

This is fundamentally impossible in libimagequant. It intentionally uses premultiplied alpha color space throughout the codebase. In this colorspace RGB and A are correlated, and are not independent channels.

Separating alpha would make PNG8 much lower quality and inefficient. Instead of reducing 16mln combinations, it'd have to work with 4 billion combinations, and visually invisible alpha combinations would take precious palette entries away from the visible RGB colors.

I suggest that you use two separate PNG files: RGB PNG8 for color, and a separate grayscale PNG for the alpha-but-not-really-alpha channel.

@matthewlai
Copy link
Author

@kornelski I see. Thanks. I'll look into those options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants