test_tiff.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. namespace opencv_test { namespace {
  6. #ifdef HAVE_TIFF
  7. // these defines are used to resolve conflict between tiff.h and opencv2/core/types_c.h
  8. #define uint64 uint64_hack_
  9. #define int64 int64_hack_
  10. #include "tiff.h"
  11. #ifdef __ANDROID__
  12. // Test disabled as it uses a lot of memory.
  13. // It is killed with SIGKILL by out of memory killer.
  14. TEST(Imgcodecs_Tiff, DISABLED_decode_tile16384x16384)
  15. #else
  16. TEST(Imgcodecs_Tiff, decode_tile16384x16384)
  17. #endif
  18. {
  19. // see issue #2161
  20. cv::Mat big(16384, 16384, CV_8UC1, cv::Scalar::all(0));
  21. string file3 = cv::tempfile(".tiff");
  22. string file4 = cv::tempfile(".tiff");
  23. std::vector<int> params;
  24. params.push_back(TIFFTAG_ROWSPERSTRIP);
  25. params.push_back(big.rows);
  26. EXPECT_NO_THROW(cv::imwrite(file4, big, params));
  27. EXPECT_NO_THROW(cv::imwrite(file3, big.colRange(0, big.cols - 1), params));
  28. big.release();
  29. try
  30. {
  31. cv::imread(file3, IMREAD_UNCHANGED);
  32. EXPECT_NO_THROW(cv::imread(file4, IMREAD_UNCHANGED));
  33. }
  34. catch(const std::bad_alloc&)
  35. {
  36. // not enough memory
  37. }
  38. EXPECT_EQ(0, remove(file3.c_str()));
  39. EXPECT_EQ(0, remove(file4.c_str()));
  40. }
  41. TEST(Imgcodecs_Tiff, write_read_16bit_big_little_endian)
  42. {
  43. // see issue #2601 "16-bit Grayscale TIFF Load Failures Due to Buffer Underflow and Endianness"
  44. // Setup data for two minimal 16-bit grayscale TIFF files in both endian formats
  45. uchar tiff_sample_data[2][86] = { {
  46. // Little endian
  47. 0x49, 0x49, 0x2a, 0x00, 0x0c, 0x00, 0x00, 0x00, 0xad, 0xde, 0xef, 0xbe, 0x06, 0x00, 0x00, 0x01,
  48. 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x00, 0x01, 0x00,
  49. 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00,
  50. 0x00, 0x00, 0x06, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01,
  51. 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x17, 0x01, 0x04, 0x00, 0x01, 0x00,
  52. 0x00, 0x00, 0x04, 0x00, 0x00, 0x00 }, {
  53. // Big endian
  54. 0x4d, 0x4d, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x0c, 0xde, 0xad, 0xbe, 0xef, 0x00, 0x06, 0x01, 0x00,
  55. 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x00,
  56. 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x10,
  57. 0x00, 0x00, 0x01, 0x06, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x11,
  58. 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x01, 0x17, 0x00, 0x04, 0x00, 0x00,
  59. 0x00, 0x01, 0x00, 0x00, 0x00, 0x04 }
  60. };
  61. // Test imread() for both a little endian TIFF and big endian TIFF
  62. for (int i = 0; i < 2; i++)
  63. {
  64. string filename = cv::tempfile(".tiff");
  65. // Write sample TIFF file
  66. FILE* fp = fopen(filename.c_str(), "wb");
  67. ASSERT_TRUE(fp != NULL);
  68. ASSERT_EQ((size_t)1, fwrite(tiff_sample_data[i], 86, 1, fp));
  69. fclose(fp);
  70. Mat img = imread(filename, IMREAD_UNCHANGED);
  71. EXPECT_EQ(1, img.rows);
  72. EXPECT_EQ(2, img.cols);
  73. EXPECT_EQ(CV_16U, img.type());
  74. EXPECT_EQ(sizeof(ushort), img.elemSize());
  75. EXPECT_EQ(1, img.channels());
  76. EXPECT_EQ(0xDEAD, img.at<ushort>(0,0));
  77. EXPECT_EQ(0xBEEF, img.at<ushort>(0,1));
  78. EXPECT_EQ(0, remove(filename.c_str()));
  79. }
  80. }
  81. TEST(Imgcodecs_Tiff, decode_tile_remainder)
  82. {
  83. /* see issue #3472 - dealing with tiled images where the tile size is
  84. * not a multiple of image size.
  85. * The tiled images were created with 'convert' from ImageMagick,
  86. * using the command 'convert <input> -define tiff:tile-geometry=128x128 -depth [8|16] <output>
  87. * Note that the conversion to 16 bits expands the range from 0-255 to 0-255*255,
  88. * so the test converts back but rounding errors cause small differences.
  89. */
  90. const string root = cvtest::TS::ptr()->get_data_path();
  91. cv::Mat img = imread(root + "readwrite/non_tiled.tif",-1);
  92. ASSERT_FALSE(img.empty());
  93. ASSERT_TRUE(img.channels() == 3);
  94. cv::Mat tiled8 = imread(root + "readwrite/tiled_8.tif", -1);
  95. ASSERT_FALSE(tiled8.empty());
  96. ASSERT_PRED_FORMAT2(cvtest::MatComparator(0, 0), img, tiled8);
  97. cv::Mat tiled16 = imread(root + "readwrite/tiled_16.tif", -1);
  98. ASSERT_FALSE(tiled16.empty());
  99. ASSERT_TRUE(tiled16.elemSize() == 6);
  100. tiled16.convertTo(tiled8, CV_8UC3, 1./256.);
  101. ASSERT_PRED_FORMAT2(cvtest::MatComparator(2, 0), img, tiled8);
  102. // What about 32, 64 bit?
  103. }
  104. TEST(Imgcodecs_Tiff, decode_infinite_rowsperstrip)
  105. {
  106. const uchar sample_data[142] = {
  107. 0x49, 0x49, 0x2a, 0x00, 0x10, 0x00, 0x00, 0x00, 0x56, 0x54,
  108. 0x56, 0x5a, 0x59, 0x55, 0x5a, 0x00, 0x0a, 0x00, 0x00, 0x01,
  109. 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  110. 0x01, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00,
  111. 0x00, 0x00, 0x02, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00,
  112. 0x08, 0x00, 0x00, 0x00, 0x03, 0x01, 0x03, 0x00, 0x01, 0x00,
  113. 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0x01, 0x03, 0x00,
  114. 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x11, 0x01,
  115. 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
  116. 0x15, 0x01, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00,
  117. 0x00, 0x00, 0x16, 0x01, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00,
  118. 0xff, 0xff, 0xff, 0xff, 0x17, 0x01, 0x04, 0x00, 0x01, 0x00,
  119. 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x1c, 0x01, 0x03, 0x00,
  120. 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  121. 0x00, 0x00
  122. };
  123. const string filename = cv::tempfile(".tiff");
  124. std::ofstream outfile(filename.c_str(), std::ofstream::binary);
  125. outfile.write(reinterpret_cast<const char *>(sample_data), sizeof sample_data);
  126. outfile.close();
  127. EXPECT_NO_THROW(cv::imread(filename, IMREAD_UNCHANGED));
  128. EXPECT_EQ(0, remove(filename.c_str()));
  129. }
  130. TEST(Imgcodecs_Tiff, readWrite_unsigned)
  131. {
  132. const string root = cvtest::TS::ptr()->get_data_path();
  133. const string filenameInput = root + "readwrite/gray_8u.tif";
  134. const string filenameOutput = cv::tempfile(".tiff");
  135. const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
  136. ASSERT_FALSE(img.empty());
  137. ASSERT_EQ(CV_8UC1, img.type());
  138. Mat matS8;
  139. img.convertTo(matS8, CV_8SC1);
  140. ASSERT_TRUE(cv::imwrite(filenameOutput, matS8));
  141. const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
  142. ASSERT_EQ(img2.type(), matS8.type());
  143. ASSERT_EQ(img2.size(), matS8.size());
  144. EXPECT_LE(cvtest::norm(matS8, img2, NORM_INF | NORM_RELATIVE), 1e-3);
  145. EXPECT_EQ(0, remove(filenameOutput.c_str()));
  146. }
  147. TEST(Imgcodecs_Tiff, readWrite_32FC1)
  148. {
  149. const string root = cvtest::TS::ptr()->get_data_path();
  150. const string filenameInput = root + "readwrite/test32FC1.tiff";
  151. const string filenameOutput = cv::tempfile(".tiff");
  152. const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
  153. ASSERT_FALSE(img.empty());
  154. ASSERT_EQ(CV_32FC1,img.type());
  155. ASSERT_TRUE(cv::imwrite(filenameOutput, img));
  156. const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
  157. ASSERT_EQ(img2.type(), img.type());
  158. ASSERT_EQ(img2.size(), img.size());
  159. EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 1e-3);
  160. EXPECT_EQ(0, remove(filenameOutput.c_str()));
  161. }
  162. TEST(Imgcodecs_Tiff, readWrite_64FC1)
  163. {
  164. const string root = cvtest::TS::ptr()->get_data_path();
  165. const string filenameInput = root + "readwrite/test64FC1.tiff";
  166. const string filenameOutput = cv::tempfile(".tiff");
  167. const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
  168. ASSERT_FALSE(img.empty());
  169. ASSERT_EQ(CV_64FC1, img.type());
  170. ASSERT_TRUE(cv::imwrite(filenameOutput, img));
  171. const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
  172. ASSERT_EQ(img2.type(), img.type());
  173. ASSERT_EQ(img2.size(), img.size());
  174. EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 1e-3);
  175. EXPECT_EQ(0, remove(filenameOutput.c_str()));
  176. }
  177. TEST(Imgcodecs_Tiff, readWrite_32FC3_SGILOG)
  178. {
  179. const string root = cvtest::TS::ptr()->get_data_path();
  180. const string filenameInput = root + "readwrite/test32FC3_sgilog.tiff";
  181. const string filenameOutput = cv::tempfile(".tiff");
  182. const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
  183. ASSERT_FALSE(img.empty());
  184. ASSERT_EQ(CV_32FC3, img.type());
  185. ASSERT_TRUE(cv::imwrite(filenameOutput, img));
  186. const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
  187. ASSERT_EQ(img2.type(), img.type());
  188. ASSERT_EQ(img2.size(), img.size());
  189. EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 0.01);
  190. EXPECT_EQ(0, remove(filenameOutput.c_str()));
  191. }
  192. TEST(Imgcodecs_Tiff, readWrite_32FC3_RAW)
  193. {
  194. const string root = cvtest::TS::ptr()->get_data_path();
  195. const string filenameInput = root + "readwrite/test32FC3_raw.tiff";
  196. const string filenameOutput = cv::tempfile(".tiff");
  197. const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
  198. ASSERT_FALSE(img.empty());
  199. ASSERT_EQ(CV_32FC3, img.type());
  200. std::vector<int> params;
  201. params.push_back(IMWRITE_TIFF_COMPRESSION);
  202. params.push_back(1/*COMPRESSION_NONE*/);
  203. ASSERT_TRUE(cv::imwrite(filenameOutput, img, params));
  204. const Mat img2 = cv::imread(filenameOutput, IMREAD_UNCHANGED);
  205. ASSERT_EQ(img2.type(), img.type());
  206. ASSERT_EQ(img2.size(), img.size());
  207. EXPECT_LE(cvtest::norm(img, img2, NORM_INF | NORM_RELATIVE), 1e-3);
  208. EXPECT_EQ(0, remove(filenameOutput.c_str()));
  209. }
  210. TEST(Imgcodecs_Tiff, read_palette_color_image)
  211. {
  212. const string root = cvtest::TS::ptr()->get_data_path();
  213. const string filenameInput = root + "readwrite/test_palette_color_image.tif";
  214. const Mat img = cv::imread(filenameInput, IMREAD_UNCHANGED);
  215. ASSERT_FALSE(img.empty());
  216. ASSERT_EQ(CV_8UC3, img.type());
  217. }
  218. //==================================================================================================
  219. typedef testing::TestWithParam<int> Imgcodecs_Tiff_Modes;
  220. TEST_P(Imgcodecs_Tiff_Modes, decode_multipage)
  221. {
  222. const int mode = GetParam();
  223. const string root = cvtest::TS::ptr()->get_data_path();
  224. const string filename = root + "readwrite/multipage.tif";
  225. const string page_files[] = {
  226. "readwrite/multipage_p1.tif",
  227. "readwrite/multipage_p2.tif",
  228. "readwrite/multipage_p3.tif",
  229. "readwrite/multipage_p4.tif",
  230. "readwrite/multipage_p5.tif",
  231. "readwrite/multipage_p6.tif"
  232. };
  233. const size_t page_count = sizeof(page_files)/sizeof(page_files[0]);
  234. vector<Mat> pages;
  235. bool res = imreadmulti(filename, pages, mode);
  236. ASSERT_TRUE(res == true);
  237. ASSERT_EQ(page_count, pages.size());
  238. for (size_t i = 0; i < page_count; i++)
  239. {
  240. const Mat page = imread(root + page_files[i], mode);
  241. EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), page, pages[i]);
  242. }
  243. }
  244. const int all_modes[] =
  245. {
  246. IMREAD_UNCHANGED,
  247. IMREAD_GRAYSCALE,
  248. IMREAD_COLOR,
  249. IMREAD_ANYDEPTH,
  250. IMREAD_ANYCOLOR
  251. };
  252. INSTANTIATE_TEST_CASE_P(AllModes, Imgcodecs_Tiff_Modes, testing::ValuesIn(all_modes));
  253. //==================================================================================================
  254. TEST(Imgcodecs_Tiff_Modes, write_multipage)
  255. {
  256. const string root = cvtest::TS::ptr()->get_data_path();
  257. const string filename = root + "readwrite/multipage.tif";
  258. const string page_files[] = {
  259. "readwrite/multipage_p1.tif",
  260. "readwrite/multipage_p2.tif",
  261. "readwrite/multipage_p3.tif",
  262. "readwrite/multipage_p4.tif",
  263. "readwrite/multipage_p5.tif",
  264. "readwrite/multipage_p6.tif"
  265. };
  266. const size_t page_count = sizeof(page_files) / sizeof(page_files[0]);
  267. vector<Mat> pages;
  268. for (size_t i = 0; i < page_count; i++)
  269. {
  270. const Mat page = imread(root + page_files[i]);
  271. pages.push_back(page);
  272. }
  273. string tmp_filename = cv::tempfile(".tiff");
  274. bool res = imwrite(tmp_filename, pages);
  275. ASSERT_TRUE(res);
  276. vector<Mat> read_pages;
  277. imreadmulti(tmp_filename, read_pages);
  278. for (size_t i = 0; i < page_count; i++)
  279. {
  280. EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), read_pages[i], pages[i]);
  281. }
  282. }
  283. //==================================================================================================
  284. TEST(Imgcodecs_Tiff, imdecode_no_exception_temporary_file_removed)
  285. {
  286. const string root = cvtest::TS::ptr()->get_data_path();
  287. const string filename = root + "../cv/shared/lena.png";
  288. cv::Mat img = cv::imread(filename);
  289. ASSERT_FALSE(img.empty());
  290. std::vector<uchar> buf;
  291. EXPECT_NO_THROW(cv::imencode(".tiff", img, buf));
  292. EXPECT_NO_THROW(cv::imdecode(buf, IMREAD_UNCHANGED));
  293. }
  294. TEST(Imgcodecs_Tiff, decode_black_and_write_image_pr12989_grayscale)
  295. {
  296. const string filename = cvtest::findDataFile("readwrite/bitsperpixel1.tiff");
  297. cv::Mat img;
  298. ASSERT_NO_THROW(img = cv::imread(filename, IMREAD_GRAYSCALE));
  299. ASSERT_FALSE(img.empty());
  300. EXPECT_EQ(64, img.cols);
  301. EXPECT_EQ(64, img.rows);
  302. EXPECT_EQ(CV_8UC1, img.type()) << cv::typeToString(img.type());
  303. // Check for 0/255 values only: 267 + 3829 = 64*64
  304. EXPECT_EQ(267, countNonZero(img == 0));
  305. EXPECT_EQ(3829, countNonZero(img == 255));
  306. }
  307. TEST(Imgcodecs_Tiff, decode_black_and_write_image_pr12989_default)
  308. {
  309. const string filename = cvtest::findDataFile("readwrite/bitsperpixel1.tiff");
  310. cv::Mat img;
  311. ASSERT_NO_THROW(img = cv::imread(filename)); // by default image type is CV_8UC3
  312. ASSERT_FALSE(img.empty());
  313. EXPECT_EQ(64, img.cols);
  314. EXPECT_EQ(64, img.rows);
  315. EXPECT_EQ(CV_8UC3, img.type()) << cv::typeToString(img.type());
  316. }
  317. TEST(Imgcodecs_Tiff, decode_black_and_write_image_pr17275_grayscale)
  318. {
  319. const string filename = cvtest::findDataFile("readwrite/bitsperpixel1_min.tiff");
  320. cv::Mat img;
  321. ASSERT_NO_THROW(img = cv::imread(filename, IMREAD_GRAYSCALE));
  322. ASSERT_FALSE(img.empty());
  323. EXPECT_EQ(64, img.cols);
  324. EXPECT_EQ(64, img.rows);
  325. EXPECT_EQ(CV_8UC1, img.type()) << cv::typeToString(img.type());
  326. // Check for 0/255 values only: 267 + 3829 = 64*64
  327. EXPECT_EQ(267, countNonZero(img == 0));
  328. EXPECT_EQ(3829, countNonZero(img == 255));
  329. }
  330. TEST(Imgcodecs_Tiff, decode_black_and_write_image_pr17275_default)
  331. {
  332. const string filename = cvtest::findDataFile("readwrite/bitsperpixel1_min.tiff");
  333. cv::Mat img;
  334. ASSERT_NO_THROW(img = cv::imread(filename)); // by default image type is CV_8UC3
  335. ASSERT_FALSE(img.empty());
  336. EXPECT_EQ(64, img.cols);
  337. EXPECT_EQ(64, img.rows);
  338. EXPECT_EQ(CV_8UC3, img.type()) << cv::typeToString(img.type());
  339. }
  340. TEST(Imgcodecs_Tiff, count_multipage)
  341. {
  342. const string root = cvtest::TS::ptr()->get_data_path();
  343. {
  344. const string filename = root + "readwrite/multipage.tif";
  345. ASSERT_EQ((size_t)6, imcount(filename));
  346. }
  347. {
  348. const string filename = root + "readwrite/test32FC3_raw.tiff";
  349. ASSERT_EQ((size_t)1, imcount(filename));
  350. }
  351. }
  352. TEST(Imgcodecs_Tiff, read_multipage_indexed)
  353. {
  354. const string root = cvtest::TS::ptr()->get_data_path();
  355. const string filename = root + "readwrite/multipage.tif";
  356. const string page_files[] = {
  357. "readwrite/multipage_p1.tif",
  358. "readwrite/multipage_p2.tif",
  359. "readwrite/multipage_p3.tif",
  360. "readwrite/multipage_p4.tif",
  361. "readwrite/multipage_p5.tif",
  362. "readwrite/multipage_p6.tif"
  363. };
  364. const int page_count = sizeof(page_files) / sizeof(page_files[0]);
  365. vector<Mat> single_pages;
  366. for (int i = 0; i < page_count; i++)
  367. {
  368. // imread and imreadmulti have different default values for the flag
  369. const Mat page = imread(root + page_files[i], IMREAD_ANYCOLOR);
  370. single_pages.push_back(page);
  371. }
  372. ASSERT_EQ((size_t)page_count, single_pages.size());
  373. {
  374. SCOPED_TRACE("Edge Cases");
  375. vector<Mat> multi_pages;
  376. bool res = imreadmulti(filename, multi_pages, 0, 0);
  377. // If we asked for 0 images and we successfully read 0 images should this be false ?
  378. ASSERT_TRUE(res == false);
  379. ASSERT_EQ((size_t)0, multi_pages.size());
  380. res = imreadmulti(filename, multi_pages, 0, 123123);
  381. ASSERT_TRUE(res == true);
  382. ASSERT_EQ((size_t)6, multi_pages.size());
  383. }
  384. {
  385. SCOPED_TRACE("Read all with indices");
  386. vector<Mat> multi_pages;
  387. bool res = imreadmulti(filename, multi_pages, 0, 6);
  388. ASSERT_TRUE(res == true);
  389. ASSERT_EQ((size_t)page_count, multi_pages.size());
  390. for (int i = 0; i < page_count; i++)
  391. {
  392. EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), multi_pages[i], single_pages[i]);
  393. }
  394. }
  395. {
  396. SCOPED_TRACE("Read one by one");
  397. vector<Mat> multi_pages;
  398. for (int i = 0; i < page_count; i++)
  399. {
  400. bool res = imreadmulti(filename, multi_pages, i, 1);
  401. ASSERT_TRUE(res == true);
  402. ASSERT_EQ((size_t)1, multi_pages.size());
  403. EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), multi_pages[0], single_pages[i]);
  404. multi_pages.clear();
  405. }
  406. }
  407. {
  408. SCOPED_TRACE("Read multiple at a time");
  409. vector<Mat> multi_pages;
  410. for (int i = 0; i < page_count/2; i++)
  411. {
  412. bool res = imreadmulti(filename, multi_pages, i*2, 2);
  413. ASSERT_TRUE(res == true);
  414. ASSERT_EQ((size_t)2, multi_pages.size());
  415. EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), multi_pages[0], single_pages[i * 2]) << i;
  416. EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0), multi_pages[1], single_pages[i * 2 + 1]);
  417. multi_pages.clear();
  418. }
  419. }
  420. }
  421. TEST(Imgcodecs_Tiff, read_bigtiff_images)
  422. {
  423. const string root = cvtest::TS::ptr()->get_data_path();
  424. const string filenamesInput[] = {
  425. "readwrite/BigTIFF.tif",
  426. "readwrite/BigTIFFMotorola.tif",
  427. "readwrite/BigTIFFLong.tif",
  428. "readwrite/BigTIFFLong8.tif",
  429. "readwrite/BigTIFFMotorolaLongStrips.tif",
  430. "readwrite/BigTIFFLong8Tiles.tif",
  431. "readwrite/BigTIFFSubIFD4.tif",
  432. "readwrite/BigTIFFSubIFD8.tif"
  433. };
  434. for (int i = 0; i < 8; i++)
  435. {
  436. const Mat bigtiff_img = imread(root + filenamesInput[i], IMREAD_UNCHANGED);
  437. ASSERT_FALSE(bigtiff_img.empty());
  438. EXPECT_EQ(64, bigtiff_img.cols);
  439. EXPECT_EQ(64, bigtiff_img.rows);
  440. ASSERT_EQ(CV_8UC3, bigtiff_img.type());
  441. }
  442. }
  443. #endif
  444. }} // namespace