]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
1 | // |
2 | // Copyright 2012 Andreas Pokorny | |
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 | #ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_GRAY_ALPHA_HPP | |
9 | #define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_GRAY_ALPHA_HPP | |
10 | ||
11 | #include <boost/gil/color_convert.hpp> | |
12 | #include <boost/gil/gray.hpp> | |
13 | #include <boost/gil/typedefs.hpp> | |
14 | ||
15 | #include <boost/gil/detail/mp11.hpp> | |
16 | ||
17 | namespace boost{ namespace gil { | |
18 | ||
19 | using gray_alpha_t = mp11::mp_list<gray_color_t,alpha_t>; | |
20 | ||
21 | using gray_alpha_layout_t = layout<gray_alpha_t>; | |
22 | using alpha_gray_layout_t = layout<gray_alpha_layout_t, mp11::mp_list_c<int,1,0>>; | |
23 | ||
f67539c2 TL |
24 | BOOST_GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, alpha_gray) |
25 | BOOST_GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, alpha_gray) | |
26 | BOOST_GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, alpha_gray) | |
27 | BOOST_GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, alpha_gray) | |
28 | BOOST_GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, alpha_gray) | |
29 | BOOST_GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, alpha_gray) | |
30 | BOOST_GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, alpha_gray) | |
31 | ||
32 | BOOST_GIL_DEFINE_ALL_TYPEDEFS(8, uint8_t, gray_alpha) | |
33 | BOOST_GIL_DEFINE_ALL_TYPEDEFS(8s, int8_t, gray_alpha) | |
34 | BOOST_GIL_DEFINE_ALL_TYPEDEFS(16, uint16_t, gray_alpha) | |
35 | BOOST_GIL_DEFINE_ALL_TYPEDEFS(16s, int16_t, gray_alpha) | |
36 | BOOST_GIL_DEFINE_ALL_TYPEDEFS(32, uint32_t, gray_alpha) | |
37 | BOOST_GIL_DEFINE_ALL_TYPEDEFS(32s, int32_t, gray_alpha) | |
38 | BOOST_GIL_DEFINE_ALL_TYPEDEFS(32f, float32_t, gray_alpha) | |
92f5a8d4 TL |
39 | |
40 | /// \ingroup ColorConvert | |
41 | /// \brief Gray Alpha to RGBA | |
42 | template <> | |
43 | struct default_color_converter_impl<gray_alpha_t,rgba_t> { | |
44 | template <typename P1, typename P2> | |
45 | void operator()(const P1& src, P2& dst) const { | |
46 | get_color(dst,red_t()) = | |
47 | channel_convert<typename color_element_type<P2, red_t>::type>(get_color(src,gray_color_t())); | |
48 | get_color(dst,green_t())= | |
49 | channel_convert<typename color_element_type<P2, green_t>::type>(get_color(src,gray_color_t())); | |
50 | get_color(dst,blue_t()) = | |
51 | channel_convert<typename color_element_type<P2, blue_t>::type>(get_color(src,gray_color_t())); | |
52 | get_color(dst,alpha_t()) = | |
53 | channel_convert<typename color_element_type<P2, alpha_t>::type>(get_color(src,alpha_t())); | |
54 | } | |
55 | }; | |
56 | ||
57 | /// \brief Gray Alpha to RGB | |
58 | template <> | |
59 | struct default_color_converter_impl<gray_alpha_t,rgb_t> { | |
60 | template <typename P1, typename P2> | |
61 | void operator()(const P1& src, P2& dst) const { | |
62 | get_color(dst,red_t()) = | |
63 | channel_convert<typename color_element_type<P2, red_t>::type>( | |
64 | channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) ) | |
65 | ); | |
66 | get_color(dst,green_t()) = | |
67 | channel_convert<typename color_element_type<P2, green_t>::type>( | |
68 | channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) ) | |
69 | ); | |
70 | get_color(dst,blue_t()) = | |
71 | channel_convert<typename color_element_type<P2, blue_t>::type>( | |
72 | channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) ) | |
73 | ); | |
74 | } | |
75 | }; | |
76 | ||
77 | /// \brief Gray Alpha to Gray | |
78 | template <> | |
79 | struct default_color_converter_impl<gray_alpha_t,gray_t> { | |
80 | template <typename P1, typename P2> | |
81 | void operator()(const P1& src, P2& dst) const { | |
82 | get_color(dst,gray_color_t()) = | |
83 | channel_convert<typename color_element_type<P2, gray_color_t>::type>( | |
84 | channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) ) | |
85 | ); | |
86 | } | |
87 | }; | |
88 | ||
89 | } // namespace gil | |
90 | } // namespace boost | |
91 | ||
92 | #endif |