76 if ( std::isnan( value ) )
82 auto it = std::find_if( mTransparentSingleValuePixelList.constBegin(), mTransparentSingleValuePixelList.constEnd(), [value](
const TransparentSingleValuePixel &p ) {
83 return ( value > p.min && value < p.max ) || ( p.includeMinimum && qgsDoubleNear( value, p.min ) ) || ( 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 ) {
109 return qgsDoubleNear( p.red, redValue, p.fuzzyToleranceRed ) && qgsDoubleNear( p.green, greenValue, p.fuzzyToleranceGreen ) && qgsDoubleNear( p.blue, blueValue, p.fuzzyToleranceBlue );
112 if ( it != mTransparentThreeValuePixelList.constEnd() )
127 QDomElement rasterTransparencyElem = doc.createElement( u
"rasterTransparency"_s );
128 if ( !mTransparentSingleValuePixelList.isEmpty() )
130 QDomElement singleValuePixelListElement = doc.createElement( u
"singleValuePixelList"_s );
131 auto it = mTransparentSingleValuePixelList.constBegin();
132 for ( ; it != mTransparentSingleValuePixelList.constEnd(); ++it )
134 QDomElement pixelListElement = doc.createElement( u
"pixelListEntry"_s );
137 pixelListElement.setAttribute( u
"percentTransparent"_s, QString::number( 100.0 * ( 1 - it->opacity ) ) );
138 singleValuePixelListElement.appendChild( pixelListElement );
140 rasterTransparencyElem.appendChild( singleValuePixelListElement );
142 if ( !mTransparentThreeValuePixelList.isEmpty() )
144 QDomElement threeValuePixelListElement = doc.createElement( u
"threeValuePixelList"_s );
145 auto it = mTransparentThreeValuePixelList.constBegin();
146 for ( ; it != mTransparentThreeValuePixelList.constEnd(); ++it )
148 QDomElement pixelListElement = doc.createElement( u
"pixelListEntry"_s );
152 pixelListElement.setAttribute( u
"percentTransparent"_s, QString::number( 100.0 * ( 1 - it->opacity ) ) );
154 pixelListElement.setAttribute( u
"toleranceRed"_s, QString::number( it->fuzzyToleranceRed ) );
156 pixelListElement.setAttribute( u
"toleranceGreen"_s, QString::number( it->fuzzyToleranceGreen ) );
158 pixelListElement.setAttribute( u
"toleranceBlue"_s, QString::number( it->fuzzyToleranceBlue ) );
159 threeValuePixelListElement.appendChild( pixelListElement );
161 rasterTransparencyElem.appendChild( threeValuePixelListElement );
163 parentElem.appendChild( rasterTransparencyElem );
173 mTransparentSingleValuePixelList.clear();
174 mTransparentThreeValuePixelList.clear();
175 QDomElement currentEntryElem;
177 const QDomElement singlePixelListElem = elem.firstChildElement( u
"singleValuePixelList"_s );
178 if ( !singlePixelListElem.isNull() )
180 const QDomNodeList entryList = singlePixelListElem.elementsByTagName( u
"pixelListEntry"_s );
181 for (
int i = 0; i < entryList.size(); ++i )
183 currentEntryElem = entryList.at( i ).toElement();
186 const double opacity = 1.0 - currentEntryElem.attribute( u
"percentTransparent"_s ).toDouble() / 100.0;
188 if ( currentEntryElem.hasAttribute( u
"pixelValue"_s ) )
190 min = max = currentEntryElem.attribute( u
"pixelValue"_s ).toDouble();
194 min = currentEntryElem.attribute( u
"min"_s ).toDouble();
195 max = currentEntryElem.attribute( u
"max"_s ).toDouble();
200 const QDomElement threeValuePixelListElem = elem.firstChildElement( u
"threeValuePixelList"_s );
201 if ( !threeValuePixelListElem.isNull() )
203 const QDomNodeList entryList = threeValuePixelListElem.elementsByTagName( u
"pixelListEntry"_s );
204 for (
int i = 0; i < entryList.size(); ++i )
206 currentEntryElem = entryList.at( i ).toElement();
207 const double red = currentEntryElem.attribute( u
"red"_s ).toDouble();
208 const double green = currentEntryElem.attribute( u
"green"_s ).toDouble();
209 const double blue = currentEntryElem.attribute( u
"blue"_s ).toDouble();
210 const double opacity = 1.0 - currentEntryElem.attribute( u
"percentTransparent"_s ).toDouble() / 100.0;
212 const double toleranceRed = currentEntryElem.attribute( u
"toleranceRed"_s ).toDouble( &redOk );
213 bool greenOk =
false;
214 const double toleranceGreen = currentEntryElem.attribute( u
"toleranceGreen"_s ).toDouble( &greenOk );
216 const double toleranceBlue = currentEntryElem.attribute( u
"toleranceBlue"_s ).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).