A simple check should be implemented which does not write a paletted image but an RGB(A) image in case the (uncompressed) size is smaller for the latter.
For example, with 8-bit palettes and RGB, a palette entry requires 3 bytes (4 bytes for RGBA) and a pixel requires one byte.
For the RGB image, a pixel requires 3 bytes (4 bytes for RGBA).
Thus, a saving occurs for images with 384 or less pixels, if the number of palette entries would be larger than 2/3 pixel count (RGBA < 342 pixels: 3/4 pixel count).
That is a common case with small images, e. g. icons or thumbnails.
Log in to post a comment.