Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / gil / test / extension / io / raw_test.cpp
1 //
2 // Copyright 2013 Christian Henning
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #define BOOST_TEST_MODULE raw_test
9 #define BOOST_FILESYSTEM_VERSION 3
10 #define BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
11
12 #include <boost/gil.hpp>
13 #include <boost/gil/extension/io/raw.hpp>
14
15 #include <boost/mp11.hpp>
16 #include <boost/test/unit_test.hpp>
17
18 #include <fstream>
19
20 #include "mandel_view.hpp"
21 #include "paths.hpp"
22 #include "subimage_test.hpp"
23
24 using namespace std;
25 using namespace boost;
26 using namespace gil;
27 namespace fs = boost::filesystem;
28
29 using tag_t = raw_tag;
30
31 BOOST_AUTO_TEST_SUITE( gil_io_raw_tests )
32
33 #ifdef BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
34
35 BOOST_AUTO_TEST_CASE( read_image_info_using_string )
36 {
37   {
38     /// raw_tag reader's can only constructed with char*, std::string, and LibRaw object
39
40     using backend_t = get_reader_backend<char const*, tag_t>::type;
41
42     backend_t b = make_reader_backend(raw_filename.c_str(),
43                                       image_read_settings<raw_tag>());
44
45     backend_t backend = read_image_info(raw_filename, tag_t());
46
47     BOOST_CHECK_EQUAL( backend._info._width , 2176 );
48     BOOST_CHECK_EQUAL( backend._info._height, 1448 );
49   }
50
51     {
52         fs::path my_path( raw_filename );
53
54         using backend_t = get_reader_backend<fs::path, tag_t>::type;
55
56         backend_t backend = read_image_info(my_path, tag_t());
57
58         BOOST_CHECK_EQUAL( backend._info._width , 2176 );
59         BOOST_CHECK_EQUAL( backend._info._height, 1448 );
60     }
61 }
62
63 BOOST_AUTO_TEST_CASE( read_image_test )
64 {
65   {
66     rgb8_image_t img;
67     read_image( raw_filename, img, tag_t() );
68
69     BOOST_CHECK_EQUAL( img.width() , 2176 );
70     BOOST_CHECK_EQUAL( img.height(), 1448 );
71   }
72
73   {
74     fs::path my_path( raw_filename );
75
76     rgb8_image_t img;
77     read_image( my_path, img, tag_t() );
78
79     BOOST_CHECK_EQUAL( img.width() , 2176 );
80     BOOST_CHECK_EQUAL( img.height(), 1448 );
81   }
82 }
83
84 BOOST_AUTO_TEST_CASE( read_and_convert_image_test )
85 {
86   rgb8_image_t img;
87   read_and_convert_image( raw_filename, img, tag_t() );
88
89   BOOST_CHECK_EQUAL( img.width() , 2176 );
90   BOOST_CHECK_EQUAL( img.height(), 1448 );
91 }
92
93 BOOST_AUTO_TEST_CASE( read_view_test )
94 {
95   rgb8_image_t img( 2176, 1448 );
96   read_view( raw_filename, view( img ), tag_t() );
97 }
98
99 BOOST_AUTO_TEST_CASE( read_and_convert_view_test )
100 {
101   rgb8_image_t img( 2176, 1448 );
102   read_and_convert_view( raw_filename, view( img ), tag_t() );
103 }
104
105 // BOOST_AUTO_TEST_CASE( subimage_test )
106 // {
107 //   run_subimage_test<rgb8_image_t, tag_t>(raw_filename, point_t(0, 0), point_t(127, 1));
108 //   run_subimage_test<rgb8_image_t, tag_t>(raw_filename, point_t(39, 7), point_t(50, 50));
109 // }
110
111 BOOST_AUTO_TEST_CASE( dynamic_image_test )
112 {
113   using my_img_types = mp11::mp_list
114       <
115           gray8_image_t,
116           gray16_image_t,
117           rgb8_image_t,
118           rgba8_image_t
119       >;
120
121   any_image< my_img_types > runtime_image;
122
123   read_image(raw_filename.c_str(), runtime_image, tag_t());
124 }
125
126 #endif // BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
127
128 BOOST_AUTO_TEST_SUITE_END()