From: Ashod Nakashian Date: Mon, 29 Dec 2014 15:51:27 +0000 (-0500) Subject: Added imread and imreadmulti regression tests. X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~2749^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=473964806cb76d3a81d1f53b59e5c1031a55e796;p=platform%2Fupstream%2Fopencv.git Added imread and imreadmulti regression tests. --- diff --git a/modules/imgcodecs/src/grfmt_tiff.cpp b/modules/imgcodecs/src/grfmt_tiff.cpp index 7046276..021ff27 100644 --- a/modules/imgcodecs/src/grfmt_tiff.cpp +++ b/modules/imgcodecs/src/grfmt_tiff.cpp @@ -189,7 +189,7 @@ bool TiffDecoder::nextPage() { // Prepare the next page, if any. return m_tif && - TIFFReadDirectory(static_cast(m_tif)) && + TIFFReadDirectory(static_cast(m_tif)) && readHeader(); } diff --git a/modules/imgcodecs/test/test_grfmt.cpp b/modules/imgcodecs/test/test_grfmt.cpp index 451a3a1..d3f21f1 100644 --- a/modules/imgcodecs/test/test_grfmt.cpp +++ b/modules/imgcodecs/test/test_grfmt.cpp @@ -45,6 +45,68 @@ using namespace cv; using namespace std; +static +bool mats_equal(const Mat& lhs, const Mat& rhs) +{ + if (lhs.channels() != rhs.channels() || + lhs.depth() != rhs.depth() || + lhs.size().height != rhs.size().height || + lhs.size().width != rhs.size().width) + { + return false; + } + + Mat diff = (lhs != rhs); + const Scalar s = sum(diff); + for (int i = 0; i < s.channels; ++i) + { + if (s[i] != 0) + { + return false; + } + } + + return true; +} + +static +bool imread_compare(const string& filepath, int flags = IMREAD_COLOR) +{ + vector pages; + if (!imreadmulti(filepath, pages, flags) || + pages.empty()) + { + return false; + } + + const Mat single = imread(filepath, flags); + return mats_equal(single, pages[0]); +} + +TEST(Imgcodecs_imread, regression) +{ + const char* const filenames[] = + { + "color_palette_alpha.png", + "multipage.tif", + "rle.hdr", + "ordinary.bmp", + "rle8.bmp", + "test_1_c1.jpg" + }; + + const string folder = string(cvtest::TS::ptr()->get_data_path()) + "/readwrite/"; + + for (size_t i = 0; i < sizeof(filenames) / sizeof(filenames[0]); ++i) + { + ASSERT_TRUE(imread_compare(folder + string(filenames[i]), IMREAD_UNCHANGED)); + ASSERT_TRUE(imread_compare(folder + string(filenames[i]), IMREAD_GRAYSCALE)); + ASSERT_TRUE(imread_compare(folder + string(filenames[i]), IMREAD_COLOR)); + ASSERT_TRUE(imread_compare(folder + string(filenames[i]), IMREAD_ANYDEPTH)); + ASSERT_TRUE(imread_compare(folder + string(filenames[i]), IMREAD_ANYCOLOR)); + ASSERT_TRUE(imread_compare(folder + string(filenames[i]), IMREAD_LOAD_GDAL)); + } +} class CV_GrfmtWriteBigImageTest : public cvtest::BaseTest { @@ -591,6 +653,46 @@ TEST(Imgcodecs_Tiff, decode_tile_remainder) CV_GrfmtReadTifTiledWithNotFullTiles test; test.safe_run(); } +class CV_GrfmtReadTifMultiPage : public cvtest::BaseTest +{ +private: + void compare(int flags) + { + const string folder = string(cvtest::TS::ptr()->get_data_path()) + "/readwrite/"; + const int page_count = 6; + + vector pages; + bool res = imreadmulti(folder + "multipage.tif", pages, flags); + ASSERT_TRUE(res == true); + ASSERT_TRUE(pages.size() == page_count); + + for (int i = 0; i < page_count; i++) + { + char buffer[256]; + sprintf(buffer, "%smultipage_p%d.tif", folder.c_str(), i + 1); + const string filepath(buffer); + const Mat page = imread(filepath, flags); + ASSERT_TRUE(mats_equal(page, pages[i])); + } + } + +public: + void run(int) + { + compare(IMREAD_UNCHANGED); + compare(IMREAD_GRAYSCALE); + compare(IMREAD_COLOR); + compare(IMREAD_ANYDEPTH); + compare(IMREAD_ANYCOLOR); + compare(IMREAD_LOAD_GDAL); + } +}; + +TEST(Imgcodecs_Tiff, decode_multipage) +{ + CV_GrfmtReadTifMultiPage test; test.safe_run(); +} + #endif #ifdef HAVE_WEBP