Closed
Description
Saving a PNG with bitdepth < 8 results in a distorted image. See this example of a monochrome image saved at 1bpp:
The same occurs with bit depths of 2 and 4, but the distortions are smaller.
The cause seems to be the lack of a bit mask on the right side of the or operation on line 280 in spngsave.c
for( x = 0; x < n; x++ ) {
bits <<= spng->bitdepth;
bits |= p[x];
if( (x & pixel_mask) == pixel_mask )
*q++ = bits;
}