mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge branch 4.x
This commit is contained in:
@@ -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