Merge pull request #1311 from leszekhanusz:png_palette_alpha

This commit is contained in:
Roman Donchenko
2013-08-26 16:59:44 +04:00
committed by OpenCV Buildbot
2 changed files with 111 additions and 10 deletions

View File

@@ -171,7 +171,9 @@ bool PngDecoder::readHeader()
if( !m_buf.empty() || m_f )
{
png_uint_32 wdth, hght;
int bit_depth, color_type;
int bit_depth, color_type, num_trans=0;
png_bytep trans;
png_color_16p trans_values;
png_read_info( png_ptr, info_ptr );
@@ -187,15 +189,22 @@ bool PngDecoder::readHeader()
{
switch(color_type)
{
case PNG_COLOR_TYPE_RGB:
case PNG_COLOR_TYPE_PALETTE:
m_type = CV_8UC3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
m_type = CV_8UC4;
break;
default:
m_type = CV_8UC1;
case PNG_COLOR_TYPE_RGB:
m_type = CV_8UC3;
break;
case PNG_COLOR_TYPE_PALETTE:
png_get_tRNS( png_ptr, info_ptr, &trans, &num_trans, &trans_values);
//Check if there is a transparency value in the palette
if ( num_trans > 0 )
m_type = CV_8UC4;
else
m_type = CV_8UC3;
break;
case PNG_COLOR_TYPE_RGB_ALPHA:
m_type = CV_8UC4;
break;
default:
m_type = CV_8UC1;
}
if( bit_depth == 16 )
m_type = CV_MAKETYPE(CV_16U, CV_MAT_CN(m_type));