test_bmp.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html
  4. #include "test_precomp.hpp"
  5. #include "test_common.hpp"
  6. #include <vector>
  7. namespace opencv_test { namespace {
  8. // See https://github.com/opencv/opencv/issues/27789
  9. // See https://github.com/opencv/opencv/issues/23233
  10. TEST(Imgcodecs_BMP, encode_decode_over1GB_regression27789)
  11. {
  12. applyTestTag( CV_TEST_TAG_MEMORY_2GB, CV_TEST_TAG_LONG );
  13. // Create large Mat over 1GB
  14. // 20000 px * 18000 px * 24 bpp(3ch) = 1,080,000,000 bytes
  15. // 1 GiB = 1,073,741,824 bytes
  16. cv::Mat src(20000, 18000, CV_8UC3, cv::Scalar(0,0,0));
  17. // Encode large BMP file.
  18. std::vector<uint8_t> buf;
  19. bool ret = false;
  20. ASSERT_NO_THROW(ret = cv::imencode(".bmp", src, buf, {}));
  21. ASSERT_TRUE(ret);
  22. src.release(); // To reduce usage memory, it is needed.
  23. // Decode large BMP file.
  24. cv::Mat dst;
  25. ASSERT_NO_THROW(dst = cv::imdecode(buf, cv::IMREAD_COLOR));
  26. ASSERT_FALSE(dst.empty());
  27. }
  28. TEST(Imgcodecs_BMP, write_read_over1GB_regression27789)
  29. {
  30. // tag CV_TEST_TAG_VERYLONG applied to skip on CI. The test writes ~1GB file.
  31. applyTestTag( CV_TEST_TAG_MEMORY_2GB, CV_TEST_TAG_VERYLONG );
  32. string bmpFilename = cv::tempfile(".bmp"); // To remove it, test must use EXPECT_* instead of ASSERT_*.
  33. // Create large Mat over 1GB
  34. // 20000 px * 18000 px * 24 bpp(3ch) = 1,080,000,000 bytes
  35. // 1 GiB = 1,073,741,824 bytes
  36. cv::Mat src(20000, 18000, CV_8UC3, cv::Scalar(0,0,0));
  37. // Write large BMP file.
  38. bool ret = false;
  39. EXPECT_NO_THROW(ret = cv::imwrite(bmpFilename, src, {}));
  40. EXPECT_TRUE(ret);
  41. // Read large BMP file.
  42. cv::Mat dst;
  43. EXPECT_NO_THROW(dst = cv::imread(bmpFilename, cv::IMREAD_COLOR));
  44. EXPECT_FALSE(dst.empty());
  45. remove(bmpFilename.c_str());
  46. }
  47. }} // namespace