Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add gamma controls to the raster layer properties
  • Loading branch information
alexbruy committed Jun 30, 2020
1 parent ccae627 commit f37ac2e
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 80 deletions.
27 changes: 25 additions & 2 deletions src/gui/raster/qgsrasterlayerproperties.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgsgui.h"
#include "qgsapplication.h"
#include "qgsbrightnesscontrastfilter.h"
#include "qgsgammacorrectionfilter.h"
#include "qgscontrastenhancement.h"
#include "qgscoordinatetransform.h"
#include "qgsprojectionselectiondialog.h"
Expand Down Expand Up @@ -163,6 +164,10 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
connect( mSliderContrast, &QAbstractSlider::valueChanged, mContrastSpinBox, &QSpinBox::setValue );
connect( mContrastSpinBox, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), mSliderContrast, &QAbstractSlider::setValue );

// gamma correction controls
connect( mSliderGamma, &QAbstractSlider::valueChanged, this, &QgsRasterLayerProperties::updateGammaSpinBox );
connect( mGammaSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsRasterLayerProperties::updateGammaSlider );

// Connect saturation slider and spin box
connect( sliderSaturation, &QAbstractSlider::valueChanged, spinBoxSaturation, &QSpinBox::setValue );
connect( spinBoxSaturation, static_cast < void ( QSpinBox::* )( int ) > ( &QSpinBox::valueChanged ), sliderSaturation, &QAbstractSlider::setValue );
Expand Down Expand Up @@ -753,17 +758,23 @@ void QgsRasterLayerProperties::sync()
QgsDebugMsg( QStringLiteral( "populate transparency tab" ) );

/*
* Style tab (brightness and contrast)
* Style tab
*/

//set brightness and contrast
QgsBrightnessContrastFilter *brightnessFilter = mRasterLayer->brightnessFilter();
if ( brightnessFilter )
{
mSliderBrightness->setValue( brightnessFilter->brightness() );
mSliderContrast->setValue( brightnessFilter->contrast() );
}

//set the transparency slider
//set gamma
QgsGammaCorrectionFilter *gammaFilter = mRasterLayer->gammaCorrectionFilter();
if ( gammaFilter )
{
mGammaSpinBox->setValue( gammaFilter->gamma() );
}

/*
* Transparent Pixel Tab
Expand Down Expand Up @@ -927,6 +938,7 @@ void QgsRasterLayerProperties::apply()

mRasterLayer->brightnessFilter()->setBrightness( mSliderBrightness->value() );
mRasterLayer->brightnessFilter()->setContrast( mSliderContrast->value() );
mRasterLayer->gammaCorrectionFilter()->setGamma( mGammaSpinBox->value() );

QgsDebugMsg( QStringLiteral( "processing transparency tab" ) );
/*
Expand Down Expand Up @@ -2312,6 +2324,7 @@ void QgsRasterLayerProperties::mResetColorRenderingBtn_clicked()
mBlendModeComboBox->setBlendMode( QPainter::CompositionMode_SourceOver );
mSliderBrightness->setValue( 0 );
mSliderContrast->setValue( 0 );
mGammaSpinBox->setValue( 1 );
sliderSaturation->setValue( 0 );
comboGrayscale->setCurrentIndex( ( int ) QgsHueSaturationFilter::GrayscaleOff );
mColorizeCheck->setChecked( false );
Expand Down Expand Up @@ -2359,3 +2372,13 @@ void QgsRasterLayerProperties::showHelp()
QgsHelp::openHelp( QStringLiteral( "working_with_raster/raster_properties.html" ) );
}
}

void QgsRasterLayerProperties::updateGammaSpinBox( int value )
{
whileBlocking( mGammaSpinBox )->setValue( value / 100.0 );
}

void QgsRasterLayerProperties::updateGammaSlider( double value )
{
whileBlocking( mSliderGamma )->setValue( value * 100 );
}
10 changes: 10 additions & 0 deletions src/gui/raster/qgsrasterlayerproperties.h
Expand Up @@ -125,7 +125,17 @@ class GUI_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private

void pixelSelected( const QgsPointXY &, const Qt::MouseButton & );

/**
* updates gamma spinbox on slider changes
* \since QGIS 3.16
*/
void updateGammaSpinBox( int value );

/**
* updates gamma slider on spinbox changes
* \since QGIS 3.16
*/
void updateGammaSlider( double value );

void mRenderTypeComboBox_currentIndexChanged( int index );
//! Load the default style when appropriate button is pressed.
Expand Down

0 comments on commit f37ac2e

Please sign in to comment.