From 39bc5df72ab6ccbb3a86c28e6da62f77525742b1 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Tue, 25 Feb 2025 15:24:25 +0300 Subject: [PATCH] Merge pull request #26973 from sturkmen72:png_test Add a test related IMWRITE_PNG_COMPRESSION parameter #26973 ### 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 - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [x] 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 --- modules/imgcodecs/test/test_png.cpp | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/modules/imgcodecs/test/test_png.cpp b/modules/imgcodecs/test/test_png.cpp index 4cf0e0cd99..2eb8a82a96 100644 --- a/modules/imgcodecs/test/test_png.cpp +++ b/modules/imgcodecs/test/test_png.cpp @@ -327,6 +327,38 @@ const string pngsuite_files_corrupted[] = { INSTANTIATE_TEST_CASE_P(/*nothing*/, Imgcodecs_Png_PngSuite_Corrupted, testing::ValuesIn(pngsuite_files_corrupted)); +typedef testing::TestWithParam> Imgcodecs_Png_ImwriteFlags; + +TEST_P(Imgcodecs_Png_ImwriteFlags, compression_level) +{ + const string root = cvtest::TS::ptr()->get_data_path(); + const string filename = root + get<0>(GetParam()); + + const int compression_level = get<1>(GetParam()); + const size_t compression_level_output_size = get<2>(GetParam()); + + Mat src = imread(filename, IMREAD_UNCHANGED); + EXPECT_FALSE(src.empty()) << "Cannot read test image " << filename; + + vector buf; + imencode(".png", src, buf, { IMWRITE_PNG_COMPRESSION, compression_level }); + EXPECT_EQ(buf.size(), compression_level_output_size); +} + +INSTANTIATE_TEST_CASE_P(/**/, + Imgcodecs_Png_ImwriteFlags, + testing::Values( + make_tuple("../perf/512x512.png", 0, 788279), + make_tuple("../perf/512x512.png", 1, 179503), + make_tuple("../perf/512x512.png", 2, 176007), + make_tuple("../perf/512x512.png", 3, 170497), + make_tuple("../perf/512x512.png", 4, 163357), + make_tuple("../perf/512x512.png", 5, 159190), + make_tuple("../perf/512x512.png", 6, 156621), + make_tuple("../perf/512x512.png", 7, 155696), + make_tuple("../perf/512x512.png", 8, 153708), + make_tuple("../perf/512x512.png", 9, 152181))); + #endif // HAVE_PNG }} // namespace