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)
6 /// \brief Unit test for subchroma_image type.
8 #include <boost/test/unit_test.hpp>
10 #include <boost/gil.hpp>
11 #include <boost/gil/extension/toolbox/color_spaces/ycbcr.hpp>
12 #include <boost/gil/extension/toolbox/image_types/subchroma_image.hpp>
14 #include <boost/mp11.hpp>
17 using namespace boost;
20 BOOST_AUTO_TEST_SUITE( toolbox_tests )
22 BOOST_AUTO_TEST_CASE( subchroma_image_test )
25 ycbcr_601_8_pixel_t a( 10, 20, 30 );
29 color_convert( a, b );
30 color_convert( a, c );
31 BOOST_ASSERT( static_equal( b, c ));
33 color_convert( b, a );
37 ycbcr_709_8_pixel_t a( 10, 20, 30 );
41 color_convert( a, b );
42 color_convert( a, c );
43 BOOST_ASSERT( static_equal( b, c ));
45 color_convert( b, a );
49 using pixel_t = rgb8_pixel_t;
50 using image_t = subchroma_image<pixel_t>;
52 image_t img( 640, 480 );
54 fill_pixels( view( img )
55 , pixel_t( 10, 20, 30 )
60 using pixel_t = rgb8_pixel_t;
62 subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 4, 4>> a(640, 480);
63 static_assert(a.ss_X == 1 && a.ss_Y == 1, "");
64 subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 4, 0>> b(640, 480);
65 static_assert(b.ss_X == 1 && b.ss_Y == 2, "");
66 subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 2, 2>> c(640, 480);
67 static_assert(c.ss_X == 2 && c.ss_Y == 1, "");
68 subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 2, 0>> d(640, 480);
69 static_assert(d.ss_X == 2 && d.ss_Y == 2, "");
70 subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 1, 1>> e(640, 480);
71 static_assert(e.ss_X == 4 && e.ss_Y == 1, "");
72 subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 1, 0>> f(640, 480);
73 static_assert(f.ss_X == 4 && f.ss_Y == 2, "");
75 fill_pixels( view( a ), pixel_t( 10, 20, 30 ) );
76 fill_pixels( view( b ), pixel_t( 10, 20, 30 ) );
77 fill_pixels( view( c ), pixel_t( 10, 20, 30 ) );
78 fill_pixels( view( d ), pixel_t( 10, 20, 30 ) );
79 fill_pixels( view( e ), pixel_t( 10, 20, 30 ) );
80 fill_pixels( view( f ), pixel_t( 10, 20, 30 ) );
85 using pixel_t = ycbcr_601_8_pixel_t;
86 using factors_t = mp11::mp_list_c<int, 4, 2, 2>;
87 using image_t = subchroma_image<pixel_t, factors_t>;
89 std::size_t y_width = 640;
90 std::size_t y_height = 480;
92 std::size_t image_size = ( y_width * y_height )
93 + ( y_width / image_t::ss_X ) * ( y_height / image_t::ss_Y )
94 + ( y_width / image_t::ss_X ) * ( y_height / image_t::ss_Y );
96 vector< unsigned char > data( image_size );
98 image_t::view_t v = subchroma_view< pixel_t, factors_t >( y_width
103 p = *v.xy_at( 0, 0 );
107 BOOST_AUTO_TEST_SUITE_END()