hsl_hsv_test.cpp 2.0 KB

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