From ca2796aa7ff75c5bb5a74a1f3a4de9538bb9c45e Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sun, 14 Aug 2022 10:26:24 +0100 Subject: [PATCH] fix low-bitdepth spng save There was a missing shift, thanks jeffska See https://github.com/libvips/libvips/issues/2985 --- ChangeLog | 1 + libvips/foreign/spngsave.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index fd0cfb36..3c753524 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ - fix libpng fallback when spng is disabled in meson - add "unlimited" to jpegload - better 0 detection in unpremultiply +- fix low bitdepth spng save [jeffska] 21/11/21 started 8.13 - configure fails for requested but unmet dependencies [remicollet] diff --git a/libvips/foreign/spngsave.c b/libvips/foreign/spngsave.c index 5162e189..594871ce 100644 --- a/libvips/foreign/spngsave.c +++ b/libvips/foreign/spngsave.c @@ -270,6 +270,7 @@ vips_foreign_save_spng_pack( VipsForeignSaveSpng *spng, VipsPel *q, VipsPel *p, size_t n ) { int pixel_mask = 8 / spng->bitdepth - 1; + int shift = 8 - spng->bitdepth; VipsPel bits; size_t x; @@ -277,7 +278,7 @@ vips_foreign_save_spng_pack( VipsForeignSaveSpng *spng, bits = 0; for( x = 0; x < n; x++ ) { bits <<= spng->bitdepth; - bits |= p[x]; + bits |= p[x] >> shift; if( (x & pixel_mask) == pixel_mask ) *q++ = bits;