TuttleOFX  1
HSLOverlay.cpp
Go to the documentation of this file.
00001 #include "HSLOverlay.hpp"
00002 
00003 namespace tuttle {
00004 namespace plugin {
00005 namespace histogram {
00006         
00007 
00008 /*Contructor when Nuke overlay works
00009 HSLOverlay::HSLOverlay(OfxInteractHandle handle, OFX::ImageEffect* effect):OFX::OverlayInteract( handle ),_infos( effect )
00010 {
00011         _plugin = static_cast<HistogramPlugin*>(_effect);
00012         _plugin->addRefOverlayData();
00013 }*/
00014 
00015 //temporary constructor
00016 HSLOverlay::HSLOverlay(HistogramPlugin* plugin)
00017 {
00018         _plugin = plugin;
00019         _plugin->addRefOverlayData();
00020 }
00021 
00022 /*Destructor*/
00023 HSLOverlay::~HSLOverlay()
00024 {
00025         _plugin->releaseOverlayData();
00026 }
00027 
00028 /**
00029  * Display of the RGB histograms data
00030  */
00031 bool HSLOverlay::draw(const OFX::DrawArgs& args)
00032 {       
00033         bool hasGridBeenDisplayed = false;      //grid has not been displayed yet
00034         
00035         //height of the window (image for test)
00036         //width of the window (image for test)
00037         OfxPointI size = _plugin->_clipSrc->getPixelRodSize(args.time);
00038     const double step = size.x / (double)(getOverlayData()._data._step -1);
00039         
00040     double heightH, heightS,heightL;
00041     heightH = heightS = heightL = size.y;
00042     if(!(_plugin->_paramDisplayTypeSelection->getValue() == 1))
00043     {
00044                 //get max of the three channels
00045         const Number maxH = *(std::max_element(getOverlayData()._data._bufferHue.begin(),getOverlayData()._data._bufferHue.end()));
00046         const Number maxS = *(std::max_element(getOverlayData()._data._bufferSaturation.begin(),getOverlayData()._data._bufferSaturation.end()));
00047         const Number maxL = *(std::max_element(getOverlayData()._data._bufferLightness.begin(),getOverlayData()._data._bufferLightness.end()));
00048             
00049                 //Adapt maximal value (3 cases)
00050         if(maxH > maxS && maxH > maxL)                          //H is the max
00051         {
00052                         heightS = maxS*heightH/maxH;
00053             heightL = maxL*heightH/maxH;
00054         }
00055         else if(maxS > maxH && maxS > maxL)                     //S is the max
00056         {
00057             heightH = maxH*heightS/maxS;
00058             heightL = maxL*heightS/maxS;
00059         }
00060         else                                                                            //L is the max
00061         {
00062             heightH = maxH*heightL/maxL;
00063             heightS = maxS*heightL/maxL;
00064         }
00065     }
00066         float selectionMultiplier = (float)_plugin->_paramSelectionMultiplierSelection->getValue();
00067         //Display on screen if specified (HSL)
00068         if(_plugin->_paramOverlayHSelection->getValue())                        //HUE CHANNEL
00069         {
00070                 if(!hasGridBeenDisplayed)       //if grid has not been displayed yet
00071                 {
00072                         displayGrid(size.y, size.x); //display grid on screen
00073                         hasGridBeenDisplayed = true; //set grid has already been displayed to true
00074                 }
00075                 displayASpecificHistogram(getOverlayData()._data._bufferHue,getOverlayData()._selectionData._bufferHue,step,heightH,size.x,redHisto,selectionMultiplier);
00076                 if(getOnlyChannelSelectedHSL()==eSelectedChannelH)
00077                 {
00078                         displaySelectionPoints(getOverlayData()._selectionData._bufferHue,step,size.x,redHisto);                                //selection points
00079                         displayAverageBar(getOverlayData()._averageData._averageHue,averageHisto,size.x,size.y,step);                   //average bar
00080                         displayHueIndicator(size,kPrecisionHueIndicator);                                                                                               //indicator
00081                 }
00082         }
00083         if(_plugin->_paramOverlaySSelection->getValue())                        //SATURATION CHANNEL
00084         {
00085                 if(!hasGridBeenDisplayed)       //if grid has not been displayed yet
00086                 {
00087                         displayGrid(size.y, size.x); //display grid on screen
00088                         hasGridBeenDisplayed = true; //set grid has already been displayed to true
00089                 }
00090                 
00091                 displayASpecificHistogram(getOverlayData()._data._bufferSaturation,getOverlayData()._selectionData._bufferSaturation,step,heightS,size.x,greenHisto,selectionMultiplier);
00092                 if(getOnlyChannelSelectedHSL()==eSelectedChannelS)
00093                 {
00094                         displaySelectionPoints(getOverlayData()._selectionData._bufferSaturation,step,size.x,greenHisto);               //selection points
00095                         displayAverageBar(getOverlayData()._averageData._averageSaturation,averageHisto,size.x,size.y,step);    //average bar
00096                         displaySaturationIndicator(size);                                                                                                                               //indicator
00097                 }
00098         }
00099         if(_plugin->_paramOverlayLSelection->getValue())                        //LIGHTNESS CHANNEL
00100         {
00101                 if(!hasGridBeenDisplayed)       //if grid has not been displayed yet
00102                 {
00103                         displayGrid(size.y, size.x); //display grid on screen
00104                         hasGridBeenDisplayed = true; //set grid has already been displayed to true
00105                 }
00106                                 
00107                 displayASpecificHistogram(getOverlayData()._data._bufferLightness,getOverlayData()._selectionData._bufferLightness,step,heightL,size.x,blueHisto,selectionMultiplier);
00108                 if(getOnlyChannelSelectedHSL()==eSelectedChannelL)
00109                 {
00110                         displaySelectionPoints(getOverlayData()._selectionData._bufferLightness,step,size.x,blueHisto);         //selection points
00111                         displayAverageBar(getOverlayData()._averageData._averageLightness,averageHisto,size.x,size.y,step);     //average bar
00112                         displayLightnessIndicator(size);                                                                                                                                //indicator
00113                 }
00114         }
00115         //Display border (separate from histograms to eliminate blending)
00116         if(_plugin->_paramOverlayHSelection->getValue())
00117                 displayASpecificHistogramBorder(getOverlayData()._data._bufferHue,step,heightH,size.x,redHisto);                        //H
00118         if(_plugin->_paramOverlaySSelection->getValue())
00119                 displayASpecificHistogramBorder(getOverlayData()._data._bufferSaturation,step,heightS,size.x,greenHisto);       //S
00120         if(_plugin->_paramOverlayLSelection->getValue())
00121                 displayASpecificHistogramBorder(getOverlayData()._data._bufferLightness,step,heightL,size.x,blueHisto); //L
00122         return true;
00123 }
00124 
00125 /**
00126  * Permits to know if there is only one RGB channel selected
00127  * @return "R", "G", "B" if there is only one channel selected,  "none" or "more" else
00128  */
00129 ESelectedChannelHSL HSLOverlay::getOnlyChannelSelectedHSL() const
00130 {
00131         //get all of the checkbox states HSL
00132         bool H = _plugin->_paramOverlayHSelection->getValue();  //check box H value
00133         bool S = _plugin->_paramOverlaySSelection->getValue();  //check box S value
00134         bool L = _plugin->_paramOverlayLSelection->getValue();  //check box L value
00135         
00136         if(H||S||L)
00137         {
00138                 if(H && !S && !L)
00139                         return eSelectedChannelH;                       //Only hue is selected
00140                 if(!H && S && !L)
00141                         return eSelectedChannelS;                       //Only saturation is selected
00142                 if(!H && !S && L)
00143                         return eSelectedChannelL;                       //Only lightness is selected
00144                 return eSelectedChannelMoreHSL;                 //More than one HSL channel are selected
00145         }
00146         return eSelectedChannelNoneHSL;                         //None HSL channel is selected
00147 }
00148 
00149 /**
00150  * Get overlay data from plugin
00151  * @return 
00152  */
00153 OverlayData& HSLOverlay::getOverlayData()
00154 {
00155         return _plugin->getOverlayData();
00156 }
00157 
00158 /**
00159  * Display grid on screen
00160  */
00161 void HSLOverlay::displayGrid(float height, float width)
00162 {
00163         glBegin(GL_LINES);
00164         //draw standard reference
00165         glColor3f(.9f,.9f,.9f);                                                         //white color
00166         glVertex2f(-0.1f,0); glVertex2f(-0.1f,height);          //Y axis
00167         glVertex2f(0,-0.1f); glVertex2f(width,-0.1f);           //X axis
00168         
00169         //compute step X and Y
00170         float stepY = (float)(height/10.0f);
00171         float stepX = (float)(width/10.0f);
00172         float stepYm = (float)(height/20.0f);
00173         float stepXm = (float)(width/20.0f);
00174         
00175         //drawing minor grid
00176         glColor3f(.2f,.2f,.2f);         //gray color
00177         float baseY = 0;                        //initialize y to O
00178         float baseX = 0;                        //initialize x to 0
00179         for(unsigned int i=0; i< 20; ++i)
00180         {
00181                 baseY += stepYm;        //update Y position
00182                 baseX += stepXm; //update X position
00183                 glVertex2f(-0.1f,baseY);        glVertex2f(width,baseY); //draw Y axis
00184                 glVertex2f(baseX, -0.1f);       glVertex2f(baseX,height);//draw X axis
00185         }
00186         
00187         //drawing major grid
00188         glColor3f(.5f,.5f,.5f);         //gray color
00189         baseY = 0;                      //initialize y to O
00190         baseX = 0;                      //initialize x to 0
00191         for(unsigned int i=0; i< 10; ++i)
00192         {
00193                 baseY += stepY; //update Y position
00194                 baseX += stepX; //update X position
00195                 glVertex2f(-0.1f,baseY);        glVertex2f(width,baseY); //draw Y axis
00196                 glVertex2f(baseX, -0.1f);       glVertex2f(baseX,height);//draw X axis
00197         }
00198 
00199         //draw grid
00200         glEnd();
00201 }
00202 
00203 
00204 }
00205 }
00206 }