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/toolbox/color_spaces/hsl.hpp>
10 #include <boost/gil/extension/toolbox/color_spaces/hsv.hpp>
11
12 #include <boost/test/unit_test.hpp>
13
14 using namespace std;
15 using namespace boost;
16 using namespace gil;
17
18 BOOST_AUTO_TEST_SUITE( toolbox_tests )
19
BOOST_AUTO_TEST_CASE(hsl_hsv_test)20 BOOST_AUTO_TEST_CASE( hsl_hsv_test )
21 {
22 {
23 rgb8_pixel_t p( 128, 0, 128 );
24
25 hsl32f_pixel_t h;
26
27 color_convert( p, h );
28 color_convert( h, p );
29 }
30
31 {
32 size_t width = 640;
33 size_t height = 480;
34
35 hsl32f_image_t hsl_img( width, height );
36 hsv32f_image_t hsv_img( width, height );
37
38 for( size_t y = 0; y < height; y++ )
39 {
40 hsl32f_view_t::x_iterator hsl_x_it = view( hsl_img ).row_begin( y );
41 hsv32f_view_t::x_iterator hsv_x_it = view( hsv_img ).row_begin( y );
42
43 float v = static_cast<float>( height - y )
44 / height;
45
46 for( size_t x = 0; x < width; x++ )
47 {
48 float hue = ( x + 1.f ) / width;
49
50 hsl_x_it[x] = hsl32f_pixel_t( hue, 1.0, v );
51 hsv_x_it[x] = hsv32f_pixel_t( hue, 1.0, v );
52 }
53 }
54 }
55
56 {
57 rgb8_image_t rgb_img( 640, 480 );
58 fill_pixels( view(rgb_img), rgb8_pixel_t( 255, 128, 64 ));
59 hsl32f_image_t hsl_img( view( rgb_img ).dimensions() );
60
61 copy_pixels( color_converted_view<hsl32f_pixel_t>( view( rgb_img ))
62 , view( hsl_img ));
63 }
64
65 {
66 rgb8_image_t rgb_img( 640, 480 );
67 fill_pixels( view(rgb_img), rgb8_pixel_t( 255, 128, 64 ));
68 hsv32f_image_t hsv_img( view( rgb_img ).dimensions() );
69
70 copy_pixels( color_converted_view<hsv32f_pixel_t>( view( rgb_img ))
71 , view( hsv_img ));
72 }
73 }
74
75 BOOST_AUTO_TEST_SUITE_END()
76