TuttleOFX  1
gray_alpha.hpp
Go to the documentation of this file.
00001 /*
00002     Copyright 2007-2008 Andreas Pokorny
00003     Use, modification and distribution are subject to the Boost Software License,
00004     Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
00005     http://www.boost.org/LICENSE_1_0.txt).
00006 */
00007 
00008 /*************************************************************************************************/
00009 
00010 
00011 #ifndef BOOST_GIL_GRAY_ALPHA_HPP_INCLUDED
00012 #define BOOST_GIL_GRAY_ALPHA_HPP_INCLUDED
00013 
00014 ////////////////////////////////////////////////////////////////////////////////////////
00015 /// \file               
00016 /// \brief
00017 /// \author Andreas Pokorny \n
00018 ///         
00019 /// \date   2007-2008 \n
00020 ///
00021 ////////////////////////////////////////////////////////////////////////////////////////
00022 
00023 #include <boost/gil/gil_config.hpp>
00024 #include <boost/mpl/contains.hpp>
00025 #include <boost/gil/gray.hpp>
00026 #include <boost/gil/typedefs.hpp>
00027 
00028 namespace boost { namespace gil {
00029 
00030 typedef mpl::vector2<gray_color_t,alpha_t> gray_alpha_t;
00031 
00032 typedef layout<gray_alpha_t> gray_alpha_layout_t;
00033 typedef layout<gray_alpha_layout_t, mpl::vector2_c<int,1,0> > alpha_gray_layout_t;
00034 
00035 GIL_DEFINE_BASE_TYPEDEFS(8,  alpha_gray)
00036 GIL_DEFINE_BASE_TYPEDEFS(8s, alpha_gray)
00037 GIL_DEFINE_BASE_TYPEDEFS(16, alpha_gray)
00038 GIL_DEFINE_BASE_TYPEDEFS(16s,alpha_gray)
00039 GIL_DEFINE_BASE_TYPEDEFS(32 ,alpha_gray)
00040 GIL_DEFINE_BASE_TYPEDEFS(32s,alpha_gray)
00041 GIL_DEFINE_BASE_TYPEDEFS(32f,alpha_gray)
00042 
00043 GIL_DEFINE_ALL_TYPEDEFS(8,  gray_alpha)
00044 GIL_DEFINE_ALL_TYPEDEFS(8s, gray_alpha)
00045 GIL_DEFINE_ALL_TYPEDEFS(16, gray_alpha)
00046 GIL_DEFINE_ALL_TYPEDEFS(16s,gray_alpha)
00047 GIL_DEFINE_ALL_TYPEDEFS(32 ,gray_alpha)
00048 GIL_DEFINE_ALL_TYPEDEFS(32s,gray_alpha)
00049 GIL_DEFINE_ALL_TYPEDEFS(32f,gray_alpha)
00050 
00051 /// \ingroup ColorConvert
00052 /// \brief Gray Alpha to RGBA
00053 template <>
00054 struct default_color_converter_impl<gray_alpha_t,rgba_t> {
00055     template <typename P1, typename P2>
00056     void operator()(const P1& src, P2& dst) const {
00057         get_color(dst,red_t())  =
00058             channel_convert<typename color_element_type<P2, red_t>::type>(get_color(src,gray_color_t()));
00059         get_color(dst,green_t())=
00060             channel_convert<typename color_element_type<P2, green_t>::type>(get_color(src,gray_color_t()));
00061         get_color(dst,blue_t()) =
00062             channel_convert<typename color_element_type<P2, blue_t>::type>(get_color(src,gray_color_t()));
00063         get_color(dst,alpha_t()) =
00064             channel_convert<typename color_element_type<P2, alpha_t>::type>(get_color(src,alpha_t()));
00065     }
00066 };
00067 
00068 template <>
00069 struct default_color_converter_impl<gray_alpha_t,rgb_t> {
00070     template <typename P1, typename P2>
00071     void operator()(const P1& src, P2& dst) const {
00072         get_color(dst,red_t())  =
00073             channel_convert<typename color_element_type<P2, red_t>::type>(
00074                 channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) ) 
00075                 );
00076         get_color(dst,green_t())  =
00077             channel_convert<typename color_element_type<P2, green_t>::type>(
00078                 channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) ) 
00079                 );
00080         get_color(dst,blue_t())  =
00081             channel_convert<typename color_element_type<P2, blue_t>::type>(
00082                 channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) ) 
00083                 );
00084     }
00085 };
00086 
00087 template <>
00088 struct default_color_converter_impl<gray_alpha_t,gray_t> {
00089     template <typename P1, typename P2>
00090     void operator()(const P1& src, P2& dst) const {
00091         get_color(dst,gray_color_t())  =
00092             channel_convert<typename color_element_type<P2, gray_color_t>::type>(
00093                 channel_multiply(get_color(src,gray_color_t()),get_color(src,alpha_t()) ) 
00094                 );
00095     }
00096 };
00097 
00098 } // gil
00099 } // boost
00100 
00101 #endif // BOOST_GIL_GRAY_ALPHA_HPP_INCLUDED