21 #include <QDomDocument> 22 #include <QDomElement> 28 , mSaturationScale( 1 )
30 , mColorizeOn( false )
31 , mColorizeColor(
QColor::fromRgb( 255, 128, 128 ) )
34 , mColorizeStrength( 100 )
123 return block2( bandNo, extent, width, height );
140 if ( !inputBlock || inputBlock->
isEmpty() )
147 if ( mSaturation == 0 && mGrayscaleMode ==
GrayscaleOff && !mColorizeOn )
161 QRgb myNoDataColor = qRgba( 0, 0, 0, 0 );
166 double alphaFactor = 1.0;
170 if ( inputBlock->
color( i ) == myNoDataColor )
172 outputBlock->
setColor( i, myNoDataColor );
176 myRgb = inputBlock->
color( i );
177 myColor =
QColor( myRgb );
180 alpha = qAlpha( myRgb );
190 myColor.
getRgb( &r, &g, &b );
195 alphaFactor = alpha / 255.;
202 myColor.
getHsl( &h, &s, &l );
205 if (( mGrayscaleMode !=
GrayscaleOff ) || ( mSaturationScale != 1 ) )
207 processSaturation( r, g, b, h, s, l );
213 processColorization( r, g, b, h, s, l );
225 outputBlock->
setColor( i, qRgba( r, g, b, alpha ) );
233 void QgsHueSaturationFilter::processColorization(
int &r,
int &g,
int &b,
int &h,
int &s,
int &l )
244 if ( mColorizeStrength == 100 )
247 myColor = colorizedColor;
250 myColor.
getRgb( &r, &g, &b );
255 int colorizedR, colorizedG, colorizedB;
256 colorizedColor.
getRgb( &colorizedR, &colorizedG, &colorizedB );
259 double p = ( double ) mColorizeStrength / 100.;
260 r = p * colorizedR + ( 1 - p ) * r;
261 g = p * colorizedG + ( 1 - p ) * g;
262 b = p * colorizedB + ( 1 - p ) * b;
266 myColor.getHsl( &h, &s, &l );
271 void QgsHueSaturationFilter::processSaturation(
int &r,
int &g,
int &b,
int &h,
int &s,
int &l )
277 switch ( mGrayscaleMode )
286 myColor.
getRgb( &r, &g, &b );
292 int luminosity = 0.21 * r + 0.72 * g + 0.07 * b;
293 r = g = b = luminosity;
297 myColor.
getHsl( &h, &s, &l );
303 int average = ( r + g + b ) / 3;
308 myColor.
getHsl( &h, &s, &l );
314 if ( mSaturationScale < 1 )
317 s = qMin((
int )( s * mSaturationScale ), 255 );
323 s = qMin((
int )( 255. * ( 1 - pow( 1 - ( s / 255. ), pow( mSaturationScale, 2 ) ) ) ), 255 );
328 myColor.
getRgb( &r, &g, &b );
336 mSaturation = qBound( -100, saturation, 100 );
339 mSaturationScale = (( double ) mSaturation / 100 ) + 1;
347 mColorizeH = mColorizeColor.
hue();
353 if ( parentElem.
isNull() )
373 if ( filterElem.
isNull() )
381 mColorizeOn = ( bool )filterElem.
attribute(
"colorizeOn",
"0" ).
toInt();
382 int mColorizeRed = filterElem.
attribute(
"colorizeRed",
"255" ).
toInt();
383 int mColorizeGreen = filterElem.
attribute(
"colorizeGreen",
"128" ).
toInt();
384 int mColorizeBlue = filterElem.
attribute(
"colorizeBlue",
"128" ).
toInt();
386 mColorizeStrength = filterElem.
attribute(
"colorizeStrength",
"100" ).
toInt();
virtual int bandCount() const =0
Get number of bands.
A rectangle specified with double values.
void writeXML(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
Unknown or unspecified type.
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const
void setColorizeColor(const QColor &colorizeColor)
bool setInput(QgsRasterInterface *input) override
Set input.
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height) override
Read block of data using given extent and size.
virtual QgsRasterInterface * input() const
Current input.
int bandCount() const override
Get number of bands.
QGis::DataType dataType(int bandNo) const override
Returns data type for the band specified by number.
void getHsl(int *h, int *s, int *l, int *a) const
virtual QgsRasterBlock * block2(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)
Read block of data using given extent and size.
QColor fromHsl(int h, int s, int l, int a)
bool setColor(int row, int column, QRgb color)
Set color on position.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
QString number(int n, int base)
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.
~QgsHueSaturationFilter()
virtual QGis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
void setColorizeOn(bool colorizeOn)
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.
QgsHueSaturationFilter(QgsRasterInterface *input=nullptr)
virtual QgsRectangle extent()
Get the extent of the interface.
void readXML(const QDomElement &filterElem) override
Sets base class members from xml.
void getRgb(int *r, int *g, int *b, int *a) const
Color and saturation filter pipe for rasters.
DataType
Raster data types.
QgsHueSaturationFilter * clone() const override
Clone itself, create deep copy.
QColor colorizeColor() const
QgsRasterBlock * block2(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
void setColorizeStrength(int colorizeStrength)
QDomElement createElement(const QString &tagName)
QgsRasterInterface * mInput
Feedback object tailored for raster block reading.
void setGrayscaleMode(QgsHueSaturationFilter::GrayscaleMode grayscaleMode)
void setSaturation(int saturation)