Skip to content
Permalink
Browse files
Fix branch to apply to current master
  • Loading branch information
nyalldawson committed Mar 27, 2013
2 parents 86a246a + 4435c4f commit 0f7e90b922fc43d667fb701f34a0ce1559aa7e7d
@@ -83,6 +83,13 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer* lyr, QgsMapCanv

connect( sliderTransparency, SIGNAL( valueChanged( int ) ), this, SLOT( sliderTransparency_valueChanged( int ) ) );

// brightness/contrast controls
connect( mSliderBrightness, SIGNAL( valueChanged( int ) ), mBrightnessSpinBox, SLOT( setValue( int ) ) );
connect( mBrightnessSpinBox, SIGNAL( valueChanged( int ) ), mSliderBrightness, SLOT( setValue( int ) ) );

connect( mSliderContrast, SIGNAL( valueChanged( int ) ), mContrastSpinBox, SLOT( setValue( int ) ) );
connect( mContrastSpinBox, SIGNAL( valueChanged( int ) ), mSliderContrast, SLOT( setValue( int ) ) );

// Connect saturation slider and spin box
connect( sliderSaturation, SIGNAL( valueChanged( int ) ), spinBoxSaturation, SLOT( setValue( int ) ) );
connect( spinBoxSaturation, SIGNAL( valueChanged( int ) ), sliderSaturation, SLOT( setValue( int ) ) );
@@ -561,6 +568,19 @@ void QgsRasterLayerProperties::sync()

QgsDebugMsg( "populate transparency tab" );

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

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

//set the transparency slider

/*
* Transparent Pixel Tab
*/
@@ -706,6 +726,9 @@ void QgsRasterLayerProperties::apply()
//set whether the layer histogram should be inverted
//mRasterLayer->setInvertHistogram( cboxInvertColorMap->isChecked() );

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

QgsDebugMsg( "processing transparency tab" );
/*
* Transparent Pixel Tab
@@ -18,6 +18,7 @@
#include "qgsrasterdataprovider.h"
#include "qgsbrightnesscontrastfilter.h"

#include <qmath.h>
#include <QDomDocument>
#include <QDomElement>

@@ -145,9 +146,9 @@ QgsRasterBlock * QgsBrightnessContrastFilter::block( int bandNo, QgsRectangle c
// adjust image
QRgb myNoDataColor = qRgba( 0, 0, 0, 0 );
QRgb myColor;
int r, g, b;

double f = ( 259 * ( mContrast + 255 ) ) / ( 255 * ( 259 - mContrast ) );
int r, g, b;
double f = qPow(( mContrast + 100 ) / 100.0, 2 );

for ( size_t i = 0; i < ( size_t )width*height; i++ )
{
@@ -158,9 +159,9 @@ QgsRasterBlock * QgsBrightnessContrastFilter::block( int bandNo, QgsRectangle c
}

myColor = inputBlock->color( i );
r = qBound( 0, qRound( f * ( qBound( 0, qRed( myColor ) + mBrightness, 255 ) - 128 ) + 128 ), 255 );
g = qBound( 0, qRound( f * ( qBound( 0, qGreen( myColor ) + mBrightness, 255 ) - 128 ) + 128 ), 255 );
b = qBound( 0, qRound( f * ( qBound( 0, qBlue( myColor ) + mBrightness, 255 ) - 128 ) + 128 ), 255 );
r = qBound( 0, ( int )((((( qRed( myColor ) / 255.0 ) - 0.5 ) * f ) + 0.5 ) * 255 ) + mBrightness, 255 );
g = qBound( 0, ( int )((((( qGreen( myColor ) / 255.0 ) - 0.5 ) * f ) + 0.5 ) * 255 ) + mBrightness, 255 );
b = qBound( 0, ( int )((((( qBlue( myColor ) / 255.0 ) - 0.5 ) * f ) + 0.5 ) * 255 ) + mBrightness, 255 );

outputBlock->setColor( i, qRgb( r, g, b ) );
}
@@ -45,7 +45,7 @@ class CORE_EXPORT QgsBrightnessContrastFilter : public QgsRasterInterface
void setBrightness( int brightness ) { mBrightness = qBound( -255, brightness, 255 ); }
int brightness() const { return mBrightness; }

void setContrast( int contrast ) { mContrast = qBound( -255, contrast, 255 ); }
void setContrast( int contrast ) { mContrast = qBound( -100, contrast, 100 ); }
int contrast() const { return mContrast; }

void writeXML( QDomDocument& doc, QDomElement& parentElem );
@@ -54,11 +54,11 @@ class CORE_EXPORT QgsBrightnessContrastFilter : public QgsRasterInterface
void readXML( const QDomElement& filterElem );

private:
/**Current brightness coefficient value. Default: 0. Range: -255...255*/
/** Current brightness coefficient value. Default: 0. Range: -255...255 */
int mBrightness;

/**Current contrast coefficient value. Default: 0. Range: -255...255*/
int mContrast;
/** Current contrast coefficient value. Default: 0. Range: -100...100 */
double mContrast;
};

#endif // QGSBRIGHTNESSCONTRASTFILTER_H
@@ -248,6 +248,103 @@
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mBrightessContrastGroupBox">
<property name="title">
<string>Brightness and Contrast</string>
</property>
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>
<property name="saveCollapsedState" stdset="0">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Brightness</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="mSliderBrightness">
<property name="minimum">
<number>-255</number>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::NoTicks</enum>
</property>
<property name="tickInterval">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="mBrightnessSpinBox">
<property name="minimum">
<number>-255</number>
</property>
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Contrast</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="mSliderContrast">
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="mContrastSpinBox">
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mHueSaturationGroupBox">
<property name="title">
@@ -1469,11 +1566,6 @@ 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 0f7e90b

Please sign in to comment.