TuttleOFX  1
layout.hpp
Go to the documentation of this file.
00001 #ifndef _TERRY_COLOR_LAYOUT_HPP_
00002 #define _TERRY_COLOR_LAYOUT_HPP_
00003 
00004 #include "colorspace.hpp"
00005 
00006 namespace terry {
00007 namespace color {
00008 
00009 /**
00010  * @bief All supported layouts
00011  */
00012 namespace layout {
00013 
00014 /// \ingroup LayoutModel
00015 typedef boost::gil::layout<colorspace::rgb_t> rgb;
00016 typedef boost::gil::layout<colorspace::rgba_t> rgba;
00017 typedef boost::gil::layout<colorspace::yuv_t> yuv;
00018 typedef boost::gil::layout<colorspace::YPbPr_t> YPbPr;
00019 typedef boost::gil::layout<colorspace::hsv_t> hsv;
00020 typedef boost::gil::layout<colorspace::hsl_t> hsl;
00021 typedef boost::gil::layout<colorspace::lab_t> lab;
00022 typedef boost::gil::layout<colorspace::luv_t> luv;
00023 typedef boost::gil::layout<colorspace::XYZ_t> XYZ;
00024 typedef boost::gil::layout<colorspace::Yxy_t> Yxy;
00025 
00026 }
00027 
00028 ////////////////////////////////////////////////////////////////////////////////
00029 
00030 
00031 
00032 ////////////////////////////////////////////////////////////////////////////////
00033 ////////////////////////////////////////////////////////////////////////////////
00034 
00035 
00036 template< typename Pixel,
00037           class IN,
00038           class OUT >
00039 struct pixel_color_layout_t
00040 {
00041         typedef typename channel_type<Pixel>::type Channel;
00042         const IN&  _in;
00043         const OUT& _out;
00044 
00045         pixel_color_layout_t( const IN& in, const OUT& out )
00046         : _in(in)
00047         , _out(out)
00048         {}
00049 
00050         Pixel& operator()( const Pixel& p1,
00051                            Pixel& p2 ) const
00052         {
00053                 static_for_each(
00054                                 p1, p2,
00055                                 channel_color_layout_t< Channel, IN, OUT >( _in, _out )
00056                         );
00057                 return p2;
00058         }
00059 };
00060 
00061 template< class IN,
00062           class OUT >
00063 struct transform_pixel_color_layout_t
00064 {
00065         const IN&  _in;
00066         const OUT& _out;
00067 
00068         transform_pixel_color_layout_t( const IN& in, const OUT& out )
00069         : _in(in)
00070         , _out(out)
00071         {}
00072 
00073         template< typename Pixel>
00074         Pixel operator()( const Pixel& p1 ) const
00075         {
00076                 Pixel p2;
00077                 pixel_color_layout_t<Pixel, IN, OUT>( _in, _out )( p1, p2 );
00078                 return p2;
00079         }
00080 };
00081 
00082 /**
00083  * @example layout_convert_view( srcView, dstView, layout::rgb(), layout::hsl() );
00084  */
00085 template<class LayoutIN, class LayoutOUT, class View>
00086 void layout_convert_view( const View& src, View& dst, const LayoutIN& layoutIn = LayoutIN(), const LayoutOUT& layoutOut = LayoutOUT() )
00087 {
00088         boost::gil::transform_pixels( src, dst, transform_pixel_color_layout_t<LayoutIN, LayoutOUT>( layoutIn, layoutOut ) );
00089 }
00090 
00091 /**
00092  * @example layout_convert_pixel( srcPix, dstPix, layout::rgb(), layout::hsl() );
00093  */
00094 template<class LayoutIN, class LayoutOUT, class Pixel>
00095 void layout_convert_pixel( const Pixel& src, Pixel& dst, const LayoutIN& layoutIn = LayoutIN(), const LayoutOUT& layoutOut = LayoutOUT() )
00096 {
00097         pixel_color_layout_t<Pixel, LayoutIN, LayoutOUT>( layoutIn, layoutOut )( src, dst );
00098 }
00099 
00100 
00101 
00102 }
00103 }
00104 
00105 #endif
00106