Skip to content

Commit

Permalink
Fix branch to apply to current master
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Mar 27, 2013
2 parents 86a246a + 4435c4f commit 0f7e90b
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 14 deletions.
23 changes: 23 additions & 0 deletions src/app/qgsrasterlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/core/raster/qgsbrightnesscontrastfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "qgsrasterdataprovider.h"
#include "qgsbrightnesscontrastfilter.h"

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

Expand Down Expand Up @@ -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++ )
{
Expand All @@ -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 ) );
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/raster/qgsbrightnesscontrastfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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
102 changes: 97 additions & 5 deletions src/ui/qgsrasterlayerpropertiesbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit 0f7e90b

Please sign in to comment.