1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge pull request #27087 from sturkmen72:apng_CV_16U

Fixing imread() function 16 bit APNG reading problem
This commit is contained in:
Alexander Smorkalov
2025-03-20 17:29:45 +03:00
committed by GitHub
3 changed files with 69 additions and 3 deletions
+10 -1
View File
@@ -451,6 +451,9 @@ bool PngDecoder::readData( Mat& img )
delay_den = 100;
m_animation.durations.push_back(cvRound(1000.*delay_num/delay_den));
if (mat_cur.depth() == CV_16U && img.depth() == CV_8U)
mat_cur.convertTo(mat_cur, CV_8U, 1. / 255);
if (mat_cur.channels() == img.channels())
mat_cur.copyTo(img);
else if (img.channels() == 1)
@@ -485,7 +488,7 @@ bool PngDecoder::readData( Mat& img )
return false;
}
// Asking for blend over with no alpha is invalid.
if (bop == 1 && img.channels() != 4)
if (bop == 1 && mat_cur.channels() != 4)
{
return false;
}
@@ -514,6 +517,9 @@ bool PngDecoder::readData( Mat& img )
delay_den = 100;
m_animation.durations.push_back(cvRound(1000.*delay_num/delay_den));
if (mat_cur.depth() == CV_16U && img.depth() == CV_8U)
mat_cur.convertTo(mat_cur, CV_8U, 1. / 255);
if (mat_cur.channels() == img.channels())
mat_cur.copyTo(img);
else if (img.channels() == 1)
@@ -775,6 +781,9 @@ bool PngDecoder::processing_start(void* frame_ptr, const Mat& img)
else
png_set_rgb_to_gray(m_png_ptr, 1, 0.299, 0.587); // RGB->Gray
if (!isBigEndian() && m_bit_depth == 16)
png_set_swap(m_png_ptr);
for (size_t i = 0; i < m_chunksInfo.size(); i++)
png_process_data(m_png_ptr, m_info_ptr, m_chunksInfo[i].p.data(), m_chunksInfo[i].p.size());
+1 -1
View File
@@ -505,7 +505,7 @@ imread_( const String& filename, int flags, OutputArray mat )
{
if (decoder->readData(real_mat))
{
CV_CheckTrue(original_ptr == real_mat.data, "Internal imread issue");
CV_CheckTrue((decoder->getFrameCount() > 1) || original_ptr == real_mat.data, "Internal imread issue");
success = true;
}
}