21 #include <QDomDocument>
22 #include <QDomElement>
30 mColorizeColor( QColor::fromRgb( 255, 128, 128 ) ),
31 mColorizeStrength( 100 )
121 QgsDebugMsg( QString(
"width = %1 height = %2 extent = %3" ).arg( width ).arg( height ).arg( extent.
toString() ) );
132 if ( !inputBlock || inputBlock->
isEmpty() )
153 QRgb myNoDataColor = qRgba( 0, 0, 0, 0 );
158 double alphaFactor = 1.0;
162 if ( inputBlock->
color( i ) == myNoDataColor )
164 outputBlock->
setColor( i, myNoDataColor );
168 myRgb = inputBlock->
color( i );
169 myColor = QColor( myRgb );
172 alpha = qAlpha( myRgb );
182 myColor.getRgb( &r, &g, &b );
187 alphaFactor = alpha / 255.;
191 myColor = QColor::fromRgb( r, g, b );
194 myColor.getHsl( &h, &s, &l );
217 outputBlock->
setColor( i, qRgba( r, g, b, alpha ) );
234 QColor colorizedColor = QColor::fromHsl( h, s, l );
239 myColor = colorizedColor;
242 myColor.getRgb( &r, &g, &b );
247 int colorizedR, colorizedG, colorizedB;
248 colorizedColor.getRgb( &colorizedR, &colorizedG, &colorizedB );
252 r = p * colorizedR + ( 1 - p ) * r;
253 g = p * colorizedG + ( 1 - p ) * g;
254 b = p * colorizedB + ( 1 - p ) * b;
257 myColor = QColor::fromRgb( r, g, b );
258 myColor.getHsl( &h, &s, &l );
277 myColor = QColor::fromHsl( h, s, l );
278 myColor.getRgb( &r, &g, &b );
284 int luminosity = 0.21 * r + 0.72 * g + 0.07 * b;
285 r = g = b = luminosity;
288 myColor = QColor::fromRgb( r, g, b );
289 myColor.getHsl( &h, &s, &l );
295 int average = ( r + g + b ) / 3;
299 myColor = QColor::fromRgb( r, g, b );
300 myColor.getHsl( &h, &s, &l );
315 s = qMin((
int )( 255. * ( 1 - pow( 1 - ( s / 255. ) , pow(
mSaturationScale, 2 ) ) ) ), 255 );
319 myColor = QColor::fromHsl( h, s, l );
320 myColor.getRgb( &r, &g, &b );
345 if ( parentElem.isNull() )
350 QDomElement filterElem = doc.createElement(
"huesaturation" );
352 filterElem.setAttribute(
"saturation", QString::number(
mSaturation ) );
353 filterElem.setAttribute(
"grayscaleMode", QString::number(
mGrayscaleMode ) );
354 filterElem.setAttribute(
"colorizeOn", QString::number(
mColorizeOn ) );
355 filterElem.setAttribute(
"colorizeRed", QString::number(
mColorizeColor.red() ) );
356 filterElem.setAttribute(
"colorizeGreen", QString::number(
mColorizeColor.green() ) );
357 filterElem.setAttribute(
"colorizeBlue", QString::number(
mColorizeColor.blue() ) );
358 filterElem.setAttribute(
"colorizeStrength", QString::number(
mColorizeStrength ) );
360 parentElem.appendChild( filterElem );
365 if ( filterElem.isNull() )
370 setSaturation( filterElem.attribute(
"saturation",
"0" ).toInt() );
373 mColorizeOn = ( bool )filterElem.attribute(
"colorizeOn",
"0" ).toInt();
374 int mColorizeRed = filterElem.attribute(
"colorizeRed",
"255" ).toInt();
375 int mColorizeGreen = filterElem.attribute(
"colorizeGreen",
"128" ).toInt();
376 int mColorizeBlue = filterElem.attribute(
"colorizeBlue",
"128" ).toInt();
377 setColorizeColor( QColor::fromRgb( mColorizeRed, mColorizeGreen, mColorizeBlue ) );