Skip to content

Fix invalid PNG bit depth when using deprecated --colours arg#4971

Merged
jcupitt merged 1 commit intolibvips:masterfrom
felixbuenemann:fix-colours-bitdepth-calculation
Mar 31, 2026
Merged

Fix invalid PNG bit depth when using deprecated --colours arg#4971
jcupitt merged 1 commit intolibvips:masterfrom
felixbuenemann:fix-colours-bitdepth-calculation

Conversation

@felixbuenemann
Copy link
Copy Markdown
Collaborator

ceil(log2(colours)) can produce non-power-of-two values (e.g. 5 for --colours 32) which libpng rejects.
Use g_bit_storage() to compute the minimum bits needed, then round up to a valid PNG palette bit depth (1, 2, 4, or 8).

ceil(log2(colours)) can produce non-power-of-two values (e.g. 5 for
--colours 32) which libpng rejects. Use g_bit_storage() to compute
the minimum bits needed, then round up to a valid PNG palette bit
depth (1, 2, 4, or 8).
@felixbuenemann
Copy link
Copy Markdown
Collaborator Author

@jcupitt Can I merge this simple fix?

@jcupitt jcupitt merged commit 3dfe205 into libvips:master Mar 31, 2026
8 checks passed
@jcupitt
Copy link
Copy Markdown
Member

jcupitt commented Mar 31, 2026

Sorry @felixbuenemann! Done.

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