Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 146 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ members = [
"piet-web",
"piet-web/examples/basic",
"piet-svg"
]
, "piet-next", "cpu-sparse"]

default-members = [
"piet",
Expand Down
17 changes: 17 additions & 0 deletions cpu-sparse/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "cpu-sparse"
version = "0.1.0"
authors = ["Raph Levien <[email protected]>"]
description = "An experimental CPU 2D renderer based on sparse strips"
license = "Apache-2.0 OR MIT"
edition = "2021"
keywords = ["graphics", "2d"]
categories = ["graphics"]

[dependencies]
piet-next = { path = "../piet-next" }
flatten = { git = "https://github.com/linebender/gpu-stroke-expansion-paper", rev = "827ccf6" }

[dev-dependencies]
png = "0.17.14"
roxmltree = "0.20.0"
38 changes: 38 additions & 0 deletions cpu-sparse/examples/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2024 the Piet Authors
// SPDX-License-Identifier: Apache-2.0 OR MIT

use std::io::BufWriter;

use cpu_sparse::{CsRenderCtx, Pixmap};
use piet_next::peniko::color::palette;
use piet_next::peniko::kurbo::{BezPath, Stroke};
use piet_next::RenderCtx;

const WIDTH: usize = 1024;
const HEIGHT: usize = 256;

pub fn main() {
let mut ctx = CsRenderCtx::new(WIDTH, HEIGHT);
let mut path = BezPath::new();
path.move_to((10.0, 10.0));
path.line_to((180.0, 20.0));
path.line_to((30.0, 40.0));
path.close_path();
let piet_path = path.into();
ctx.fill(&piet_path, palette::css::REBECCA_PURPLE.into());
let stroke = Stroke::new(5.0);
ctx.stroke(&piet_path, &stroke, palette::css::DARK_BLUE.into());
if let Some(filename) = std::env::args().nth(1) {
let mut pixmap = Pixmap::new(WIDTH, HEIGHT);
ctx.render_to_pixmap(&mut pixmap);
pixmap.unpremultiply();
let file = std::fs::File::create(filename).unwrap();
let w = BufWriter::new(file);
let mut encoder = png::Encoder::new(w, WIDTH as u32, HEIGHT as u32);
encoder.set_color(png::ColorType::Rgba);
let mut writer = encoder.write_header().unwrap();
writer.write_image_data(pixmap.data()).unwrap();
} else {
ctx.debug_dump();
}
}
Loading
Loading