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

Merge pull request #27013 from asmorkalov:as/imencode_animation

Test for in-memory animation encoding and decoding #27013
 
Tests for https://github.com/opencv/opencv/pull/26964

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Alexander Smorkalov
2025-03-12 18:10:06 +03:00
committed by GitHub
parent bbcdbca872
commit 7481cb50b5
3 changed files with 223 additions and 0 deletions
+48
View File
@@ -588,6 +588,54 @@ INSTANTIATE_TEST_CASE_P(/**/,
Imgcodecs_ImageCollection,
testing::ValuesIn(exts_multi));
TEST(Imgcodecs_APNG, imdecode_animation)
{
Animation gt_animation, mem_animation;
// Set the path to the test image directory and filename for loading.
const string root = cvtest::TS::ptr()->get_data_path();
const string filename = root + "pngsuite/tp1n3p08.png";
EXPECT_TRUE(imreadanimation(filename, gt_animation));
EXPECT_EQ(1000, gt_animation.durations.back());
std::vector<unsigned char> buf;
readFileBytes(filename, buf);
EXPECT_TRUE(imdecodeanimation(buf, mem_animation));
EXPECT_EQ(mem_animation.frames.size(), gt_animation.frames.size());
EXPECT_EQ(mem_animation.bgcolor, gt_animation.bgcolor);
EXPECT_EQ(mem_animation.loop_count, gt_animation.loop_count);
for (size_t i = 0; i < gt_animation.frames.size(); i++)
{
EXPECT_EQ(0, cvtest::norm(mem_animation.frames[i], gt_animation.frames[i], NORM_INF));
EXPECT_EQ(mem_animation.durations[i], gt_animation.durations[i]);
}
}
TEST(Imgcodecs_APNG, imencode_animation)
{
Animation gt_animation, mem_animation;
// Set the path to the test image directory and filename for loading.
const string root = cvtest::TS::ptr()->get_data_path();
const string filename = root + "pngsuite/tp1n3p08.png";
EXPECT_TRUE(imreadanimation(filename, gt_animation));
EXPECT_EQ(1000, gt_animation.durations.back());
std::vector<unsigned char> buf;
EXPECT_TRUE(imencodeanimation(".png", gt_animation, buf));
EXPECT_TRUE(imdecodeanimation(buf, mem_animation));
EXPECT_EQ(mem_animation.frames.size(), gt_animation.frames.size());
EXPECT_EQ(mem_animation.bgcolor, gt_animation.bgcolor);
EXPECT_EQ(mem_animation.loop_count, gt_animation.loop_count);
for (size_t i = 0; i < gt_animation.frames.size(); i++)
{
EXPECT_EQ(0, cvtest::norm(mem_animation.frames[i], gt_animation.frames[i], NORM_INF));
EXPECT_EQ(mem_animation.durations[i], gt_animation.durations[i]);
}
}
#endif // HAVE_PNG
}} // namespace