透明颜色混合算法
一般數學計算中,顏色取值是:R,G,B∈[0,255],A∈[0,1]R,G,B \in \left [ 0, 255 \right ], A\in \left [ 0, 1 \right ]R,G,B∈[0,255],A∈[0,1]
所以對于一般的顏色混合有:Color(RGBA)=Color(R1G1B1A1)+Color(R2G2B2A2)Color(RGBA) = Color(R_{1}G_{1}B_{1}A_{1}) + Color(R_{2}G_{2}B_{2}A_{2})Color(RGBA)=Color(R1?G1?B1?A1?)+Color(R2?G2?B2?A2?)
標準的顏色混合算法如下:
A=1?(1?α1)?(1?α2)A = 1 - \left ( 1-\alpha _{1} \right )*\left ( 1-\alpha _{2} \right)A=1?(1?α1?)?(1?α2?)
R=1A(α1R1+(1?α1)α2R2)R = \frac{1}{A}(\alpha _{1}R_{1}+ (1 - \alpha _{1})\alpha _{2}R_{2})R=A1?(α1?R1?+(1?α1?)α2?R2?)
G=1A(α1G1+(1?α1)α2G2)G = \frac{1}{A}(\alpha _{1}G_{1}+ (1 - \alpha _{1})\alpha _{2}G_{2})G=A1?(α1?G1?+(1?α1?)α2?G2?)
B=1A(α1B1+(1?α1)α2B2)B = \frac{1}{A}(\alpha _{1}B_{1}+ (1 - \alpha _{1})\alpha _{2}B_{2})B=A1?(α1?B1?+(1?α1?)α2?B2?)
但是在計算機圖像中,透明度alpha通常也是A∈[0,255]A \in \left [ 0, 255 \right ]A∈[0,255]
所以,根據變化得到的代碼是:
化簡后:
float a1 = A1; float a2 = A2 - (a1 * A2)/256; float a = a1 + a2;R = (a1*R1 + a2*R2)/a; G = (a1*G1 + a2*G2)/a; B = (a1*B1 + a2*B2)/a; A = a;總結
- 上一篇: LeetCode-数据库题(二) (52
- 下一篇: PP模块