TuttleOFX
1
|
00001 #ifndef _TUTTLE_PLUGIN_HISTOGRAMKEYER_PROCESS_HPP_ 00002 #define _TUTTLE_PLUGIN_HISTOGRAMKEYER_PROCESS_HPP_ 00003 00004 #include <tuttle/plugin/ImageGilFilterProcessor.hpp> 00005 #include <terry/clamp.hpp> 00006 00007 namespace tuttle { 00008 namespace plugin { 00009 namespace histogramKeyer { 00010 00011 /** 00012 * @brief HistogramKeyer process 00013 * 00014 */ 00015 00016 /** 00017 * Functor which compute alpha for each pixel 00018 */ 00019 struct Compute_alpha_pixel 00020 { 00021 bool _isOutputBW; // is output black & white (or alpha channel) 00022 HistogramKeyerProcessParams<float> _params; 00023 00024 template< typename Pixel> 00025 Pixel operator()( const Pixel& p ) 00026 { 00027 using namespace boost::gil; 00028 00029 rgb32f_pixel_t convert_to_rgb; 00030 color_convert( p, convert_to_rgb ); // first step : p to rgb_pixel 00031 terry::clamp_converter<rgb32f_pixel_t>()( convert_to_rgb, convert_to_rgb ); 00032 hsl32f_pixel_t hsl_pix; 00033 color_convert(convert_to_rgb,hsl_pix ); // second step : rgb_pixel to hsl_pixel 00034 00035 double alpha = 1.0; 00036 00037 //RGBA 00038 for( int v = 0; v < boost::gil::num_channels<Pixel>::type::value -1; ++v ) // RGB but not alpha (doesn't needed) 00039 { 00040 if(_params._boolRGB[v]->getValue()) //if current channel check-box is active 00041 { 00042 double value = _params._paramColorRGB->getValue( v, _params._time,p[v] ); 00043 00044 //clamp mode 00045 if(_params._boolClampCurveValues->getValue()) 00046 { 00047 if(value > 1.0) //clamp values superior to 1 00048 value = 1.0; 00049 else if(value < 0.0) //clamp values inferior to 0 00050 value = 0.0; 00051 } 00052 value *= (double) _params._multiplierRGB[v]->getValue(); //multiplier RGB channels 00053 alpha *= value; 00054 } 00055 } 00056 //HSL 00057 for( int v = 0; v < boost::gil::num_channels<hsl32f_pixel_t>::type::value; ++v ) 00058 { 00059 if(_params._boolHSL[v]->getValue()) //if current channel check-box is active 00060 { 00061 double value = _params._paramColorHSL->getValue( v, _params._time,hsl_pix[v] ); 00062 //clamp mode 00063 if(_params._boolClampCurveValues->getValue()) 00064 { 00065 if(value > 1.0) //clamp values superior to 1 00066 value = 1.0; 00067 else if(value < 0.0) //clamp values inferior to 0 00068 value = 0.0; 00069 } 00070 value *= (double) _params._multiplierHSL[v]->getValue(); //multiplier HSL channels 00071 alpha *= value; 00072 } 00073 } 00074 Pixel ret; 00075 if( ! _params._boolReverseMask->getValue() ) //revert mask 00076 alpha = 1-alpha; 00077 00078 if( _isOutputBW ) // output is gray scale image 00079 { 00080 gray32f_pixel_t inter; // need a gray_pixel 00081 inter[0] = alpha; 00082 color_convert( inter, ret ); // convert gray_pixel to rgba_pixel 00083 } 00084 else // output is alpha channel 00085 { 00086 for( std::size_t i = 0; i < boost::gil::num_channels<Pixel>::type::value -1; ++i ) 00087 ret[i] = p[i]; 00088 ret[3] = alpha; //fill alpha channel up 00089 } 00090 return ret; 00091 } 00092 }; 00093 00094 template<class View> 00095 class HistogramKeyerProcess : public ImageGilFilterProcessor<View> 00096 { 00097 public: 00098 typedef typename View::value_type Pixel; 00099 typedef typename boost::gil::channel_type<View>::type Channel; 00100 typedef float Scalar; 00101 protected: 00102 HistogramKeyerPlugin& _plugin; ///< Rendering plugin 00103 HistogramKeyerProcessParams<Scalar> _params; ///< parameters 00104 00105 public: 00106 HistogramKeyerProcess( HistogramKeyerPlugin& effect ); 00107 00108 void setup( const OFX::RenderArguments& args ); 00109 00110 void multiThreadProcessImages( const OfxRectI& procWindowRoW ); 00111 }; 00112 00113 } 00114 } 00115 } 00116 00117 #include "HistogramKeyerProcess.tcc" 00118 00119 #endif