• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_FILESYSTEM_VERSION 3
9 #define BOOST_GIL_IO_ADD_FS_PATH_SUPPORT
10 #include <boost/gil.hpp>
11 #include <boost/gil/extension/io/raw.hpp>
12 
13 #include <boost/mp11.hpp>
14 #include <boost/core/lightweight_test.hpp>
15 
16 #include <fstream>
17 
18 #include "mandel_view.hpp"
19 #include "paths.hpp"
20 #include "subimage_test.hpp"
21 
22 namespace fs = boost::filesystem;
23 namespace gil = boost::gil;
24 namespace mp11 = boost::mp11;
25 
26 #ifdef BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
27 
test_read_image_info_using_string()28 void test_read_image_info_using_string()
29 {
30     {
31         /// raw_tag reader's can only constructed with char*, std::string, and LibRaw object
32 
33         using backend_t = gil::get_reader_backend<char const *, gil::raw_tag>::type;
34         backend_t b = gil::make_reader_backend(raw_filename.c_str(),
35             gil::image_read_settings<gil::raw_tag>());
36         backend_t backend = gil::read_image_info(raw_filename, gil::raw_tag());
37 
38         BOOST_TEST_EQ(backend._info._width, 2176);
39         BOOST_TEST_EQ(backend._info._height, 1448);
40     }
41     {
42         fs::path my_path(raw_filename);
43         using backend_t = gil::get_reader_backend<fs::path, gil::raw_tag>::type;
44         backend_t backend = gil::read_image_info(my_path, gil::raw_tag());
45 
46         BOOST_TEST_EQ(backend._info._width, 2176);
47         BOOST_TEST_EQ(backend._info._height, 1448);
48     }
49 }
50 
test_read_image()51 void test_read_image()
52 {
53     {
54         gil::rgb8_image_t img;
55         gil::read_image(raw_filename, img, gil::raw_tag());
56 
57         BOOST_TEST_EQ(img.width(), 2176);
58         BOOST_TEST_EQ(img.height(), 1448);
59     }
60 
61     {
62         fs::path my_path(raw_filename);
63         gil::rgb8_image_t img;
64         gil::read_image(my_path, img, gil::raw_tag());
65 
66         BOOST_TEST_EQ(img.width(), 2176);
67         BOOST_TEST_EQ(img.height(), 1448);
68     }
69 }
70 
test_read_and_convert_image()71 void test_read_and_convert_image()
72 {
73     gil::rgb8_image_t img;
74     gil::read_and_convert_image(raw_filename, img, gil::raw_tag());
75 
76     BOOST_TEST_EQ(img.width(), 2176);
77     BOOST_TEST_EQ(img.height(), 1448);
78 }
79 
test_read_view()80 void test_read_view()
81 {
82     gil::rgb8_image_t img(2176, 1448);
83     gil::read_view(raw_filename, gil::view(img), gil::raw_tag());
84 }
85 
test_read_and_convert_view()86 void test_read_and_convert_view()
87 {
88     gil::rgb8_image_t img(2176, 1448);
89     gil::read_and_convert_view(raw_filename, gil::view(img), gil::raw_tag());
90 }
91 
test_subimage()92 void test_subimage()
93 {
94     run_subimage_test<gil::rgb8_image_t, gil::raw_tag>(raw_filename, gil::point_t(0, 0), gil::point_t(127, 1));
95     run_subimage_test<gil::rgb8_image_t, gil::raw_tag>(raw_filename, gil::point_t(39, 7), gil::point_t(50, 50));
96 }
97 
test_dynamic_image()98 void test_dynamic_image()
99 {
100   using my_img_types = mp11::mp_list
101       <
102           gil::gray8_image_t,
103           gil::gray16_image_t,
104           gil::rgb8_image_t,
105           gil::rgba8_image_t
106       >;
107 
108   gil::any_image<my_img_types> image;
109   gil::read_image(raw_filename.c_str(), image, gil::raw_tag());
110 }
111 
main()112 int main()
113 {
114     test_read_image_info_using_string();
115     test_read_image();
116     test_read_and_convert_image();
117     test_read_view();
118     test_read_and_convert_view();
119     //test_subimage();
120     test_dynamic_image();
121 
122     return boost::report_errors();
123 }
124 
125 #else
main()126 int main() {}
127 #endif // BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
128