fix: allow compression=0 for pngsave - #101
Merged
Merged
Conversation
cshum
approved these changes
Sep 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vipsgen_set_int skips zero values, so the Go zero value falls back to the libvips default. pngsave compression is 0-9 with default 6, so Compression: 0 currently gets silently dropped and you end up with level 6. There's no way to ask for an uncompressed PNG. Same issue as effort=0 in #95.
This whitelists compression for the pngsave family (pngsave, pngsave_buffer, pngsave_target) to use vipsgen_set_int_allow_zero.
Checked the libvips registrations on 8.16.1 / 8.17.3 / 8.18.6, ranges and defaults are the same across the CI matrix.
Not whitelisting params where 0 is an index or an auto marker (jpegsave quant_table, tiffsave/ppmsave bitdepth, jxlsave tier), since explicit 0 is indistinguishable from unset there. pngsave effort stays out too, its range is 1-10.
Snapshot tests cover both directions: pngsave compression uses allow_zero, while pngsave effort and dzsave compression keep the zero-skip.
Also renamed shouldAllowZeroEffort to shouldIntAllowZero since it's no longer effort-specific.
One thing I wasn't sure about: dzsave compression (range -1..9, default 0). 0 means "store" there as well, but since 0 is also the default, the zero-skip makes no difference today. Could add it for consistency so that compression=0 means "no compression" everywhere, but left it out to keep this minimal.