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;
102 if ( !redContrastElem.
isNull() )
106 redContrastEnhancement->
readXML( redContrastElem );
111 if ( !greenContrastElem.
isNull() )
115 greenContrastEnhancement->
readXML( greenContrastElem );
120 if ( !blueContrastElem.
isNull() )
124 blueContrastEnhancement->
readXML( blueContrastElem );
128 greenContrastEnhancement, blueContrastEnhancement );
135 return block2( bandNo, extent, width, height );
149 && mRedBand > 0 && mGreenBand > 0 && mBlueBand > 0
150 &&
mAlphaBand < 1 && !mRedContrastEnhancement && !mGreenContrastEnhancement && !mBlueContrastEnhancement );
157 if ( mGreenBand > 0 )
165 if ( bands.
size() < 1 )
180 for ( ; bandIt != bands.
constEnd(); ++bandIt )
182 bandBlocks.
insert( *bandIt, defaultPointer );
191 for ( ; bandIt != bands.
constEnd(); ++bandIt )
193 bandBlocks[*bandIt] =
mInput->
block2( *bandIt, extent, width, height, feedback );
194 if ( !bandBlocks[*bandIt] )
199 for ( ; bandIt != bands.
constBegin(); --bandIt )
201 delete bandBlocks[*bandIt];
209 redBlock = bandBlocks[mRedBand];
211 if ( mGreenBand > 0 )
213 greenBlock = bandBlocks[mGreenBand];
217 blueBlock = bandBlocks[mBlueBand];
226 for (
int i = 0; i < bandBlocks.
size(); i++ )
228 delete bandBlocks.
value( i );
243 outputBlock->
setColor( i, myDefaultColor );
247 int redVal = ( int )redBlock->
value( i );
248 int greenVal = ( int )greenBlock->
value( i );
249 int blueVal = ( int )blueBlock->
value( i );
250 outputBlock->
setColor( i, qRgba( redVal, greenVal, blueVal, 255 ) );
255 bool isNoData =
false;
261 redVal = redBlock->
value( i );
262 if ( redBlock->
isNoData( i ) ) isNoData =
true;
264 if ( !isNoData && mGreenBand > 0 )
266 greenVal = greenBlock->
value( i );
267 if ( greenBlock->
isNoData( i ) ) isNoData =
true;
269 if ( !isNoData && mBlueBand > 0 )
271 blueVal = blueBlock->
value( i );
272 if ( blueBlock->
isNoData( i ) ) isNoData =
true;
276 outputBlock->
setColor( i, myDefaultColor );
285 outputBlock->
setColor( i, myDefaultColor );
290 if ( mRedContrastEnhancement )
294 if ( mGreenContrastEnhancement )
298 if ( mBlueContrastEnhancement )
311 currentOpacity *= alphaBlock->
value( i ) / 255.0;
316 outputBlock->
setColor( i, qRgba( redVal, greenVal, blueVal, 255 ) );
320 outputBlock->
setColor( i, qRgba( currentOpacity * redVal, currentOpacity * greenVal, currentOpacity * blueVal, currentOpacity * 255 ) );
326 for ( ; bandDelIt != bandBlocks.
constEnd(); ++bandDelIt )
328 delete bandDelIt.
value();
336 if ( parentElem.
isNull() )
344 rasterRendererElem.
setAttribute(
"greenBand", mGreenBand );
345 rasterRendererElem.
setAttribute(
"blueBand", mBlueBand );
348 if ( mRedContrastEnhancement )
351 mRedContrastEnhancement->
writeXML( doc, redContrastElem );
354 if ( mGreenContrastEnhancement )
357 mGreenContrastEnhancement->
writeXML( doc, greenContrastElem );
358 rasterRendererElem.
appendChild( greenContrastElem );
360 if ( mBlueContrastEnhancement )
363 mBlueContrastEnhancement->
writeXML( doc, blueContrastElem );
364 rasterRendererElem.
appendChild( blueContrastElem );
372 if ( mRedBand != -1 )
374 bandList << mRedBand;
376 if ( mGreenBand != -1 )
378 bandList << mGreenBand;
380 if ( mBlueBand != -1 )
382 bandList << mBlueBand;
A rectangle specified with double values.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
void writeXML(QDomDocument &doc, QDomElement &parentElem) const
const QgsContrastEnhancement * blueContrastEnhancement() const
void readXML(const QDomElement &elem)
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 appendChild(const QDomNode &newChild)
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.
bool isValueInDisplayableRange(double)
Return true if pixel is in stretable range, false if pixel is outside of range (i.e., clipped)
const_iterator constBegin() const
virtual QgsRasterInterface * input() const
Current input.
void copyCommonProperties(const QgsRasterRenderer *other)
Copies common properties like opacity / transparency data from other renderer.
void writeXML(QDomDocument &doc, QDomElement &parentElem) const override
Write base class members to xml.
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.
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.
QList< int > usesBands() const override
Returns a list of band numbers used by the renderer.
QgsRasterTransparency * mRasterTransparency
Raster transparency per color or value.
bool setColor(int row, int column, QRgb color)
Set color on position.
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.
void setAttribute(const QString &name, const QString &value)
int toInt(bool *ok, int base) const
const_iterator constEnd() const
bool usesTransparency() const
const_iterator constEnd() const
void _writeXML(QDomDocument &doc, QDomElement &rasterRendererElem) const
Write upper class info into rasterrenderer element (called by writeXML method of subclasses) ...
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.
const_iterator constBegin() const
virtual QgsRectangle extent()
Get the extent of the interface.
const QgsContrastEnhancement * redContrastEnhancement() const
const QgsContrastEnhancement * greenContrastEnhancement() const
int enhanceContrast(double)
Apply the contrast enhancement to a value.
QDomElement firstChildElement(const QString &tagName) const
DataType
Raster data types.
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.
double mOpacity
Global alpha value (0-1)
Manipulates raster pixel values so that they enhanceContrast or clip into a specified numerical range...
iterator insert(const Key &key, const T &value)
QgsMultiBandColorRenderer(QgsRasterInterface *input, int redBand, int greenBand, int blueBand, QgsContrastEnhancement *redEnhancement=nullptr, QgsContrastEnhancement *greenEnhancement=nullptr, QgsContrastEnhancement *blueEnhancement=nullptr)
QDomElement createElement(const QString &tagName)
~QgsMultiBandColorRenderer()
QgsRasterInterface * mInput
Feedback object tailored for raster block reading.
QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height) override
Read block of data using given extent and size.
Raster renderer pipe that applies colors to a raster.
const T value(const Key &key) const