166 |
166 |
|
167 |
167 |
if( bit_depth <= 8 || bit_depth == 16 )
|
168 |
168 |
{
|
169 |
|
m_type = color_type == PNG_COLOR_TYPE_RGB ||
|
170 |
|
color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
|
171 |
|
color_type == PNG_COLOR_TYPE_PALETTE ? CV_8UC3 : CV_8UC1;
|
|
169 |
switch(color_type)
|
|
170 |
{
|
|
171 |
case PNG_COLOR_TYPE_RGB:
|
|
172 |
case PNG_COLOR_TYPE_PALETTE:
|
|
173 |
m_type = CV_8UC3;
|
|
174 |
break;
|
|
175 |
case PNG_COLOR_TYPE_RGB_ALPHA:
|
|
176 |
m_type = CV_8UC4;
|
|
177 |
break;
|
|
178 |
default:
|
|
179 |
m_type = CV_8UC1;
|
|
180 |
}
|
172 |
181 |
if( bit_depth == 16 )
|
173 |
182 |
m_type = CV_MAKETYPE(CV_16U, CV_MAT_CN(m_type));
|
174 |
183 |
result = true;
|
... | ... | |
209 |
218 |
else if( !isBigEndian() )
|
210 |
219 |
png_set_swap( png_ptr );
|
211 |
220 |
|
212 |
|
/* observation: png_read_image() writes 400 bytes beyond
|
213 |
|
* end of data when reading a 400x118 color png
|
214 |
|
* "mpplus_sand.png". OpenCV crashes even with demo
|
215 |
|
* programs. Looking at the loaded image I'd say we get 4
|
216 |
|
* bytes per pixel instead of 3 bytes per pixel. Test
|
217 |
|
* indicate that it is a good idea to always ask for
|
218 |
|
* stripping alpha.. 18.11.2004 Axel Walthelm
|
219 |
|
*/
|
220 |
|
png_set_strip_alpha( png_ptr );
|
|
221 |
if(img.channels() < 4)
|
|
222 |
{
|
|
223 |
/* observation: png_read_image() writes 400 bytes beyond
|
|
224 |
* end of data when reading a 400x118 color png
|
|
225 |
* "mpplus_sand.png". OpenCV crashes even with demo
|
|
226 |
* programs. Looking at the loaded image I'd say we get 4
|
|
227 |
* bytes per pixel instead of 3 bytes per pixel. Test
|
|
228 |
* indicate that it is a good idea to always ask for
|
|
229 |
* stripping alpha.. 18.11.2004 Axel Walthelm
|
|
230 |
*/
|
|
231 |
png_set_strip_alpha( png_ptr );
|
|
232 |
}
|
221 |
233 |
|
222 |
234 |
if( m_color_type == PNG_COLOR_TYPE_PALETTE )
|
223 |
235 |
png_set_palette_to_rgb( png_ptr );
|