TuttleOFX  1
HistogramDisplay.cpp
Go to the documentation of this file.
00001 #include "HistogramDisplay.hpp"
00002 
00003 #include <tuttle/plugin/opengl/gl.h>
00004 #include <boost/gil/extension/color/hsv.hpp>
00005 
00006 namespace tuttle {
00007 namespace plugin {
00008 namespace histogram {
00009 
00010 /**
00011  * Display the given vector on screen
00012  * @param v specific vector to display on overlay
00013  * @param step step of the display
00014  * @param height maximal height
00015  * @param width maximal width
00016  * @param color color used to display
00017  */
00018 void displayASpecificHistogram(const HistogramVector& v,const HistogramVector& selection_v, const double step, const double height, const double width, const HistogramColor color,float selectionMultiplier)
00019 {
00020         if(v.size())
00021         {
00022                 //maximum data in the current channel vector
00023                 const Number max_value = *(std::max_element(v.begin(),v.end()));
00024                 const float ratio = height/max_value;
00025                 //OpenGL 2.X
00026                 glEnable(GL_BLEND);
00027                 glBlendFunc(GL_ONE, GL_ONE); //additive blending active
00028                 glColor3f(color._colorFill.r, color._colorFill.g, color._colorFill.b);
00029                 //Display option
00030                 glBegin( GL_QUAD_STRIP );
00031                 double base_step = 0.0;//first point
00032                 for(unsigned int i=0; i<v.size(); ++i)
00033                 {
00034                         const float value = (float)(v.at(i)*ratio);
00035                         float selection_value = (float)(selection_v.at(i)*ratio);
00036                         selection_value*= selectionMultiplier;
00037                         if(selection_value > value) //if selection value is bigger than normal value replace it
00038                                 selection_value = value;
00039                         glVertex2f((float)(base_step), (float)(value));
00040                         glVertex2f((float)(base_step), (float)(selection_value));
00041                         base_step += step;
00042                 }
00043                 glVertex2f((float)width,0.0f);//last point
00044                 glEnd();
00045                 glDisable(GL_BLEND);
00046         }
00047 }
00048 
00049 /**
00050  * Display the given vector on screen (only border)
00051  * @param v specific vector to display on overlay
00052  * @param step step of the display
00053  * @param height maximal height
00054  * @param width maximal width
00055  * @param color color used to display
00056  */
00057 void displayASpecificHistogramBorder(const HistogramVector& v, const double step, const double height, const double width, const HistogramColor color)
00058 {
00059         //Draw the border line
00060         glBegin( GL_LINE_STRIP );
00061         //maximum data in the current channel vector
00062         const Number max_value = *(std::max_element(v.begin(),v.end()));
00063         const float ratio = height/max_value;
00064         double base_step = 0.0;
00065         glColor3f(color._colorBorder.r, color._colorBorder.g, color._colorBorder.b);
00066         for(unsigned int i=0; i<v.size(); ++i)
00067         {
00068                 const float value = (float)(v.at(i)*ratio);
00069                 glVertex2f((float)(base_step), float(value));
00070                 base_step += step;
00071         }
00072         glEnd();
00073 }
00074 
00075 /**
00076  * display selection points under the histograms
00077  * @param selection_v buffer which contains all of the selection points
00078  * @param step step for display
00079  * @param width width of the source clip
00080  * @param color color using for display
00081  */
00082 void displaySelectionPoints(const HistogramVector& selection_v, const double step, const double width, const HistogramColor color)
00083 {
00084         glBegin( GL_POINTS );
00085         double base_step = 0.0;
00086         glColor3f(color._colorBorder.r, color._colorBorder.g, color._colorBorder.b);
00087         for(unsigned int i=0; i<selection_v.size(); ++i)
00088         {
00089                 if(selection_v.at(i) != 0)
00090                 {
00091                         glVertex2f((float)(base_step), -10.0f);
00092                 }       
00093                 base_step += step;
00094         }
00095         glEnd();
00096 }
00097 
00098 /**
00099  * display the red indicator (openGL)
00100  * @param size size of the source clip
00101  */
00102 void displayRedIndicator(const OfxPointI size)
00103 {
00104         double heightIndicator = (size.y-10)*0.07;
00105         double width = size.x;
00106         
00107         glPushMatrix();
00108         glTranslated(0.0f,-20.0f,0.0f);
00109         glBegin( GL_QUADS);
00110         
00111         glColor3f(0.0f, 0.0f, 0.0f);    
00112         glVertex2f(0.0f,0.0f);
00113         
00114         glColor3f(1.0f, 0.0f, 0.0f);    
00115         glVertex2f((float)width,0.0f);
00116         
00117         glColor3f(1.0f, 0.0f, 0.0f);    
00118         glVertex2f((float)width,(float)(-heightIndicator));
00119         
00120         glColor3f(0.0f, 0.0f, 0.0f);    
00121         glVertex2f(0.0f,(float)(-heightIndicator));
00122         glEnd();
00123         glPopMatrix();
00124         
00125 }
00126 
00127 /**
00128  * display the green indicator (openGL)
00129  * @param size size of the source clip
00130  */
00131 void displayGreenIndicator(const OfxPointI size)
00132 {
00133         double heightIndicator = size.y*0.07;
00134         double width = size.x;
00135         
00136         glPushMatrix();
00137         glTranslated(0.0f,-20.0f,0.0f);
00138         glBegin( GL_QUADS);
00139         
00140         glColor3f(0.0f, 0.0f, 0.0f);    
00141         glVertex2f(0.0f,0.0f);
00142         
00143         glColor3f(0.0f, 1.0f, 0.0f);    
00144         glVertex2f((float)width,0.0f);
00145         
00146         glColor3f(0.0f, 1.0f, 0.0f);    
00147         glVertex2f((float)width,(float)(-heightIndicator));
00148         
00149         glColor3f(0.0f, 0.0f, 0.0f);    
00150         glVertex2f(0.0f,(float)(-heightIndicator));
00151         glEnd();
00152         glPopMatrix();
00153         
00154 }
00155 
00156 /**
00157  * display the green indicator (openGL)
00158  * @param size size of the source clip
00159  */
00160 void displayBlueIndicator(const OfxPointI size)
00161 {
00162         double heightIndicator = size.y*0.07;
00163         double width = size.x;
00164         
00165         glPushMatrix();
00166         glTranslated(0.0f,-20.0f,0.0f);
00167         
00168         glBegin( GL_QUADS);
00169         
00170         glColor3f(0.0f, 0.0f, 0.0f);    
00171         glVertex2f(0.0f,0.0f);
00172         
00173         glColor3f(0.0f, 0.0f, 1.0f);    
00174         glVertex2f((float)width,0.0f);
00175         
00176         glColor3f(0.0f, 0.0f, 1.0f);    
00177         glVertex2f((float)width,(float)(-heightIndicator));
00178         
00179         glColor3f(0.0f, 0.0f, 0.0f);    
00180         glVertex2f(0.0f,(float)(-heightIndicator));
00181         glEnd();
00182         glPopMatrix();
00183 }
00184 
00185 /**
00186  * display the lightness indicator (openGL)
00187  * @param size size of the source clip
00188  */
00189 void displayLightnessIndicator(const OfxPointI size)
00190 {
00191         double heightIndicator = size.y*0.07;
00192         double width = size.x;
00193         
00194         glPushMatrix();
00195         glTranslated(0.0f,-20.0f,0.0f);
00196         glBegin( GL_QUADS);
00197         
00198         glColor3f(0.0f, 0.0f, 0.0f);    
00199         glVertex2f(0.0f,0.0f);
00200         
00201         glColor3f(1.0f, 1.0f, 1.0f);    
00202         glVertex2f((float)width,0.0f);
00203         
00204         glColor3f(1.0f, 1.0f, 1.0f);    
00205         glVertex2f((float)width,(float)(-heightIndicator));
00206         
00207         glColor3f(0.0f, 0.0f, 0.0f);    
00208         glVertex2f(0.0f,(float)(-heightIndicator));
00209         glEnd();
00210         glPopMatrix();
00211 }
00212 
00213 /**
00214  * display the saturation indicator (openGL)
00215  * @param size size of the source clip
00216  */
00217 void displaySaturationIndicator(const OfxPointI size)
00218 {
00219         double heightIndicator = size.y*0.07;
00220         double width = size.x;
00221         
00222         glPushMatrix();
00223         glTranslated(0.0f,-20.0f,0.0f);
00224         glBegin( GL_QUADS);
00225         
00226         glColor3f(0.5f, 0.5f, 0.5f);    
00227         glVertex2f(0.0f,0.0f);
00228         
00229         glColor3f(1.0f, 0.0f, 0.0f);    
00230         glVertex2f((float)width,0.0f);
00231         
00232         glColor3f(1.0f, 0.0f, 0.0f);    
00233         glVertex2f((float)width,(float)(-heightIndicator));
00234         
00235         glColor3f(0.5f, 0.5f, 0.5f);    
00236         glVertex2f(0.0f,(float)(-heightIndicator));
00237         glEnd();
00238         glPopMatrix();
00239 }
00240 
00241 /**
00242  * display the hue indicator (openGL)
00243  * @param size size of the source clip
00244  * @param precisionHueIndicator number of step of the indicator
00245  */
00246 void displayHueIndicator(const OfxPointI size, int precisionHueIndicator)
00247 {
00248         static const float length = 360.0;      
00249         const double heightIndicator = size.y*0.07;
00250         const double width = size.x;
00251         glPushMatrix();
00252         glTranslated(0.0f,-20.0f,0.0f);
00253         glBegin( GL_QUAD_STRIP);
00254         const float ratio = length / (float)(kPrecisionHueIndicator-1.0);
00255         float hue = 0.0f;
00256         for( std::ssize_t i = 0; i < precisionHueIndicator; ++i )
00257         {
00258                 boost::gil::hsv32f_pixel_t hsl_pix;                     //declare a HSL pixel
00259                 boost::gil::rgb32f_pixel_t pix(0,0,0);                  //declare a RGB pixel (don't need alpha)
00260                 hsl_pix[0] = (float)(hue/length);                       //fill up HSL pixel
00261                 hsl_pix[1] = (float)(1.0);
00262                 hsl_pix[2] = (float)(1.0);
00263                 
00264                 color_convert(hsl_pix, pix);                            //convert HSL=>RGB for OpenGl 
00265                 glColor3f(pix[0],pix[1],pix[2]);                        //generate openGL color
00266                 
00267                 glVertex2f(hue*(width/length),-0.0f);   
00268                 glVertex2f(hue*(width/length),(float)(-heightIndicator));       //draw quad
00269                 hue+=ratio;
00270         }
00271         glEnd();
00272         glPopMatrix();
00273 }
00274 
00275 /**
00276  * Display an average bar on screen
00277  * @param average average of the current channel
00278  * @param color color chosed to display
00279  * @param width width of the image (1 into Nuke overlay)
00280  * @param height height of the image
00281  * @param step (image width/nbstep in histograms buffers)
00282  */
00283 void displayAverageBar(const int average, HistogramColor color, const int width, const int height,const double step)
00284 {
00285         if(average ==0)
00286                 return;
00287         float _average = average*step;
00288         glColor3f(color._colorBorder.r, color._colorBorder.g, color._colorBorder.b);
00289         glBegin(GL_LINES);
00290         glVertex2i((float)(_average),0.0f);
00291         glVertex2i((float)(_average),(float)height);
00292         glEnd();
00293 }
00294 
00295 }
00296 }
00297 }