Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge upstream/main into stream/issue-5902-text-antialias.

nrq6993-a11y5be2b29463ae
diff --cc crates/text/src/render.rs
index 7fff345a6,39eef2075..7128085dc
--- a/crates/text/src/render.rs
+++ b/crates/text/src/render.rs
@@@ -298,8 -279,23 +301,23 @@@ pub fn rasterize_warped(layout: &TextLa
}
let comps = color_in(&format, c);
let a = c.alpha.clamp(0.0, 1.0);
- for (i, &cv) in cov.iter().enumerate() {
- let cv = shape_antialias_coverage(cv, antialias);
+ composite(&mut acc, &cov, w, stride, &comps, a, antialias);
+ }
+ // Unpremultiply.
+ unpremultiply(&mut acc, n, stride, format.sample);
+ surface.write_region_par(rect, &acc);
+ surface.prune();
+ Rendered { surface, rect }
+ }
+
-/// Composites one colour's coverage over the premultiplied accumulator, resolving `AntiAlias::None`
-/// to 0/1 first. A pixel's maths reads and writes only its own slots, so the rows are done in any
++/// Composites one colour's coverage over the premultiplied accumulator, after [`shape_antialias_coverage`].
++/// A pixel's maths reads and writes only its own slots, so the rows are done in any
+ /// order — one per thread — for exactly the same bytes.
+ fn composite(acc: &mut [f32], cov: &[f32], width: usize, stride: usize, comps: &[f32], a: f32, antialias: AntiAlias) {
+ let n = comps.len();
+ let row = |acc: &mut [f32], cov: &[f32]| {
+ for (cv, px) in cov.iter().zip(acc.chunks_exact_mut(stride)) {
- let cv = if antialias == AntiAlias::None { if *cv >= 0.5 { 1.0 } else { 0.0 } } else { *cv };
++ let cv = shape_antialias_coverage(*cv, antialias);
let s = cv * a;
if s <= 0.0 {
continue;