C++ (Qt)static inline qreal c_to_f( int v ) { return qreal( v ) / 255.; } QColor operator+( const QColor &c1, const QColor &c2 ){ if( !c1.alpha() && !c2.alpha() ) return QColor( 0, 0, 0, 0 ); qreal a1 = c_to_f( c1.alpha() ); qreal a2 = c_to_f( c2.alpha() ); qreal a = qBound( 0., a1 + a2, 1. ); qreal r = qBound( 0., ( ( c_to_f( c1.red() ) * a1 + c_to_f( c2.red() ) * a2 ) / a, 1. ); qreal g = qBound( 0., ( ( c_to_f( c1.green() ) * a1 + c_to_f( c2.green() ) * a2 ) / a, 1. ); qreal b = qBound( 0., ( ( c_to_f( c1.blue() ) * a1 + c_to_f( c2.blue() ) * a2 ) / a, 1. );; return QColor::fromRgbF( r, g, b, a );}
C++ (Qt)QColor operator+( const QColor &c1, const QColor &c2 ){ if( !c1.alpha() && !c2.alpha() ) return QColor( 0, 0, 0, 0 ); qreal a1 = c1.alphaF(); qreal a2 = c2.alphaF(); qreal a = qBound( 0., a1 + a2, 1. ); qreal r = qBound( 0., ( c1.redF() * a1 + c2.redF() * a2 ) / a, 1. ); qreal g = qBound( 0., ( c1.greenF() * a1 + c2.greenF() * a2 ) / a, 1. ); qreal b = qBound( 0., ( c1.blueF() * a1 + c2.blueF() * a2 ) / a, 1. ); return QColor::fromRgbF( r, g, b, a );}
C++ (Qt)const QColor operator+(const QColor &c1, const QColor &c2) { qreal x = 0.5 * (1.0 - c1.alphaF() + c2.alphaF()); qreal alpha = 0.5 * (c1.alphaF() + c2.alphaF()); qreal red = c1.redF() * (1.0 - x) + x * c2.redF(); greal green = c1.greenF() * (1.0 - x) + x * c2.greenF(); qreal blue = c1.blueF() * (1.0 - x) + x * c2.blueF(); return QColor(red, green, blue, alpha);}
C++ (Qt)const QColor operator+(const QColor &c1, const QColor &c2) { qreal x = 0.5 * (1.0 - c1.alphaF() + c2.alphaF());