lvandeve / lodepng

PNG encoder and decoder in C and C++.
zlib License
2.08k stars 425 forks source link

LFS_MINSUM oddities #147

Open runewalsh opened 3 years ago

runewalsh commented 3 years ago

sum += s < 128 ? s : (255U - s);

Taking abs((int8_t)s) straightly will yield 256 - s, not 255 - s. With 255, the absolute values of the negative numbers become off by one from what they should be. Also, for me, 256 behaves more often better than not: resulting PNGs are consistently smaller by several ppm. Was there any source for 255?

While we at it, it doesn't look like libpng prevents filter 0 (FILTER_NONE) from being analyzed by the minimal-sum-of-absolute-differences heuristic on a general basis, like you do. At least, if you turn a bunch of low-variation samples from [−1; 1] with the mean of 0 into an image by remapping them to [0; 255], it can fit it nicely.