embedded-graphics-colorcast

Crates.ioembedded-graphics-colorcast
lib.rsembedded-graphics-colorcast
version0.1.1
created_at2025-12-12 16:55:06.643232+00
updated_at2025-12-29 12:05:12.059619+00
descriptionColor casting for embedded-graphics binary images
homepage
repositoryhttps://github.com/kpcyrd/embedded-graphics-colorcast
max_upload_size
id1981869
size23,412
(kpcyrd)

documentation

README

embedded-graphics-colorcast

Color casting for embedded-graphics images.

This crate provides an Image struct that wraps around an ImageRaw<BinaryColor> and allows rendering it to any draw target by mapping the binary colors to the target's color type.

It was originally developed for use with [https://github.com/kpcyrd/embedded-mono-img].

use embedded_graphics::{
    image::{ImageRaw, ImageRawBE},
    pixelcolor::{BinaryColor, Rgb565},
    prelude::*,
};
use embedded_graphics_colorcast::Image;

let mut display: Display<Rgb565> = Display::default();

// Raw big endian image data for demonstration purposes. A real image would likely be much
// larger.
let data = [
    0x00, 0x00, 0xF8, 0x00, 0x07, 0xE0, 0xFF, 0xE0, //
    0x00, 0x1F, 0x07, 0xFF, 0xF8, 0x1F, 0xFF, 0xFF, //
];

// Create a raw image instance. Other image formats will require different code to load them.
// All code after loading is the same for any image format.
let raw: ImageRawBE<BinaryColor> = ImageRaw::new(&data, 4);

// Create an `Image` object to position the image at `Point::zero()`.
let image = Image::new(&raw, Point::zero(), Rgb565::WHITE);

// Draw the image to the display.
image.draw(&mut display)?;

Acknowledgements

This repository contains trait implementations and documentation copied over from the embedded-graphics project (with very minor modifications).

License

MIT OR Apache-2.0

Commit count: 0

cargo fmt