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
This commit is contained in:
Suleyman TURKMEN 2025-02-25 15:24:25 +03:00 committed by GitHub
parent 6a6a5a765d
commit 39bc5df72a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<testing::tuple<string, int, size_t>> 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<uchar> 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