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>
15 using namespace boost;
18 BOOST_AUTO_TEST_SUITE( toolbox_tests )
20 BOOST_AUTO_TEST_CASE( subchroma_image_test )
23 ycbcr_601_8_pixel_t a( 10, 20, 30 );
27 color_convert( a, b );
28 color_convert( a, c );
29 BOOST_ASSERT( static_equal( b, c ));
31 color_convert( b, a );
35 ycbcr_709_8_pixel_t a( 10, 20, 30 );
39 color_convert( a, b );
40 color_convert( a, c );
41 BOOST_ASSERT( static_equal( b, c ));
43 color_convert( b, a );
47 using pixel_t = rgb8_pixel_t;
48 using image_t = subchroma_image<pixel_t>;
50 image_t img( 640, 480 );
52 fill_pixels( view( img )
53 , pixel_t( 10, 20, 30 )
58 using pixel_t = rgb8_pixel_t;
60 subchroma_image<pixel_t, mpl::vector_c<int, 4, 4, 4>> a(640, 480);
61 static_assert(a.ss_X == 1 && a.ss_Y == 1, "");
62 subchroma_image<pixel_t, mpl::vector_c<int, 4, 4, 0>> b(640, 480);
63 static_assert(b.ss_X == 1 && b.ss_Y == 2, "");
64 subchroma_image<pixel_t, mpl::vector_c<int, 4, 2, 2>> c(640, 480);
65 static_assert(c.ss_X == 2 && c.ss_Y == 1, "");
66 subchroma_image<pixel_t, mpl::vector_c<int, 4, 2, 0>> d(640, 480);
67 static_assert(d.ss_X == 2 && d.ss_Y == 2, "");
68 subchroma_image<pixel_t, mpl::vector_c<int, 4, 1, 1>> e(640, 480);
69 static_assert(e.ss_X == 4 && e.ss_Y == 1, "");
70 subchroma_image<pixel_t, mpl::vector_c<int, 4, 1, 0>> f(640, 480);
71 static_assert(f.ss_X == 4 && f.ss_Y == 2, "");
73 fill_pixels( view( a ), pixel_t( 10, 20, 30 ) );
74 fill_pixels( view( b ), pixel_t( 10, 20, 30 ) );
75 fill_pixels( view( c ), pixel_t( 10, 20, 30 ) );
76 fill_pixels( view( d ), pixel_t( 10, 20, 30 ) );
77 fill_pixels( view( e ), pixel_t( 10, 20, 30 ) );
78 fill_pixels( view( f ), pixel_t( 10, 20, 30 ) );
83 using pixel_t = ycbcr_601_8_pixel_t;
84 using factors_t = mpl::vector_c<int, 4, 2, 2>;
85 using image_t = subchroma_image<pixel_t, factors_t>;
87 std::size_t y_width = 640;
88 std::size_t y_height = 480;
90 std::size_t image_size = ( y_width * y_height )
91 + ( y_width / image_t::ss_X ) * ( y_height / image_t::ss_Y )
92 + ( y_width / image_t::ss_X ) * ( y_height / image_t::ss_Y );
94 vector< unsigned char > data( image_size );
96 image_t::view_t v = subchroma_view< pixel_t, factors_t >( y_width
101 p = *v.xy_at( 0, 0 );
105 BOOST_AUTO_TEST_SUITE_END()