tiny-skia icon indicating copy to clipboard operation
tiny-skia copied to clipboard

Port analytical anti-aliased Path filling

Open RazrFalcon opened this issue 5 years ago • 1 comments

Aka SkScan_AAAPath.cpp.

There are a lot of code, like 2000-2500 LOC, and this method used only in some specific cases. Mainly for polygons, afaiu. Not sure if it's worth it.

RazrFalcon avatar Nov 07 '20 21:11 RazrFalcon

Example of aliasing

fn main() {
    let mut paint = Paint::default();
    paint.anti_alias = true;
    paint.set_color_rgba8(255, 0, 0, 255);

    let mut n = 12;
    let mut pixmap = Pixmap::new(n, n).unwrap();
    let width = 1. / n as f32;
    for x in 0..n {
        for y in 0..n {

            let origin = ((x as f32) * (1.0 + width), (y as f32) * (1.0 + width));

            pixmap.fill_path(&{
                let mut pb = PathBuilder::new();
                pb.move_to(origin.0, origin.1);
                pb.line_to(origin.0, origin.1 + width);
                pb.line_to(origin.0 + width, origin.1 + width);
                pb.line_to(origin.0 + width, origin.1);
                pb.close();
                pb.finish().unwrap()
            }, &paint,FillRule::EvenOdd,Transform::identity(),None);
        }
    }

    pixmap.save_png("./image.png").unwrap();
}

Render (x10) image

Azervu avatar Feb 07 '22 18:02 Azervu