TuttleOFX
1
|
00001 #ifndef _TERRY_OPENEXR_HALF_HPP_ 00002 #define _TERRY_OPENEXR_HALF_HPP_ 00003 00004 /** 00005 * @warning The file depends on the half.h file of OpenEXR project. 00006 */ 00007 00008 #include <half.h> // OpenEXR Half float 00009 00010 #include <boost/integer.hpp> // for boost::uint_t 00011 #include <boost/gil/gil_all.hpp> 00012 #include <boost/type_traits.hpp> 00013 00014 namespace boost { 00015 namespace gil { 00016 00017 template <int N> 00018 struct devicen_t; 00019 template <int N> 00020 struct devicen_layout_t; 00021 00022 /////////////////////////////////////////////////////////////////////////////// 00023 /// @brief Define channel traits to support ilm half 00024 /////////////////////////////////////////////////////////////////////////////// 00025 00026 template <> 00027 struct channel_traits<half> : public detail::channel_traits_impl<half, false> 00028 { 00029 static half min_value() { return HALF_MIN; } 00030 static half max_value() { return HALF_MAX; } 00031 }; 00032 00033 /////////////////////////////////////////////////////////////////////////////// 00034 /// @typedef an half trait between 0 and 1 00035 /////////////////////////////////////////////////////////////////////////////// 00036 00037 struct half_zero 00038 { 00039 static half apply() { return half( 0.0f ); } 00040 }; 00041 struct half_one 00042 { 00043 static half apply() { return half( 1.0f ); } 00044 }; 00045 typedef scoped_channel_value< half, half_zero, half_one> bits16h; 00046 00047 inline bits16h operator+( bits16h _lhs, bits16h _rhs ) 00048 { 00049 return bits16h( _lhs += half( _rhs ) ); 00050 } 00051 00052 inline bits16h operator-( bits16h _lhs, bits16h _rhs ) 00053 { 00054 return bits16h( _lhs -= half( _rhs ) ); 00055 } 00056 00057 inline bits16h operator* ( bits16h _lhs, bits16h _rhs ) 00058 { 00059 return bits16h( _lhs *= half( _rhs ) ); 00060 } 00061 00062 inline bits16h operator/( bits16h _lhs, bits16h _rhs ) 00063 { 00064 return bits16h( _lhs /= half( _rhs ) ); 00065 } 00066 00067 /////////////////////////////////////////////////////////////////////////////// 00068 /// channel conversion from half channel 00069 /////////////////////////////////////////////////////////////////////////////// 00070 template <typename DstChannelV> 00071 struct channel_converter_unsigned<bits16h, DstChannelV> 00072 : public std::unary_function<bits16h, DstChannelV> 00073 { 00074 DstChannelV operator()( bits16h h ) const 00075 { 00076 return DstChannelV( half( h ) 00077 * float(channel_traits<DstChannelV>::max_value() ) + 0.5f ); 00078 } 00079 00080 }; 00081 00082 /////////////////////////////////////////////////////////////////////////////// 00083 /// channel conversion to half channel 00084 /////////////////////////////////////////////////////////////////////////////// 00085 template <typename SrcChannelV> 00086 struct channel_converter_unsigned<SrcChannelV, bits16h> 00087 : public std::unary_function<SrcChannelV, bits16h> 00088 { 00089 bits16h operator()( SrcChannelV x ) const 00090 { 00091 return bits16h( float(x) 00092 / float(channel_traits<SrcChannelV>::max_value() ) ); 00093 } 00094 00095 }; 00096 00097 /////////////////////////////////////////////////////////////////////////////// 00098 template <> 00099 struct channel_converter_unsigned<bits16h, bits16h> 00100 : public std::unary_function<bits16h, bits16h> 00101 { 00102 bits16h operator()( bits16h h ) const 00103 { 00104 return h; 00105 } 00106 00107 }; 00108 00109 /////////////////////////////////////////////////////////////////////////////// 00110 template <> 00111 struct channel_converter_unsigned<bits32f, bits16h> 00112 : public std::unary_function<bits32f, bits16h> 00113 { 00114 bits16h operator()( bits32f f ) const 00115 { 00116 return bits16h( half( f ) ); 00117 } 00118 00119 }; 00120 00121 /////////////////////////////////////////////////////////////////////////////// 00122 template <> 00123 struct channel_converter_unsigned<bits16h, bits32f> 00124 : public std::unary_function<bits16h, bits32f> 00125 { 00126 bits32f operator()( bits16h h ) const 00127 { 00128 return bits32f( float(half( h ) ) ); 00129 } 00130 00131 }; 00132 00133 /////////////////////////////////////////////////////////////////////////////// 00134 template<> 00135 struct channel_multiplier_unsigned<bits16h> 00136 : public std::binary_function<bits16h, bits16h, bits16h> 00137 { 00138 bits16h operator()( bits16h a, bits16h b ) const 00139 { 00140 return a* b; 00141 } 00142 00143 }; 00144 00145 /////////////////////////////////////////////////////////////////////////////// 00146 /// defines gil types with new bits16h trait 00147 /////////////////////////////////////////////////////////////////////////////// 00148 00149 GIL_DEFINE_BASE_TYPEDEFS( 16h, gray ) 00150 GIL_DEFINE_BASE_TYPEDEFS( 16h, bgr ) 00151 GIL_DEFINE_BASE_TYPEDEFS( 16h, argb ) 00152 GIL_DEFINE_BASE_TYPEDEFS( 16h, abgr ) 00153 GIL_DEFINE_BASE_TYPEDEFS( 16h, bgra ) 00154 00155 GIL_DEFINE_ALL_TYPEDEFS( 16h, rgb ) 00156 GIL_DEFINE_ALL_TYPEDEFS( 16h, rgba ) 00157 GIL_DEFINE_ALL_TYPEDEFS( 16h, cmyk ) 00158 00159 template <int N> 00160 struct devicen_t; 00161 template <int N> 00162 struct devicen_layout_t; 00163 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL( 16h, dev2n, devicen_t<2>, devicen_layout_t<2>) 00164 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL( 16h, dev3n, devicen_t<3>, devicen_layout_t<3>) 00165 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL( 16h, dev4n, devicen_t<4>, devicen_layout_t<4>) 00166 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL( 16h, dev5n, devicen_t<5>, devicen_layout_t<5>) 00167 00168 } 00169 } 00170 00171 #endif