C++ (Qt)QColor mix2clr(const QColor &clr1, const QColor &clr2) { qreal r = clr1.redF() + (clr2.redF() - clr1.redF()) * clr2.alphaF(); qreal g = clr1.greenF() + (clr2.greenF() - clr1.greenF()) * clr2.alphaF(); qreal b = clr1.blueF() + (clr2.blueF() - clr1.blueF()) * clr2.alphaF(); return QColor(r, g, b, qMax(clr1.alphaF(), clr2.alphaF()));}
C++ (Qt)inline qreal __blend(qreal s, qreal d, qreal a){ return s + (d - s) * a;} QColor color_blend(const QColor& c1, const QColor& c2){ QColor res; res.setRedF(__blend(c1.redF(), c2.redF(), c2.alphaF())); res.setGreenF(__blend(c1.greenF(), c2.greenF(), c2.alphaF())); res.setBlueF(__blend(c1.blueF(), c2.blueF(), c2.alphaF())); res.setAlphaF((1 - c1.alphaF()) * c2.alphaF() + c1.alphaF()); return res;}
C++ (Qt) ... return QColor(r, g, b, qMax(clr1.alphaF(), clr2.alphaF()))
C++ (Qt)QColor CombineTrans( const QColor & fore, const QColor & back ){ float foreA = fore.alphaF(); float backA = back.alphaF(); if (foreA + backA <= 0.0f) return QColor(0, 0, 0, 0); // full transparent float newA = backA * (1.0f - foreA); // added alpha float sumA = foreA + newA; // combined alpha // Red component float foreR = fore.redF(); float backR = back.redF(); float sumR = (foreR * foreA + backR * newA) / sumA; // Green & Blue components ... QColor result; result.setRgbF(sumR, sumG, sumB, sumA); return result;}
C++ (Qt)// Red component float foreR = fore.redF(); float backR = back.redF(); float sumR = (foreR * foreA + backR * newA) / sumA;
C++ (Qt) qreal r = clr1.redF() + (clr2.redF() - clr1.redF()) * clr2.alphaF();
C++ (Qt)inline qreal __blend(qreal s, qreal d, qreal a){ return s + (d - s) * a;}