Skip to content

Saving low bit depth PNG results in distorted image. #2985

Closed
@jeffska

Description

@jeffska

Saving a PNG with bitdepth < 8 results in a distorted image. See this example of a monochrome image saved at 1bpp:

image

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;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions