(top: RgbaColor, bottom: RgbaColor)
| 53 | } |
| 54 | |
| 55 | function compositeOver(top: RgbaColor, bottom: RgbaColor): RgbaColor { |
| 56 | const alpha = top.a + bottom.a * (1 - top.a) |
| 57 | if (alpha <= 0) { |
| 58 | return { r: 0, g: 0, b: 0, a: 0 } |
| 59 | } |
| 60 | |
| 61 | return { |
| 62 | r: (top.r * top.a + bottom.r * bottom.a * (1 - top.a)) / alpha, |
| 63 | g: (top.g * top.a + bottom.g * bottom.a * (1 - top.a)) / alpha, |
| 64 | b: (top.b * top.a + bottom.b * bottom.a * (1 - top.a)) / alpha, |
| 65 | a: alpha, |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | function toOpaqueRgbString(color: RgbaColor): string { |
| 70 | return `rgb(${Math.round(color.r)}, ${Math.round(color.g)}, ${Math.round(color.b)})` |
no outgoing calls
no test coverage detected