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 );
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 );
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();
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.
unsigned long long qgssize
qgssize is used instead of size_t, because size_t is stdlib type, unknown by SIP, and it would be har...
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.