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() )
147 QRgb myNoDataColor = qRgba( 0, 0, 0, 0 );
151 double f = qPow((
mContrast + 100 ) / 100.0, 2 );
153 for (
size_t i = 0; i < ( size_t )width*height; i++ )
155 if ( inputBlock->
color( i ) == myNoDataColor )
157 outputBlock->
setColor( i, myNoDataColor );
161 myColor = inputBlock->
color( i );
162 alpha = qAlpha( myColor );
168 outputBlock->
setColor( i, qRgba( r, g, b, alpha ) );
180 return qBound( 0, (
int )(((((( colorComponent / 255.0 ) - 0.5 ) * contrastFactor ) + 0.5 ) * 255 ) + brightness ), 255 );
186 double alphaFactor = alpha / 255.;
187 double adjustedColor = colorComponent / alphaFactor;
190 return alphaFactor * qBound( 0., (((((( adjustedColor / 255.0 ) - 0.5 ) * contrastFactor ) + 0.5 ) * 255 ) + brightness ), 255. );
196 if ( parentElem.isNull() )
201 QDomElement filterElem = doc.createElement(
"brightnesscontrast" );
203 filterElem.setAttribute(
"brightness", QString::number(
mBrightness ) );
204 filterElem.setAttribute(
"contrast", QString::number(
mContrast ) );
205 parentElem.appendChild( filterElem );
210 if ( filterElem.isNull() )
215 mBrightness = filterElem.attribute(
"brightness",
"0" ).toInt();
216 mContrast = filterElem.attribute(
"contrast",
"0" ).toInt();
double mContrast
Current contrast coefficient value.
virtual int bandCount() const =0
Get number of bands.
A rectangle specified with double values.
void writeXML(QDomDocument &doc, QDomElement &parentElem) const
Write base class members to xml.
int mBrightness
Current brightness coefficient value.
virtual QgsRasterInterface * input() const
Current input.
~QgsBrightnessContrastFilter()
QgsRasterInterface * clone() const
Clone itself, create deep copy.
QGis::DataType dataType(int bandNo) const
Returns data type for the band specified by number.
bool setColor(int row, int column, QRgb color)
Set color on position.
void setBrightness(int brightness)
void setContrast(int contrast)
void readXML(const QDomElement &filterElem)
Sets base class members from xml.
QgsBrightnessContrastFilter(QgsRasterInterface *input=0)
virtual QGis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
Base class for processing filters like renderers, reprojector, resampler etc.
bool reset(QGis::DataType theDataType, int theWidth, int theHeight)
Reset block.
int adjustColorComponent(int colorComponent, int alpha, int brightness, double contrastFactor) const
Adjusts a color component by the specified brightness and contrast factor.
int bandCount() const
Get number of bands.
Brightness/contrast filter pipe for rasters.
DataType
Raster data types.
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)=0
Read block of data using given extent and size.
QRgb color(int row, int column) const
Read a single color.
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)
Read block of data using given extent and size.
QgsRasterInterface * mInput
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
bool setInput(QgsRasterInterface *input)
Set input.
bool isEmpty() const
Returns true if block is empty, i.e.