22 #include <QDomDocument> 23 #include <QDomElement> 29 QgsRasterRenderer( input,
"paletted" ), mBand( bandNumber ), mNColors( nColors ), mLabels( labels )
32 for (
int i = 0; i <
nColors; ++i )
34 mColors[i] = colorArray[i].
rgba();
40 QgsRasterRenderer( input,
"paletted" ), mBand( bandNumber ), mColors( colorArray ), mNColors( nColors ), mLabels( labels )
54 renderer->mLabels = mLabels;
71 if ( !paletteElem.
isNull() )
80 for (
int i = 0; i < paletteEntries.
size(); ++i )
85 if ( value >= nColors && value <= 10000 ) nColors = value + 1;
91 for (
int i = 0; i <
nColors; ++i )
96 if ( value >= 0 && value < nColors )
98 colors[value] =
QColor( entryElem.
attribute(
"color",
"#000000" ) ).rgba();
102 if ( value >= labels.
size() ) labels.
resize( value + 1 );
103 labels[value] =
label;
124 for (
int i = 0; i < mNColors; ++i )
126 colorArray[i] =
QColor( mColors[i] );
137 QRgb* rgbValues =
new QRgb[mNColors];
138 for (
int i = 0; i < mNColors; ++i )
140 rgbValues[i] = mColors[i];
147 if ( idx >= mLabels.
size() )
149 mLabels.
resize( idx + 1 );
151 mLabels[idx] =
label;
156 return block2( bandNo, extent, width, height );
162 if ( !
mInput || mNColors == 0 )
169 if ( !inputBlock || inputBlock->
isEmpty() )
185 if ( !alphaBlock || alphaBlock->
isEmpty() )
194 alphaBlock = inputBlock;
208 unsigned int* outputData = (
unsigned int* )( outputBlock->
bits() );
211 for (
qgssize i = 0; i < rasterSize; ++i )
215 outputData[i] = myDefaultColor;
218 int val = ( int ) inputBlock->
value( i );
219 if ( !hasTransparency )
221 outputData[i] = mColors[val];
232 currentOpacity *= alphaBlock->
value( i ) / 255.0;
235 outputData[i] = qRgba( currentOpacity * currentColor.
red(), currentOpacity * currentColor.
green(), currentOpacity * currentColor.
blue(), currentOpacity * 255 );
250 if ( parentElem.
isNull() )
260 for (
int i = 0; i < mNColors; ++i )
265 if ( !
label( i ).isEmpty() )
271 rasterRendererElem.
appendChild( colorPaletteElem );
278 for (
int i = 0; i < mNColors; ++i )
281 symbolItems.push_back( qMakePair( lab,
QColor( mColors[i] ) ) );
QDomNodeList elementsByTagName(const QString &tagname) const
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)
Renderer for paletted raster images.
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.
virtual QgsRasterInterface * input() const
Current input.
void copyCommonProperties(const QgsRasterRenderer *other)
Copies common properties like opacity / transparency data from other renderer.
void setLabel(int idx, const QString &label)
Set category label.
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height) override
Read block of data using given extent and size.
double toDouble(bool *ok) const
bool isNoData(int row, int column)
Check if value at position is no data.
int nColors() const
Returns number of colors.
void readXML(const QDomElement &rendererElem) override
Sets base class members from xml.
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.
QDomElement toElement() const
QgsPalettedRasterRenderer(QgsRasterInterface *input, int bandNumber, QColor *colorArray, int nColors, const QVector< QString > &labels=QVector< QString >())
Renderer owns color array.
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
~QgsPalettedRasterRenderer()
bool usesTransparency() const
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) ...
QString label(int idx) const
Return optional category label.
int mAlphaBand
Read alpha value from 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...
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
bool reset(QGis::DataType theDataType, int theWidth, int theHeight)
Reset block.
QList< int > usesBands() const override
Returns a list of band numbers used by the renderer.
virtual QgsRectangle extent()
Get the extent of the interface.
QColor * colors() const
Returns copy of color array (caller takes ownership)
QgsPalettedRasterRenderer * clone() const override
Clone itself, create deep copy.
char * bits(int row, int column)
Get pointer to data.
void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const override
Get symbology items if provided by renderer.
QDomElement firstChildElement(const QString &tagName) const
double value(int row, int column) const
Read a single value if type of block is numeric.
double mOpacity
Global alpha value (0-1)
QRgb * rgbArray() const
Returns copy of rgb array (caller takes ownership)
QDomElement createElement(const QString &tagName)
QgsRasterInterface * mInput
Feedback object tailored for raster block reading.
Raster renderer pipe that applies colors to a raster.
QgsRasterBlock * block2(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr) override
Read block of data using given extent and size.
QDomNode at(int index) const