21 #include <QDomDocument>
22 #include <QDomElement>
26 QgsRasterRenderer( input,
"singlebandgray" ), mGrayBand( grayBand ), mGradient( BlackToWhite ), mContrastEnhancement( 0 )
56 int grayBand = elem.attribute(
"grayBand",
"-1" ).toInt();
60 if ( elem.attribute(
"gradient" ) ==
"WhiteToBlack" )
65 QDomElement contrastEnhancementElem = elem.firstChildElement(
"contrastEnhancement" );
66 if ( !contrastEnhancementElem.isNull() )
70 ce->
readXML( contrastEnhancementElem );
85 QgsDebugMsg( QString(
"width = %1 height = %2" ).arg( width ).arg( height ) );
94 if ( !inputBlock || inputBlock->
isEmpty() )
106 if ( !alphaBlock || alphaBlock->
isEmpty() )
116 alphaBlock = inputBlock;
131 outputBlock->
setColor( i, myDefaultColor );
134 double grayVal = inputBlock->
value( i );
143 currentAlpha *= alphaBlock->
value( i ) / 255.0;
150 outputBlock->
setColor( i, myDefaultColor );
158 grayVal = 255 - grayVal;
163 outputBlock->
setColor( i, qRgba( grayVal, grayVal, grayVal, 255 ) );
167 outputBlock->
setColor( i, qRgba( currentAlpha * grayVal, currentAlpha * grayVal, currentAlpha * grayVal, currentAlpha * 255 ) );
182 if ( parentElem.isNull() )
187 QDomElement rasterRendererElem = doc.createElement(
"rasterrenderer" );
190 rasterRendererElem.setAttribute(
"grayBand",
mGrayBand );
195 gradient =
"BlackToWhite";
199 gradient =
"WhiteToBlack";
201 rasterRendererElem.setAttribute(
"gradient", gradient );
205 QDomElement contrastElem = doc.createElement(
"contrastEnhancement" );
207 rasterRendererElem.appendChild( contrastElem );
209 parentElem.appendChild( rasterRendererElem );
void writeXML(QDomDocument &doc, QDomElement &parentElem) const
A rectangle specified with double values.
static QgsRasterRenderer * create(const QDomElement &elem, QgsRasterInterface *input)
QgsSingleBandGrayRenderer(QgsRasterInterface *input, int grayBand)
void readXML(const QDomElement &elem)
ContrastEnhancementAlgorithm contrastEnhancementAlgorithm() const
bool isValueInDisplayableRange(double)
Return true if pixel is in stretable range, false if pixel is outside of range (i.e., clipped)
Gradient gradient() const
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)
QList< int > usesBands() const
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
int alphaValue(double, int theGlobalTransparency=255) const
Returns the transparency value for a single value Pixel.
double value(int row, int column) const
Read a single value if type of block is numeric.
QgsRasterBlock * block(int bandNo, QgsRectangle const &extent, int width, int height)
Read block of data using given extent and size.
Raster renderer pipe for single band gray.
double minimumValue() const
Return the minimum value for the contrast enhancement range.
QgsContrastEnhancement * mContrastEnhancement
int mAlphaBand
Read alpha value from band.
virtual QGis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
void setAlphaBand(int 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...
void readXML(const QDomElement &rendererElem)
Sets base class members from xml.
bool reset(QGis::DataType theDataType, int theWidth, int theHeight)
Reset block.
void setGradient(Gradient theGradient)
void setContrastEnhancement(QgsContrastEnhancement *ce)
Takes ownership.
int enhanceContrast(double)
Apply the contrast enhancement to a value.
QgsRasterInterface * clone() const
Clone itself, create deep copy.
double maximumValue() const
Return the maximum value for the contrast enhancement range.
DataType
Raster data types.
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)=0
Read block of data using given extent and size.
void legendSymbologyItems(QList< QPair< QString, QColor > > &symbolItems) const
Get symbology items if provided by renderer.
double mOpacity
Global alpha value (0-1)
Manipulates raster pixel values so that they enhanceContrast or clip into a specified numerical range...
void writeXML(QDomDocument &doc, QDomElement &parentElem) const
Write base class members to xml.
void setOpacity(double opacity)
void _writeXML(QDomDocument &doc, QDomElement &rasterRendererElem) const
Write upper class info into rasterrenderer element (called by writeXML method of subclasses) ...
QgsRasterInterface * mInput
void setRasterTransparency(QgsRasterTransparency *t)
Raster renderer pipe that applies colors to a raster.
bool isEmpty() const
Returns true if block is empty, i.e.
~QgsSingleBandGrayRenderer()