22 #include <QDomDocument> 23 #include <QDomElement> 114 return block2( bandNo, extent, width, height );
131 if ( !inputBlock || inputBlock->
isEmpty() )
138 if ( mBrightness == 0 && mContrast == 0 )
152 QRgb myNoDataColor = qRgba( 0, 0, 0, 0 );
156 double f = qPow(( mContrast + 100 ) / 100.0, 2 );
160 if ( inputBlock->
color( i ) == myNoDataColor )
162 outputBlock->
setColor( i, myNoDataColor );
166 myColor = inputBlock->
color( i );
167 alpha = qAlpha( myColor );
169 r = adjustColorComponent( qRed( myColor ), alpha, mBrightness, f );
170 g = adjustColorComponent( qGreen( myColor ), alpha, mBrightness, f );
171 b = adjustColorComponent( qBlue( myColor ), alpha, mBrightness, f );
173 outputBlock->
setColor( i, qRgba( r, g, b, alpha ) );
180 int QgsBrightnessContrastFilter::adjustColorComponent(
int colorComponent,
int alpha,
int brightness,
double contrastFactor )
const 185 return qBound( 0, (
int )(((((( colorComponent / 255.0 ) - 0.5 ) * contrastFactor ) + 0.5 ) * 255 ) +
brightness ), 255 );
187 else if ( alpha == 0 )
196 double alphaFactor = alpha / 255.;
197 double adjustedColor = colorComponent / alphaFactor;
200 return alphaFactor * qBound( 0., (((((( adjustedColor / 255.0 ) - 0.5 ) * contrastFactor ) + 0.5 ) * 255 ) +
brightness ), 255. );
206 if ( parentElem.
isNull() )
220 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 * block2(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
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()
virtual QgsRasterBlock * block2(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)
Read block of data using given extent and size.
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.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
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
QRgb color(int row, int column) const
Read a single color.
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
bool isEmpty() const
Returns true if block is empty, i.e.
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.
QDomElement createElement(const QString &tagName)
void readXML(const QDomElement &filterElem) override
Sets base class members from xml.
QgsRasterInterface * mInput
Feedback object tailored for raster block reading.
QgsBrightnessContrastFilter(QgsRasterInterface *input=nullptr)