MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / compositeOver

Function compositeOver

src/utils/snapCapture.ts:55–67  ·  view source on GitHub ↗
(top: RgbaColor, bottom: RgbaColor)

Source from the content-addressed store, hash-verified

53}
54
55function 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
69function toOpaqueRgbString(color: RgbaColor): string {
70 return `rgb(${Math.round(color.r)}, ${Math.round(color.g)}, ${Math.round(color.b)})`

Callers 1

getEffectiveBackgroundFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected