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, p.fuzzyToleranceRed )
 
  110           && qgsDoubleNear( p.green, greenValue, p.fuzzyToleranceGreen )
 
  111           && qgsDoubleNear( p.blue, blueValue, p.fuzzyToleranceBlue );
 
  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 ) ) );
 
  157        pixelListElement.setAttribute( QStringLiteral( 
"toleranceRed" ), QString::number( it->fuzzyToleranceRed ) );
 
  159        pixelListElement.setAttribute( QStringLiteral( 
"toleranceGreen" ), QString::number( it->fuzzyToleranceGreen ) );
 
  161        pixelListElement.setAttribute( QStringLiteral( 
"toleranceBlue" ), QString::number( it->fuzzyToleranceBlue ) );
 
  162      threeValuePixelListElement.appendChild( pixelListElement );
 
  164    rasterTransparencyElem.appendChild( threeValuePixelListElement );
 
  166  parentElem.appendChild( rasterTransparencyElem );
 
 
  176  mTransparentSingleValuePixelList.clear();
 
  177  mTransparentThreeValuePixelList.clear();
 
  178  QDomElement currentEntryElem;
 
  180  const QDomElement singlePixelListElem = elem.firstChildElement( QStringLiteral( 
"singleValuePixelList" ) );
 
  181  if ( !singlePixelListElem.isNull() )
 
  183    const QDomNodeList entryList = singlePixelListElem.elementsByTagName( QStringLiteral( 
"pixelListEntry" ) );
 
  184    for ( 
int i = 0; i < entryList.size(); ++i )
 
  186      currentEntryElem = entryList.at( i ).toElement();
 
  189      const double opacity = 1.0 - currentEntryElem.attribute( QStringLiteral( 
"percentTransparent" ) ).toDouble() / 100.0;
 
  191      if ( currentEntryElem.hasAttribute( QStringLiteral( 
"pixelValue" ) ) )
 
  193        min = max = currentEntryElem.attribute( QStringLiteral( 
"pixelValue" ) ).toDouble();
 
  197        min = currentEntryElem.attribute( QStringLiteral( 
"min" ) ).toDouble();
 
  198        max = currentEntryElem.attribute( QStringLiteral( 
"max" ) ).toDouble();
 
  203  const QDomElement threeValuePixelListElem = elem.firstChildElement( QStringLiteral( 
"threeValuePixelList" ) );
 
  204  if ( !threeValuePixelListElem.isNull() )
 
  206    const QDomNodeList entryList = threeValuePixelListElem.elementsByTagName( QStringLiteral( 
"pixelListEntry" ) );
 
  207    for ( 
int i = 0; i < entryList.size(); ++i )
 
  209      currentEntryElem = entryList.at( i ).toElement();
 
  210      const double red = currentEntryElem.attribute( QStringLiteral( 
"red" ) ).toDouble();
 
  211      const double green = currentEntryElem.attribute( QStringLiteral( 
"green" ) ).toDouble();
 
  212      const double blue = currentEntryElem.attribute( QStringLiteral( 
"blue" ) ).toDouble();
 
  213      const double opacity = 1.0 - currentEntryElem.attribute( QStringLiteral( 
"percentTransparent" ) ).toDouble() / 100.0;
 
  215      const double toleranceRed = currentEntryElem.attribute( QStringLiteral( 
"toleranceRed" ) ).toDouble( &redOk );
 
  216      bool greenOk = 
false;
 
  217      const double toleranceGreen = currentEntryElem.attribute( QStringLiteral( 
"toleranceGreen" ) ).toDouble( &greenOk );
 
  219      const double toleranceBlue = currentEntryElem.attribute( QStringLiteral( 
"toleranceBlue" ) ).toDouble( &blueOk );
 
  221                                              redOk ? toleranceRed : 4 * std::numeric_limits<double>::epsilon(),
 
  222                                              greenOk ? toleranceGreen : 4 * std::numeric_limits<double>::epsilon(),
 
  223                                              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)