libpng
libpng copied to clipboard
Setting PNG_NO_FILTERS actually sets PNG_ALL_FILTERS
I wanted to test performance improvements disabling compression and filtering for ffmpegthumbnailer and gdk-pixbuf for thumbnail generation and display.
When I edited the filtering parameters, I noticed that when setting
png_set_filter(png_ptr, 0, PNG_NO_FILTERS);
the resulting PNG files would still have all 5 types of filters in use.
I checked the source code here and saw these odd lines of code: https://github.com/glennrp/libpng/blob/libpng16/pngwutil.c#L824-L832
Somehow there is a logic depending on the bit-depth to actually set either PNG_FILTER_NONE for palette and low bit-depth pictures and PNG_ALL_FILTERS for anything else.
I figured setting
png_set_filter(png_ptr, 0, PNG_FILTER_NONE);
directly brought the desired result, but the above behavior is very misleading.
Could this be a bug in the code or is this maybe defined in the specification?
At that point PNG_NO_FILTERS means a filter value wasn't previously set, so that code is filling in the defaults.
Calling png_set_filter with either PNG_NO_FILTERS or PNG_FILTER_VALUE_NONE (same value) will save PNG_FILTER_NONE, so that should stick.
https://github.com/glennrp/libpng/blob/823ef44f01764127276fc0fc1c4dfa5f01c64a2e/pngwrite.c#L1028-L1029