stockbook

CI crates.io docs.rs

Stockbook embeds 1-bit raster images in your code at compile time.

Designed primarily for #![no_std] usage, in embedded or other program-memory-constrained environments. toml [dependencies] stockbook = "0.1.0"

The main functionality of Stockbook is the stamp! macro, which lets you include data similarly to how include_bytes! does, but from an image, specifically a 1-bit black and white image. The macro returns a Stamp struct, which just holds the image's width, height, and a static reference to the pixel data. The pixel data is represented internally as an array of bytes, in which individual bits correspond to individual pixels.

Example

File assets/invader.png (scaled x8 for preview, originally 11x8 px):

Invader

File src/lib.rs:

```rust use stockbook::{stamp, Color, Stamp};

static INVADER_SPRITE: Stamp = stamp!("assets/invader.png");

pub fn drawinvader() { for (x, y, color) in PLAYERSPRITE.pixels() { match color { Color::Black => {}, // Treat as transparent Color::White => drawpixelat(x, y), } } }

fn drawpixelat(x: usize, y: usize) { /* ... */ } ```

Supported formats

Stockbook uses the image crate under the hood. See its own list of supported formats for more details.

Unstable features

Although this library works on stable, any changes to images referenced by the stamp! macro might not be detected because of caching. Therefore, until track_path API (Tracking Issue) stabilizes, it is recommended to use the nightly toolchain, however functionality behind this feature is unstable and may change or stop compiling at any time.

License

This software is licensed under the MIT license.

See the LICENSE file for more details.