[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/graphics/darkroom/src
From:       Cyrille Berger <cyb () lepi ! org>
Date:       2008-08-21 21:09:18
Message-ID: 1219352958.542097.24599.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 850626 by berger:

add a level processing of raw images
make post processing happen in floats

 M  +43 -0     Darkroom.cpp  
 M  +2 -0      Darkroom.h  
 M  +4 -4      LevelsOptions.ui  
 M  +34 -7     PostProcessor.cpp  


--- trunk/playground/graphics/darkroom/src/Darkroom.cpp #850625:850626
@@ -16,6 +16,7 @@
 
 #include "Darkroom.h"
 
+#include <cmath>
 #include <unistd.h>
 
 #include <QDesktopWidget>
@@ -323,6 +324,27 @@
   
   d->levelsOptions.ingradient->showMiddleCursor( true );
   
+  connect( d->levelsOptions.blackspin, SIGNAL(valueChanged(double)), \
SLOT(optionsChanged())); +  connect( d->levelsOptions.whitespin, \
SIGNAL(valueChanged(double)), SLOT(optionsChanged())); +  connect( \
d->levelsOptions.ingradient, SIGNAL(middleValueChanged(double)), \
SLOT(optionsChanged())); +
+  connect( d->levelsOptions.blackspin, SIGNAL(valueChanged(double)), \
d->levelsOptions.ingradient, SLOT(setLeftValue(double))); +  connect( \
d->levelsOptions.whitespin, SIGNAL(valueChanged(double)), \
d->levelsOptions.ingradient, SLOT(setRighttValue(double))); +
+  connect( d->levelsOptions.ingradient, SIGNAL(leftValueChanged(double)), \
d->levelsOptions.blackspin, SLOT(setValue(double))); +  connect( \
d->levelsOptions.ingradient, SIGNAL(rightValueChanged(double)), \
d->levelsOptions.whitespin, SLOT(setValue(double))); +  connect( \
d->levelsOptions.ingradient, SIGNAL(middleValueChanged(double)), this, \
SLOT(slotGammaValueChanged(double))); +
+
+  connect( d->levelsOptions.outblackspin, SIGNAL(valueChanged(double)), \
SLOT(optionsChanged())); +  connect( d->levelsOptions.outwhitespin, \
SIGNAL(valueChanged(double)), SLOT(optionsChanged())); +
+  connect( d->levelsOptions.outblackspin, SIGNAL(valueChanged(double)), \
d->levelsOptions.outgradient, SLOT(setLeftValue(double))); +  connect( \
d->levelsOptions.outwhitespin, SIGNAL(valueChanged(double)), \
d->levelsOptions.outgradient, SLOT(setRighttValue(double))); +
+  connect( d->levelsOptions.outgradient, SIGNAL(leftValueChanged(double)), \
d->levelsOptions.outblackspin, SLOT(setValue(double))); +  connect( \
d->levelsOptions.outgradient, SIGNAL(rightValueChanged(double)), \
d->levelsOptions.outwhitespin, SLOT(setValue(double))); +
   addDockWidget( Qt::LeftDockWidgetArea, levelsDockWidget );
 #endif
   
@@ -458,6 +480,13 @@
   processingOptions.setOption("RedCurve", curveToList(  d->redCurveWidget ) );
   processingOptions.setOption("GreenCurve", curveToList(  d->greenCurveWidget ) );
   processingOptions.setOption("BlueCurve", curveToList(  d->blueCurveWidget ) );
+  
+  // Set Levels options
+  processingOptions.setOption("InputBlackValue", \
d->levelsOptions.ingradient->leftValue() ); +  \
processingOptions.setOption("InputWhiteValue", \
d->levelsOptions.ingradient->rightValue() ); +  \
processingOptions.setOption("InputGamma", computeGamma() ); +  \
processingOptions.setOption("OutputBlackValue", \
d->levelsOptions.outgradient->leftValue() ); +  \
processingOptions.setOption("OutputWhiteValue", \
d->levelsOptions.outgradient->rightValue() );  #endif
 
   return processingOptions;
@@ -661,6 +690,20 @@
   d->histogramDockerWidget.histogramWidget->update();
 }
 
+void Darkroom::slotGammaValueChanged(double)
+{
+  d->levelsOptions.gammaspin->setNum( computeGamma() );
+}
+
+double Darkroom::computeGamma() const
+{
+  double delta = (double) ( d->levelsOptions.ingradient->rightValue() - \
d->levelsOptions.ingradient->leftValue() ) / 2.0; +  double mid = \
(double)d->levelsOptions.ingradient->leftValue() + delta; +  double tmp = \
(d->levelsOptions.ingradient->middleValue() - mid) / delta; +  return 1.0 / pow (10, \
tmp); +}
+
+
 void Darkroom::optionsChanged()
 {
   if( d->currentRawFile )
--- trunk/playground/graphics/darkroom/src/Darkroom.h #850625:850626
@@ -68,6 +68,7 @@
     void slotEnableNoiseReduction( bool );
     void slotHistogramTypeChanged(int);
     void optionsChanged();
+    void slotGammaValueChanged(double);
   protected:
     virtual void closeEvent(QCloseEvent *event);
   private:
@@ -80,6 +81,7 @@
     bool idling();
     void createCurveWidget( KCurve** curveWidget, const QString& dockTitle, const \
QString& objectName );  void cleanUp();
+    double computeGamma() const;
   private:
     struct Private;
     Private* const d;
--- trunk/playground/graphics/darkroom/src/LevelsOptions.ui #850625:850626
@@ -48,7 +48,7 @@
      <item>
       <layout class="QHBoxLayout" name="_2" >
        <item>
-        <widget class="QSpinBox" name="blackspin" >
+        <widget class="QDoubleSpinBox" name="blackspin" >
          <property name="buttonSymbols" >
           <enum>QAbstractSpinBox::PlusMinus</enum>
          </property>
@@ -103,7 +103,7 @@
         </spacer>
        </item>
        <item>
-        <widget class="QSpinBox" name="whitespin" >
+        <widget class="QDoubleSpinBox" name="whitespin" >
          <property name="buttonSymbols" >
           <enum>QAbstractSpinBox::PlusMinus</enum>
          </property>
@@ -141,7 +141,7 @@
      <item>
       <layout class="QHBoxLayout" name="_4" >
        <item>
-        <widget class="QSpinBox" name="outblackspin" >
+        <widget class="QDoubleSpinBox" name="outblackspin" >
          <property name="buttonSymbols" >
           <enum>QAbstractSpinBox::PlusMinus</enum>
          </property>
@@ -167,7 +167,7 @@
         </spacer>
        </item>
        <item>
-        <widget class="QSpinBox" name="outwhitespin" >
+        <widget class="QDoubleSpinBox" name="outwhitespin" >
          <property name="buttonSymbols" >
           <enum>QAbstractSpinBox::PlusMinus</enum>
          </property>
--- trunk/playground/graphics/darkroom/src/PostProcessor.cpp #850625:850626
@@ -123,17 +123,44 @@
   QList<QPointF> greenPoints = processingOptions.asPointFList( "GreenCurve" );
   QList<QPointF> bluePoints = processingOptions.asPointFList( "BlueCurve" );
   QString beginProgram = "const float exposure = " + QString::number( d->exposure ) \
                + ";\n";
-  QString program16Src = beginProgram + "const float lightTable[][2] = " + \
                valueListToCTL( lightPoints, 0xFFFF ) + ";";;
-  program16Src += "const float redTable[][2] = " + valueListToCTL( redPoints, 0xFFFF \
                ) + ";";;
-  program16Src += "const float greenTable[][2] = " + valueListToCTL( greenPoints, \
                0xFFFF ) + ";";;
-  program16Src += "const float blueTable[][2] = " + valueListToCTL( bluePoints, \
0xFFFF ) + ";";; +  QString program16Src = beginProgram + "const float \
lightTable[][2] = " + valueListToCTL( lightPoints, 1.0 ) + ";"; +  program16Src += \
"const float redTable[][2] = " + valueListToCTL( redPoints, 1.0 ) + ";"; +  \
program16Src += "const float greenTable[][2] = " + valueListToCTL( greenPoints, 1.0 ) \
+ ";"; +  program16Src += "const float blueTable[][2] = " + valueListToCTL( \
bluePoints, 1.0 ) + ";"; +  program16Src += "const float inputBlackValue = " + \
QString::number( processingOptions.asDouble("InputBlackValue") ) + ";"; +  \
program16Src += "const float inputWhiteValue = " + QString::number( \
processingOptions.asDouble("InputWhiteValue") ) + ";"; +  program16Src += "const \
float inputGamma = " + QString::number( processingOptions.asDouble("InputGamma") ) + \
";"; +  program16Src += "const float outputBlackValue = " + QString::number( \
processingOptions.asDouble("OutputBlackValue") ) + ";"; +  program16Src += "const \
float outputWhiteValue = " + QString::number( \
processingOptions.asDouble("OutputWhiteValue") ) + ";";  QString endProg = "\
+float intToFloat( int v ) \
+{ \
+  return v / 65535.0; \
+} \
+int floatToInt( float v ) \
+{ \
+  return v * 65535; \
+} \
+float adjustLevel( float v ) \
+{ \
+  if( v < inputBlackValue ) \
+  { \
+    return outputBlackValue; \
+  } else if( v > inputWhiteValue ) { \
+    return outputWhiteValue; \
+  } \
+  float a = (v - inputBlackValue) / (inputWhiteValue - inputBlackValue); \
+  a = (outputWhiteValue - outputBlackValue) * pow(a, (1.0 / inputGamma)); \
+  return (outputBlackValue + a); \
+} \
 void apply( int rIn, int gIn, int bIn, output int rOut, output int gOut, output int \
bOut) \  { \
-  rOut = interpolateCubic1D( redTable, interpolateCubic1D( lightTable, rIn * \
                exposure ) ); \
-  gOut = interpolateCubic1D( greenTable, interpolateCubic1D( lightTable, gIn * \
                exposure ) ); \
-  bOut = interpolateCubic1D( blueTable, interpolateCubic1D( lightTable, bIn * \
exposure ) ); \ +  rOut = floatToInt( interpolateCubic1D( redTable, \
interpolateCubic1D( lightTable, adjustLevel( intToFloat(rIn) ) * exposure ) ) ); \ +  \
gOut = floatToInt( interpolateCubic1D( greenTable, interpolateCubic1D( lightTable, \
adjustLevel( intToFloat(gIn) ) * exposure ) ) ); \ +  bOut = floatToInt( \
interpolateCubic1D( blueTable, interpolateCubic1D( lightTable, adjustLevel( \
intToFloat(bIn) ) * exposure ) ) ); \  }";
+  
+
   program16Src += endProg;
   OpenCTL::Module p16("apply");
   p16.setSource( program16Src.toAscii ().data());


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic