21 #include <QDomDocument>
22 #include <QDomElement>
28 , mSaturationScale( 1 )
30 , mColorizeOn( false )
31 , mColorizeColor(
QColor::fromRgb( 255, 128, 128 ) )
34 , mColorizeStrength( 100 )
135 if ( !inputBlock || inputBlock->
isEmpty() )
142 if ( mSaturation == 0 && mGrayscaleMode ==
GrayscaleOff && !mColorizeOn )
156 QRgb myNoDataColor = qRgba( 0, 0, 0, 0 );
161 double alphaFactor = 1.0;
165 if ( inputBlock->
color( i ) == myNoDataColor )
167 outputBlock->
setColor( i, myNoDataColor );
171 myRgb = inputBlock->
color( i );
172 myColor =
QColor( myRgb );
175 alpha = qAlpha( myRgb );
185 myColor.
getRgb( &r, &g, &b );
190 alphaFactor = alpha / 255.;
197 myColor.
getHsl( &h, &s, &l );
200 if (( mGrayscaleMode !=
GrayscaleOff ) || ( mSaturationScale != 1 ) )
202 processSaturation( r, g, b, h, s, l );
208 processColorization( r, g, b, h, s, l );
220 outputBlock->
setColor( i, qRgba( r, g, b, alpha ) );
228 void QgsHueSaturationFilter::processColorization(
int &r,
int &g,
int &b,
int &h,
int &s,
int &l )
239 if ( mColorizeStrength == 100 )
242 myColor = colorizedColor;
245 myColor.
getRgb( &r, &g, &b );
250 int colorizedR, colorizedG, colorizedB;
251 colorizedColor.
getRgb( &colorizedR, &colorizedG, &colorizedB );
254 double p = ( double ) mColorizeStrength / 100.;
255 r = p * colorizedR + ( 1 - p ) * r;
256 g = p * colorizedG + ( 1 - p ) * g;
257 b = p * colorizedB + ( 1 - p ) * b;
261 myColor.getHsl( &h, &s, &l );
266 void QgsHueSaturationFilter::processSaturation(
int &r,
int &g,
int &b,
int &h,
int &s,
int &l )
272 switch ( mGrayscaleMode )
281 myColor.
getRgb( &r, &g, &b );
287 int luminosity = 0.21 * r + 0.72 * g + 0.07 * b;
288 r = g = b = luminosity;
292 myColor.
getHsl( &h, &s, &l );
298 int average = ( r + g + b ) / 3;
303 myColor.
getHsl( &h, &s, &l );
309 if ( mSaturationScale < 1 )
312 s = qMin((
int )( s * mSaturationScale ), 255 );
318 s = qMin((
int )( 255. * ( 1 - pow( 1 - ( s / 255. ), pow( mSaturationScale, 2 ) ) ) ), 255 );
323 myColor.
getRgb( &r, &g, &b );
331 mSaturation = qBound( -100, saturation, 100 );
334 mSaturationScale = (( double ) mSaturation / 100 ) + 1;
342 mColorizeH = mColorizeColor.
hue();
348 if ( parentElem.
isNull() )
368 if ( filterElem.
isNull() )
376 mColorizeOn = ( bool )filterElem.
attribute(
"colorizeOn",
"0" ).
toInt();
377 int mColorizeRed = filterElem.
attribute(
"colorizeRed",
"255" ).
toInt();
378 int mColorizeGreen = filterElem.
attribute(
"colorizeGreen",
"128" ).
toInt();
379 int mColorizeBlue = filterElem.
attribute(
"colorizeBlue",
"128" ).
toInt();
381 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.
QDomNode appendChild(const QDomNode &newChild)
QString attribute(const QString &name, const QString &defValue) const
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.
QgsHueSaturationFilter(QgsRasterInterface *input=0)
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
QColor fromHsl(int h, int s, int l, int a)
bool setColor(int row, int column, QRgb color)
Set color on position.
QString number(int n, int base)
void setAttribute(const QString &name, const QString &value)
QgsRasterInterface * clone() const override
Clone itself, create deep copy.
int toInt(bool *ok, int base) const
void setColorizeColor(QColor colorizeColor)
~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.
QColor colorizeColor() const
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.
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)=0
Read block of data using given extent and size.
void setColorizeStrength(int colorizeStrength)
QRgb color(int row, int column) const
Read a single color.
QDomElement createElement(const QString &tagName)
QgsRasterInterface * mInput
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
void setGrayscaleMode(QgsHueSaturationFilter::GrayscaleMode grayscaleMode)
void setSaturation(int saturation)
bool isEmpty() const
Returns true if block is empty, i.e.