Skip to main content

denise_render/
lib.rs

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