22 #include <QDomDocument>
23 #include <QDomElement>
27 QColor* colorArray,
int nColors ):
31 for (
int i = 0; i <
nColors; ++i )
33 mColors[i] = colorArray[i].rgba();
39 QgsRasterRenderer( input,
"paletted" ), mBand( bandNumber ), mColors( colorArray ), mNColors( nColors )
64 int bandNumber = elem.attribute(
"band",
"-1" ).toInt();
68 QDomElement paletteElem = elem.firstChildElement(
"colorPalette" );
69 if ( !paletteElem.isNull() )
71 QDomNodeList paletteEntries = paletteElem.elementsByTagName(
"paletteEntry" );
73 QDomElement entryElem;
78 for (
int i = 0; i < paletteEntries.size(); ++i )
80 entryElem = paletteEntries.at( i ).toElement();
82 value = ( int )entryElem.attribute(
"value",
"0" ).toDouble();
83 if ( value >= nColors && value <= 10000 ) nColors = value + 1;
85 QgsDebugMsg( QString(
"nColors = %1" ).arg( nColors ) );
89 for (
int i = 0; i <
nColors; ++i )
91 entryElem = paletteEntries.at( i ).toElement();
92 value = ( int )entryElem.attribute(
"value",
"0" ).toDouble();
93 QgsDebugMsg( entryElem.attribute(
"color",
"#000000" ) );
94 if ( value >= 0 && value < nColors )
96 colors[value] = QColor( entryElem.attribute(
"color",
"#000000" ) ).rgba();
100 QgsDebugMsg( QString(
"value %1 out of range" ).arg( value ) );
115 QColor* colorArray =
new QColor[
mNColors ];
116 for (
int i = 0; i <
mNColors; ++i )
118 colorArray[i] = QColor(
mColors[i] );
129 QRgb* rgbValues =
new QRgb[
mNColors];
130 for (
int i = 0; i <
mNColors; ++i )
147 if ( !inputBlock || inputBlock->
isEmpty() )
163 if ( !alphaBlock || alphaBlock->
isEmpty() )
172 alphaBlock = inputBlock;
186 unsigned int* outputData = (
unsigned int* )( outputBlock->
bits() );
188 size_t rasterSize = ( size_t )width * height;
189 for (
size_t i = 0; i < rasterSize; ++i )
193 outputData[i] = myDefaultColor;
196 int val = ( int ) inputBlock->
value( i );
197 if ( !hasTransparency )
210 currentOpacity *= alphaBlock->
value( i ) / 255.0;
212 QColor currentColor = QColor(
mColors[val] );
213 outputData[i] = qRgba( currentOpacity * currentColor.red(), currentOpacity * currentColor.green(), currentOpacity * currentColor.blue(), currentOpacity * 255 );
228 if ( parentElem.isNull() )
233 QDomElement rasterRendererElem = doc.createElement(
"rasterrenderer" );
236 rasterRendererElem.setAttribute(
"band",
mBand );
237 QDomElement colorPaletteElem = doc.createElement(
"colorPalette" );
238 for (
int i = 0; i <
mNColors; ++i )
240 QDomElement colorElem = doc.createElement(
"paletteEntry" );
241 colorElem.setAttribute(
"value", i );
242 colorElem.setAttribute(
"color", QColor(
mColors[i] ).name() );
243 colorPaletteElem.appendChild( colorElem );
245 rasterRendererElem.appendChild( colorPaletteElem );
247 parentElem.appendChild( rasterRendererElem );
252 for (
int i = 0; i <
mNColors; ++i )
254 symbolItems.push_back( qMakePair( QString::number( i ), QColor(
mColors[i] ) ) );