Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / gil / test / extension / toolbox / subchroma_image.cpp
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
6 /// \brief Unit test for subchroma_image type.
7
8 #include <boost/test/unit_test.hpp>
9
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>
13
14 #include <boost/mp11.hpp>
15
16 using namespace std;
17 using namespace boost;
18 using namespace gil;
19
20 BOOST_AUTO_TEST_SUITE( toolbox_tests )
21
22 BOOST_AUTO_TEST_CASE( subchroma_image_test )
23 {
24     {
25         ycbcr_601_8_pixel_t a( 10, 20, 30 );
26         rgb8_pixel_t b;
27         bgr8_pixel_t c;
28
29         color_convert( a, b );
30         color_convert( a, c );
31         BOOST_ASSERT( static_equal( b, c ));
32
33         color_convert( b, a );
34     }
35
36     {
37         ycbcr_709_8_pixel_t a( 10, 20, 30 );
38         rgb8_pixel_t b;
39         bgr8_pixel_t c;
40
41         color_convert( a, b );
42         color_convert( a, c );
43         BOOST_ASSERT( static_equal( b, c ));
44
45         color_convert( b, a );
46     }
47
48     {
49         using pixel_t = rgb8_pixel_t;
50         using image_t = subchroma_image<pixel_t>;
51
52         image_t img( 640, 480 );
53
54         fill_pixels( view( img )
55                    , pixel_t( 10, 20, 30 )
56                    );
57     }
58
59     {
60         using pixel_t = rgb8_pixel_t;
61
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, "");
74
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 ) );
81
82     }
83
84     {
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>;
88
89         std::size_t y_width     = 640;
90         std::size_t y_height    = 480;
91
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 );
95
96         vector< unsigned char > data( image_size );
97
98         image_t::view_t v = subchroma_view< pixel_t, factors_t >( y_width
99                                                                 , y_height
100                                                                 , &data.front()
101                                                                 );
102         rgb8_pixel_t p;
103         p = *v.xy_at( 0, 0 );
104     }
105 }
106
107 BOOST_AUTO_TEST_SUITE_END()