Skip to content
Permalink
Browse files

UI to control brightness and contrast values in raster properties,

attempt to fix contrast calculation
  • Loading branch information
alexbruy committed Mar 26, 2013
1 parent 8bf6df2 commit 4435c4f3d0cda1a13ff34c0a25f80ecf0179d4ce
@@ -82,6 +82,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 ) ) );

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

@@ -527,6 +534,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
*/
@@ -672,6 +692,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
@@ -72,7 +72,7 @@
<item row="0" column="0" colspan="4">
<widget class="QTabWidget" name="tabBar">
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<property name="iconSize">
<size>
@@ -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>
<spacer name="verticalSpacer">
<property name="orientation">
@@ -1183,7 +1280,7 @@ p, li { white-space: pre-wrap; }
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Lucida Grande'; font-size:13pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Droid Sans'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'Cantarell'; font-size:11pt;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>

0 comments on commit 4435c4f

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