• 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 #include <boost/gil.hpp>
9 #include <boost/gil/extension/io/jpeg.hpp>
10 
11 #include <boost/core/lightweight_test.hpp>
12 
13 #include "paths.hpp"
14 #include "scanline_read_test.hpp"
15 
16 #include <cmath>
17 #include <sstream>
18 #include <string>
19 
20 namespace gil = boost::gil;
21 
22 #ifdef BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
23 
test_read_header()24 void test_read_header()
25 {
26     using backend_t = gil::get_reader_backend<std::string const, gil::jpeg_tag>::type;
27     backend_t backend = gil::read_image_info(jpeg_filename, gil::jpeg_tag());
28 
29     BOOST_TEST_EQ(backend._info._width, 1000u);
30     BOOST_TEST_EQ(backend._info._height, 600u);
31 
32     BOOST_TEST_EQ(backend._info._num_components, 3);
33     BOOST_TEST_EQ(backend._info._color_space, JCS_YCbCr);
34 
35     BOOST_TEST_EQ(backend._info._data_precision, 8);
36 }
37 
test_read_pixel_density()38 void test_read_pixel_density()
39 {
40     using backend_t = gil::get_reader_backend<std::string const, gil::jpeg_tag>::type;
41     backend_t backend = gil::read_image_info(jpeg_in + "EddDawson/36dpi.jpg", gil::jpeg_tag());
42 
43     gil::rgb8_image_t img;
44     gil::read_image(jpeg_in + "EddDawson/36dpi.jpg", img, gil::jpeg_tag());
45 
46     gil::image_write_info<gil::jpeg_tag> write_settings;
47     write_settings.set_pixel_dimensions(backend._info._width, backend._info._height, backend._info._pixel_width_mm, backend._info._pixel_height_mm);
48 
49     std::stringstream in_memory(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
50     gil::write_view(in_memory, gil::view(img), write_settings);
51 
52     using backend2_t = gil::get_reader_backend<std::stringstream, gil::jpeg_tag>::type;
53     backend2_t backend2 = gil::read_image_info(in_memory, gil::jpeg_tag());
54 
55     // Because of rounding the two results differ slightly.
56     if (std::abs(backend._info._pixel_width_mm - backend2._info._pixel_width_mm) > 10.0 || std::abs(backend._info._pixel_height_mm - backend2._info._pixel_height_mm) > 10.0)
57     {
58         BOOST_TEST_EQ(0, 1);
59     }
60 }
61 
test_read_reference_images()62 void test_read_reference_images()
63 {
64     using image_t = gil::rgb8_image_t;
65     image_t img;
66     read_image(jpeg_filename, img, gil::jpeg_tag());
67 
68 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
69     gil::write_view(jpeg_out + "rgb8_test.jpg", gil::view(img), gil::jpeg_tag());
70 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
71 }
72 
test_dct_method_read()73 void test_dct_method_read()
74 {
75     using image_t = gil::rgb8_image_t;
76     image_t img;
77 
78     gil::image_read_settings<gil::jpeg_tag> settings;
79     settings._dct_method = gil::jpeg_dct_method::fast;
80 
81     gil::read_image(jpeg_filename, img, settings);
82 
83 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
84     gil::write_view(jpeg_out + "fast_dct_read_test.jpg", gil::view(img), gil::jpeg_tag());
85 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
86 }
87 
test_read_reference_images_image_iterator()88 void test_read_reference_images_image_iterator()
89 {
90     test_scanline_reader<gil::rgb8_image_t, gil::jpeg_tag>(jpeg_filename.c_str());
91 }
92 
main()93 int main()
94 {
95     test_read_header();
96     test_read_pixel_density();
97     test_read_reference_images();
98     test_dct_method_read();
99     test_read_reference_images_image_iterator();
100 
101     return boost::report_errors();
102 }
103 
104 #else
main()105 int main() {}
106 #endif // BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
107