png palette: order of entries

there is no restrictive rules concerning how to order entries in the palette. some methods of ordering actually result in image data that benefits significantly from filtering.

about trials

each sample is tested with filter none vs the heuristic one defined by Lee Daniel Crocke minimum sum of absolute differences. all samples are encoded with zlib (strategy 3 -RLE-, compression level 9, memlevel 8). the filter that procudes smallest output is selected.

sample 1 : gradients colors, no transparency

Original > Popularity >= Luminance >=
None | 29316 Bytes None | 29310 Bytes None | 29310 Bytes
Popularity > Luminance < Original <
None | 29309 Bytes None | 29065 Bytes None | 29060 Bytes
Popularity < Popularity <= Color >
None | 29045 Bytes None | 29044 Bytes Heuristic | 27416 Bytes
Color < Nearest - L*a*b* - Dark Nearest - RGB - Dark
Heuristic | 27372 Bytes Heuristic | 25039 Bytes Heuristic | 24964 Bytes
Nearest - L*a*b* - Popular Nearest - RGB - Popular
Heuristic | 24872 Bytes Heuristic | 24814 Bytes

sample 2 : gradients colors, transparency

Original > Popularity >= Popularity >
tRNS ignored tRNS ignored tRNS ignored
None | 21818 Bytes None | 21816 Bytes None | 21816 Bytes
Popularity <= Popularity < Original >
tRNS ignored tRNS ignored tRNS first
None | 21673 Bytes None | 21671 Bytes None | 21653 Bytes
Popularity >= Popularity > None <
tRNS first tRNS first tRNS first
None | 21649 Bytes None | 21649 Bytes None | 21508 Bytes
Popularity <= Popularity < Color <
tRNS first tRNS first tRNS ignored
None | 21502 Bytes None | 21502 Bytes Heuristic | 19864 Bytes
Color > Luminance < Luminance >
tRNS ignored tRNS ignored tRNS ignored
Heuristic | 19756 Bytes Heuristic | 19756 Bytes Heuristic | 19864 Bytes
Nearest L*a*b* - Bright Nearest (W) L*a*b* - Bright Nearest RGB - Bright
tRNS ignored tRNS ignored tRNS ignored
Heuristic | 19541 Bytes Heuristic | 19487 Bytes Heuristic | 19410 Bytes
Nearest L*a*b* - Bright Nearest (W) RGB - Bright Nearest (W) L*a*b* - Dark
tRNS sorted tRNS ignored tRNS ignored
Heuristic | 19268 Bytes Heuristic | 19254 Bytes Heuristic | 19230 Bytes
Nearest (W) L*a*b* - Popular Nearest L*a*b* - Popular Nearest L*a*b* - Dark
tRNS ignored tRNS ignored tRNS ignored
Heuristic | 19216 Bytes Heuristic | 19205 Bytes Heuristic | 19200 Bytes
Nearest (W) YUV - Bright Nearest YUV - Bright Nearest L*a*b* - Popular
tRNS ignored tRNS ignored tRNS sorted
Heuristic | 19183 Bytes Heuristic | 19156 Bytes Heuristic | 19073 Bytes
Nearest (W) L*a*b* - Popular Nearest YUV - Dark Nearest YUV - Popular
tRNS sorted tRNS ignored tRNS ignored
Heuristic | 19049 Bytes Heuristic | 18946 Bytes Heuristic | 18940 Bytes
Nearest RGB - Popular Nearest (W) YUV - Dark Nearest (W) RGB - Dark
tRNS ignored tRNS ignored tRNS ignored
Heuristic | 18935 Bytes Heuristic | 18929 Bytes Heuristic | 18904 Bytes
Nearest (W) RGB - Popular Nearest (W) YUV - Popular Nearest RGB - Dark
tRNS ignored tRNS ignored tRNS ignored
Heuristic | 18902 Bytes Heuristic | 18896 Bytes Heuristic | 18893 Bytes
Color < Color > Luminance <
tRNS sorted tRNS sorted tRNS sorted
Heuristic | 18629 Bytes Heuristic | 18416 Bytes Heuristic | 18332 Bytes
Luminance < Nearest RGB -Popular Luminance >
tRNS first tRNS sorted tRNS first
Heuristic | 18292 Bytes Heuristic | 18260 Bytes Heuristic | 18241 Bytes
Color < Color > Luminance >
tRNS first tRNS first tRNS sorted
Heuristic | 18238 Bytes Heuristic | 18229 Bytes Heuristic | 18196 Bytes
Nearest (W) L*a*b* - Popular Nearest (W) L*a*b* - Dark Nearest L*a*b* - Popular
tRNS first tRNS first tRNS first
Heuristic | 18168 Bytes Heuristic | 18125 Bytes Heuristic | 18124 Bytes
Nearest L*a*b* - Dark Nearest (W) RGB - Bright Nearest (W) RGB - Popular
tRNS first tRNS sorted tRNS first
Heuristic | 18091 Bytes Heuristic | 18061 Bytes Heuristic | 18042 Bytes
Nearest RGB - Popular Nearest RGB - Bright Nearest (W) L*a*b* - Bright
tRNS first tRNS sorted tRNS first
Heuristic | 18091 Bytes Heuristic | 18061 Bytes Heuristic | 18042 Bytes
Nearest L*a*b* - Bright Nearest (W) YUV - Popular Nearest (W) YUV - Popular
tRNS first tRNS first tRNS sort
Heuristic | 17994 Bytes Heuristic | 17961 Bytes Heuristic | 17938 Bytes
Nearest (W) RGB - Dark Nearest RGB - Dark Nearest (W) RGB - Bright
tRNS first tRNS first tRNS first
Heuristic | 17885 Bytes Heuristic | 17876 Bytes Heuristic | 17848 Bytes
Nearest YUV - Popular Nearest (W) YUV - Dark Nearest YUV - Dark
tRNS first tRNS first tRNS first
Heuristic | 17839 Bytes Heuristic | 17816 Bytes Heuristic | 17814 Bytes
Nearest YUV - Popular Nearest YUV - Bright Nearest (W) YUV - Bright
tRNS sorted tRNS first tRNS first
Heuristic | 17809 Bytes Heuristic | 17800 Bytes Heuristic | 17779 Bytes
Nearest RGB - Bright Nearest YUV - Bright
tRNS first tRNS sorted
Heuristic | 17779 Bytes Heuristic | 17608 Bytes

filters and compression

test a specific sorting on a unique sample, with different filters and compression algorithms

filters and compression results
zlib libdeflate zopfli
rank size rank size rank size
1 | fs1 17489 Bytes 1 | fs2 17242 Bytes 1 | fs8 16957 Bytes
2 | fs6 17505 Bytes 2 | fs1 17244 Bytes 2 | fs2 16958 Bytes
3 | en 17629 Bytes 3 | min 17257 Bytes 3 | fs1 16984 Bytes
4 | fs8 17632 Bytes 4 | fs3 17259 Bytes 4 | fs5 17009 Bytes
5 | fs2 17656 Bytes 5 | fs5 17286 Bytes 5 | fs6 17026 Bytes
6 | fs3 17673 Bytes 6 | fs6 17293 Bytes 6 | fs3 17030 Bytes
7 | min 17679 Bytes 7 | fs4 17305 Bytes 7 | db 17037 Bytes
8 | fs5 17702 Bytes 8 | fs8 17310 Bytes 8 | en 17038 Bytes
9 | fs4 17718 Bytes 9 | db 17313 Bytes 9 | min 17048 Bytes
10 | db 17733 Bytes 10 | en 17321 Bytes 10 | fs4 17063 Bytes
11 | bf 17890 Bytes 11 | bf 17437 Bytes 11 | fs7 17172 Bytes
12 | fs7 17962 Bytes 12 | fs7 17567 Bytes 12 | bf 17194 Bytes
13 | fs9 18142 Bytes 13 | fs9 17742 Bytes 13 | fs9 17505 Bytes
14 | none 21934 Bytes 14 | none 20902 Bytes 14 | none 20692 Bytes
pngwolf (combinations) - with same compression settings
zlib libdeflate zopfli
result size result size result size
wolf 17565 Bytes wolf 17076 Bytes wolf 16964 Bytes