21 #include <QDomDocument> 22 #include <QDomElement> 26 QgsRasterRenderer( input,
"singlebandgray" ), mGrayBand( grayBand ), mGradient( BlackToWhite ), mContrastEnhancement( nullptr )
32 delete mContrastEnhancement;
42 if ( mContrastEnhancement )
60 if ( elem.
attribute(
"gradient" ) ==
"WhiteToBlack" )
66 if ( !contrastEnhancementElem.
isNull() )
70 ce->
readXML( contrastEnhancementElem );
78 delete mContrastEnhancement;
79 mContrastEnhancement = ce;
94 if ( !inputBlock || inputBlock->
isEmpty() )
106 if ( !alphaBlock || alphaBlock->
isEmpty() )
116 alphaBlock = inputBlock;
131 outputBlock->
setColor( i, myDefaultColor );
134 double grayVal = inputBlock->
value( i );
143 currentAlpha *= alphaBlock->
value( i ) / 255.0;
146 if ( mContrastEnhancement )
150 outputBlock->
setColor( i, myDefaultColor );
158 grayVal = 255 - grayVal;
163 outputBlock->
setColor( i, qRgba( grayVal, grayVal, grayVal, 255 ) );
167 outputBlock->
setColor( i, qRgba( currentAlpha * grayVal, currentAlpha * grayVal, currentAlpha * grayVal, currentAlpha * 255 ) );
182 if ( parentElem.
isNull() )
190 rasterRendererElem.
setAttribute(
"grayBand", mGrayBand );
195 gradient =
"BlackToWhite";
199 gradient =
"WhiteToBlack";
201 rasterRendererElem.
setAttribute(
"gradient", gradient );
203 if ( mContrastEnhancement )
206 mContrastEnhancement->
writeXML( doc, contrastElem );
226 if ( mGrayBand != -1 )
228 bandList << mGrayBand;
void writeXML(QDomDocument &doc, QDomElement &parentElem) const
A rectangle specified with double values.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
QgsSingleBandGrayRenderer(QgsRasterInterface *input, int grayBand)
void readXML(const QDomElement &elem)
QDomNode appendChild(const QDomNode &newChild)
ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const
void writeXML(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
QList< int > usesBands() const override
Returns a list of band numbers used by the renderer.
QString attribute(const QString &name, const QString &defValue) const
bool isValueInDisplayableRange(double)
Return true if pixel is in stretable range, false if pixel is outside of range (i.e., clipped)
virtual QgsRasterInterface * input() const
Current input.
Gradient gradient() const
QgsSingleBandGrayRenderer * clone() const override
Clone itself, create deep copy.
bool isNoData(int row, int column)
Check if value at position is no data.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
void readXML(const QDomElement &rendererElem) override
Sets base class members from xml.
QgsRasterBlock * block(int bandNo, QgsRectangle const &extent, int width, int height) override
Read block of data using given extent and size.
QgsRasterTransparency * mRasterTransparency
Raster transparency per color or value.
void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const override
Get symbology items if provided by renderer.
bool setColor(int row, int column, QRgb color)
Set color on position.
static const QRgb NODATA_COLOR
int alphaValue(double, int theGlobalTransparency=255) const
Returns the transparency value for a single value Pixel.
QString number(int n, int base)
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
#define QgsDebugMsgLevel(str, level)
double value(int row, int column) const
Read a single value if type of block is numeric.
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const
Raster renderer pipe for single band gray.
double minimumValue() const
Return the minimum value for the contrast enhancement range.
int mAlphaBand
Read alpha value from band.
virtual QGis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
void setAlphaBand(int band)
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.
void setGradient(Gradient theGradient)
virtual QgsRectangle extent()
Get the extent of the interface.
void setContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
int enhanceContrast(double)
Apply the contrast enhancement to a value.
double maximumValue() const
Return the maximum value for the contrast enhancement range.
QDomElement firstChildElement(const QString &tagName) const
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.
double mOpacity
Global alpha value (0-1)
Manipulates raster pixel values so that they enhanceContrast or clip into a specified numerical range...
Defines the list of pixel values to be considered as transparent or semi transparent when rendering r...
void setOpacity(double opacity)
QDomElement createElement(const QString &tagName)
void _writeXML(QDomDocument &doc, QDomElement &rasterRendererElem) const
Write upper class info into rasterrenderer element (called by writeXML method of subclasses) ...
QgsRasterInterface * mInput
void setRasterTransparency(QgsRasterTransparency *t)
Raster renderer pipe that applies colors to a raster.
bool isEmpty() const
Returns true if block is empty, i.e.
~QgsSingleBandGrayRenderer()