Imported Upstream version 1.71.0
[platform/upstream/boost.git] / libs / gil / io / test / 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/test/unit_test.hpp>
16
17 #include <fstream>
18
19 #include "mandel_view.hpp"
20 #include "paths.hpp"
21 #include "subimage_test.hpp"
22
23 using namespace std;
24 using namespace boost;
25 using namespace gil;
26 namespace fs = boost::filesystem;
27
28 using tag_t = raw_tag;
29
30 BOOST_AUTO_TEST_SUITE( gil_io_raw_tests )
31
32 #ifdef BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
33
34 BOOST_AUTO_TEST_CASE( read_image_info_using_string )
35 {
36   {
37     /// raw_tag reader's can only constructed with char*, std::string, and LibRaw object
38
39     using backend_t = get_reader_backend<char const*, tag_t>::type;
40
41     backend_t b = make_reader_backend(raw_filename.c_str(),
42                                       image_read_settings<raw_tag>());
43
44     backend_t backend = read_image_info(raw_filename, tag_t());
45
46     BOOST_CHECK_EQUAL( backend._info._width , 2176 );
47     BOOST_CHECK_EQUAL( backend._info._height, 1448 );
48   }
49
50     {
51         fs::path my_path( raw_filename );
52
53         using backend_t = get_reader_backend<fs::path, tag_t>::type;
54
55         backend_t backend = read_image_info(my_path, tag_t());
56
57         BOOST_CHECK_EQUAL( backend._info._width , 2176 );
58         BOOST_CHECK_EQUAL( backend._info._height, 1448 );
59     }
60 }
61
62 BOOST_AUTO_TEST_CASE( read_image_test )
63 {
64   {
65     rgb8_image_t img;
66     read_image( raw_filename, img, tag_t() );
67
68     BOOST_CHECK_EQUAL( img.width() , 2176 );
69     BOOST_CHECK_EQUAL( img.height(), 1448 );
70   }
71
72   {
73     fs::path my_path( raw_filename );
74
75     rgb8_image_t img;
76     read_image( my_path, img, tag_t() );
77
78     BOOST_CHECK_EQUAL( img.width() , 2176 );
79     BOOST_CHECK_EQUAL( img.height(), 1448 );
80   }
81 }
82
83 BOOST_AUTO_TEST_CASE( read_and_convert_image_test )
84 {
85   rgb8_image_t img;
86   read_and_convert_image( raw_filename, img, tag_t() );
87
88   BOOST_CHECK_EQUAL( img.width() , 2176 );
89   BOOST_CHECK_EQUAL( img.height(), 1448 );
90 }
91
92 BOOST_AUTO_TEST_CASE( read_view_test )
93 {
94   rgb8_image_t img( 2176, 1448 );
95   read_view( raw_filename, view( img ), tag_t() );
96 }
97
98 BOOST_AUTO_TEST_CASE( read_and_convert_view_test )
99 {
100   rgb8_image_t img( 2176, 1448 );
101   read_and_convert_view( raw_filename, view( img ), tag_t() );
102 }
103
104 // BOOST_AUTO_TEST_CASE( subimage_test )
105 // {
106 //   run_subimage_test<rgb8_image_t, tag_t>(raw_filename, point_t(0, 0), point_t(127, 1));
107 //   run_subimage_test<rgb8_image_t, tag_t>(raw_filename, point_t(39, 7), point_t(50, 50));
108 // }
109
110 BOOST_AUTO_TEST_CASE( dynamic_image_test )
111 {
112   using my_img_types = mpl::vector
113       <
114           gray8_image_t,
115           gray16_image_t,
116           rgb8_image_t,
117           rgba8_image_t
118       >;
119
120   any_image< my_img_types > runtime_image;
121
122   read_image(raw_filename.c_str(), runtime_image, tag_t());
123 }
124
125 #endif // BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
126
127 BOOST_AUTO_TEST_SUITE_END()