TonicTones
Src/Operators/ReinhardGlobalOperator/ReinhardGlobalOperator.cpp
00001 //      ReinhardGlobalOperator.cpp
00002 //      
00003 //      Copyright 2010 Jérémy Laumon <jeremy.laumon@gmail.com>
00004 //      
00005 //      This program is free software; you can redistribute it and/or modify
00006 //      it under the terms of the GNU General Public License as published by
00007 //      the Free Software Foundation; either version 2 of the License, or
00008 //      (at your option) any later version.
00009 //      
00010 //      This program is distributed in the hope that it will be useful,
00011 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //      GNU General Public License for more details.
00014 //      
00015 //      You should have received a copy of the GNU General Public License
00016 //      along with this program; if not, write to the Free Software
00017 //      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00018 //      MA 02110-1301, USA.
00019 
00020 
00021 #include <ReinhardGlobalOperator.h>
00022 #include <Exceptions.h>
00023 #include <math.h>
00024 
00025 #define OPERATOR_NAME "Reinhard Global Operator"
00026 
00027 Q_EXPORT_PLUGIN2(TT_ReinhardGlobalOperator, ReinhardGlobalOperatorFactory)
00028 
00029 
00038 ReinhardGlobalOperator::ReinhardGlobalOperator() :
00039     inputImage(NULL),
00040     outputImage(NULL),
00041     avLum(0.0),
00042     keyValue(0.18),
00043     burnOut(false),
00044     lumWhite2(1.0)
00045 {
00046     
00047 }
00048 
00049 void ReinhardGlobalOperator::setupUi(QWidget* parent)
00050 {
00051     ui.setupUi(parent);
00052     
00053     connect(ui.keyValueSlider, SIGNAL(sliderReleased()), this, SLOT(toneMap()));
00054     connect(ui.keyValueSlider, SIGNAL(valueChanged(int)), this, SLOT(updateKeyValue(int)));
00055     connect(ui.burnOutGroupBox, SIGNAL(toggled(bool)), this, SLOT(updateBurnOut(bool)));
00056     connect(ui.whiteValueSpinBox, SIGNAL(editingFinished()), this, SLOT(updateLumWhite()));
00057     connect(ui.whiteValueOkButton, SIGNAL(clicked()), this, SLOT(toneMap()));
00058 }
00059 
00063 QString ReinhardGlobalOperator::name() const
00064 {
00065     return tr(OPERATOR_NAME);
00066 }
00067 
00068 const HdrImage* ReinhardGlobalOperator::getToneMappedImage() const
00069 {
00070     return outputImage;
00071 }
00072 
00078 void ReinhardGlobalOperator::setImage(const HdrImage* image)
00079 {
00080     if (!image->hasY())
00081         throw Exception(tr("Image passed to %1 does not contains Y data. Cannot turn water into wine.").arg(name()));
00082     
00083     QTime t;
00084     t.start();
00085     
00086     inputImage = image;
00087     QSize size = inputImage->size();
00088     delete outputImage;
00089     outputImage = new HdrImage(*inputImage);
00090     const double delta = 0.0001;
00091     float lumMax = 0.f;
00092 
00093     //compute avLum and lumMax
00094     //TO COMPLETE
00095     
00096     ui.whiteValueSpinBox->setMaximum(qMin(lumMax,float(1e19)));
00097     ui.whiteValueSpinBox->setValue(qMin(lumMax,float(1e19)));
00098     ui.keyValueSlider->setValue(18); // = 0.18
00099     ui.burnOutGroupBox->setChecked(false);
00100     
00101     msg = tr("Operator Init: %1 ms").arg(t.elapsed());
00102     
00103     toneMap();
00104 }
00105 
00111 void ReinhardGlobalOperator::toneMap()
00112 {
00113     if (inputImage)
00114     {
00115         QTime t;
00116         t.start();
00117         
00118         QSize size = inputImage->size();
00119         int width = size.width();
00120         int height = size.height();
00121         int Y = inputImage->YIndex();
00122 
00123         //apply the luminance modification
00124         if(burnOut) {
00125             //TO COMPLETE
00126         } else {
00127             //TO COMPLETE
00128         }
00129         
00130         emit message(msg + tr("  Tone Mapping: %1 ms").arg(t.elapsed()));
00131                 
00132         emit imageUpdated();
00133     }
00134 }
00135 
00141 void ReinhardGlobalOperator::updateKeyValue(int value)
00142 {
00143     keyValue = float(value)/100.0;
00144     ui.keyValue->setText(QString("%1").arg(keyValue, 0, 'f', 2));
00145 }
00146 
00153 void ReinhardGlobalOperator::updateBurnOut(bool enabled)
00154 {
00155     burnOut = enabled;
00156     updateLumWhite();
00157 }
00158 
00165 void ReinhardGlobalOperator::updateLumWhite()
00166 {
00167     float value = ui.whiteValueSpinBox->value();
00168     lumWhite2 = value*value;
00169     toneMap();
00170 }
00171 
00172 //----------------------------------------------------------------------
00173 
00184 ToneMappingOperatorPtr ReinhardGlobalOperatorFactory::createOperator() const
00185 {
00186     return ToneMappingOperatorPtr(new ReinhardGlobalOperator);
00187 }
00188 
00192 QString ReinhardGlobalOperatorFactory::operatorName() const
00193 {
00194     return tr(OPERATOR_NAME);
00195 }
 All Classes Functions Variables