Skip to content

Commit

Permalink
Added luma weighted grain
Browse files Browse the repository at this point in the history
  • Loading branch information
masc4ii committed Nov 25, 2020
1 parent fef883d commit ae954d1
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 24 deletions.
19 changes: 19 additions & 0 deletions platform/qt/MainWindow.cpp
Expand Up @@ -3694,6 +3694,11 @@ void MainWindow::readXmlElementsFromFile(QXmlStreamReader *Rxml, ReceiptSettings
receipt->setGrainStrength( Rxml->readElementText().toInt() );
Rxml->readNext();
}
else if( Rxml->isStartElement() && Rxml->name() == "grainLumaWeight" )
{
receipt->setGrainLumaWeight( (bool)Rxml->readElementText().toInt() );
Rxml->readNext();
}
else if( Rxml->isStartElement() && Rxml->name() == "rawFixesEnabled" )
{
receipt->setRawFixesEnabled( (bool)Rxml->readElementText().toInt() );
Expand Down Expand Up @@ -3995,6 +4000,7 @@ void MainWindow::writeXmlElementsToFile(QXmlStreamWriter *xmlWriter, ReceiptSett
xmlWriter->writeTextElement( "rbfDenoiserChroma", QString( "%1" ).arg( receipt->rbfDenoiserChroma() ) );
xmlWriter->writeTextElement( "rbfDenoiserRange", QString( "%1" ).arg( receipt->rbfDenoiserRange() ) );
xmlWriter->writeTextElement( "grainStrength", QString( "%1" ).arg( receipt->grainStrength() ) );
xmlWriter->writeTextElement( "grainLumaWeight", QString( "%1" ).arg( receipt->grainLumaWeightEnabled() ) );
xmlWriter->writeTextElement( "rawFixesEnabled", QString( "%1" ).arg( receipt->rawFixesEnabled() ) );
xmlWriter->writeTextElement( "verticalStripes", QString( "%1" ).arg( receipt->verticalStripes() ) );
xmlWriter->writeTextElement( "focusPixels", QString( "%1" ).arg( receipt->focusPixels() ) );
Expand Down Expand Up @@ -4251,6 +4257,7 @@ void MainWindow::setSliders(ReceiptSettings *receipt, bool paste)
ui->horizontalSliderRbfDenoiseRange->setValue( receipt->rbfDenoiserRange() );

ui->horizontalSliderGrainStrength->setValue( receipt->grainStrength() );
ui->checkBoxGrainLumaWeight->setChecked( receipt->grainLumaWeightEnabled() );

ui->checkBoxRawFixEnable->setChecked( receipt->rawFixesEnabled() );
on_checkBoxRawFixEnable_clicked( receipt->rawFixesEnabled() );
Expand Down Expand Up @@ -4468,6 +4475,7 @@ void MainWindow::setReceipt( ReceiptSettings *receipt )
receipt->setRbfDenoiserChroma( ui->horizontalSliderRbfDenoiseChroma->value() );
receipt->setRbfDenoiserRange( ui->horizontalSliderRbfDenoiseRange->value() );
receipt->setGrainStrength( ui->horizontalSliderGrainStrength->value() );
receipt->setGrainLumaWeight( ui->checkBoxGrainLumaWeight->isChecked() );

receipt->setRawFixesEnabled( ui->checkBoxRawFixEnable->isChecked() );
receipt->setVerticalStripes( toolButtonVerticalStripesCurrentIndex() );
Expand Down Expand Up @@ -4592,6 +4600,7 @@ void MainWindow::replaceReceipt(ReceiptSettings *receiptTarget, ReceiptSettings
if( paste && cdui->checkBoxDenoise->isChecked() ) receiptTarget->setRbfDenoiserChroma( receiptSource->rbfDenoiserChroma() );
if( paste && cdui->checkBoxDenoise->isChecked() ) receiptTarget->setRbfDenoiserRange( receiptSource->rbfDenoiserRange() );
if( paste && cdui->checkBoxGrain->isChecked() ) receiptTarget->setGrainStrength( receiptSource->grainStrength() );
if( paste && cdui->checkBoxGrain->isChecked() ) receiptTarget->setGrainLumaWeight( receiptSource->grainLumaWeightEnabled() );

if( paste && cdui->checkBoxRawCorrectEnable->isChecked() ) receiptTarget->setRawFixesEnabled( receiptSource->rawFixesEnabled() );
if( paste && cdui->checkBoxDarkFrameSubtraction->isChecked() ) receiptTarget->setDarkFrameFileName( receiptSource->darkFrameFileName() );
Expand Down Expand Up @@ -4783,6 +4792,7 @@ void MainWindow::addClipToExportQueue(int row, QString fileName)
receipt->setRbfDenoiserChroma( GET_RECEIPT( row )->rbfDenoiserChroma() );
receipt->setRbfDenoiserRange( GET_RECEIPT( row )->rbfDenoiserRange() );
receipt->setGrainStrength( GET_RECEIPT( row )->grainStrength() );
receipt->setGrainLumaWeight( GET_RECEIPT( row )->grainLumaWeightEnabled() );

receipt->setRawFixesEnabled( GET_RECEIPT( row )->rawFixesEnabled() );
receipt->setVerticalStripes( GET_RECEIPT( row )->verticalStripes() );
Expand Down Expand Up @@ -5508,6 +5518,7 @@ void MainWindow::on_horizontalSliderGamma_valueChanged(int position)
{
double value = position / 100.0;
processingSetGamma( m_pProcessingObject, value );
//processingSetGammaAndTonemapping( m_pProcessingObject, value, processingGetTonemappingFunction( m_pProcessingObject ) );
ui->label_GammaVal->setText( QString("%1").arg( value, 0, 'f', 2 ) );
ui->lineEditTransferFunction->setText( processingGetTransferFunction( m_pProcessingObject ) );
m_frameChanged = true;
Expand Down Expand Up @@ -6511,6 +6522,14 @@ void MainWindow::on_checkBoxChromaSeparation_toggled(bool checked)
m_frameChanged = true;
}

//Enable / Disable grain luma weight
void MainWindow::on_checkBoxGrainLumaWeight_toggled(bool checked)
{
if( checked ) processingSetGrainLumaWeightEnable( m_pProcessingObject );
else processingSetGrainLumaWeightDisable( m_pProcessingObject );
m_frameChanged = true;
}

//Chose profile
void MainWindow::on_comboBoxProfile_currentIndexChanged(int index)
{
Expand Down
1 change: 1 addition & 0 deletions platform/qt/MainWindow.h
Expand Up @@ -171,6 +171,7 @@ private slots:
void on_checkBoxCreativeAdjustments_toggled(bool checked);
void on_checkBoxExrMode_toggled(bool checked);
void on_checkBoxChromaSeparation_toggled(bool checked);
void on_checkBoxGrainLumaWeight_toggled(bool checked);
void on_comboBoxProfile_currentIndexChanged(int index);
void on_comboBoxProfile_activated(int index);
void on_comboBoxTonemapFct_currentIndexChanged(int index);
Expand Down
60 changes: 36 additions & 24 deletions platform/qt/MainWindow.ui
Expand Up @@ -468,9 +468,9 @@ QGroupBox::indicator:checked:disabled {
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>266</width>
<height>5523</height>
<y>-2298</y>
<width>265</width>
<height>5491</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayoutScrollArea">
Expand Down Expand Up @@ -5534,6 +5534,36 @@ QGroupBox::indicator:checked:disabled {
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="2">
<widget class="DoubleClickLabel" name="label_GrainStrength">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_37">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="toolTip">
<string>Recursive bilateral filtering</string>
</property>
<property name="text">
<string>Grain Strength</string>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer_48">
<property name="orientation">
Expand Down Expand Up @@ -5578,33 +5608,15 @@ QGroupBox::indicator:checked:disabled {
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_37">
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="checkBoxGrainLumaWeight">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="toolTip">
<string>Recursive bilateral filtering</string>
</property>
<property name="text">
<string>Grain Strength</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="DoubleClickLabel" name="label_GrainStrength">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<string>Luma Weight</string>
</property>
</widget>
</item>
Expand Down
1 change: 1 addition & 0 deletions platform/qt/ReceiptSettings.cpp
Expand Up @@ -49,6 +49,7 @@ ReceiptSettings::ReceiptSettings()
m_rbfDenoiserChroma = 0;
m_rbfDenoiserRange = 40;
m_grainStrength = 0;
m_grainLumaWeightEnable = false;
m_highlightReconstruction = false;
m_useCamMatrix = 1;
m_chromaSeparation = false;
Expand Down
3 changes: 3 additions & 0 deletions platform/qt/ReceiptSettings.h
Expand Up @@ -55,6 +55,7 @@ class ReceiptSettings
void setRbfDenoiserChroma( int value ) {m_rbfDenoiserChroma = value;}
void setRbfDenoiserRange( int value ) {m_rbfDenoiserRange = value;}
void setGrainStrength( int value ) {m_grainStrength = value;}
void setGrainLumaWeight( bool on ) {m_grainLumaWeightEnable = on;}
void setHighlightReconstruction( bool on ){m_highlightReconstruction = on;}
void setCamMatrixUsed( uint8_t val ) {m_useCamMatrix = val;}
void setChromaSeparation( bool on ) {m_chromaSeparation = on;}
Expand Down Expand Up @@ -158,6 +159,7 @@ class ReceiptSettings
int rbfDenoiserChroma( void ){return m_rbfDenoiserChroma;}
int rbfDenoiserRange( void ){return m_rbfDenoiserRange;}
int grainStrength( void ){return m_grainStrength;}
bool grainLumaWeightEnabled( void ){return m_grainLumaWeightEnable;}
bool isHighlightReconstruction( void ){return m_highlightReconstruction;}
uint8_t camMatrixUsed( void ){return m_useCamMatrix;}
bool isChromaSeparation( void ){return m_chromaSeparation;}
Expand Down Expand Up @@ -270,6 +272,7 @@ class ReceiptSettings
int m_rbfDenoiserChroma;
int m_rbfDenoiserRange;
int m_grainStrength;
bool m_grainLumaWeightEnable;
bool m_highlightReconstruction;
uint8_t m_useCamMatrix;
bool m_chromaSeparation;
Expand Down
1 change: 1 addition & 0 deletions src/processing/processing_object.h
Expand Up @@ -188,6 +188,7 @@ typedef struct {

/* Grain Generator */
uint8_t grainStrength;
uint8_t grainLumaWeight;

/* Gradient */
double gradient_exposure_stops;
Expand Down
12 changes: 12 additions & 0 deletions src/processing/raw_processing.c
Expand Up @@ -174,6 +174,9 @@ processingObject_t * initProcessingObject()
processingSetHueVsCurves(processing, 0, NULL, NULL, 3);
processingSetVignetteStrength(processing, 0);

processingSetGrainStrength(processing, 0);
processingSetGrainLumaWeightDisable(processing);

/* Colour default parameters */
processingSetGamut(processing, GAMUT_Rec709);
processingSetTonemappingFunction(processing, TONEMAP_Reinhard);
Expand Down Expand Up @@ -536,10 +539,19 @@ void applyProcessingObject( processingObject_t * processing,
if( processing->grainStrength > 0 ) //Switch on/off
{
int strength = 50 * processing->grainStrength;
#pragma omp parallel for
for( int i = 0; i < img_s; i+=3 )
{
uint32_t randomval = randomseed1 ^ ((i*randomseed2) * (randomseed3-i) * (i+randomseed4));
int grain = ( randomval % strength ) - ( strength >> 2 ); //change value for strength

if( processing->grainLumaWeight )
{
uint32_t sumL = outputImage[i+0] + outputImage[i+1] + outputImage[i+2];
double weight = sumL / 1.5 / 65535.0;
grain *= weight;
}

outputImage[i+0] = LIMIT16( outputImage[i+0] + grain );
outputImage[i+1] = LIMIT16( outputImage[i+1] + grain );
outputImage[i+2] = LIMIT16( outputImage[i+2] + grain );
Expand Down
2 changes: 2 additions & 0 deletions src/processing/raw_processing.h
Expand Up @@ -170,6 +170,8 @@ void processingSet3WayCorrection( processingObject_t * processing,

/* Grain */
#define processingSetGrainStrength(processing, strength) (processing)->grainStrength = (strength)
#define processingSetGrainLumaWeightEnable(processing) (processing)->grainLumaWeight = 1
#define processingSetGrainLumaWeightDisable(processing) (processing)->grainLumaWeight = 0

/* Vignette */
void processingSetVignetteStrength(processingObject_t * processing, int8_t value);
Expand Down

0 comments on commit ae954d1

Please sign in to comment.