Imported Upstream version 1.71.0
[platform/upstream/boost.git] / libs / gil / toolbox / test / 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 using namespace std;
15 using namespace boost;
16 using namespace gil;
17
18 BOOST_AUTO_TEST_SUITE( toolbox_tests )
19
20 BOOST_AUTO_TEST_CASE( subchroma_image_test )
21 {
22     {
23         ycbcr_601_8_pixel_t a( 10, 20, 30 );
24         rgb8_pixel_t b;
25         bgr8_pixel_t c;
26
27         color_convert( a, b );
28         color_convert( a, c );
29         BOOST_ASSERT( static_equal( b, c ));
30
31         color_convert( b, a );
32     }
33
34     {
35         ycbcr_709_8_pixel_t a( 10, 20, 30 );
36         rgb8_pixel_t b;
37         bgr8_pixel_t c;
38
39         color_convert( a, b );
40         color_convert( a, c );
41         BOOST_ASSERT( static_equal( b, c ));
42
43         color_convert( b, a );
44     }
45
46     {
47         using pixel_t = rgb8_pixel_t;
48         using image_t = subchroma_image<pixel_t>;
49
50         image_t img( 640, 480 );
51
52         fill_pixels( view( img )
53                    , pixel_t( 10, 20, 30 )
54                    );
55     }
56
57     {
58         using pixel_t = rgb8_pixel_t;
59
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, "");
72
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 ) );
79
80     }
81
82     {
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>;
86
87         std::size_t y_width     = 640;
88         std::size_t y_height    = 480;
89
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 );
93
94         vector< unsigned char > data( image_size );
95
96         image_t::view_t v = subchroma_view< pixel_t, factors_t >( y_width
97                                                                 , y_height
98                                                                 , &data.front()
99                                                                 );
100         rgb8_pixel_t p;
101         p = *v.xy_at( 0, 0 );
102     }
103 }
104
105 BOOST_AUTO_TEST_SUITE_END()