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

Normalize to RGBA when decoding indexed images #11

Open
mourner opened this issue Sep 26, 2019 · 1 comment
Open

Normalize to RGBA when decoding indexed images #11

mourner opened this issue Sep 26, 2019 · 1 comment

Comments

@mourner
Copy link

mourner commented Sep 26, 2019

@targos Thanks for such a nice library! Just sharing something I found unexpected (after trying to switch to fast-png from pngjs):

  • If you want to manipulate pixel data after decoding an indexed image, you have to normalize it into RGBA (from palette + indices) manually. This is 1) not documented, 2) inconvenient. Maybe worth adding a normalize option to decode?
  • The format of the palette property is [[r, g, b], [r, g, b]], which is inefficient — allocating more memory than necessary. Since we know the number of colors before hand, ideally this would be returned in flat typed form — Uint8ClampedArray([r, g, b, r, g, b, ...]).
@targos
Copy link
Member

targos commented Sep 26, 2019

  • A normalize options sounds good. Do you think it should be a general option (that would normalize any image to 32-bit RGBA) or just something that handles palette conversion? Would you like to work on it?
  • It is true that using an array of arrays takes more memory. But I'm not sure it's worth changing it, because the palette may contain at most 256 entries.

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