denise_render/lib.rs
1//! Denise's software rasteriser.
2//!
3//! Rectangles, rounded rectangles, circles, arcs, lines, rectangular clipping
4//! and source-over alpha blending, straight into a [`denise::Frame`]. No GPU, no
5//! path builder, no allocator: this crate needs neither `std` nor `alloc`, and
6//! every operation writes through a borrowed slice the caller already owns.
7//!
8//! ```no_run
9//! # use denise::{Color, Frame, Rect, Point};
10//! # use denise_render::Canvas;
11//! # fn draw(frame: &mut Frame<'_>, damage: &[Rect]) {
12//! let mut canvas = Canvas::new(frame);
13//! for region in damage {
14//! // Everything inside this borrow is confined to `region`.
15//! let mut c = canvas.with_clip(*region);
16//! c.clear(Color::from_rgb888(0x1E1E2E));
17//! c.fill_rounded_rect(Rect::new(40, 40, 200, 64), 12, Color::rgba(255, 255, 255, 32));
18//! c.draw_line(Point::new(40, 120), Point::new(240, 121), Color::WHITE);
19//! // A 70% progress ring. Angles are binary turns: 0 is twelve o'clock,
20//! // clockwise positive, no radians and no floats anywhere.
21//! c.stroke_arc(Point::new(300, 90), 40, 8, 0, 70 * denise_render::TURN / 100, Color::WHITE);
22//! }
23//! # }
24//! ```
25//!
26//! # No floating point
27//!
28//! The rasteriser is integer throughout, including anti-aliasing coverage. That
29//! avoids a `libm` dependency on `no_std` targets and keeps output bit-identical
30//! between x86 and ARM, so the reference tests mean the same thing on a developer's
31//! desktop and on the Pi.
32//!
33//! # No `unsafe`
34//!
35//! Deliberately, for now. Bounds checks are hoisted by working through row slices
36//! rather than indexing pixel by pixel. If the benches ever show that costing real
37//! time, that is the evidence needed to justify unchecked access — not before.
38
39#![cfg_attr(not(feature = "std"), no_std)]
40
41pub mod blend;
42pub mod canvas;
43pub mod coverage;
44pub mod font;
45
46mod arc;
47mod line;
48mod rect;
49mod rounded;
50
51#[cfg(test)]
52mod testing;
53
54pub use arc::TURN;
55pub use blend::Paint;
56pub use canvas::{Canvas, PixelView};
57pub use coverage::Mask;
58pub use font::BitmapFont;
59
60/// Compiles the examples in this crate's README, so they cannot drift from the API
61/// they claim to demonstrate. Never built except under `cargo test --doc`.
62#[cfg(doctest)]
63#[doc = include_str!("../README.md")]
64struct Readme;