def pixel.over

gralha-svg-render@0.1.0.1 · svg.bend:5165

import gralha-svg-render@0.1.0.1/svg.bend as Svg
import Base

5165# front over back, both premultiplied: front + back * (255 - alpha) / 255 per
5166# channel, written as one expression over the four lanes.
5167def pixel.over(+front: U32, +back: U32) -> U32:
5168  +fa = U32.div(front, 16777216)
5169  +keep = (255 - fa : U32)
5170  +fb = U32.mod(U32.div(front, 65536), 256)
5171  +fg = U32.mod(U32.div(front, 256), 256)
5172  +fr = U32.mod(front, 256)
5173  +ba = U32.div(back, 16777216)
5174  +bb = U32.mod(U32.div(back, 65536), 256)
5175  +bg = U32.mod(U32.div(back, 256), 256)
5176  +br = U32.mod(back, 256)
5177  (fr + U32.div((br * keep + 127 : U32), 255) + (fg + U32.div((bg * keep + 127 : U32), 255)) * 256 + (fb + U32.div((bb * keep + 127 : U32), 255)) * 65536 + (fa + U32.div((ba * keep + 127 : U32), 255)) * 16777216 : U32)

Uses (6)

Used by (1)