1 //
2 // Copyright 2013 Christian Henning
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #include <boost/gil.hpp>
9 #include <boost/gil/extension/toolbox/color_spaces/ycbcr.hpp>
10 #include <boost/gil/extension/toolbox/image_types/subchroma_image.hpp>
11
12 #include <boost/core/lightweight_test.hpp>
13 #include <boost/mp11.hpp>
14
15 #include <vector>
16
17 namespace gil = boost::gil;
18 namespace mp11 = boost::mp11;
19
test_subchroma_image()20 void test_subchroma_image()
21 {
22 {
23 gil::ycbcr_601_8_pixel_t a(10, 20, 30);
24 gil::rgb8_pixel_t b;
25 gil::bgr8_pixel_t c;
26
27 gil::color_convert(a, b);
28 gil::color_convert(a, c);
29 BOOST_TEST(gil::static_equal(b, c));
30
31 gil::color_convert(b, a);
32 }
33 {
34 gil::ycbcr_709_8_pixel_t a(10, 20, 30);
35 gil::rgb8_pixel_t b;
36 gil::bgr8_pixel_t c;
37
38 gil::color_convert(a, b);
39 gil::color_convert(a, c);
40 BOOST_TEST(gil::static_equal(b, c));
41
42 gil::color_convert(b, a);
43 }
44
45 {
46 using pixel_t = gil::rgb8_pixel_t;
47 using image_t = gil::subchroma_image<pixel_t>;
48 image_t img(320, 240);
49 gil::fill_pixels(view(img), pixel_t(10, 20, 30));
50
51 // TODO: Add BOOST_TEST checkpoints
52 }
53 {
54 using pixel_t = gil::rgb8_pixel_t;
55
56 gil::subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 4, 4>> a(640, 480);
57 static_assert(a.ss_X == 1 && a.ss_Y == 1, "");
58 gil::subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 4, 0>> b(640, 480);
59 static_assert(b.ss_X == 1 && b.ss_Y == 2, "");
60 gil::subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 2, 2>> c(640, 480);
61 static_assert(c.ss_X == 2 && c.ss_Y == 1, "");
62 gil::subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 2, 0>> d(640, 480);
63 static_assert(d.ss_X == 2 && d.ss_Y == 2, "");
64 gil::subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 1, 1>> e(640, 480);
65 static_assert(e.ss_X == 4 && e.ss_Y == 1, "");
66 gil::subchroma_image<pixel_t, mp11::mp_list_c<int, 4, 1, 0>> f(640, 480);
67 static_assert(f.ss_X == 4 && f.ss_Y == 2, "");
68
69 gil::fill_pixels(view(a), pixel_t(10, 20, 30));
70 gil::fill_pixels(view(b), pixel_t(10, 20, 30));
71 gil::fill_pixels(view(c), pixel_t(10, 20, 30));
72 gil::fill_pixels(view(d), pixel_t(10, 20, 30));
73 gil::fill_pixels(view(e), pixel_t(10, 20, 30));
74 gil::fill_pixels(view(f), pixel_t(10, 20, 30));
75
76 // TODO: Add BOOST_TEST checkpoints
77 }
78 {
79 using pixel_t = gil::ycbcr_601_8_pixel_t;
80 using factors_t = mp11::mp_list_c<int, 4, 2, 2>;
81 using image_t = gil::subchroma_image<pixel_t, factors_t>;
82
83 std::size_t const y_width = 320;
84 std::size_t const y_height = 240;
85
86 std::size_t image_size = (y_width * y_height)
87 + (y_width / image_t::ss_X) * (y_height / image_t::ss_Y)
88 + (y_width / image_t::ss_X) * (y_height / image_t::ss_Y);
89
90 std::vector<unsigned char> data(image_size); // TODO: Initialize? --mloskot
91
92 image_t::view_t v = gil::subchroma_view<pixel_t, factors_t>(y_width, y_height, &data.front());
93 //gil::rgb8_pixel_t p; // TODO: Why RGB?? --mloskot
94 //p = *v.xy_at(0, 0);
95 auto p = *v.xy_at(0, 0);
96
97 // TODO: Add BOOST_TEST checkpoints
98 }
99 }
100
main()101 int main()
102 {
103 test_subchroma_image();
104
105 return ::boost::report_errors();
106 }
107