76 if ( std::isnan( value ) )
82 auto it = std::find_if( mTransparentSingleValuePixelList.constBegin(), mTransparentSingleValuePixelList.constEnd(), [value](
const TransparentSingleValuePixel & p )
84 return ( value > p.min && value < p.max )
85 || ( p.includeMinimum && qgsDoubleNear( value, p.min ) )
86 || ( p.includeMaximum && qgsDoubleNear( value, p.max ) );
89 if ( it != mTransparentSingleValuePixelList.constEnd() )
105 if ( std::isnan( redValue ) || std::isnan( greenValue ) || std::isnan( blueValue ) )
111 auto it = std::find_if( mTransparentThreeValuePixelList.constBegin(), mTransparentThreeValuePixelList.constEnd(), [redValue, greenValue, blueValue](
const TransparentThreeValuePixel & p )
113 return qgsDoubleNear( p.red, redValue, p.fuzzyToleranceRed )
114 && qgsDoubleNear( p.green, greenValue, p.fuzzyToleranceGreen )
115 && qgsDoubleNear( p.blue, blueValue, p.fuzzyToleranceBlue );
118 if ( it != mTransparentThreeValuePixelList.constEnd() )
133 QDomElement rasterTransparencyElem = doc.createElement( u
"rasterTransparency"_s );
134 if ( !mTransparentSingleValuePixelList.isEmpty() )
136 QDomElement singleValuePixelListElement = doc.createElement( u
"singleValuePixelList"_s );
137 auto it = mTransparentSingleValuePixelList.constBegin();
138 for ( ; it != mTransparentSingleValuePixelList.constEnd(); ++it )
140 QDomElement pixelListElement = doc.createElement( u
"pixelListEntry"_s );
143 pixelListElement.setAttribute( u
"percentTransparent"_s, QString::number( 100.0 * ( 1 - it->opacity ) ) );
144 singleValuePixelListElement.appendChild( pixelListElement );
146 rasterTransparencyElem.appendChild( singleValuePixelListElement );
149 if ( !mTransparentThreeValuePixelList.isEmpty() )
151 QDomElement threeValuePixelListElement = doc.createElement( u
"threeValuePixelList"_s );
152 auto it = mTransparentThreeValuePixelList.constBegin();
153 for ( ; it != mTransparentThreeValuePixelList.constEnd(); ++it )
155 QDomElement pixelListElement = doc.createElement( u
"pixelListEntry"_s );
159 pixelListElement.setAttribute( u
"percentTransparent"_s, QString::number( 100.0 * ( 1 - it->opacity ) ) );
161 pixelListElement.setAttribute( u
"toleranceRed"_s, QString::number( it->fuzzyToleranceRed ) );
163 pixelListElement.setAttribute( u
"toleranceGreen"_s, QString::number( it->fuzzyToleranceGreen ) );
165 pixelListElement.setAttribute( u
"toleranceBlue"_s, QString::number( it->fuzzyToleranceBlue ) );
166 threeValuePixelListElement.appendChild( pixelListElement );
168 rasterTransparencyElem.appendChild( threeValuePixelListElement );
170 parentElem.appendChild( rasterTransparencyElem );
180 mTransparentSingleValuePixelList.clear();
181 mTransparentThreeValuePixelList.clear();
182 QDomElement currentEntryElem;
184 const QDomElement singlePixelListElem = elem.firstChildElement( u
"singleValuePixelList"_s );
185 if ( !singlePixelListElem.isNull() )
187 const QDomNodeList entryList = singlePixelListElem.elementsByTagName( u
"pixelListEntry"_s );
188 for (
int i = 0; i < entryList.size(); ++i )
190 currentEntryElem = entryList.at( i ).toElement();
193 const double opacity = 1.0 - currentEntryElem.attribute( u
"percentTransparent"_s ).toDouble() / 100.0;
195 if ( currentEntryElem.hasAttribute( u
"pixelValue"_s ) )
197 min = max = currentEntryElem.attribute( u
"pixelValue"_s ).toDouble();
201 min = currentEntryElem.attribute( u
"min"_s ).toDouble();
202 max = currentEntryElem.attribute( u
"max"_s ).toDouble();
207 const QDomElement threeValuePixelListElem = elem.firstChildElement( u
"threeValuePixelList"_s );
208 if ( !threeValuePixelListElem.isNull() )
210 const QDomNodeList entryList = threeValuePixelListElem.elementsByTagName( u
"pixelListEntry"_s );
211 for (
int i = 0; i < entryList.size(); ++i )
213 currentEntryElem = entryList.at( i ).toElement();
214 const double red = currentEntryElem.attribute( u
"red"_s ).toDouble();
215 const double green = currentEntryElem.attribute( u
"green"_s ).toDouble();
216 const double blue = currentEntryElem.attribute( u
"blue"_s ).toDouble();
217 const double opacity = 1.0 - currentEntryElem.attribute( u
"percentTransparent"_s ).toDouble() / 100.0;
219 const double toleranceRed = currentEntryElem.attribute( u
"toleranceRed"_s ).toDouble( &redOk );
220 bool greenOk =
false;
221 const double toleranceGreen = currentEntryElem.attribute( u
"toleranceGreen"_s ).toDouble( &greenOk );
223 const double toleranceBlue = currentEntryElem.attribute( u
"toleranceBlue"_s ).toDouble( &blueOk );
225 redOk ? toleranceRed : 4 * std::numeric_limits<double>::epsilon(),
226 greenOk ? toleranceGreen : 4 * std::numeric_limits<double>::epsilon(),
227 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).