Skip to content
Permalink
Browse files

[FEATURE] Add colorize control for raster layers

  • Loading branch information
nyalldawson committed Mar 26, 2013
1 parent 3d02fbe commit f5431f4fdb371e600fe657b1198f7187cd8fdaf9
@@ -90,6 +90,9 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv
// 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 ) ) );

// enable or disable Build Pyramids button depending on selection in pyramid list
connect( lbxPyramidResolutions, SIGNAL( itemSelectionChanged() ), this, SLOT( toggleBuildPyramidsButton() ) );

@@ -262,7 +265,12 @@ 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
mColorizeCheck->setChecked( hueSaturationFilter->colorizeOn() );
btnColorizeColor->setEnabled( hueSaturationFilter->colorizeOn() );
btnColorizeColor->setColor( hueSaturationFilter->colorizeColor() );
}

//blend mode
mBlendModeComboBox->setBlendMode( mRasterLayer->blendMode() );
@@ -828,6 +836,8 @@ void QgsRasterLayerProperties::apply()
{
hueSaturationFilter->setSaturation( sliderSaturation->value() );
hueSaturationFilter->setGrayscaleMode(( QgsHueSaturationFilter::GrayscaleMode ) comboGrayscale->currentIndex() );
hueSaturationFilter->setColorizeOn( mColorizeCheck->checkState() );
hueSaturationFilter->setColorizeColor( btnColorizeColor->color() );
}


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

@@ -129,7 +131,7 @@ QgsRasterBlock * QgsHueSaturationFilter::block( int bandNo, QgsRectangle const
return outputBlock;
}

if ( mSaturation == 0 && mGrayscaleMode == GrayscaleOff )
if ( mSaturation == 0 && mGrayscaleMode == GrayscaleOff && !mColorizeOn )
{
QgsDebugMsg( "No hue/saturation change." );
delete outputBlock;
@@ -151,6 +153,11 @@ QgsRasterBlock * QgsHueSaturationFilter::block( int bandNo, QgsRectangle const
// Scale saturation value to [0-2], where 0 = desaturated
double saturationScale = (( double ) mSaturation / 100 ) + 1;

// Get hue, saturation for colorized color
int colorizeH, colorizeS;
colorizeH = mColorizeColor.hue();
colorizeS = mColorizeColor.saturation();

for ( size_t i = 0; i < ( size_t )width*height; i++ )
{
if ( inputBlock->color( i ) == myNoDataColor )
@@ -208,6 +215,18 @@ QgsRasterBlock * QgsHueSaturationFilter::block( int bandNo, QgsRectangle const
}
}

// Colorizing?
if ( mColorizeOn )
{
// Update hsl values (these may have changed with saturation/grayscale adjustments)
myColor.getHsl( &h, &s, &l );

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

// Convert back to rgb
outputBlock->setColor( i, myColor.rgb() );
}
@@ -227,6 +246,11 @@ void QgsHueSaturationFilter::writeXML( QDomDocument& doc, QDomElement& parentEle

filterElem.setAttribute( "saturation", QString::number( mSaturation ) );
filterElem.setAttribute( "grayscaleMode", QString::number( mGrayscaleMode ) );
filterElem.setAttribute( "colorizeOn", QString::number( mColorizeOn ) );
filterElem.setAttribute( "colorizeRed", QString::number( mColorizeColor.red() ) );
filterElem.setAttribute( "colorizeGreen", QString::number( mColorizeColor.green() ) );
filterElem.setAttribute( "colorizeBlue", QString::number( mColorizeColor.blue() ) );

parentElem.appendChild( filterElem );
}

@@ -239,4 +263,11 @@ void QgsHueSaturationFilter::readXML( const QDomElement& filterElem )

mSaturation = filterElem.attribute( "saturation", "0" ).toInt();
mGrayscaleMode = ( QgsHueSaturationFilter::GrayscaleMode )filterElem.attribute( "grayscaleMode", "0" ).toInt();

mColorizeOn = ( bool )filterElem.attribute( "colorizeOn", "0" ).toInt();
int mColorizeRed = filterElem.attribute( "colorizeRed", "255" ).toInt();
int mColorizeGreen = filterElem.attribute( "colorizeGreen", "0" ).toInt();
int mColorizeBlue = filterElem.attribute( "colorizeBlue", "0" ).toInt();
mColorizeColor = QColor::fromRgb( mColorizeRed, mColorizeGreen, mColorizeBlue );

}
@@ -58,6 +58,11 @@ class CORE_EXPORT QgsHueSaturationFilter : public QgsRasterInterface
void setGrayscaleMode( QgsHueSaturationFilter::GrayscaleMode grayscaleMode ) { mGrayscaleMode = grayscaleMode; }
QgsHueSaturationFilter::GrayscaleMode grayscaleMode() const { return mGrayscaleMode; }

void setColorizeOn( bool colorizeOn ) { mColorizeOn = colorizeOn; }
bool colorizeOn() const { return mColorizeOn; }
void setColorizeColor( QColor colorizeColor ) { mColorizeColor = colorizeColor; }
QColor colorizeColor() const { return mColorizeColor; }

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

/**Sets base class members from xml. Usually called from create() methods of subclasses*/
@@ -70,6 +75,10 @@ class CORE_EXPORT QgsHueSaturationFilter : public QgsRasterInterface
/**Current grayscale mode*/
QgsHueSaturationFilter::GrayscaleMode mGrayscaleMode;

/**Colorize settings*/
bool mColorizeOn;
QColor mColorizeColor;

};

#endif // QGSHUESATURATIONFILTER_H
@@ -288,7 +288,7 @@
</property>
</widget>
</item>
<item row="0" column="2">
<item row="0" column="3">
<widget class="QSpinBox" name="spinBoxSaturation">
<property name="minimum">
<number>-100</number>
@@ -311,14 +311,14 @@
</property>
</widget>
</item>
<item row="0" column="4">
<item row="0" column="5">
<widget class="QLabel" name="labelGrayscale">
<property name="text">
<string>Grayscale</string>
</property>
</widget>
</item>
<item row="0" column="5">
<item row="0" column="6">
<widget class="QComboBox" name="comboGrayscale">
<item>
<property name="text">
@@ -342,6 +342,26 @@
</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>
</layout>
</widget>
</item>
@@ -1403,6 +1423,11 @@ p, li { white-space: pre-wrap; }
<extends>QComboBox</extends>
<header>qgsblendmodecombobox.h</header>
</customwidget>
<customwidget>
<class>QgsColorButton</class>
<extends>QPushButton</extends>
<header>qgscolorbutton.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tabBar</tabstop>

0 comments on commit f5431f4

Please sign in to comment.
You can’t perform that action at this time.