2 // Copyright 2013 Christian Henning
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
8 //#define BOOST_TEST_MODULE targa_read_test_module
10 #include <boost/gil.hpp>
11 #include <boost/gil/extension/io/targa.hpp>
13 #include <boost/test/unit_test.hpp>
14 #include <boost/type_traits/is_same.hpp>
17 #include "scanline_read_test.hpp"
20 using namespace boost::gil;
22 using tag_t = targa_tag;
24 BOOST_AUTO_TEST_SUITE( gil_io_targa_tests )
26 #ifdef BOOST_GIL_IO_USE_TARGA_FILEFORMAT_TEST_SUITE_IMAGES
28 template< typename Image >
29 void test_targa_scanline_reader( string filename )
31 test_scanline_reader<Image, targa_tag>( string( targa_in + filename ).c_str() );
34 template< typename Image >
35 void write( Image& img
36 , const string& file_name
39 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
40 write_view( targa_out + file_name
44 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
47 BOOST_AUTO_TEST_CASE( read_header_test )
50 using backend_t = get_reader_backend<std::string const, tag_t>::type;
52 backend_t backend = read_image_info( targa_filename
56 BOOST_CHECK_EQUAL( backend._info._header_size , 18 );
57 BOOST_CHECK_EQUAL( backend._info._offset , 18 );
58 BOOST_CHECK_EQUAL( backend._info._color_map_type , 0 );
59 BOOST_CHECK_EQUAL( backend._info._image_type , 10 );
60 BOOST_CHECK_EQUAL( backend._info._color_map_start , 0 );
61 BOOST_CHECK_EQUAL( backend._info._color_map_length, 0 );
62 BOOST_CHECK_EQUAL( backend._info._color_map_depth , 0 );
63 BOOST_CHECK_EQUAL( backend._info._x_origin , 0 );
64 BOOST_CHECK_EQUAL( backend._info._y_origin , 0 );
65 BOOST_CHECK_EQUAL( backend._info._width , 124 );
66 BOOST_CHECK_EQUAL( backend._info._height , 124 );
67 BOOST_CHECK_EQUAL( backend._info._bits_per_pixel , 24 );
68 BOOST_CHECK_EQUAL( backend._info._descriptor , 0 );
72 BOOST_AUTO_TEST_CASE( read_reference_images_test )
74 // 24BPP_compressed.tga
77 read_image( targa_in + "24BPP_compressed.tga", img, tag_t() );
79 typename rgb8_image_t::x_coord_t width = view( img ).width();
80 typename rgb8_image_t::y_coord_t height = view( img ).height();
82 BOOST_CHECK_EQUAL( width , 124 );
83 BOOST_CHECK_EQUAL( height, 124 );
84 BOOST_CHECK( view( img )(0, 0) == rgb8_pixel_t(248, 0, 248) );
85 BOOST_CHECK( view( img )(width-1, 0) == rgb8_pixel_t(0, 0, 248) );
86 BOOST_CHECK( view( img )(0, height-1) == rgb8_pixel_t(248, 0, 0) );
87 BOOST_CHECK( view( img )(width-1, height-1) == rgb8_pixel_t(248, 0, 248) );
89 write( img, "24BPP_compressed_out.tga" );
92 // 24BPP_uncompressed.tga
95 read_image( targa_in + "24BPP_uncompressed.tga", img, tag_t() );
97 typename rgb8_image_t::x_coord_t width = view( img ).width();
98 typename rgb8_image_t::y_coord_t height = view( img ).height();
100 BOOST_CHECK_EQUAL( width , 124 );
101 BOOST_CHECK_EQUAL( height, 124 );
102 BOOST_CHECK( view( img )(0, 0) == rgb8_pixel_t(248, 0, 248) );
103 BOOST_CHECK( view( img )(width-1, 0) == rgb8_pixel_t(0, 0, 248) );
104 BOOST_CHECK( view( img )(0, height-1) == rgb8_pixel_t(248, 0, 0) );
105 BOOST_CHECK( view( img )(width-1, height-1) == rgb8_pixel_t(248, 0, 248) );
107 write( img, "24BPP_uncompressed_out.tga" );
109 test_targa_scanline_reader< bgr8_image_t >( "24BPP_uncompressed.tga" );
112 // 32BPP_compressed.tga
115 read_image( targa_in + "32BPP_compressed.tga", img, tag_t() );
117 typename rgba8_image_t::x_coord_t width = view( img ).width();
118 typename rgba8_image_t::y_coord_t height = view( img ).height();
120 BOOST_CHECK_EQUAL( width , 124 );
121 BOOST_CHECK_EQUAL( height, 124 );
122 BOOST_CHECK( view( img )(0, 0) == rgba8_pixel_t(248, 0, 248, 255) );
123 BOOST_CHECK( view( img )(width-1, 0) == rgba8_pixel_t(0, 0, 248, 255) );
124 BOOST_CHECK( view( img )(0, height-1) == rgba8_pixel_t(0, 0, 0, 0) );
125 BOOST_CHECK( view( img )(width-1, height-1) == rgba8_pixel_t(248, 0, 248, 255) );
127 write( img, "32BPP_compressed_out.tga" );
130 // 32BPP_uncompressed.tga
133 read_image( targa_in + "32BPP_uncompressed.tga", img, tag_t() );
135 typename rgba8_image_t::x_coord_t width = view( img ).width();
136 typename rgba8_image_t::y_coord_t height = view( img ).height();
138 BOOST_CHECK_EQUAL( width , 124 );
139 BOOST_CHECK_EQUAL( height, 124 );
140 BOOST_CHECK( view( img )(0, 0) == rgba8_pixel_t(248, 0, 248, 255) );
141 BOOST_CHECK( view( img )(width-1, 0) == rgba8_pixel_t(0, 0, 248, 255) );
142 BOOST_CHECK( view( img )(0, height-1) == rgba8_pixel_t(0, 0, 0, 0) );
143 BOOST_CHECK( view( img )(width-1, height-1) == rgba8_pixel_t(248, 0, 248, 255) );
145 write( img, "32BPP_uncompressed_out.tga" );
147 test_targa_scanline_reader< bgra8_image_t >( "32BPP_uncompressed.tga" );
150 // 24BPP_compressed_ul_origin.tga
153 read_image( targa_in + "24BPP_compressed_ul_origin.tga", img, tag_t() );
155 typename rgb8_image_t::x_coord_t width = view( img ).width();
156 typename rgb8_image_t::y_coord_t height = view( img ).height();
158 BOOST_CHECK_EQUAL( width , 124 );
159 BOOST_CHECK_EQUAL( height, 124 );
160 BOOST_CHECK( view( img )(0, 0) == rgb8_pixel_t(248, 0, 248) );
161 BOOST_CHECK( view( img )(width-1, 0) == rgb8_pixel_t(0, 0, 248) );
162 BOOST_CHECK( view( img )(0, height-1) == rgb8_pixel_t(248, 0, 0) );
163 BOOST_CHECK( view( img )(width-1, height-1) == rgb8_pixel_t(248, 0, 248) );
165 write( img, "24BPP_compressed_ul_origin_out.tga" );
168 // 24BPP_uncompressed_ul_origin.tga
171 read_image( targa_in + "24BPP_uncompressed_ul_origin.tga", img, tag_t() );
173 typename rgb8_image_t::x_coord_t width = view( img ).width();
174 typename rgb8_image_t::y_coord_t height = view( img ).height();
176 BOOST_CHECK_EQUAL( width , 124 );
177 BOOST_CHECK_EQUAL( height, 124 );
178 BOOST_CHECK( view( img )(0, 0) == rgb8_pixel_t(248, 0, 248) );
179 BOOST_CHECK( view( img )(width-1, 0) == rgb8_pixel_t(0, 0, 248) );
180 BOOST_CHECK( view( img )(0, height-1) == rgb8_pixel_t(248, 0, 0) );
181 BOOST_CHECK( view( img )(width-1, height-1) == rgb8_pixel_t(248, 0, 248) );
183 write( img, "24BPP_uncompressed_ul_origin_out.tga" );
186 // 32BPP_compressed_ul_origin.tga
189 read_image( targa_in + "32BPP_compressed_ul_origin.tga", img, tag_t() );
191 typename rgba8_image_t::x_coord_t width = view( img ).width();
192 typename rgba8_image_t::y_coord_t height = view( img ).height();
194 BOOST_CHECK_EQUAL( width , 124 );
195 BOOST_CHECK_EQUAL( height, 124 );
196 BOOST_CHECK( view( img )(0, 0) == rgba8_pixel_t(248, 0, 248, 255) );
197 BOOST_CHECK( view( img )(width-1, 0) == rgba8_pixel_t(0, 0, 248, 255) );
198 BOOST_CHECK( view( img )(0, height-1) == rgba8_pixel_t(0, 0, 0, 0) );
199 BOOST_CHECK( view( img )(width-1, height-1) == rgba8_pixel_t(248, 0, 248, 255) );
201 write( img, "32BPP_compressed_ul_origin_out.tga" );
204 // 32BPP_uncompressed_ul_origin.tga
207 read_image( targa_in + "32BPP_uncompressed_ul_origin.tga", img, tag_t() );
209 typename rgba8_image_t::x_coord_t width = view( img ).width();
210 typename rgba8_image_t::y_coord_t height = view( img ).height();
212 BOOST_CHECK_EQUAL( width , 124 );
213 BOOST_CHECK_EQUAL( height, 124 );
214 BOOST_CHECK( view( img )(0, 0) == rgba8_pixel_t(248, 0, 248, 255) );
215 BOOST_CHECK( view( img )(width-1, 0) == rgba8_pixel_t(0, 0, 248, 255) );
216 BOOST_CHECK( view( img )(0, height-1) == rgba8_pixel_t(0, 0, 0, 0) );
217 BOOST_CHECK( view( img )(width-1, height-1) == rgba8_pixel_t(248, 0, 248, 255) );
219 write( img, "32BPP_uncompressed_ul_origin_out.tga" );
223 BOOST_AUTO_TEST_CASE( partial_image_test )
225 const std::string filename( targa_in + "24BPP_compressed.tga" );
231 , image_read_settings< targa_tag >( point_t( 0, 0 ), point_t( 50, 50 ) )
234 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
235 write_view( targa_out + "targa_partial.tga"
239 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
243 #endif // BOOST_GIL_IO_USE_TARGA_FILEFORMAT_TEST_SUITE_IMAGES
245 BOOST_AUTO_TEST_SUITE_END()