Skip to content
Permalink
Browse files
Add strength slider for raster colorization
  • Loading branch information
nyalldawson committed Mar 26, 2013
1 parent f5431f4 commit 3f4e2a033f245a8d454f02e42da24518b80dbc83
@@ -87,11 +87,15 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
connect( sliderSaturation, SIGNAL( valueChanged( int ) ), spinBoxSaturation, SLOT( setValue( int ) ) );
connect( spinBoxSaturation, SIGNAL( valueChanged( int ) ), sliderSaturation, SLOT( setValue( int ) ) );

// Connect colorize strength slider and spin box
connect( sliderColorizeStrength, SIGNAL( valueChanged( int ) ), spinColorizeStrength, SLOT( setValue( int ) ) );
connect( spinColorizeStrength, SIGNAL( valueChanged( int ) ), sliderColorizeStrength, SLOT( setValue( int ) ) );

// enable or disable saturation slider and spin box depending on grayscale combo choice
connect( comboGrayscale, SIGNAL( currentIndexChanged( int ) ), this, SLOT( toggleSaturationControls( int ) ) );

// enable or disable colorize colorbutton with colorize checkbox
connect( mColorizeCheck, SIGNAL( toggled( bool ) ), btnColorizeColor, SLOT( setEnabled( bool ) ) );
connect( mColorizeCheck, SIGNAL( toggled( bool ) ), this, SLOT( toggleColorizeControls( bool ) ) );

// enable or disable Build Pyramids button depending on selection in pyramid list
connect( lbxPyramidResolutions, SIGNAL( itemSelectionChanged() ), this, SLOT( toggleBuildPyramidsButton() ) );
@@ -265,12 +269,13 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv

// Set initial state of saturation controls based on grayscale mode choice
toggleSaturationControls( hueSaturationFilter->grayscaleMode() == QgsHueSaturationFilter::GrayscaleOff );
// Set initial state of colorize controls

// Set initial state of colorize controls
mColorizeCheck->setChecked( hueSaturationFilter->colorizeOn() );
btnColorizeColor->setEnabled( hueSaturationFilter->colorizeOn() );
btnColorizeColor->setColor( hueSaturationFilter->colorizeColor() );
}
toggleColorizeControls( hueSaturationFilter->colorizeOn() );
sliderColorizeStrength->setValue( hueSaturationFilter->colorizeStrength() );
}

//blend mode
mBlendModeComboBox->setBlendMode( mRasterLayer->blendMode() );
@@ -838,9 +843,9 @@ void QgsRasterLayerProperties::apply()
hueSaturationFilter->setGrayscaleMode(( QgsHueSaturationFilter::GrayscaleMode ) comboGrayscale->currentIndex() );
hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
hueSaturationFilter->setColorizeStrength( sliderColorizeStrength->value() );
}


//set the blend mode for the layer
mRasterLayer->setBlendMode(( QgsMapLayer::BlendMode ) mBlendModeComboBox->blendMode() );

@@ -1491,6 +1496,15 @@ void QgsRasterLayerProperties::toggleSaturationControls( int theValue )
}
}

void QgsRasterLayerProperties::toggleColorizeControls( bool colorizeEnabled )
{
// Enable or disable colorize controls based on checkbox
btnColorizeColor->setEnabled( colorizeEnabled );
sliderColorizeStrength->setEnabled( colorizeEnabled );
spinColorizeStrength->setEnabled( colorizeEnabled );
}


QLinearGradient QgsRasterLayerProperties::redGradient()
{
//define a gradient
@@ -106,6 +106,9 @@ class QgsRasterLayerProperties : public QDialog, private Ui::QgsRasterLayerPrope
/**Enable or disable saturation controls depending on choice of grayscale mode */
void toggleSaturationControls( int theValue );

/**Enable or disable colorize controls depending on checkbox */
void toggleColorizeControls( bool colorizeEnabled );

/** Update items in pipe list */
void pipeItemClicked( QTreeWidgetItem * item, int column );

@@ -27,7 +27,8 @@ QgsHueSaturationFilter::QgsHueSaturationFilter( QgsRasterInterface* input )
mSaturation( 0 ),
mGrayscaleMode( QgsHueSaturationFilter::GrayscaleOff ),
mColorizeOn( false ),
mColorizeColor( QColor::fromRgb( 255, 128, 128 ) )
mColorizeColor( QColor::fromRgb( 255, 128, 128 ) ),
mColorizeStrength( 100 )
{
}

@@ -218,13 +219,33 @@ QgsRasterBlock * QgsHueSaturationFilter::block( int bandNo, QgsRectangle const
// Colorizing?
if ( mColorizeOn )
{
// Update hsl values (these may have changed with saturation/grayscale adjustments)
// Update hsl, rgb values (these may have changed with saturation/grayscale adjustments)
myColor.getHsl( &h, &s, &l );
myColor.getRgb( &r, &g, &b );

// Overwrite hue and saturation with values from colorize color
h = colorizeH;
s = colorizeS;
myColor = QColor::fromHsl( h, s, l );
QColor colorizedColor = QColor::fromHsl( h, s, l );

if ( mColorizeStrength == 100 )
{
// Full strength
myColor = colorizedColor;
}
else
{
// Get rgb for colorized color
int colorizedR, colorizedG, colorizedB;
colorizedColor.getRgb( &colorizedR, &colorizedG, &colorizedB );

// Now, linearly scale by colorize strength
double p = ( double ) mColorizeStrength / 100.;
r = p * colorizedR + ( 1 - p ) * r;
g = p * colorizedG + ( 1 - p ) * g;
b = p * colorizedB + ( 1 - p ) * b;
myColor = QColor::fromRgb( r, g, b );
}
}

// Convert back to rgb
@@ -250,6 +271,7 @@ void QgsHueSaturationFilter::writeXML( QDomDocument& doc, QDomElement& parentEle
filterElem.setAttribute( "colorizeRed", QString::number( mColorizeColor.red() ) );
filterElem.setAttribute( "colorizeGreen", QString::number( mColorizeColor.green() ) );
filterElem.setAttribute( "colorizeBlue", QString::number( mColorizeColor.blue() ) );
filterElem.setAttribute( "colorizeStrength", QString::number( mColorizeStrength ) );

parentElem.appendChild( filterElem );
}
@@ -269,5 +291,6 @@ void QgsHueSaturationFilter::readXML( const QDomElement& filterElem )
int mColorizeGreen = filterElem.attribute( "colorizeGreen", "0" ).toInt();
int mColorizeBlue = filterElem.attribute( "colorizeBlue", "0" ).toInt();
mColorizeColor = QColor::fromRgb( mColorizeRed, mColorizeGreen, mColorizeBlue );
mColorizeStrength = filterElem.attribute( "colorizeStrength", "100" ).toInt();

}
@@ -62,6 +62,8 @@ class CORE_EXPORT QgsHueSaturationFilter : public QgsRasterInterface
bool colorizeOn() const { return mColorizeOn; }
void setColorizeColor( QColor colorizeColor ) { mColorizeColor = colorizeColor; }
QColor colorizeColor() const { return mColorizeColor; }
void setColorizeStrength( int colorizeStrength ) { mColorizeStrength = colorizeStrength; }
int colorizeStrength() const { return mColorizeStrength; }

void writeXML( QDomDocument& doc, QDomElement& parentElem );

@@ -78,6 +80,7 @@ class CORE_EXPORT QgsHueSaturationFilter : public QgsRasterInterface
/**Colorize settings*/
bool mColorizeOn;
QColor mColorizeColor;
int mColorizeStrength;

};

@@ -288,7 +288,7 @@
</property>
</widget>
</item>
<item row="0" column="3">
<item row="0" column="4">
<widget class="QSpinBox" name="spinBoxSaturation">
<property name="minimum">
<number>-100</number>
@@ -311,14 +311,14 @@
</property>
</widget>
</item>
<item row="0" column="5">
<item row="0" column="6">
<widget class="QLabel" name="labelGrayscale">
<property name="text">
<string>Grayscale</string>
</property>
</widget>
</item>
<item row="0" column="6">
<item row="0" column="7">
<widget class="QComboBox" name="comboGrayscale">
<item>
<property name="text">
@@ -342,26 +342,72 @@
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsColorButton" name="btnColorizeColor">
<property name="maximumSize">
<size>
<width>64</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="mColorizeCheck">
<property name="text">
<string>Colorize</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QgsColorButton" name="btnColorizeColor">
<property name="maximumSize">
<size>
<width>64</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelColorizeStrength">
<property name="text">
<string>Strength</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="sliderColorizeStrength">
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>25</number>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="4">
<widget class="QSpinBox" name="spinColorizeStrength">
<property name="suffix">
<string>%</string>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>

0 comments on commit 3f4e2a0

Please sign in to comment.