subchroma_image.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright 2013 Christian Henning
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. /// \brief Unit test for subchroma_image type.
  6. #include <boost/test/unit_test.hpp>
  7. #include <boost/gil.hpp>
  8. #include <boost/gil/extension/toolbox/color_spaces/ycbcr.hpp>
  9. #include <boost/gil/extension/toolbox/image_types/subchroma_image.hpp>
  10. #include <boost/mp11.hpp>
  11. using namespace std;
  12. using namespace boost;
  13. using namespace gil;
  14. BOOST_AUTO_TEST_SUITE( toolbox_tests )
  15. BOOST_AUTO_TEST_CASE( subchroma_image_test )
  16. {
  17. {
  18. ycbcr_601_8_pixel_t a( 10, 20, 30 );
  19. rgb8_pixel_t b;
  20. bgr8_pixel_t c;
  21. color_convert( a, b );
  22. color_convert( a, c );
  23. BOOST_ASSERT( static_equal( b, c ));
  24. color_convert( b, a );
  25. }
  26. {
  27. ycbcr_709_8_pixel_t a( 10, 20, 30 );
  28. rgb8_pixel_t b;
  29. bgr8_pixel_t c;
  30. color_convert( a, b );
  31. color_convert( a, c );
  32. BOOST_ASSERT( static_equal( b, c ));
  33. color_convert( b, a );
  34. }
  35. {
  36. using pixel_t = rgb8_pixel_t;
  37. using image_t = subchroma_image<pixel_t>;
  38. image_t img( 640, 480 );
  39. fill_pixels( view( img )
  40. , pixel_t( 10, 20, 30 )
  41. );
  42. }
  43. {
  44. using pixel_t = rgb8_pixel_t;
  45. subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 4, 4>> a(640, 480);
  46. static_assert(a.ss_X == 1 && a.ss_Y == 1, "");
  47. subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 4, 0>> b(640, 480);
  48. static_assert(b.ss_X == 1 && b.ss_Y == 2, "");
  49. subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 2, 2>> c(640, 480);
  50. static_assert(c.ss_X == 2 && c.ss_Y == 1, "");
  51. subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 2, 0>> d(640, 480);
  52. static_assert(d.ss_X == 2 && d.ss_Y == 2, "");
  53. subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 1, 1>> e(640, 480);
  54. static_assert(e.ss_X == 4 && e.ss_Y == 1, "");
  55. subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 1, 0>> f(640, 480);
  56. static_assert(f.ss_X == 4 && f.ss_Y == 2, "");
  57. fill_pixels( view( a ), pixel_t( 10, 20, 30 ) );
  58. fill_pixels( view( b ), pixel_t( 10, 20, 30 ) );
  59. fill_pixels( view( c ), pixel_t( 10, 20, 30 ) );
  60. fill_pixels( view( d ), pixel_t( 10, 20, 30 ) );
  61. fill_pixels( view( e ), pixel_t( 10, 20, 30 ) );
  62. fill_pixels( view( f ), pixel_t( 10, 20, 30 ) );
  63. }
  64. {
  65. using pixel_t = ycbcr_601_8_pixel_t;
  66. using factors_t = mp11::mp_list_c<int, 4, 2, 2>;
  67. using image_t = subchroma_image<pixel_t, factors_t>;
  68. std::size_t y_width = 640;
  69. std::size_t y_height = 480;
  70. std::size_t image_size = ( y_width * y_height )
  71. + ( y_width / image_t::ss_X ) * ( y_height / image_t::ss_Y )
  72. + ( y_width / image_t::ss_X ) * ( y_height / image_t::ss_Y );
  73. vector< unsigned char > data( image_size );
  74. image_t::view_t v = subchroma_view< pixel_t, factors_t >( y_width
  75. , y_height
  76. , &data.front()
  77. );
  78. rgb8_pixel_t p;
  79. p = *v.xy_at( 0, 0 );
  80. }
  81. }
  82. BOOST_AUTO_TEST_SUITE_END()