TuttleOFX  1
base.hpp
Go to the documentation of this file.
00001 #ifndef _TERRY_COLOR_COLORSPACE_BASE_HPP_
00002 #define _TERRY_COLOR_COLORSPACE_BASE_HPP_
00003 
00004 #include <boost/mpl/vector.hpp>
00005 
00006 #include <boost/gil/gil_all.hpp>
00007 #include <boost/gil/pixel.hpp>
00008 #include <boost/gil/locator.hpp>
00009 #include <boost/gil/typedefs.hpp>
00010 
00011 #include <terry/numeric/init.hpp>
00012 
00013 namespace terry {
00014 using namespace ::boost::gil;
00015 
00016 #define TERRY_DEFINE_GIL_INTERNALS_4(CS) \
00017         \
00018         template <typename IC> \
00019         inline typename type_from_x_iterator<planar_pixel_iterator<IC,color::CS##_colorspace_t> >::view_t \
00020         planar_##CS##_view(std::size_t width, std::size_t height, IC a, IC b, IC c, IC d, std::ptrdiff_t rowsize_in_bytes) { \
00021                 typedef typename type_from_x_iterator<planar_pixel_iterator<IC,color::CS##_colorspace_t> >::view_t RView; \
00022                 return RView(width, height, typename RView::locator(planar_pixel_iterator<IC,color::CS##_colorspace_t>(a,b,c,d), rowsize_in_bytes)); \
00023         }
00024 
00025 
00026 #define TERRY_DEFINE_GIL_INTERNALS_3(CS) \
00027         \
00028         template <typename IC> \
00029         inline typename type_from_x_iterator<planar_pixel_iterator<IC,color::CS##_colorspace_t> >::view_t \
00030         planar_##CS##_view(std::size_t width, std::size_t height, \
00031                                         IC a, IC b, IC c, \
00032                                         std::ptrdiff_t rowsize_in_bytes) { \
00033                 typedef typename type_from_x_iterator<planar_pixel_iterator<IC,color::CS##_colorspace_t> >::view_t RView; \
00034                 return RView(width, height, \
00035                                          typename RView::locator(planar_pixel_iterator<IC,color::CS##_colorspace_t>(a,b,c), \
00036                                                                                          rowsize_in_bytes)); \
00037         }
00038 
00039 // A customized version of the equivalent GIL define.
00040 // We only have removed the forward declarations
00041 // which creates compilation troubles, with terry namespace...
00042 #define TERRY_GIL_DEFINE_BASE_TYPEDEFS_INTERNAL(T,CS,LAYOUT)                                              \
00043     typedef pixel<bits##T, LAYOUT >                        CS##T##_pixel_t;        \
00044     typedef const pixel<bits##T, LAYOUT >                   CS##T##c_pixel_t;        \
00045     typedef pixel<bits##T, LAYOUT >&                      CS##T##_ref_t;            \
00046     typedef const pixel<bits##T, LAYOUT >&                CS##T##c_ref_t;            \
00047     typedef CS##T##_pixel_t*                                               CS##T##_ptr_t;            \
00048     typedef CS##T##c_pixel_t*                                               CS##T##c_ptr_t;            \
00049     typedef memory_based_step_iterator<CS##T##_ptr_t>                               CS##T##_step_ptr_t;        \
00050     typedef memory_based_step_iterator<CS##T##c_ptr_t>                               CS##T##c_step_ptr_t;    \
00051     typedef memory_based_2d_locator<memory_based_step_iterator<CS##T##_ptr_t> >       CS##T##_loc_t;            \
00052     typedef memory_based_2d_locator<memory_based_step_iterator<CS##T##c_ptr_t> >       CS##T##c_loc_t;            \
00053     typedef memory_based_2d_locator<memory_based_step_iterator<CS##T##_step_ptr_t> >  CS##T##_step_loc_t;        \
00054     typedef memory_based_2d_locator<memory_based_step_iterator<CS##T##c_step_ptr_t> > CS##T##c_step_loc_t;    \
00055     typedef image_view<CS##T##_loc_t>                                        CS##T##_view_t;            \
00056     typedef image_view<CS##T##c_loc_t>                                        CS##T##c_view_t;        \
00057     typedef image_view<CS##T##_step_loc_t>                                    CS##T##_step_view_t;    \
00058     typedef image_view<CS##T##c_step_loc_t>                                   CS##T##c_step_view_t;    \
00059     typedef image<CS##T##_pixel_t,false,std::allocator<unsigned char> >           CS##T##_image_t;
00060 
00061 // A customized version of the equivalent GIL define
00062 // CS = 'bgr' CS_FULL = 'rgb_t' LAYOUT='bgr_layout_t'
00063 #define TERRY_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(T,CS,CS_FULL,LAYOUT)                                                                \
00064     TERRY_GIL_DEFINE_BASE_TYPEDEFS_INTERNAL(T,CS,LAYOUT)                                                                    \
00065     typedef planar_pixel_reference<bits##T&,CS_FULL >                                          CS##T##_planar_ref_t;        \
00066     typedef planar_pixel_reference<const bits##T&,CS_FULL >                                      CS##T##c_planar_ref_t;        \
00067     typedef planar_pixel_iterator<bits##T*,CS_FULL >                                          CS##T##_planar_ptr_t;        \
00068     typedef planar_pixel_iterator<const bits##T*,CS_FULL >                                      CS##T##c_planar_ptr_t;        \
00069     typedef memory_based_step_iterator<CS##T##_planar_ptr_t>                              CS##T##_planar_step_ptr_t;    \
00070     typedef memory_based_step_iterator<CS##T##c_planar_ptr_t>                              CS##T##c_planar_step_ptr_t;    \
00071     typedef memory_based_2d_locator<memory_based_step_iterator<CS##T##_planar_ptr_t> >          CS##T##_planar_loc_t;        \
00072     typedef memory_based_2d_locator<memory_based_step_iterator<CS##T##c_planar_ptr_t> >      CS##T##c_planar_loc_t;        \
00073     typedef memory_based_2d_locator<memory_based_step_iterator<CS##T##_planar_step_ptr_t> >  CS##T##_planar_step_loc_t;    \
00074     typedef memory_based_2d_locator<memory_based_step_iterator<CS##T##c_planar_step_ptr_t> > CS##T##c_planar_step_loc_t;    \
00075     typedef image_view<CS##T##_planar_loc_t>                                      CS##T##_planar_view_t;        \
00076     typedef image_view<CS##T##c_planar_loc_t>                                      CS##T##c_planar_view_t;        \
00077     typedef image_view<CS##T##_planar_step_loc_t>                                  CS##T##_planar_step_view_t;    \
00078     typedef image_view<CS##T##c_planar_step_loc_t>                                  CS##T##c_planar_step_view_t;\
00079     typedef image<CS##T##_pixel_t,true,std::allocator<unsigned char> >              CS##T##_planar_image_t;
00080 
00081 #define TERRY_DEFINE_ALL_TYPEDEFS(T,CS)         \
00082     TERRY_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(T,CS,color::CS##_colorspace_t,color::CS##_layout_t)
00083 
00084 #define TERRY_DEFINE_COLORSPACE_STANDARD_TYPEDEFS(CS) \
00085         TERRY_DEFINE_ALL_TYPEDEFS(8,  CS) \
00086         TERRY_DEFINE_ALL_TYPEDEFS(8s, CS) \
00087         TERRY_DEFINE_ALL_TYPEDEFS(16, CS) \
00088         TERRY_DEFINE_ALL_TYPEDEFS(16s,CS) \
00089         TERRY_DEFINE_ALL_TYPEDEFS(32 ,CS) \
00090         TERRY_DEFINE_ALL_TYPEDEFS(32s,CS) \
00091         TERRY_DEFINE_ALL_TYPEDEFS(32f,CS)
00092 
00093 
00094 
00095 namespace color {
00096 
00097 /**
00098  * @brief Base class of all color parameters class.
00099  */
00100 struct IColorParams
00101 {
00102         virtual bool operator==( const IColorParams& other ) const = 0;
00103         bool operator!=( const IColorParams& other ) const { return ! this->operator==( other ); };
00104 };
00105 
00106 
00107 /**
00108  * @brief Fake class to finish hierachy.
00109  */
00110 struct None {};
00111 /**
00112  * @brief Fake class to finish hierachy.
00113  */
00114 struct IsRootReference
00115 {
00116         typedef None reference;
00117         typedef None params;
00118 };
00119 
00120 
00121 }
00122 }
00123 
00124 #endif
00125