Borrowed assets and caller buffers¶
RgbaView::new(width,height,pixels,encoding,alpha_mode) borrows immutable exact
packed top-to-bottom RGBA8. Dimensions are 1..4096, bytes at most 64 MiB, with an
exact widthheight4 length. Every premultiplied pixel must have RGB<=alpha; zero
alpha requires zero RGB. A malformed final pixel rejects the entire view.
No decoder metadata or ICC/gamma chunk is inferred. The consumer decides whether
an ImageAsset's decoded numeric bytes represent sRGB or another supported profile.
convert_into validates exact destination length before any write. Identical
profiles copy exact bytes. Same-encoding alpha reassociation uses exact rational
integer nearest half-up rounding. Changed transfer uses normalized f64 functions,
followed by nearest half-up byte quantization. RGBA8 linear storage is lossy;
arbitrary transfer roundtrips are not promised.
composite_source_over takes foreground and backdrop views, explicit output
encoding/alpha mode, and a caller destination. Both dimensions must match and the
output length must be exact. Full preflight precedes output writes. Safe Rust
borrows prevent input/output alias. Compositing is linear-light Porter-Duff
source-over; final alpha is linear, then RGB receives the chosen output transfer
and association. Both caller-buffer operations allocate nothing; caller-created
assets/buffers and consumer snapshots can allocate. Scalar powf/library work has
no real-time deadline guarantee.
The normalized standard sRGB transfer uses encoded breakpoint 0.04045 and divisor 12.92, otherwise exponent 2.4 with constants 0.055/1.055; inverse linear breakpoint 0.0031308 uses the inverse exponent. Source-over combines premultiplied linear RGB as Csas + Cbab(1-as), with resulting alpha as + ab(1-as). Nonzero result alpha recovers straight RGB before output encoding. Normalized contribution weights avoid unnecessary underflow at subnormal alpha.