72 if ( std::isnan( value ) )
78 auto it = std::find_if( mTransparentSingleValuePixelList.constBegin(), mTransparentSingleValuePixelList.constEnd(), [value](
const TransparentSingleValuePixel & p )
80 return ( value > p.min && value < p.max )
81 || ( p.includeMinimum && qgsDoubleNear( value, p.min ) )
82 || ( p.includeMaximum && qgsDoubleNear( value, p.max ) );
85 if ( it != mTransparentSingleValuePixelList.constEnd() )
101 if ( std::isnan( redValue ) || std::isnan( greenValue ) || std::isnan( blueValue ) )
107 auto it = std::find_if( mTransparentThreeValuePixelList.constBegin(), mTransparentThreeValuePixelList.constEnd(), [redValue, greenValue, blueValue](
const TransparentThreeValuePixel & p )
109 return qgsDoubleNear( p.red, redValue )
110 && qgsDoubleNear( p.green, greenValue )
111 && qgsDoubleNear( p.blue, blueValue );
114 if ( it != mTransparentThreeValuePixelList.constEnd() )
129 QDomElement rasterTransparencyElem = doc.createElement( QStringLiteral(
"rasterTransparency" ) );
130 if ( !mTransparentSingleValuePixelList.isEmpty() )
132 QDomElement singleValuePixelListElement = doc.createElement( QStringLiteral(
"singleValuePixelList" ) );
133 auto it = mTransparentSingleValuePixelList.constBegin();
134 for ( ; it != mTransparentSingleValuePixelList.constEnd(); ++it )
136 QDomElement pixelListElement = doc.createElement( QStringLiteral(
"pixelListEntry" ) );
139 pixelListElement.setAttribute( QStringLiteral(
"percentTransparent" ), QString::number( 100.0 * ( 1 - it->opacity ) ) );
140 singleValuePixelListElement.appendChild( pixelListElement );
142 rasterTransparencyElem.appendChild( singleValuePixelListElement );
145 if ( !mTransparentThreeValuePixelList.isEmpty() )
147 QDomElement threeValuePixelListElement = doc.createElement( QStringLiteral(
"threeValuePixelList" ) );
148 auto it = mTransparentThreeValuePixelList.constBegin();
149 for ( ; it != mTransparentThreeValuePixelList.constEnd(); ++it )
151 QDomElement pixelListElement = doc.createElement( QStringLiteral(
"pixelListEntry" ) );
155 pixelListElement.setAttribute( QStringLiteral(
"percentTransparent" ), QString::number( 100.0 * ( 1 - it->opacity ) ) );
156 threeValuePixelListElement.appendChild( pixelListElement );
158 rasterTransparencyElem.appendChild( threeValuePixelListElement );
160 parentElem.appendChild( rasterTransparencyElem );
170 mTransparentSingleValuePixelList.clear();
171 mTransparentThreeValuePixelList.clear();
172 QDomElement currentEntryElem;
174 const QDomElement singlePixelListElem = elem.firstChildElement( QStringLiteral(
"singleValuePixelList" ) );
175 if ( !singlePixelListElem.isNull() )
177 const QDomNodeList entryList = singlePixelListElem.elementsByTagName( QStringLiteral(
"pixelListEntry" ) );
178 for (
int i = 0; i < entryList.size(); ++i )
180 currentEntryElem = entryList.at( i ).toElement();
183 const double opacity = 1.0 - currentEntryElem.attribute( QStringLiteral(
"percentTransparent" ) ).toDouble() / 100.0;
185 if ( currentEntryElem.hasAttribute( QStringLiteral(
"pixelValue" ) ) )
187 min = max = currentEntryElem.attribute( QStringLiteral(
"pixelValue" ) ).toDouble();
191 min = currentEntryElem.attribute( QStringLiteral(
"min" ) ).toDouble();
192 max = currentEntryElem.attribute( QStringLiteral(
"max" ) ).toDouble();
197 const QDomElement threeValuePixelListElem = elem.firstChildElement( QStringLiteral(
"threeValuePixelList" ) );
198 if ( !threeValuePixelListElem.isNull() )
200 const QDomNodeList entryList = threeValuePixelListElem.elementsByTagName( QStringLiteral(
"pixelListEntry" ) );
201 for (
int i = 0; i < entryList.size(); ++i )
203 currentEntryElem = entryList.at( i ).toElement();
204 const double red = currentEntryElem.attribute( QStringLiteral(
"red" ) ).toDouble();
205 const double green = currentEntryElem.attribute( QStringLiteral(
"green" ) ).toDouble();
206 const double blue = currentEntryElem.attribute( QStringLiteral(
"blue" ) ).toDouble();
207 const double opacity = 1.0 - currentEntryElem.attribute( QStringLiteral(
"percentTransparent" ) ).toDouble() / 100.0;