TuttleOFX
1
|
00001 #ifndef _TUTTLE_PLUGIN_MATHOPERATOR_ALGORITHM_HPP_ 00002 #define _TUTTLE_PLUGIN_MATHOPERATOR_ALGORITHM_HPP_ 00003 00004 #include <terry/channel.hpp> 00005 00006 namespace tuttle { 00007 namespace plugin { 00008 namespace mathOperator { 00009 00010 namespace bgil = boost::gil; 00011 00012 template< class View > 00013 void MathOperatorProcess<View>::processImagePlus( OfxRectI& procWindowOutput, const OfxRectI& procWindowRoW, const boost::gil::rgba32f_pixel_t& values, const boost::gil::rgba8_pixel_t& processChannel ) 00014 { 00015 const OfxPointI procWindowSize = { 00016 procWindowRoW.x2 - procWindowRoW.x1, 00017 procWindowRoW.y2 - procWindowRoW.y1 }; 00018 00019 boost::gil::rgba32f_pixel_t wpix; 00020 for( int y = procWindowOutput.y1; 00021 y < procWindowOutput.y2; 00022 ++y ) 00023 { 00024 typename View::x_iterator src_it = this->_srcView.x_at( procWindowOutput.x1, y ); 00025 typename View::x_iterator dst_it = this->_dstView.x_at( procWindowOutput.x1, y ); 00026 for( int x = procWindowOutput.x1; 00027 x < procWindowOutput.x2; 00028 ++x, ++src_it, ++dst_it ) 00029 { 00030 color_convert( *src_it, wpix ); 00031 00032 if( processChannel[ 0 ] == 1.0 ) 00033 wpix[ 0 ] = wpix[ 0 ] + values[ 0 ] ; 00034 if( processChannel[ 1 ] == 1.0 ) 00035 wpix[ 1 ] = wpix[ 1 ] + values[ 1 ] ; 00036 if( processChannel[ 2 ] == 1.0 ) 00037 wpix[ 2 ] = wpix[ 2 ] + values[ 2 ] ; 00038 if( processChannel[ 3 ] == 1.0 ) 00039 wpix[ 3 ] = wpix[ 3 ] + values[ 3 ] ; 00040 00041 color_convert( wpix, *dst_it ); 00042 } 00043 if( this->progressForward( procWindowSize.x ) ) 00044 return; 00045 } 00046 } 00047 00048 template< class View > 00049 void MathOperatorProcess<View>::processImageMultiply( OfxRectI& procWindowOutput, const OfxRectI& procWindowRoW, const boost::gil::rgba32f_pixel_t& values, const boost::gil::rgba8_pixel_t& processChannel ) 00050 { 00051 const OfxPointI procWindowSize = { 00052 procWindowRoW.x2 - procWindowRoW.x1, 00053 procWindowRoW.y2 - procWindowRoW.y1 }; 00054 00055 boost::gil::rgba32f_pixel_t wpix; 00056 for( int y = procWindowOutput.y1; 00057 y < procWindowOutput.y2; 00058 ++y ) 00059 { 00060 typename View::x_iterator src_it = this->_srcView.x_at( procWindowOutput.x1, y ); 00061 typename View::x_iterator dst_it = this->_dstView.x_at( procWindowOutput.x1, y ); 00062 for( int x = procWindowOutput.x1; 00063 x < procWindowOutput.x2; 00064 ++x, ++src_it, ++dst_it ) 00065 { 00066 color_convert( *src_it, wpix ); 00067 00068 if( processChannel[ 0 ] == 1.0 ) 00069 wpix[ 0 ] = wpix[ 0 ] * values[ 0 ] ; 00070 if( processChannel[ 1 ] == 1.0 ) 00071 wpix[ 1 ] = wpix[ 1 ] * values[ 1 ] ; 00072 if( processChannel[ 2 ] == 1.0 ) 00073 wpix[ 2 ] = wpix[ 2 ] * values[ 2 ] ; 00074 if( processChannel[ 3 ] == 1.0 ) 00075 wpix[ 3 ] = wpix[ 3 ] * values[ 3 ] ; 00076 00077 color_convert( wpix, *dst_it ); 00078 } 00079 if( this->progressForward( procWindowSize.x ) ) 00080 return; 00081 } 00082 } 00083 00084 template< class View > 00085 void MathOperatorProcess<View>::processImagePow( OfxRectI& procWindowOutput, const OfxRectI& procWindowRoW, const boost::gil::rgba32f_pixel_t& values, const boost::gil::rgba8_pixel_t& processChannel ) 00086 { 00087 const OfxPointI procWindowSize = { 00088 procWindowRoW.x2 - procWindowRoW.x1, 00089 procWindowRoW.y2 - procWindowRoW.y1 }; 00090 00091 boost::gil::rgba32f_pixel_t wpix; 00092 for( int y = procWindowOutput.y1; 00093 y < procWindowOutput.y2; 00094 ++y ) 00095 { 00096 typename View::x_iterator src_it = this->_srcView.x_at( procWindowOutput.x1, y ); 00097 typename View::x_iterator dst_it = this->_dstView.x_at( procWindowOutput.x1, y ); 00098 for( int x = procWindowOutput.x1; 00099 x < procWindowOutput.x2; 00100 ++x, ++src_it, ++dst_it ) 00101 { 00102 color_convert( *src_it, wpix ); 00103 00104 if( processChannel[ 0 ] == 1.0 ) 00105 wpix[ 0 ] = std::pow( wpix[ 0 ], values[ 0 ] ) ; 00106 if( processChannel[ 1 ] == 1.0 ) 00107 wpix[ 1 ] = std::pow( wpix[ 1 ], values[ 1 ] ) ; 00108 if( processChannel[ 2 ] == 1.0 ) 00109 wpix[ 2 ] = std::pow( wpix[ 2 ], values[ 2 ] ) ; 00110 if( processChannel[ 3 ] == 1.0 ) 00111 wpix[ 3 ] = std::pow( wpix[ 3 ], values[ 3 ] ) ; 00112 00113 color_convert( wpix, *dst_it ); 00114 } 00115 if( this->progressForward( procWindowSize.x ) ) 00116 return; 00117 } 00118 } 00119 00120 00121 template< class View > 00122 void MathOperatorProcess<View>::processImageSqrt( OfxRectI& procWindowOutput, const OfxRectI& procWindowRoW, const boost::gil::rgba32f_pixel_t& values, const boost::gil::rgba8_pixel_t& processChannel ) 00123 { 00124 const OfxPointI procWindowSize = { 00125 procWindowRoW.x2 - procWindowRoW.x1, 00126 procWindowRoW.y2 - procWindowRoW.y1 }; 00127 00128 boost::gil::rgba32f_pixel_t wpix; 00129 for( int y = procWindowOutput.y1; 00130 y < procWindowOutput.y2; 00131 ++y ) 00132 { 00133 typename View::x_iterator src_it = this->_srcView.x_at( procWindowOutput.x1, y ); 00134 typename View::x_iterator dst_it = this->_dstView.x_at( procWindowOutput.x1, y ); 00135 for( int x = procWindowOutput.x1; 00136 x < procWindowOutput.x2; 00137 ++x, ++src_it, ++dst_it ) 00138 { 00139 color_convert( *src_it, wpix ); 00140 00141 if( processChannel[ 0 ] == 1.0 ) 00142 wpix[ 0 ] = std::sqrt( wpix[ 0 ] ) ; 00143 if( processChannel[ 1 ] == 1.0 ) 00144 wpix[ 1 ] = std::sqrt( wpix[ 1 ] ) ; 00145 if( processChannel[ 2 ] == 1.0 ) 00146 wpix[ 2 ] = std::sqrt( wpix[ 2 ] ) ; 00147 if( processChannel[ 3 ] == 1.0 ) 00148 wpix[ 3 ] = std::sqrt( wpix[ 3 ] ) ; 00149 00150 color_convert( wpix, *dst_it ); 00151 } 00152 if( this->progressForward( procWindowSize.x ) ) 00153 return; 00154 } 00155 } 00156 00157 template< class View > 00158 void MathOperatorProcess<View>::processImageLn( OfxRectI& procWindowOutput, const OfxRectI& procWindowRoW, const boost::gil::rgba32f_pixel_t& values, const boost::gil::rgba8_pixel_t& processChannel ) 00159 { 00160 const OfxPointI procWindowSize = { 00161 procWindowRoW.x2 - procWindowRoW.x1, 00162 procWindowRoW.y2 - procWindowRoW.y1 }; 00163 00164 boost::gil::rgba32f_pixel_t wpix; 00165 for( int y = procWindowOutput.y1; 00166 y < procWindowOutput.y2; 00167 ++y ) 00168 { 00169 typename View::x_iterator src_it = this->_srcView.x_at( procWindowOutput.x1, y ); 00170 typename View::x_iterator dst_it = this->_dstView.x_at( procWindowOutput.x1, y ); 00171 for( int x = procWindowOutput.x1; 00172 x < procWindowOutput.x2; 00173 ++x, ++src_it, ++dst_it ) 00174 { 00175 color_convert( *src_it, wpix ); 00176 00177 if( processChannel[ 0 ] == 1.0 ) 00178 wpix[ 0 ] = std::log( wpix[ 0 ] ) ; 00179 if( processChannel[ 1 ] == 1.0 ) 00180 wpix[ 1 ] = std::log( wpix[ 1 ] ) ; 00181 if( processChannel[ 2 ] == 1.0 ) 00182 wpix[ 2 ] = std::log( wpix[ 2 ] ) ; 00183 if( processChannel[ 3 ] == 1.0 ) 00184 wpix[ 3 ] = std::log( wpix[ 3 ] ) ; 00185 00186 color_convert( wpix, *dst_it ); 00187 } 00188 if( this->progressForward( procWindowSize.x ) ) 00189 return; 00190 } 00191 } 00192 00193 00194 template< class View > 00195 void MathOperatorProcess<View>::processImageLog( OfxRectI& procWindowOutput, const OfxRectI& procWindowRoW, const boost::gil::rgba32f_pixel_t& values, const boost::gil::rgba8_pixel_t& processChannel ) 00196 { 00197 const OfxPointI procWindowSize = { 00198 procWindowRoW.x2 - procWindowRoW.x1, 00199 procWindowRoW.y2 - procWindowRoW.y1 }; 00200 00201 boost::gil::rgba32f_pixel_t wpix; 00202 for( int y = procWindowOutput.y1; 00203 y < procWindowOutput.y2; 00204 ++y ) 00205 { 00206 typename View::x_iterator src_it = this->_srcView.x_at( procWindowOutput.x1, y ); 00207 typename View::x_iterator dst_it = this->_dstView.x_at( procWindowOutput.x1, y ); 00208 for( int x = procWindowOutput.x1; 00209 x < procWindowOutput.x2; 00210 ++x, ++src_it, ++dst_it ) 00211 { 00212 color_convert( *src_it, wpix ); 00213 00214 if( processChannel[ 0 ] == 1.0 ) 00215 wpix[ 0 ] = std::log10( wpix[ 0 ] ) ; 00216 if( processChannel[ 1 ] == 1.0 ) 00217 wpix[ 1 ] = std::log10( wpix[ 1 ] ) ; 00218 if( processChannel[ 2 ] == 1.0 ) 00219 wpix[ 2 ] = std::log10( wpix[ 2 ] ) ; 00220 if( processChannel[ 3 ] == 1.0 ) 00221 wpix[ 3 ] = std::log10( wpix[ 3 ] ) ; 00222 00223 color_convert( wpix, *dst_it ); 00224 } 00225 if( this->progressForward( procWindowSize.x ) ) 00226 return; 00227 } 00228 } 00229 00230 } 00231 } 00232 } 00233 00234 #endif