22 #include <QDomDocument> 23 #include <QDomElement> 33 , mGreenBand( greenBand )
34 , mBlueBand( blueBand )
35 , mRedContrastEnhancement( redEnhancement )
36 , mGreenContrastEnhancement( greenEnhancement )
37 , mBlueContrastEnhancement( blueEnhancement )
43 delete mRedContrastEnhancement;
44 delete mGreenContrastEnhancement;
45 delete mBlueContrastEnhancement;
53 if ( mRedContrastEnhancement )
57 if ( mGreenContrastEnhancement )
61 if ( mBlueContrastEnhancement )
71 delete mRedContrastEnhancement;
72 mRedContrastEnhancement = ce;
77 delete mGreenContrastEnhancement;
78 mGreenContrastEnhancement = ce;
83 delete mBlueContrastEnhancement;
84 mBlueContrastEnhancement = ce;
95 int redBand = elem.attribute( QStringLiteral(
"redBand" ), QStringLiteral(
"-1" ) ).toInt();
96 int greenBand = elem.attribute( QStringLiteral(
"greenBand" ), QStringLiteral(
"-1" ) ).toInt();
97 int blueBand = elem.attribute( QStringLiteral(
"blueBand" ), QStringLiteral(
"-1" ) ).toInt();
101 QDomElement redContrastElem = elem.firstChildElement( QStringLiteral(
"redContrastEnhancement" ) );
102 if ( !redContrastElem.isNull() )
106 redContrastEnhancement->
readXml( redContrastElem );
110 QDomElement greenContrastElem = elem.firstChildElement( QStringLiteral(
"greenContrastEnhancement" ) );
111 if ( !greenContrastElem.isNull() )
115 greenContrastEnhancement->
readXml( greenContrastElem );
119 QDomElement blueContrastElem = elem.firstChildElement( QStringLiteral(
"blueContrastEnhancement" ) );
120 if ( !blueContrastElem.isNull() )
124 blueContrastEnhancement->
readXml( blueContrastElem );
128 greenContrastEnhancement, blueContrastEnhancement );
136 std::unique_ptr< QgsRasterBlock > outputBlock(
new QgsRasterBlock() );
139 return outputBlock.release();
144 && mRedBand > 0 && mGreenBand > 0 && mBlueBand > 0
145 &&
mAlphaBand < 1 && !mRedContrastEnhancement && !mGreenContrastEnhancement && !mBlueContrastEnhancement );
152 if ( mGreenBand > 0 )
164 return outputBlock.release();
172 QMap<int, QgsRasterBlock *> bandBlocks;
174 QSet<int>::const_iterator bandIt = bands.constBegin();
175 for ( ; bandIt != bands.constEnd(); ++bandIt )
177 bandBlocks.insert( *bandIt, defaultPointer );
185 bandIt = bands.constBegin();
186 for ( ; bandIt != bands.constEnd(); ++bandIt )
188 bandBlocks[*bandIt] =
mInput->
block( *bandIt, extent, width, height, feedback );
189 if ( !bandBlocks[*bandIt] )
194 for ( ; bandIt != bands.constBegin(); --bandIt )
196 delete bandBlocks[*bandIt];
198 return outputBlock.release();
204 redBlock = bandBlocks[mRedBand];
206 if ( mGreenBand > 0 )
208 greenBlock = bandBlocks[mGreenBand];
212 blueBlock = bandBlocks[mBlueBand];
221 for (
int i = 0; i < bandBlocks.size(); i++ )
223 delete bandBlocks.
value( i );
225 return outputBlock.release();
238 outputBlock->setColor( i, myDefaultColor );
242 int redVal = ( int )redBlock->
value( i );
243 int greenVal = ( int )greenBlock->
value( i );
244 int blueVal = ( int )blueBlock->
value( i );
245 outputBlock->setColor( i, qRgba( redVal, greenVal, blueVal, 255 ) );
250 bool isNoData =
false;
256 redVal = redBlock->
value( i );
257 if ( redBlock->
isNoData( i ) ) isNoData =
true;
259 if ( !isNoData && mGreenBand > 0 )
261 greenVal = greenBlock->
value( i );
262 if ( greenBlock->
isNoData( i ) ) isNoData =
true;
264 if ( !isNoData && mBlueBand > 0 )
266 blueVal = blueBlock->
value( i );
267 if ( blueBlock->
isNoData( i ) ) isNoData =
true;
271 outputBlock->setColor( i, myDefaultColor );
280 outputBlock->setColor( i, myDefaultColor );
285 if ( mRedContrastEnhancement )
289 if ( mGreenContrastEnhancement )
293 if ( mBlueContrastEnhancement )
306 currentOpacity *= alphaBlock->
value( i ) / 255.0;
311 outputBlock->setColor( i, qRgba( redVal, greenVal, blueVal, 255 ) );
315 outputBlock->setColor( i, qRgba( currentOpacity * redVal, currentOpacity * greenVal, currentOpacity * blueVal, currentOpacity * 255 ) );
320 QMap<int, QgsRasterBlock *>::const_iterator bandDelIt = bandBlocks.constBegin();
321 for ( ; bandDelIt != bandBlocks.constEnd(); ++bandDelIt )
323 delete bandDelIt.value();
326 return outputBlock.release();
331 if ( parentElem.isNull() )
336 QDomElement rasterRendererElem = doc.createElement( QStringLiteral(
"rasterrenderer" ) );
338 rasterRendererElem.setAttribute( QStringLiteral(
"redBand" ), mRedBand );
339 rasterRendererElem.setAttribute( QStringLiteral(
"greenBand" ), mGreenBand );
340 rasterRendererElem.setAttribute( QStringLiteral(
"blueBand" ), mBlueBand );
343 if ( mRedContrastEnhancement )
345 QDomElement redContrastElem = doc.createElement( QStringLiteral(
"redContrastEnhancement" ) );
346 mRedContrastEnhancement->
writeXml( doc, redContrastElem );
347 rasterRendererElem.appendChild( redContrastElem );
349 if ( mGreenContrastEnhancement )
351 QDomElement greenContrastElem = doc.createElement( QStringLiteral(
"greenContrastEnhancement" ) );
352 mGreenContrastEnhancement->
writeXml( doc, greenContrastElem );
353 rasterRendererElem.appendChild( greenContrastElem );
355 if ( mBlueContrastEnhancement )
357 QDomElement blueContrastElem = doc.createElement( QStringLiteral(
"blueContrastEnhancement" ) );
358 mBlueContrastEnhancement->
writeXml( doc, blueContrastElem );
359 rasterRendererElem.appendChild( blueContrastElem );
361 parentElem.appendChild( rasterRendererElem );
367 if ( mRedBand != -1 )
369 bandList << mRedBand;
371 if ( mGreenBand != -1 )
373 bandList << mGreenBand;
375 if ( mBlueBand != -1 )
377 bandList << mBlueBand;
int alphaValue(double, int globalTransparency=255) const
Returns the transparency value for a single value Pixel.
A rectangle specified with double values.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
~QgsMultiBandColorRenderer() override
const QgsContrastEnhancement * blueContrastEnhancement() const
void writeXml(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
virtual QgsRectangle extent() const
Get the extent of the interface.
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.
DataType
Raster data types.
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
QgsMultiBandColorRenderer * 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 setGreenContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
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.
QgsRasterTransparency * mRasterTransparency
Raster transparency per color or value. Overwrites global alpha value.
static const QRgb NODATA_COLOR
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
void setRedContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
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.
void _writeXml(QDomDocument &doc, QDomElement &rasterRendererElem) const
Write upper class info into rasterrenderer element (called by writeXml method of subclasses) ...
void copyCommonProperties(const QgsRasterRenderer *other, bool copyMinMaxOrigin=true)
Copies common properties like opacity / transparency data from other renderer.
bool usesTransparency() const
void readXml(const QDomElement &elem)
int mAlphaBand
Read alpha value from band.
void readXml(const QDomElement &rendererElem) override
Sets base class members from xml. Usually called from create() methods of subclasses.
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...
const QgsContrastEnhancement * redContrastEnhancement() const
const QgsContrastEnhancement * greenContrastEnhancement() const
int enhanceContrast(double)
Apply the contrast enhancement to a value. Return values are 0 - 254, -1 means the pixel was clipped ...
void setBlueContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
double value(int row, int column) const
Read a single value if type of block is numeric.
Renderer for multiband images with the color components.
void writeXml(QDomDocument &doc, QDomElement &parentElem) const
double mOpacity
Global alpha value (0-1)
Manipulates raster pixel values so that they enhanceContrast or clip into a specified numerical range...
QgsMultiBandColorRenderer(QgsRasterInterface *input, int redBand, int greenBand, int blueBand, QgsContrastEnhancement *redEnhancement=nullptr, QgsContrastEnhancement *greenEnhancement=nullptr, QgsContrastEnhancement *blueEnhancement=nullptr)
QgsRasterInterface * mInput
Feedback object tailored for raster block reading.
Raster renderer pipe that applies colors to a raster.