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>
16 #include "scanline_read_test.hpp"
19 using namespace boost::gil;
21 using tag_t = targa_tag;
23 BOOST_AUTO_TEST_SUITE( gil_io_targa_tests )
25 #ifdef BOOST_GIL_IO_USE_TARGA_FILEFORMAT_TEST_SUITE_IMAGES
27 template< typename Image >
28 void test_targa_scanline_reader( string filename )
30 test_scanline_reader<Image, targa_tag>( string( targa_in + filename ).c_str() );
33 template< typename Image >
34 void write( Image& img
35 , const string& file_name
38 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
39 write_view( targa_out + file_name
43 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
46 BOOST_AUTO_TEST_CASE( read_header_test )
49 using backend_t = get_reader_backend<std::string const, tag_t>::type;
51 backend_t backend = read_image_info( targa_filename
55 BOOST_CHECK_EQUAL( backend._info._header_size , 18 );
56 BOOST_CHECK_EQUAL( backend._info._offset , 18 );
57 BOOST_CHECK_EQUAL( backend._info._color_map_type , 0 );
58 BOOST_CHECK_EQUAL( backend._info._image_type , 10 );
59 BOOST_CHECK_EQUAL( backend._info._color_map_start , 0 );
60 BOOST_CHECK_EQUAL( backend._info._color_map_length, 0 );
61 BOOST_CHECK_EQUAL( backend._info._color_map_depth , 0 );
62 BOOST_CHECK_EQUAL( backend._info._x_origin , 0 );
63 BOOST_CHECK_EQUAL( backend._info._y_origin , 0 );
64 BOOST_CHECK_EQUAL( backend._info._width , 124 );
65 BOOST_CHECK_EQUAL( backend._info._height , 124 );
66 BOOST_CHECK_EQUAL( backend._info._bits_per_pixel , 24 );
67 BOOST_CHECK_EQUAL( backend._info._descriptor , 0 );
71 BOOST_AUTO_TEST_CASE( read_reference_images_test )
73 // 24BPP_compressed.tga
76 read_image( targa_in + "24BPP_compressed.tga", img, tag_t() );
78 typename rgb8_image_t::x_coord_t width = view( img ).width();
79 typename rgb8_image_t::y_coord_t height = view( img ).height();
81 BOOST_CHECK_EQUAL( width , 124 );
82 BOOST_CHECK_EQUAL( height, 124 );
83 BOOST_CHECK( view( img )(0, 0) == rgb8_pixel_t(248, 0, 248) );
84 BOOST_CHECK( view( img )(width-1, 0) == rgb8_pixel_t(0, 0, 248) );
85 BOOST_CHECK( view( img )(0, height-1) == rgb8_pixel_t(248, 0, 0) );
86 BOOST_CHECK( view( img )(width-1, height-1) == rgb8_pixel_t(248, 0, 248) );
88 write( img, "24BPP_compressed_out.tga" );
91 // 24BPP_uncompressed.tga
94 read_image( targa_in + "24BPP_uncompressed.tga", img, tag_t() );
96 typename rgb8_image_t::x_coord_t width = view( img ).width();
97 typename rgb8_image_t::y_coord_t height = view( img ).height();
99 BOOST_CHECK_EQUAL( width , 124 );
100 BOOST_CHECK_EQUAL( height, 124 );
101 BOOST_CHECK( view( img )(0, 0) == rgb8_pixel_t(248, 0, 248) );
102 BOOST_CHECK( view( img )(width-1, 0) == rgb8_pixel_t(0, 0, 248) );
103 BOOST_CHECK( view( img )(0, height-1) == rgb8_pixel_t(248, 0, 0) );
104 BOOST_CHECK( view( img )(width-1, height-1) == rgb8_pixel_t(248, 0, 248) );
106 write( img, "24BPP_uncompressed_out.tga" );
108 test_targa_scanline_reader< bgr8_image_t >( "24BPP_uncompressed.tga" );
111 // 32BPP_compressed.tga
114 read_image( targa_in + "32BPP_compressed.tga", img, tag_t() );
116 typename rgba8_image_t::x_coord_t width = view( img ).width();
117 typename rgba8_image_t::y_coord_t height = view( img ).height();
119 BOOST_CHECK_EQUAL( width , 124 );
120 BOOST_CHECK_EQUAL( height, 124 );
121 BOOST_CHECK( view( img )(0, 0) == rgba8_pixel_t(248, 0, 248, 255) );
122 BOOST_CHECK( view( img )(width-1, 0) == rgba8_pixel_t(0, 0, 248, 255) );
123 BOOST_CHECK( view( img )(0, height-1) == rgba8_pixel_t(0, 0, 0, 0) );
124 BOOST_CHECK( view( img )(width-1, height-1) == rgba8_pixel_t(248, 0, 248, 255) );
126 write( img, "32BPP_compressed_out.tga" );
129 // 32BPP_uncompressed.tga
132 read_image( targa_in + "32BPP_uncompressed.tga", img, tag_t() );
134 typename rgba8_image_t::x_coord_t width = view( img ).width();
135 typename rgba8_image_t::y_coord_t height = view( img ).height();
137 BOOST_CHECK_EQUAL( width , 124 );
138 BOOST_CHECK_EQUAL( height, 124 );
139 BOOST_CHECK( view( img )(0, 0) == rgba8_pixel_t(248, 0, 248, 255) );
140 BOOST_CHECK( view( img )(width-1, 0) == rgba8_pixel_t(0, 0, 248, 255) );
141 BOOST_CHECK( view( img )(0, height-1) == rgba8_pixel_t(0, 0, 0, 0) );
142 BOOST_CHECK( view( img )(width-1, height-1) == rgba8_pixel_t(248, 0, 248, 255) );
144 write( img, "32BPP_uncompressed_out.tga" );
146 test_targa_scanline_reader< bgra8_image_t >( "32BPP_uncompressed.tga" );
149 // 24BPP_compressed_ul_origin.tga
152 read_image( targa_in + "24BPP_compressed_ul_origin.tga", img, tag_t() );
154 typename rgb8_image_t::x_coord_t width = view( img ).width();
155 typename rgb8_image_t::y_coord_t height = view( img ).height();
157 BOOST_CHECK_EQUAL( width , 124 );
158 BOOST_CHECK_EQUAL( height, 124 );
159 BOOST_CHECK( view( img )(0, 0) == rgb8_pixel_t(248, 0, 248) );
160 BOOST_CHECK( view( img )(width-1, 0) == rgb8_pixel_t(0, 0, 248) );
161 BOOST_CHECK( view( img )(0, height-1) == rgb8_pixel_t(248, 0, 0) );
162 BOOST_CHECK( view( img )(width-1, height-1) == rgb8_pixel_t(248, 0, 248) );
164 write( img, "24BPP_compressed_ul_origin_out.tga" );
167 // 24BPP_uncompressed_ul_origin.tga
170 read_image( targa_in + "24BPP_uncompressed_ul_origin.tga", img, tag_t() );
172 typename rgb8_image_t::x_coord_t width = view( img ).width();
173 typename rgb8_image_t::y_coord_t height = view( img ).height();
175 BOOST_CHECK_EQUAL( width , 124 );
176 BOOST_CHECK_EQUAL( height, 124 );
177 BOOST_CHECK( view( img )(0, 0) == rgb8_pixel_t(248, 0, 248) );
178 BOOST_CHECK( view( img )(width-1, 0) == rgb8_pixel_t(0, 0, 248) );
179 BOOST_CHECK( view( img )(0, height-1) == rgb8_pixel_t(248, 0, 0) );
180 BOOST_CHECK( view( img )(width-1, height-1) == rgb8_pixel_t(248, 0, 248) );
182 write( img, "24BPP_uncompressed_ul_origin_out.tga" );
185 // 32BPP_compressed_ul_origin.tga
188 read_image( targa_in + "32BPP_compressed_ul_origin.tga", img, tag_t() );
190 typename rgba8_image_t::x_coord_t width = view( img ).width();
191 typename rgba8_image_t::y_coord_t height = view( img ).height();
193 BOOST_CHECK_EQUAL( width , 124 );
194 BOOST_CHECK_EQUAL( height, 124 );
195 BOOST_CHECK( view( img )(0, 0) == rgba8_pixel_t(248, 0, 248, 255) );
196 BOOST_CHECK( view( img )(width-1, 0) == rgba8_pixel_t(0, 0, 248, 255) );
197 BOOST_CHECK( view( img )(0, height-1) == rgba8_pixel_t(0, 0, 0, 0) );
198 BOOST_CHECK( view( img )(width-1, height-1) == rgba8_pixel_t(248, 0, 248, 255) );
200 write( img, "32BPP_compressed_ul_origin_out.tga" );
203 // 32BPP_uncompressed_ul_origin.tga
206 read_image( targa_in + "32BPP_uncompressed_ul_origin.tga", img, tag_t() );
208 typename rgba8_image_t::x_coord_t width = view( img ).width();
209 typename rgba8_image_t::y_coord_t height = view( img ).height();
211 BOOST_CHECK_EQUAL( width , 124 );
212 BOOST_CHECK_EQUAL( height, 124 );
213 BOOST_CHECK( view( img )(0, 0) == rgba8_pixel_t(248, 0, 248, 255) );
214 BOOST_CHECK( view( img )(width-1, 0) == rgba8_pixel_t(0, 0, 248, 255) );
215 BOOST_CHECK( view( img )(0, height-1) == rgba8_pixel_t(0, 0, 0, 0) );
216 BOOST_CHECK( view( img )(width-1, height-1) == rgba8_pixel_t(248, 0, 248, 255) );
218 write( img, "32BPP_uncompressed_ul_origin_out.tga" );
222 BOOST_AUTO_TEST_CASE( partial_image_test )
224 const std::string filename( targa_in + "24BPP_compressed.tga" );
230 , image_read_settings< targa_tag >( point_t( 0, 0 ), point_t( 50, 50 ) )
233 #ifdef BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
234 write_view( targa_out + "targa_partial.tga"
238 #endif // BOOST_GIL_IO_TEST_ALLOW_WRITING_IMAGES
242 #endif // BOOST_GIL_IO_USE_TARGA_FILEFORMAT_TEST_SUITE_IMAGES
244 BOOST_AUTO_TEST_SUITE_END()