1 unstable release

0.1.0 Jan 19, 2025

#938 in Images

Download history 102/week @ 2025-01-19

102 downloads per month

MIT/Apache

16KB
286 lines

WBMP encoding and decoding library

WBMP encoding and decoding library written in Rust.

API

This library provides an Encoder and a Decoder.

Encoding

use std::fs::File;
use wbmp::Encoder;

let img_data = vec![
    0xFF, 0x00, 0xFF, 0x00,
    0xFF, 0x00, 0xFF, 0x00,
    0xFF, 0x00, 0xFF, 0x00,
    0xFF, 0x00, 0xFF, 0x00,
];
let (width, height) = (4, 4);
let mut out_file = File::create("checker.wbmp")?;
let mut encoder = Encoder::new(&mut out_file);
encoder.encode(&img_data, width, height, wbmp::ColorType::Luma8)?;

Decoding

use std::fs::File;
use std::io::BufReader;
use wbmp::Decoder;

let f = BufReader::new(File::open("path/to/file.wbmp").unwrap());
let mut decoder = Decoder::new(f)?;
let (width, height) = decoder.dimensions();

let mut img_data = vec![0_u8; (width * height) as usize];
decoder.read_image_data(img_data.as_mut_slice())?;

lib.rs:

Decoding and Encoding of WBMP Images

A decoder and encoder for WBMP (Wireless Bitmap Format) images

Related Links

No runtime deps