mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge branch 4.x
This commit is contained in:
@@ -130,7 +130,7 @@ bool GifDecoder::readData(Mat &img) {
|
||||
globalColorTable[bgColor * 3 + 1], // G
|
||||
globalColorTable[bgColor * 3 + 0], // R
|
||||
0); // A
|
||||
restore = Mat(width, height, CV_8UC4, background);
|
||||
restore = Mat(height, width, CV_8UC4, background);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
return (ptr_ - other.ptr_) / step_;
|
||||
}
|
||||
|
||||
/* Comparision */
|
||||
/* Comparison */
|
||||
bool operator==(const ChannelsIterator<Traits>& other) const CV_NOEXCEPT
|
||||
{
|
||||
return ptr_ == other.ptr_;
|
||||
|
||||
@@ -133,6 +133,7 @@ const uint32_t id_bKGD = 0x624B4744; // The bKGD chunk specifies a default backg
|
||||
const uint32_t id_tRNS = 0x74524E53; // The tRNS chunk provides transparency information
|
||||
const uint32_t id_tEXt = 0x74455874; // The tEXt chunk stores metadata as text in key-value pairs
|
||||
const uint32_t id_IEND = 0x49454E44; // end/footer chunk
|
||||
const uint32_t id_CgBI = 0x43674249; // The CgBI chunk (Apple private) is not supported.
|
||||
|
||||
APNGFrame::APNGFrame()
|
||||
{
|
||||
@@ -285,9 +286,18 @@ bool PngDecoder::readHeader()
|
||||
if (!readFromStreamOrBuffer(&sig, 8))
|
||||
return false;
|
||||
|
||||
// IHDR chunk shall be first. ( https://www.w3.org/TR/png-3/#5ChunkOrdering )
|
||||
id = read_chunk(m_chunkIHDR);
|
||||
if (id != id_IHDR)
|
||||
if (id == id_CgBI)
|
||||
{
|
||||
CV_LOG_ERROR(NULL, "CgBI chunk (Apple private) found as the first chunk. IHDR is expected.");
|
||||
return false;
|
||||
}
|
||||
if (id != id_IHDR)
|
||||
{
|
||||
CV_LOG_ERROR(NULL, "IHDR chunk shall be first. This data may be broken or malformed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_is_fcTL_loaded = false;
|
||||
while (true)
|
||||
|
||||
@@ -110,6 +110,44 @@ TEST(Imgcodecs_Png, read_color_palette_with_alpha)
|
||||
EXPECT_EQ(img.at<Vec3b>(0, 1), Vec3b(255, 0, 0));
|
||||
}
|
||||
|
||||
// IHDR shall be first.
|
||||
// See https://github.com/opencv/opencv/issues/27295
|
||||
TEST(Imgcodecs_Png, decode_regression27295)
|
||||
{
|
||||
vector<uchar> buff;
|
||||
Mat src = Mat::zeros(240, 180, CV_8UC3);
|
||||
vector<int> param;
|
||||
EXPECT_NO_THROW(imencode(".png", src, buff, param));
|
||||
|
||||
Mat img;
|
||||
|
||||
// If IHDR chunk found as the first chunk, output shall not be empty.
|
||||
// 8 means PNG signature length.
|
||||
// 4 means length field(uint32_t).
|
||||
EXPECT_EQ(buff[8+4+0], 'I');
|
||||
EXPECT_EQ(buff[8+4+1], 'H');
|
||||
EXPECT_EQ(buff[8+4+2], 'D');
|
||||
EXPECT_EQ(buff[8+4+3], 'R');
|
||||
EXPECT_NO_THROW(img = imdecode(buff, IMREAD_COLOR));
|
||||
EXPECT_FALSE(img.empty());
|
||||
|
||||
// If Non-IHDR chunk found as the first chunk, output shall be empty.
|
||||
buff[8+4+0] = 'i'; // Not 'I'
|
||||
buff[8+4+1] = 'H';
|
||||
buff[8+4+2] = 'D';
|
||||
buff[8+4+3] = 'R';
|
||||
EXPECT_NO_THROW(img = imdecode(buff, IMREAD_COLOR));
|
||||
EXPECT_TRUE(img.empty());
|
||||
|
||||
// If CgBI chunk (Apple private) found as the first chunk, output shall be empty with special message.
|
||||
buff[8+4+0] = 'C';
|
||||
buff[8+4+1] = 'g';
|
||||
buff[8+4+2] = 'B';
|
||||
buff[8+4+3] = 'I';
|
||||
EXPECT_NO_THROW(img = imdecode(buff, IMREAD_COLOR));
|
||||
EXPECT_TRUE(img.empty());
|
||||
}
|
||||
|
||||
typedef testing::TestWithParam<string> Imgcodecs_Png_PngSuite;
|
||||
|
||||
TEST_P(Imgcodecs_Png_PngSuite, decode)
|
||||
|
||||
Reference in New Issue
Block a user