21 #include <QDomDocument> 22 #include <QDomElement> 26 QgsRasterRenderer( input,
"singlebandgray" ), mGrayBand( grayBand ), mGradient( BlackToWhite ), mContrastEnhancement( nullptr )
32 delete mContrastEnhancement;
41 if ( mContrastEnhancement )
59 if ( elem.
attribute(
"gradient" ) ==
"WhiteToBlack" )
65 if ( !contrastEnhancementElem.
isNull() )
69 ce->
readXML( contrastEnhancementElem );
77 delete mContrastEnhancement;
78 mContrastEnhancement = ce;
83 return block2( bandNo, extent, width, height );
98 if ( !inputBlock || inputBlock->
isEmpty() )
110 if ( !alphaBlock || alphaBlock->
isEmpty() )
120 alphaBlock = inputBlock;
135 outputBlock->
setColor( i, myDefaultColor );
138 double grayVal = inputBlock->
value( i );
147 currentAlpha *= alphaBlock->
value( i ) / 255.0;
150 if ( mContrastEnhancement )
154 outputBlock->
setColor( i, myDefaultColor );
162 grayVal = 255 - grayVal;
167 outputBlock->
setColor( i, qRgba( grayVal, grayVal, grayVal, 255 ) );
171 outputBlock->
setColor( i, qRgba( currentAlpha * grayVal, currentAlpha * grayVal, currentAlpha * grayVal, currentAlpha * 255 ) );
186 if ( parentElem.
isNull() )
194 rasterRendererElem.
setAttribute(
"grayBand", mGrayBand );
199 gradient =
"BlackToWhite";
203 gradient =
"WhiteToBlack";
205 rasterRendererElem.
setAttribute(
"gradient", gradient );
207 if ( mContrastEnhancement )
210 mContrastEnhancement->
writeXML( doc, contrastElem );
230 if ( mGrayBand != -1 )
232 bandList << mGrayBand;
double maximumValue() const
Return the maximum value for the contrast enhancement range.
A rectangle specified with double values.
void writeXML(QDomDocument &doc, QDomElement &parentElem) const
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
QgsSingleBandGrayRenderer(QgsRasterInterface *input, int grayBand)
void readXML(const QDomElement &elem)
QDomNode appendChild(const QDomNode &newChild)
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
int alphaValue(double, int theGlobalTransparency=255) const
Returns the transparency value for a single value Pixel.
QgsRasterBlock * block2(int bandNo, QgsRectangle const &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
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.
void copyCommonProperties(const QgsRasterRenderer *other)
Copies common properties like opacity / transparency data from other renderer.
double minimumValue() const
Return the minimum value for the contrast enhancement range.
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)
Compare two doubles (but allow some difference)
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.
virtual QgsRasterBlock * block2(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)
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
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
Raster renderer pipe for single band gray.
bool isEmpty() const
Returns true if block is empty, i.e.
void _writeXML(QDomDocument &doc, QDomElement &rasterRendererElem) const
Write upper class info into rasterrenderer element (called by writeXML method of subclasses) ...
Gradient gradient() const
int mAlphaBand
Read alpha value from band.
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.
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.
QDomElement firstChildElement(const QString &tagName) const
DataType
Raster data types.
double value(int row, int column) const
Read a single value if type of block is numeric.
ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const
double mOpacity
Global alpha value (0-1)
Manipulates raster pixel values so that they enhanceContrast or clip into a specified numerical range...
QDomElement createElement(const QString &tagName)
QgsRasterInterface * mInput
Feedback object tailored for raster block reading.
Raster renderer pipe that applies colors to a raster.
~QgsSingleBandGrayRenderer()