Skip to content

fix: allow compression=0 for pngsave - #101

Merged
cshum merged 1 commit into
cshum:mainfrom
smileexpression:fix/zero-compression
Sep 7, 2026
Merged

cshum merged 1 commit into
cshum:mainfrom
smileexpression:fix/zero-compression

Conversation

@smileexpression

Copy link
Copy Markdown
Contributor

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.

@cshum
cshum merged commit e6647ec into cshum:main Sep 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants