TuttleOFX
1
|
00001 #ifndef _TERRY_GLOBALS_HPP_ 00002 #define _TERRY_GLOBALS_HPP_ 00003 00004 // HACK to use some header only utilities of tuttle 00005 #include "../../tuttle/src/tuttle/common/system/system.hpp" 00006 #include "../../tuttle/src/tuttle/common/system/compatibility.hpp" 00007 00008 #include <terry/math/Rect.hpp> 00009 00010 #include <boost/gil/channel_algorithm.hpp> // force to use the boostHack version first 00011 #include <boost/gil/gil_config.hpp> 00012 #include <boost/gil/typedefs.hpp> 00013 #include <boost/gil/image.hpp> 00014 #include <boost/gil/image_view.hpp> 00015 #include <boost/gil/image_view_factory.hpp> 00016 #include <boost/type_traits.hpp> 00017 00018 #include <ostream> 00019 00020 namespace terry { 00021 00022 /* 00023 template<class View> 00024 View getFullView( View tileView, const Rect<std::ssize_t>& bounds, const Rect<std::ssize_t>& rod ) 00025 { 00026 using namespace boost::gil; 00027 typedef typename View::value_type Pixel; 00028 00029 // if the tile is equals to the full image 00030 // directly return the tile 00031 if( bounds.x1 == rod.x1 && bounds.y1 == rod.y1 && 00032 bounds.x2 == rod.x2 && bounds.y2 == rod.y2 ) 00033 return tileView; 00034 00035 // view the tile as a full image 00036 return subimage_view( tileView, rod.x1 - bounds.x1, rod.y1 - bounds.y1, rod.x2 - rod.x1, rod.y2 - rod.y1 ); 00037 } 00038 */ 00039 00040 template <class View, typename Alloc=std::allocator<unsigned char> > 00041 struct image_from_view 00042 { 00043 typedef typename View::value_type value_type; // pixel_t 00044 typedef typename boost::gil::image<value_type, boost::gil::is_planar<View>::value, Alloc> type; 00045 }; 00046 // typedef typename view_type_from_pixel<OutPixelType, boost::gil::is_planar<View>::value >::type OutView; 00047 00048 template<class View> 00049 struct layout_type 00050 { 00051 typedef boost::gil::layout< 00052 typename boost::gil::color_space_type<View>::type, 00053 typename boost::gil::channel_mapping_type<View>::type 00054 > type; 00055 }; 00056 00057 /** 00058 * @return the current type T if it's a floating point type, 00059 * else return F 00060 */ 00061 template<typename T, typename F = boost::gil::bits32f> 00062 struct floating_channel_type_t 00063 { 00064 typedef typename boost::mpl::if_< boost::is_floating_point<T>, 00065 T, 00066 F >::type type; 00067 }; 00068 00069 template<class View> 00070 struct floating_pixel_from_view 00071 { 00072 typedef typename boost::gil::channel_mapping_type<View>::type Channel; 00073 typedef typename floating_channel_type_t<Channel>::type ChannelFloat; 00074 00075 typedef boost::gil::pixel<ChannelFloat, typename layout_type<View>::type > type; 00076 }; 00077 00078 00079 template <class View> 00080 inline float max_value() 00081 { 00082 using namespace boost::gil; 00083 return channel_traits< typename channel_type< View >::type >::max_value(); 00084 } 00085 00086 template <class View> 00087 inline float domain_max_value() 00088 { 00089 using namespace boost::gil; 00090 return channel_traits< typename channel_type< View >::type >::max_value() + 1.0f; 00091 } 00092 00093 } 00094 00095 00096 #endif