TuttleOFX
1
|
00001 #ifndef _TERRY_COLOR_CONVERTED_VIEW_HPP_ 00002 #define _TERRY_COLOR_CONVERTED_VIEW_HPP_ 00003 00004 #include <terry/channel.hpp> 00005 00006 namespace terry { 00007 00008 // from image_view_factory.hpp 00009 // the difference with color_convert is on same pixels, only return pixel without process it. 00010 namespace detail { 00011 00012 template <typename SrcConstRefP, typename DstP, typename CC > // const_reference to the source pixel and destination pixel value 00013 class color_process_deref_fn : public deref_base<color_process_deref_fn<SrcConstRefP, DstP, CC>, DstP, DstP, const DstP&, SrcConstRefP, DstP, false > 00014 { 00015 private: 00016 CC _cc; // color converter 00017 00018 public: 00019 color_process_deref_fn( ) { } 00020 00021 color_process_deref_fn( const CC& cc_in ) : _cc( cc_in ) { } 00022 00023 DstP operator( )( SrcConstRefP srcP ) const 00024 { 00025 DstP dstP; 00026 _cc( srcP, dstP ); 00027 return dstP; 00028 } 00029 }; 00030 00031 00032 // Add color converter upon dereferencing 00033 template <typename CC, typename View> 00034 struct _color_processed_view_type 00035 { 00036 00037 private: 00038 typedef typename View::value_type Pixel; 00039 typedef color_process_deref_fn<typename View::const_t::reference, Pixel, CC> deref_t; 00040 typedef typename View::template add_deref<deref_t> add_ref_t; 00041 public: 00042 typedef typename add_ref_t::type type; 00043 00044 static type make( const View& sv, const CC& cc ) 00045 { 00046 return add_ref_t::make( sv, deref_t( cc ) ); 00047 } 00048 }; 00049 00050 template <typename CC, typename View> 00051 struct color_processed_view_type : public detail::_color_processed_view_type<CC, View> 00052 { 00053 GIL_CLASS_REQUIRE( typename View::value_type, boost::gil, MutablePixelConcept ) //why does it have to be mutable? 00054 }; 00055 00056 } 00057 00058 template<typename CC, typename View> 00059 inline typename detail::color_processed_view_type<CC, View>::type color_processed_view( const View& src, const CC& cc ) 00060 { 00061 return detail::color_processed_view_type<CC, View>::make( src, cc ); 00062 } 00063 00064 } 00065 00066 #endif