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 jpeg_read_test_module
9 #include <boost/gil.hpp>
10 #include <boost/gil/extension/io/jpeg.hpp>
11
12 #include <boost/test/unit_test.hpp>
13
14 #include "paths.hpp"
15 #include "scanline_read_test.hpp"
16
17 using namespace std;
18 using namespace boost::gil;
19
20 using tag_t = jpeg_tag;
21
22 BOOST_AUTO_TEST_SUITE( gil_io_jpeg_tests )
23
24 #ifdef BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
25
BOOST_AUTO_TEST_CASE(read_header_test)26 BOOST_AUTO_TEST_CASE( read_header_test )
27 {
28 {
29 using backend_t = get_reader_backend<std::string const, tag_t>::type;
30
31 backend_t backend = read_image_info( jpeg_filename
32 , tag_t()
33 );
34
35 BOOST_CHECK_EQUAL( backend._info._width , 1000u );
36 BOOST_CHECK_EQUAL( backend._info._height , 600u );
37
38 BOOST_CHECK_EQUAL( backend._info._num_components, 3 );
39 BOOST_CHECK_EQUAL( backend._info._color_space , JCS_YCbCr );
40
41 BOOST_CHECK_EQUAL( backend._info._data_precision, 8 );
42 }
43 }
44
BOOST_AUTO_TEST_CASE(read_pixel_density_test)45 BOOST_AUTO_TEST_CASE( read_pixel_density_test )
46 {
47 using backend_t = get_reader_backend<std::string const, tag_t>::type;
48
49 backend_t backend = read_image_info( jpeg_in + "EddDawson/36dpi.jpg"
50 , tag_t()
51 );
52
53 rgb8_image_t img;
54 read_image( jpeg_in + "EddDawson/36dpi.jpg", img, jpeg_tag() );
55
56 image_write_info< jpeg_tag > write_settings;
57 write_settings.set_pixel_dimensions( backend._info._width
58 , backend._info._height
59 , backend._info._pixel_width_mm
60 , backend._info._pixel_height_mm
61 );
62
63 stringstream in_memory( ios_base::in | ios_base::out | ios_base::binary );
64 write_view( in_memory, view( img ), write_settings );
65
66 using backend2_t = get_reader_backend<stringstream, tag_t>::type;
67
68 backend2_t backend2 = read_image_info( in_memory
69 , tag_t()
70 );
71
72 // Because of rounding the two results differ slightly.
73 if( std::abs( backend._info._pixel_width_mm - backend2._info._pixel_width_mm ) > 10.0
74 || std::abs( backend._info._pixel_height_mm - backend2._info._pixel_height_mm ) > 10.0
75 )
76 {
77 BOOST_CHECK_EQUAL( 0, 1 );
78 }
79 }
80
BOOST_AUTO_TEST_CASE(read_reference_images_test)81 BOOST_AUTO_TEST_CASE( read_reference_images_test )
82 {
83 using image_t = rgb8_image_t;
84 image_t img;
85
86 read_image( jpeg_filename
87 , img
88 , tag_t()
89 );
90
91 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
92 write_view( jpeg_out + "rgb8_test.jpg"
93 , view( img )
94 , tag_t()
95 );
96 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
97 }
98
BOOST_AUTO_TEST_CASE(dct_method_read_test)99 BOOST_AUTO_TEST_CASE( dct_method_read_test )
100 {
101 using image_t = rgb8_image_t;
102 image_t img;
103
104 image_read_settings< jpeg_tag > settings;
105 settings._dct_method = jpeg_dct_method::fast;
106
107 read_image( jpeg_filename
108 , img
109 , settings
110 );
111
112 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
113 write_view( jpeg_out + "fast_dct_read_test.jpg"
114 , view( img )
115 , tag_t()
116 );
117 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
118 }
119
BOOST_AUTO_TEST_CASE(read_reference_images_image_iterator_test)120 BOOST_AUTO_TEST_CASE( read_reference_images_image_iterator_test )
121 {
122 test_scanline_reader< rgb8_image_t, jpeg_tag >( jpeg_filename.c_str() );
123 }
124
125 #endif // BOOST_GIL_IO_TEST_ALLOW_READING_IMAGES
126
127 BOOST_AUTO_TEST_SUITE_END()
128