An open API service indexing awesome lists of open source software.

https://github.com/stestagg/escpos-embed-image

Companion crate to escpos-embedded that provides the embed_image!() macro
https://github.com/stestagg/escpos-embed-image

Last synced: 11 months ago
JSON representation

Companion crate to escpos-embedded that provides the embed_image!() macro

Awesome Lists containing this project

README

          

# escpos-embed-image

A procedural macro for embedding monochrome, dithered images into ESC/POS printer drivers at compile time.

Designed as a companion to `escpos-embedded`, this crate processes Images at compile time and generates a static `Image<&'static [u8]>` compatible with the `no_std`, allocation-free printer interface.

## Features

- Compile-time image loading and conversion
- Converts image file to 1-bit dithered format (Bi-level Floyd-Steinberg)
- Outputs `Image<&'static [u8]>` struct ready for printing
- No runtime dependencies

## Example

```rust
use escpos_embedded::Image;
use escpos_embed_image::{embed_image, embed_images};

static LOGO: Image<&'static [u8]> = embed_image!("assets/logo.png");

embed_images!(
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum Assets {
#[pattern("assets/*.png")]
}
);

// Generated enum `Assets` with variants for each matched file
// Assets::Logo.get_image() -> &'static Image<&'static [u8]>
```

## How it works

- At compile time, the macro loads the image file (any supported format)
- As required: Converts it to grayscale, then applies dithering
- Packs the result into 1-bit-per-pixel (row-major) format
- Emits a static `Image` instance with dimensions and data

## Requirements

- Input must be a valid image file path
- The output image must be small enough to fit in flash/ROM (no heap)

## Crate Structure

This is a separate crate from `escpos-embedded` because it uses `proc-macro` and requires `std`. It is intended for use on the host during build/compile time only.