Expand description
AA compositing: Porter-Duff source-over with per-pixel coverage.
Single public entry: composite_aa_rgb8_opaque — RGB pixels with no
alpha plane (opaque destination). The compositing formula simplifies to
c = div255((255-a_src)*c_dst + a_src*c_src) per channel. Expressed as
[u16; LANE] lanes so that LLVM auto-vectorizes into AVX2/AVX-512 when
the binary is compiled with -C target-cpu=native.
§Why [u16; LANE] instead of explicit intrinsics
tiny-skia’s lowp pipeline uses the same technique (see src/wide/u16x16_t.rs
and its comment: “No need for explicit AVX2 SIMD; -C target-cpu=native will
autovectorize better than us”). A plain [u16; 16] array with straight
arithmetic on u16 gives LLVM the freedom to choose the best instruction
width (128/256/512-bit) for the target, without us hard-coding a specific ISA.
§div255 approximation
(v + 255) >> 8 approximates v / 255 with at most ±1 LSB of error.
This matches the tiny-skia lowp div255 and is cheaper to auto-vectorize
than the higher-precision (v + (v>>8) + 0x80) >> 8 form.
Functions§
- composite_
aa_ rgb8_ opaque - Composite a solid RGB source over an opaque destination (no alpha plane).