2 // Copyright 2012 Andreas Pokorny
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
8 #ifndef BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_GRAY_ALPHA_HPP
9 #define BOOST_GIL_EXTENSION_TOOLBOX_COLOR_SPACES_GRAY_ALPHA_HPP
11 #include <boost/gil/color_convert.hpp>
12 #include <boost/gil/gray.hpp>
13 #include <boost/gil/typedefs.hpp>
15 #include <boost/gil/detail/mp11.hpp>
17 namespace boost{ namespace gil {
19 using gray_alpha_t = mp11::mp_list<gray_color_t,alpha_t>;
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>>;
24 GIL_DEFINE_BASE_TYPEDEFS(8, uint8_t, alpha_gray)
25 GIL_DEFINE_BASE_TYPEDEFS(8s, int8_t, alpha_gray)
26 GIL_DEFINE_BASE_TYPEDEFS(16, uint16_t, alpha_gray)
27 GIL_DEFINE_BASE_TYPEDEFS(16s, int16_t, alpha_gray)
28 GIL_DEFINE_BASE_TYPEDEFS(32, uint32_t, alpha_gray)
29 GIL_DEFINE_BASE_TYPEDEFS(32s, int32_t, alpha_gray)
30 GIL_DEFINE_BASE_TYPEDEFS(32f, float32_t, alpha_gray)
32 GIL_DEFINE_ALL_TYPEDEFS(8, uint8_t, gray_alpha)
33 GIL_DEFINE_ALL_TYPEDEFS(8s, int8_t, gray_alpha)
34 GIL_DEFINE_ALL_TYPEDEFS(16, uint16_t, gray_alpha)
35 GIL_DEFINE_ALL_TYPEDEFS(16s, int16_t, gray_alpha)
36 GIL_DEFINE_ALL_TYPEDEFS(32, uint32_t, gray_alpha)
37 GIL_DEFINE_ALL_TYPEDEFS(32s, int32_t, gray_alpha)
38 GIL_DEFINE_ALL_TYPEDEFS(32f, float32_t, gray_alpha)
40 /// \ingroup ColorConvert
41 /// \brief Gray Alpha to RGBA
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()));
57 /// \brief Gray Alpha to RGB
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()) )
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()) )
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()) )
77 /// \brief Gray Alpha to Gray
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()) )