22#include <QDomDocument>
52 const int band = elem.attribute( QStringLiteral(
"band" ), QStringLiteral(
"1" ) ).toInt();
61 QgsDebugMsgLevel( QStringLiteral(
"width = %1 height = %2" ).arg( width ).arg( height ), 4 );
63 std::unique_ptr< QgsRasterBlock > outputBlock(
new QgsRasterBlock() );
64 if ( !
mInput || mInputBand == -1 )
66 return outputBlock.release();
69 const std::shared_ptr< QgsRasterBlock > inputBlock(
mInput->
block( mInputBand,
extent, width, height, feedback ) );
70 if ( !inputBlock || inputBlock->isEmpty() )
73 return outputBlock.release();
76 std::shared_ptr< QgsRasterBlock > alphaBlock;
79 alphaBlock = inputBlock;
84 return outputBlock.release();
88 const QRgb rendererColor = qRgba( mColor.red(), mColor.green(), mColor.blue(), mColor.alpha() );
90 bool isNoData =
false;
91 const qgssize blockSize =
static_cast< qgssize >( width ) * height;
92 for (
qgssize i = 0; i < blockSize; i++ )
94 double value = inputBlock->valueAndNoData( i, isNoData );
97 outputBlock->setColor( i, defaultColor );
108 const double alpha = alphaBlock->value( i );
111 outputBlock->setColor( i, defaultColor );
116 currentAlpha *= alpha / 255.0;
122 outputBlock->setColor( i, rendererColor );
126 outputBlock->setColor( i, qRgba(
static_cast<int>( currentAlpha * mColor.red() ),
127 static_cast<int>( currentAlpha * mColor.green() ),
128 static_cast<int>( currentAlpha * mColor.blue() ),
129 static_cast<int>( currentAlpha * mColor.alpha() ) ) );
133 return outputBlock.release();
148 if ( parentElem.isNull() )
153 QDomElement rasterRendererElem = doc.createElement( QStringLiteral(
"rasterrenderer" ) );
157 rasterRendererElem.setAttribute( QStringLiteral(
"band" ), mInputBand );
159 parentElem.appendChild( rasterRendererElem );
180 if ( mInputBand != -1 )
QFlags< RasterRendererFlag > RasterRendererFlags
Flags which control behavior of raster renderers.
@ InternalLayerOpacityHandling
The renderer internally handles the raster layer's opacity, so the default layer level opacity handli...
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
Feedback object tailored for raster block reading.
Base class for processing filters like renderers, reprojector, resampler etc.
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)=0
Read block of data using given extent and size.
QgsRasterInterface * mInput
virtual QgsRectangle extent() const
Gets the extent of the interface.
virtual QgsRasterInterface * input() const
Current input.
Raster renderer pipe that applies colors to a raster.
double mOpacity
Global alpha value (0-1)
int mAlphaBand
Read alpha value from band.
QRgb renderColorForNodataPixel() const
Returns the color for the renderer to use to represent nodata pixels.
void _writeXml(QDomDocument &doc, QDomElement &rasterRendererElem) const
Write upper class info into rasterrenderer element (called by writeXml method of subclasses)
int bandCount() const override
Gets number of bands.
QgsRasterTransparency * mRasterTransparency
Raster transparency per color or value. Overwrites global alpha value.
void copyCommonProperties(const QgsRasterRenderer *other, bool copyMinMaxOrigin=true)
Copies common properties like opacity / transparency data from other renderer.
void readXml(const QDomElement &rendererElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
Raster renderer which renders all data pixels using a single color.
int inputBand() const override
Returns the input band for the renderer, or -1 if no input band is available.
bool setInputBand(int band) override
Attempts to set the input band for the renderer.
void writeXml(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
Qgis::RasterRendererFlags flags() const override
Returns flags which dictate renderer behavior.
QgsRasterSingleColorRenderer * clone() const override
Clone itself, create deep copy.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
Creates an instance of the renderer based on definition from XML (used by the renderer registry)
QgsRasterSingleColorRenderer(QgsRasterInterface *input, int band, const QColor &color)
Creates a single color renderer.
QColor color() const
Returns the single color used by the renderer.
QList< int > usesBands() const override
Returns a list of band numbers used by the renderer.
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
void setColor(const QColor &color)
Sets the single color used by the renderer.
double opacityForValue(double value) const
Returns the opacity (as a value from 0 to 1) for a single value pixel.
A rectangle specified with double values.
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 qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)