22 #include <QDomDocument>
23 #include <QDomElement>
115 QgsDebugMsg( QString(
"width = %1 height = %2 extent = %3" ).arg( width ).arg( height ).arg( extent.
toString() ) );
126 if ( !inputBlock || inputBlock->
isEmpty() )
133 if ( mBrightness == 0 && mContrast == 0 )
147 QRgb myNoDataColor = qRgba( 0, 0, 0, 0 );
151 double f = qPow(( mContrast + 100 ) / 100.0, 2 );
155 if ( inputBlock->
color( i ) == myNoDataColor )
157 outputBlock->
setColor( i, myNoDataColor );
161 myColor = inputBlock->
color( i );
162 alpha = qAlpha( myColor );
164 r = adjustColorComponent( qRed( myColor ), alpha, mBrightness, f );
165 g = adjustColorComponent( qGreen( myColor ), alpha, mBrightness, f );
166 b = adjustColorComponent( qBlue( myColor ), alpha, mBrightness, f );
168 outputBlock->
setColor( i, qRgba( r, g, b, alpha ) );
175 int QgsBrightnessContrastFilter::adjustColorComponent(
int colorComponent,
int alpha,
int brightness,
double contrastFactor )
const
180 return qBound( 0, (
int )(((((( colorComponent / 255.0 ) - 0.5 ) * contrastFactor ) + 0.5 ) * 255 ) + brightness ), 255 );
182 else if ( alpha == 0 )
191 double alphaFactor = alpha / 255.;
192 double adjustedColor = colorComponent / alphaFactor;
195 return alphaFactor * qBound( 0., (((((( adjustedColor / 255.0 ) - 0.5 ) * contrastFactor ) + 0.5 ) * 255 ) + brightness ), 255. );
201 if ( parentElem.isNull() )
206 QDomElement filterElem = doc.createElement(
"brightnesscontrast" );
208 filterElem.setAttribute(
"brightness", QString::number( mBrightness ) );
209 filterElem.setAttribute(
"contrast", QString::number( mContrast ) );
210 parentElem.appendChild( filterElem );
215 if ( filterElem.isNull() )
220 mBrightness = filterElem.attribute(
"brightness",
"0" ).toInt();
221 mContrast = filterElem.attribute(
"contrast",
"0" ).toInt();