22 #include <QDomDocument>
23 #include <QDomElement>
31 QgsRasterRenderer( input,
"multibandcolor" ), mRedBand( redBand ), mGreenBand( greenBand ), mBlueBand( blueBand ),
32 mRedContrastEnhancement( redEnhancement ), mGreenContrastEnhancement( greenEnhancement ), mBlueContrastEnhancement( blueEnhancement )
38 delete mRedContrastEnhancement;
39 delete mGreenContrastEnhancement;
40 delete mBlueContrastEnhancement;
46 if ( mRedContrastEnhancement )
50 if ( mGreenContrastEnhancement )
54 if ( mBlueContrastEnhancement )
67 delete mRedContrastEnhancement; mRedContrastEnhancement = ce;
72 delete mGreenContrastEnhancement; mGreenContrastEnhancement = ce;
77 delete mBlueContrastEnhancement; mBlueContrastEnhancement = ce;
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 );
137 && mRedBand > 0 && mGreenBand > 0 && mBlueBand > 0
138 &&
mAlphaBand < 1 && !mRedContrastEnhancement && !mGreenContrastEnhancement && !mBlueContrastEnhancement );
145 if ( mGreenBand > 0 )
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];
197 redBlock = bandBlocks[mRedBand];
199 if ( mGreenBand > 0 )
201 greenBlock = bandBlocks[mGreenBand];
205 blueBlock = bandBlocks[mBlueBand];
214 for (
int i = 0; i < bandBlocks.size(); i++ )
216 delete bandBlocks.
value( 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;
252 if ( !isNoData && mGreenBand > 0 )
254 greenVal = greenBlock->
value( i );
255 if ( greenBlock->
isNoData( i ) ) isNoData =
true;
257 if ( !isNoData && mBlueBand > 0 )
259 blueVal = blueBlock->
value( i );
260 if ( blueBlock->
isNoData( i ) ) isNoData =
true;
264 outputBlock->
setColor( i, myDefaultColor );
273 outputBlock->
setColor( i, myDefaultColor );
278 if ( mRedContrastEnhancement )
282 if ( mGreenContrastEnhancement )
286 if ( mBlueContrastEnhancement )
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 );
336 if ( mRedContrastEnhancement )
338 QDomElement redContrastElem = doc.createElement(
"redContrastEnhancement" );
339 mRedContrastEnhancement->
writeXML( doc, redContrastElem );
340 rasterRendererElem.appendChild( redContrastElem );
342 if ( mGreenContrastEnhancement )
344 QDomElement greenContrastElem = doc.createElement(
"greenContrastEnhancement" );
345 mGreenContrastEnhancement->
writeXML( doc, greenContrastElem );
346 rasterRendererElem.appendChild( greenContrastElem );
348 if ( mBlueContrastEnhancement )
350 QDomElement blueContrastElem = doc.createElement(
"blueContrastEnhancement" );
351 mBlueContrastEnhancement->
writeXML( doc, blueContrastElem );
352 rasterRendererElem.appendChild( blueContrastElem );
354 parentElem.appendChild( rasterRendererElem );
360 if ( mRedBand != -1 )
362 bandList << mRedBand;
364 if ( mGreenBand != -1 )
366 bandList << mGreenBand;
368 if ( mBlueBand != -1 )
370 bandList << mBlueBand;