22 #include <QDomDocument>
23 #include <QDomElement>
31 QgsRasterRenderer( input,
"multibandcolor" ), mRedBand( redBand ), mGreenBand( greenBand ), mBlueBand( blueBand ),
32 mRedContrastEnhancement( redEnhancement ), mGreenContrastEnhancement( greenEnhancement ), mBlueContrastEnhancement( blueEnhancement )
88 int redBand = elem.attribute(
"redBand",
"-1" ).toInt();
89 int greenBand = elem.attribute(
"greenBand",
"-1" ).toInt();
90 int blueBand = elem.attribute(
"blueBand",
"-1" ).toInt();
94 QDomElement redContrastElem = elem.firstChildElement(
"redContrastEnhancement" );
95 if ( !redContrastElem.isNull() )
99 redContrastEnhancement->
readXML( redContrastElem );
103 QDomElement greenContrastElem = elem.firstChildElement(
"greenContrastEnhancement" );
104 if ( !greenContrastElem.isNull() )
108 greenContrastEnhancement->
readXML( greenContrastElem );
112 QDomElement blueContrastElem = elem.firstChildElement(
"blueContrastEnhancement" );
113 if ( !blueContrastElem.isNull() )
117 blueContrastEnhancement->
readXML( blueContrastElem );
121 greenContrastEnhancement, blueContrastEnhancement );
153 if ( bands.size() < 1 )
165 QMap<int, QgsRasterBlock*> bandBlocks;
167 QSet<int>::const_iterator bandIt = bands.constBegin();
168 for ( ; bandIt != bands.constEnd(); ++bandIt )
170 bandBlocks.insert( *bandIt, defaultPointer );
178 bandIt = bands.constBegin();
179 for ( ; bandIt != bands.constEnd(); ++bandIt )
181 bandBlocks[*bandIt] =
mInput->
block( *bandIt, extent, width, height );
182 if ( !bandBlocks[*bandIt] )
187 for ( ; bandIt != bands.constBegin(); bandIt-- )
189 delete bandBlocks[*bandIt];
214 for (
int i = 0; i < bandBlocks.size(); i++ )
216 delete bandBlocks.
value( i );
223 for (
size_t i = 0; i < ( size_t )width*height; i++ )
231 outputBlock->
setColor( i, myDefaultColor );
235 int redVal = ( int )redBlock->
value( i );
236 int greenVal = ( int )greenBlock->
value( i );
237 int blueVal = ( int )blueBlock->
value( i );
238 outputBlock->
setColor( i, qRgba( redVal, greenVal, blueVal, 255 ) );
243 bool isNoData =
false;
249 redVal = redBlock->
value( i );
250 if ( redBlock->
isNoData( i ) ) isNoData =
true;
254 greenVal = greenBlock->
value( i );
255 if ( greenBlock->
isNoData( i ) ) isNoData =
true;
259 blueVal = blueBlock->
value( i );
260 if ( blueBlock->
isNoData( i ) ) isNoData =
true;
264 outputBlock->
setColor( i, myDefaultColor );
273 outputBlock->
setColor( i, myDefaultColor );
299 currentOpacity *= alphaBlock->
value( i ) / 255.0;
304 outputBlock->
setColor( i, qRgba( redVal, greenVal, blueVal, 255 ) );
308 outputBlock->
setColor( i, qRgba( currentOpacity * redVal, currentOpacity * greenVal, currentOpacity * blueVal, currentOpacity * 255 ) );
313 QMap<int, QgsRasterBlock*>::const_iterator bandDelIt = bandBlocks.constBegin();
314 for ( ; bandDelIt != bandBlocks.constEnd(); ++bandDelIt )
316 delete bandDelIt.value();
324 if ( parentElem.isNull() )
329 QDomElement rasterRendererElem = doc.createElement(
"rasterrenderer" );
331 rasterRendererElem.setAttribute(
"redBand",
mRedBand );
332 rasterRendererElem.setAttribute(
"greenBand",
mGreenBand );
333 rasterRendererElem.setAttribute(
"blueBand",
mBlueBand );
338 QDomElement redContrastElem = doc.createElement(
"redContrastEnhancement" );
340 rasterRendererElem.appendChild( redContrastElem );
344 QDomElement greenContrastElem = doc.createElement(
"greenContrastEnhancement" );
346 rasterRendererElem.appendChild( greenContrastElem );
350 QDomElement blueContrastElem = doc.createElement(
"blueContrastEnhancement" );
352 rasterRendererElem.appendChild( blueContrastElem );
354 parentElem.appendChild( rasterRendererElem );