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;
160 for (
size_t i = 0; i < ( size_t )width*height; i++ )
162 if ( inputBlock->
color( i ) == myNoDataColor )
164 outputBlock->
setColor( i, myNoDataColor );
168 myRgb = inputBlock->
color( i );
169 myColor = QColor( myRgb );
172 alpha = qAlpha( myRgb );
175 myColor.getRgb( &r, &g, &b );
180 alphaFactor = alpha / 255.;
184 myColor = QColor::fromRgb( r, g, b );
187 myColor.getHsl( &h, &s, &l );
210 outputBlock->
setColor( i, qRgba( r, g, b, alpha ) );
227 QColor colorizedColor = QColor::fromHsl( h, s, l );
232 myColor = colorizedColor;
235 myColor.getRgb( &r, &g, &b );
240 int colorizedR, colorizedG, colorizedB;
241 colorizedColor.getRgb( &colorizedR, &colorizedG, &colorizedB );
245 r = p * colorizedR + ( 1 - p ) * r;
246 g = p * colorizedG + ( 1 - p ) * g;
247 b = p * colorizedB + ( 1 - p ) * b;
250 myColor = QColor::fromRgb( r, g, b );
251 myColor.getHsl( &h, &s, &l );
270 myColor = QColor::fromHsl( h, s, l );
271 myColor.getRgb( &r, &g, &b );
277 int luminosity = 0.21 * r + 0.72 * g + 0.07 * b;
278 r = g = b = luminosity;
281 myColor = QColor::fromRgb( r, g, b );
282 myColor.getHsl( &h, &s, &l );
288 int average = ( r + g + b ) / 3;
292 myColor = QColor::fromRgb( r, g, b );
293 myColor.getHsl( &h, &s, &l );
308 s = qMin((
int )( 255. * ( 1 - pow( 1 - ( s / 255. ) , pow(
mSaturationScale, 2 ) ) ) ), 255 );
312 myColor = QColor::fromHsl( h, s, l );
313 myColor.getRgb( &r, &g, &b );
338 if ( parentElem.isNull() )
343 QDomElement filterElem = doc.createElement(
"huesaturation" );
345 filterElem.setAttribute(
"saturation", QString::number(
mSaturation ) );
346 filterElem.setAttribute(
"grayscaleMode", QString::number(
mGrayscaleMode ) );
347 filterElem.setAttribute(
"colorizeOn", QString::number(
mColorizeOn ) );
348 filterElem.setAttribute(
"colorizeRed", QString::number(
mColorizeColor.red() ) );
349 filterElem.setAttribute(
"colorizeGreen", QString::number(
mColorizeColor.green() ) );
350 filterElem.setAttribute(
"colorizeBlue", QString::number(
mColorizeColor.blue() ) );
351 filterElem.setAttribute(
"colorizeStrength", QString::number(
mColorizeStrength ) );
353 parentElem.appendChild( filterElem );
358 if ( filterElem.isNull() )
363 setSaturation( filterElem.attribute(
"saturation",
"0" ).toInt() );
366 mColorizeOn = ( bool )filterElem.attribute(
"colorizeOn",
"0" ).toInt();
367 int mColorizeRed = filterElem.attribute(
"colorizeRed",
"255" ).toInt();
368 int mColorizeGreen = filterElem.attribute(
"colorizeGreen",
"128" ).toInt();
369 int mColorizeBlue = filterElem.attribute(
"colorizeBlue",
"128" ).toInt();
370 setColorizeColor( QColor::fromRgb( mColorizeRed, mColorizeGreen, mColorizeBlue ) );