photopea / UPNG.js

Fast and advanced PNG (APNG) decoder and encoder (lossy / lossless)
MIT License
2.1k stars 259 forks source link

UPNG.encode for RGB PNG #23

Closed friksa closed 6 years ago

friksa commented 6 years ago

It would be nice to create a PNG file that does not use the alpha channel (every pixel has a color and alpha is always 255). Since I know that there is no alpha channel, it seems like a lot of wasted space to encode an alpha channel that is always 255.

Thanks!

photopea commented 6 years ago

Hi, what exactly do you mean? what space is wasted?

friksa commented 6 years ago

A PNG that has an alpha channel is bigger than a PNG without an alpha channel.

photopea commented 6 years ago

UPNG.js was created to let programmers work with a consistent image input/output format (RGBA, 8 bits per channel), whithout worrying about PNG-specific internal representation.

It seems like you want to go into PNG-specific details. Just because UPNG wants you to give it an alpha channel, it does not mean output files are bigger, than if you gave it RGB only. In fact, UPNG.js checks, if all pixels have alpha=255, and if they do, it stores the file as RGB PNG (colour type 2 instead of 6).

The same is true for indexed image. When alpha is constant 255, "tRNS" chunk is omitted.

https://www.w3.org/TR/2003/REC-PNG-20031110/#6Colour-values