Skip to content

Commit df6b2d4

Browse files
authored
Merge pull request #1214 from asarium/fix/btaSystemMapNodes
Return correct bits-per-pixel data for 16-bit PNGs
2 parents 028ae98 + 6f84fcb commit df6b2d4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

code/pngutils/pngutils.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ int png_read_header(const char *real_filename, CFILE *img_cfp, int *w, int *h, i
145145
if (w) *w = png_get_image_width(png_ptr, info_ptr);
146146
if (h) *h = png_get_image_height(png_ptr, info_ptr);
147147
// this turns out to be near useless, but meh
148-
if (bpp) *bpp = (png_get_channels(png_ptr, info_ptr) * png_get_bit_depth(png_ptr, info_ptr));
148+
if (bpp) {
149+
// bit depth can also be 16 bit we tell libpng to reduce that to 8 bits so we also need to tell our caller about that
150+
auto bits = std::min(8, (int)png_get_bit_depth(png_ptr, info_ptr));
151+
*bpp = (png_get_channels(png_ptr, info_ptr) * bits);
152+
}
149153

150154
if (img_cfp == NULL) {
151155
cfclose(status.cfp);

0 commit comments

Comments
 (0)