73 if ( std::isnan( value ) )
79 auto it = std::find_if( mTransparentSingleValuePixelList.constBegin(), mTransparentSingleValuePixelList.constEnd(), [value](
const TransparentSingleValuePixel & p )
81 return ( value > p.min && value < p.max )
82 || ( p.includeMinimum && qgsDoubleNear( value, p.min ) )
83 || ( p.includeMaximum && qgsDoubleNear( value, p.max ) );
86 if ( it != mTransparentSingleValuePixelList.constEnd() )
102 if ( std::isnan( redValue ) || std::isnan( greenValue ) || std::isnan( blueValue ) )
108 auto it = std::find_if( mTransparentThreeValuePixelList.constBegin(), mTransparentThreeValuePixelList.constEnd(), [redValue, greenValue, blueValue](
const TransparentThreeValuePixel & p )
110 return qgsDoubleNear( p.red, redValue, p.fuzzyToleranceRed )
111 && qgsDoubleNear( p.green, greenValue, p.fuzzyToleranceGreen )
112 && qgsDoubleNear( p.blue, blueValue, p.fuzzyToleranceBlue );
115 if ( it != mTransparentThreeValuePixelList.constEnd() )
130 QDomElement rasterTransparencyElem = doc.createElement( QStringLiteral(
"rasterTransparency" ) );
131 if ( !mTransparentSingleValuePixelList.isEmpty() )
133 QDomElement singleValuePixelListElement = doc.createElement( QStringLiteral(
"singleValuePixelList" ) );
134 auto it = mTransparentSingleValuePixelList.constBegin();
135 for ( ; it != mTransparentSingleValuePixelList.constEnd(); ++it )
137 QDomElement pixelListElement = doc.createElement( QStringLiteral(
"pixelListEntry" ) );
140 pixelListElement.setAttribute( QStringLiteral(
"percentTransparent" ), QString::number( 100.0 * ( 1 - it->opacity ) ) );
141 singleValuePixelListElement.appendChild( pixelListElement );
143 rasterTransparencyElem.appendChild( singleValuePixelListElement );
146 if ( !mTransparentThreeValuePixelList.isEmpty() )
148 QDomElement threeValuePixelListElement = doc.createElement( QStringLiteral(
"threeValuePixelList" ) );
149 auto it = mTransparentThreeValuePixelList.constBegin();
150 for ( ; it != mTransparentThreeValuePixelList.constEnd(); ++it )
152 QDomElement pixelListElement = doc.createElement( QStringLiteral(
"pixelListEntry" ) );
156 pixelListElement.setAttribute( QStringLiteral(
"percentTransparent" ), QString::number( 100.0 * ( 1 - it->opacity ) ) );
158 pixelListElement.setAttribute( QStringLiteral(
"toleranceRed" ), QString::number( it->fuzzyToleranceRed ) );
160 pixelListElement.setAttribute( QStringLiteral(
"toleranceGreen" ), QString::number( it->fuzzyToleranceGreen ) );
162 pixelListElement.setAttribute( QStringLiteral(
"toleranceBlue" ), QString::number( it->fuzzyToleranceBlue ) );
163 threeValuePixelListElement.appendChild( pixelListElement );
165 rasterTransparencyElem.appendChild( threeValuePixelListElement );
167 parentElem.appendChild( rasterTransparencyElem );
177 mTransparentSingleValuePixelList.clear();
178 mTransparentThreeValuePixelList.clear();
179 QDomElement currentEntryElem;
181 const QDomElement singlePixelListElem = elem.firstChildElement( QStringLiteral(
"singleValuePixelList" ) );
182 if ( !singlePixelListElem.isNull() )
184 const QDomNodeList entryList = singlePixelListElem.elementsByTagName( QStringLiteral(
"pixelListEntry" ) );
185 for (
int i = 0; i < entryList.size(); ++i )
187 currentEntryElem = entryList.at( i ).toElement();
190 const double opacity = 1.0 - currentEntryElem.attribute( QStringLiteral(
"percentTransparent" ) ).toDouble() / 100.0;
192 if ( currentEntryElem.hasAttribute( QStringLiteral(
"pixelValue" ) ) )
194 min = max = currentEntryElem.attribute( QStringLiteral(
"pixelValue" ) ).toDouble();
198 min = currentEntryElem.attribute( QStringLiteral(
"min" ) ).toDouble();
199 max = currentEntryElem.attribute( QStringLiteral(
"max" ) ).toDouble();
204 const QDomElement threeValuePixelListElem = elem.firstChildElement( QStringLiteral(
"threeValuePixelList" ) );
205 if ( !threeValuePixelListElem.isNull() )
207 const QDomNodeList entryList = threeValuePixelListElem.elementsByTagName( QStringLiteral(
"pixelListEntry" ) );
208 for (
int i = 0; i < entryList.size(); ++i )
210 currentEntryElem = entryList.at( i ).toElement();
211 const double red = currentEntryElem.attribute( QStringLiteral(
"red" ) ).toDouble();
212 const double green = currentEntryElem.attribute( QStringLiteral(
"green" ) ).toDouble();
213 const double blue = currentEntryElem.attribute( QStringLiteral(
"blue" ) ).toDouble();
214 const double opacity = 1.0 - currentEntryElem.attribute( QStringLiteral(
"percentTransparent" ) ).toDouble() / 100.0;
216 const double toleranceRed = currentEntryElem.attribute( QStringLiteral(
"toleranceRed" ) ).toDouble( &redOk );
217 bool greenOk =
false;
218 const double toleranceGreen = currentEntryElem.attribute( QStringLiteral(
"toleranceGreen" ) ).toDouble( &greenOk );
220 const double toleranceBlue = currentEntryElem.attribute( QStringLiteral(
"toleranceBlue" ) ).toDouble( &blueOk );
222 redOk ? toleranceRed : 4 * std::numeric_limits<double>::epsilon(),
223 greenOk ? toleranceGreen : 4 * std::numeric_limits<double>::epsilon(),
224 blueOk ? toleranceBlue : 4 * std::numeric_limits<double>::epsilon() ) );
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).