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

Overview

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. Compatible with avr-progmem.

[dependencies]
stockbook = "0.3.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 type, 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/star.png (scaled x8 for preview, originally 12x12 px):

Star

File src/lib.rs:

{}, // Treat as transparent Color::White => draw_pixel_at(x, y), } } } fn draw_pixel_at(x: usize, y: usize) { /* ... */ }">
use stockbook::{stamp, Color, Stamp};

static STAR_SPRITE: Stamp = stamp!("assets/star.png");

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

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

Supported formats

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

Feature flags

  • progmem — wraps all pixel data of Stamps in avr_progmem::wrapper::ProgMems. Combined with the avr target architecture, this allows you to keep most of the data in program memory without the need to copy it to RAM. A no-op for non-avr target architectures.

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.

You might also like...
tidy-builder is a builder generator that is compile-time correct.
tidy-builder is a builder generator that is compile-time correct.

The Builder derive macro creates a compile-time correct builder which means that it only allows you to build the given struct if and only if you provi

Choose Rust types at compile-time via boolean constants

condtype Choose Rust types at compile-time via boolean constants, brought to you by Nikolai Vazquez. If you find this library useful, consider starrin

belt is a command line app that can show your time from a list of selected time zones

A CLI app to show your time from a list of selected time zones, and a rust lib to parse dates in string formats that are commonly used.

Evaluate performance gains to expect when EVM were to compile hot contracts into machine code

Convert evm bytecode to native machine code and go vroom - just an experiment, probably broken, reach out to [email protected] to contribute / productionize.

My own image file format created for fun! Install the "hif_opener.exe" to open hif files. clone the repo and compile to make your own hif file

Why am i creating this? I wanted to create my own image format since I was 12 years old using Windows 7, tryna modify GTA San Andreas. That day, when

Fast conversion between linear float and 8-bit sRGB

fast-srgb8 Small crate implementing fast conversion between linear float and 8-bit sRGB. Includes API for performing 4 simultaneous conversions, which

An Intel HAXM powered, protected mode, 32 bit, hypervisor addition calculator, written in Rust.

HyperCalc An Intel HAXM powered, protected mode, 32 bit, hypervisor addition calculator, written in Rust. Purpose None 😏 . Mostly just to learn Rust

Bit fields and masks for rust!

ubits Bit fields and masks for rust! Provides a macro for generating bit field types complete with flags and some helpful trait implementations. Suppo

CIEBII - Check if every bit is intact
CIEBII - Check if every bit is intact

CIEBII Checks If Every Byte Is Intact CIEBII is an image file format that checks if every single byte is intact. What does it do if it finds that a by

Comments
  • Add the `

    Add the `"progmem"` feature

    This pull request adds a "progmem" feature flag which wraps all pixel data of Stamps in avr_progmem::wrapper::ProgMems. Combined with the avr target, this allows the users to keep most of the data in program memory without the need to copy it to RAM.

    enhancement 
    opened by karolbelina 0
  • Add generic sizes for `Stamp`s

    Add generic sizes for `Stamp`s

    This pull request adds a way to encode the size of a Stamp in its type parameters.

    use stockbook::{stamp, Size, Stamp};
    
    static IMAGE: Stamp<Size<12, 8>> = stamp!("image_12x8.png");
    
    enhancement 
    opened by karolbelina 0
Releases(0.3.0)
  • 0.3.0(Oct 27, 2022)

    • Revert adding generic sizes for Stamps
    • Add the "progmem" feature (https://github.com/karolbelina/stockbook/pull/2)

    Full Changelog: https://github.com/karolbelina/stockbook/compare/0.2.0...0.3.0

    Source code(tar.gz)
    Source code(zip)
  • 0.2.0(Oct 23, 2022)

    • Add generic sizes for Stamps (https://github.com/karolbelina/stockbook/pull/1)

    Full Changelog: https://github.com/karolbelina/stockbook/compare/0.1.1...0.2.0

    Source code(tar.gz)
    Source code(zip)
  • 0.1.1(Oct 23, 2022)

  • 0.1.0(Oct 23, 2022)

Owner
Karol Belina
Karol Belina
A simple Node.js library to convert raster images into svg

@neplex/vectorizer A simple Node.js library to convert raster images into svg using VTracer, with time complexity of O(n). Installation npm install @n

Neplex 21 Dec 28, 2023
A bit like tee, a bit like script, but all with a fake tty. Lets you remote control and watch a process

teetty teetty is a wrapper binary to execute a command in a pty while providing remote control facilities. This allows logging the stdout of a process

Armin Ronacher 259 Jan 3, 2023
Catch Tailwindcss Errors at Compile-Time Before They Catch You, without making any change to your code! Supports overriding, extending, custom classes, custom modifiers, Plugins and many more 🚀🔥🦀

twust Twust is a powerful static checker in rust for TailwindCSS class names at compile-time. Table of Contents Overview Installation Usage Statement

null 15 Nov 8, 2023
A series of crates that I made to compile images/video into asciinema & play them.

Bad Apple A series of crates that I made to compile images/video into asciinema & play them. The end goal is to make a kernel & legacy bootloader that

S0ra 10 Nov 29, 2022
ChatGPT powered Rust proc macro that generates code at compile-time.

gpt-macro ChatGPT powered Rust proc macro that generates code at compile-time. Implemented Macros auto_impl!{} #[auto_test(...)] Usage Get ChatGPT API

Akira Moroo 429 Apr 15, 2023
Deadliner helps you keep track of the time left for your deadline by dynamically updating the wallpaper of your desktop with the time left.

Deadliner Watch the YouTube video What's Deadliner? Deadliner is a cross-platform desktop application for setting deadline for a project and keeping t

Deadliner 34 Dec 16, 2022
Convert your favorite images and wallpapers with your favorite color palettes/themes

dipc doprz' image palette converter Convert your favorite images and wallpapers with your favorite color palettes/themes Color Palettes/Themes catppuc

null 50 Apr 26, 2023
Advent of Code 2021, also an attempt to practice a bit of Rust.

Advent of Code 2021 Advent of Code 2021 (my first one!), also an attempt to practice a bit of Rust. Running (Assuming that the respective inputs are i

Edoardo Debenedetti 1 Dec 3, 2021
A strong, compile-time enforced authorization framework for rust applications.

DACquiri A compile-time enforced authorization framework for Rust applications. Authorization In typical applications, authorization checks are perfor

resync 247 Dec 20, 2022
Utilites for working with `bevy_ecs` when not all types are known at compile time

bevy_ecs_dynamic Utilities for working with bevy_ecs in situations where the types you're dealing with might not be known at compile time (e.g. script

Jakob Hellermann 17 Dec 9, 2022