PNG: fix support for images with fewer than 8 bits per pixel

Fixes #10887.