22 #include <QDomDocument> 23 #include <QDomElement> 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() )
215 if ( filterElem.
isNull() )
virtual int bandCount() const =0
Get number of bands.
A rectangle specified with double values.
QgsBrightnessContrastFilter * clone() const override
Clone itself, create deep copy.
Unknown or unspecified type.
QDomNode appendChild(const QDomNode &newChild)
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height) override
Read block of data using given extent and size.
QString attribute(const QString &name, const QString &defValue) const
virtual QgsRasterInterface * input() const
Current input.
int bandCount() const override
Get number of bands.
void writeXML(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
~QgsBrightnessContrastFilter()
bool setColor(int row, int column, QRgb color)
Set color on position.
QGis::DataType dataType(int bandNo) const override
Returns data type for the band specified by number.
void setBrightness(int brightness)
QString number(int n, int base)
void setContrast(int contrast)
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
#define QgsDebugMsgLevel(str, level)
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
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.
virtual QgsRectangle extent()
Get the extent of the interface.
bool setInput(QgsRasterInterface *input) override
Set input.
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.
QDomElement createElement(const QString &tagName)
void readXML(const QDomElement &filterElem) override
Sets base class members from xml.
QgsRasterInterface * mInput
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
bool isEmpty() const
Returns true if block is empty, i.e.
QgsBrightnessContrastFilter(QgsRasterInterface *input=nullptr)