in imagecore/formats/internal/png.cpp [105:141]
bool ImageReaderPNG::beginRead(unsigned int outputWidth, unsigned int outputHeight, EImageColorModel outputColorModel)
{
if( !supportsOutputColorModel(outputColorModel) ) {
return false;
}
if( outputWidth != m_Width || outputHeight != m_Height ) {
return false;
}
if( setjmp(png_jmpbuf(m_PNGDecompress)) ) {
return false;
}
unsigned int color_type = png_get_color_type(m_PNGDecompress, m_PNGInfo);
unsigned int bit_depth = png_get_bit_depth(m_PNGDecompress, m_PNGInfo);
if( bit_depth == 16 ) {
png_set_strip_16(m_PNGDecompress);
}
if( color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8 ) {
png_set_expand_gray_1_2_4_to_8(m_PNGDecompress);
}
if( Image::colorModelIsRGBA(outputColorModel) ) {
if( color_type == PNG_COLOR_TYPE_PALETTE ) {
png_set_palette_to_rgb(m_PNGDecompress);
}
if( png_get_valid(m_PNGDecompress, m_PNGInfo, PNG_INFO_tRNS) ) {
png_set_tRNS_to_alpha(m_PNGDecompress);
} else if( color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_PALETTE ) {
png_set_filler(m_PNGDecompress, 255, PNG_FILLER_AFTER);
}
if( color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA ) {
png_set_gray_to_rgb(m_PNGDecompress);
}
}
png_read_update_info(m_PNGDecompress, m_PNGInfo);
return true;
}