#vector-graphics #simd #render #svg #no-std

no-std wizdraw

Tiny no_std crate to fill and stroke composite bezier curves (SIMD/SSAA)

10 stable releases

2.0.0 Dec 6, 2023
1.2.1 Aug 11, 2023
1.2.0 Jun 30, 2023
1.1.4 Mar 23, 2023
1.0.0 Jul 2, 2022

#26 in Rendering

Download history 4/week @ 2024-02-12 19/week @ 2024-02-26 7/week @ 2024-03-04 12/week @ 2024-03-11 22/week @ 2024-03-18 7/week @ 2024-03-25 154/week @ 2024-04-01

197 downloads per month
Used in 4 crates (2 directly)

MIT license

37KB
735 lines

wizdraw - Tiny no_std crate to fill and stroke composite bezier curves (SIMD/SSAA)

Limitations

  • Pixels are [R, G, B, A] values with 8-bit components
  • Point coordinates are pairs of f32

Features

  • simd: include SIMD code, which can speed rendering up when anti-aliasing is used.
  • stroke: include the util::stroke_path utility function.

By default, this crate doesn't use SIMD because a nightly toolchain is required for that.

Example

use wizdraw::{Canvas, Color, CubicBezier, Point, SsaaConfig, util};
use wizdraw::rgb::ComponentBytes;

// size of our output buffer: 1000x1000px
let mut canvas = Canvas::new(1000, 1000);

// the unit for these coordinates is a pixel
let path = [
    CubicBezier {
        c1: Point::new(250.0, 600.0),
        c2: Point::new(250.0, 250.0),
        c3: Point::new(750.0, 250.0),
        c4: Point::new(750.0, 600.0),
    },
    CubicBezier {
        c1: Point::new(750.0, 600.0),
        c2: Point::new(750.0, 400.0),
        c3: Point::new(250.0, 400.0),
        c4: Point::new(250.0, 600.0),
    },
];

// We'll generate another path which represents a line along the other path
let mut contour = Vec::new();
let stroke_width = 10.0; // px
let max_error = 1.0; // px
util::stroke_path(&path, stroke_width, &mut contour, max_error);

// use SIMD functions, if this wizdraw build has the feature
let try_to_use_simd = true;

// we'll use the highest SSAA config
let ssaa = SsaaConfig::X16;

// path holes won't show up on the output
let dont_show_holes = false;

// fill the path with a rainbow texture
canvas.fill(&path, util::rainbow, try_to_use_simd, ssaa, dont_show_holes);

// we'll draw the contour in myrtle
let myrtle = |_x, _y| Color::new(100, 100, 255, 255);
canvas.fill(&contour, myrtle, try_to_use_simd, ssaa, dont_show_holes);

// Time to use our render!
let pixels: &[Color] = canvas.pixels();
let bytes: &[u8] = pixels.as_bytes();

Demo: PNG output

Check out the png_demo example to generate this image:

output.png

Dependencies

~1.5MB
~22K SLoC