bmp8bit 0.1.0

Converts raster image to 256 colors format and writes it as bmp
Documentation
  • Coverage
  • 0%
    0 out of 32 items documented0 out of 21 items with examples
  • Size
  • Source code size: 54.39 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.3 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 40s Average build duration of successful builds.
  • all releases: 40s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Documentation
  • zelenyhleb/bmp8bit
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • zelenyhleb

bmp8bit

Popular image libraries written in Rust do not allow color table based bmps to be saved. This small crate extends image-rs so it is able to write Dynamic Image as 256-colors BMP.

Theoretically it can write images with custom color tables, but I never tried it. See the Usage section for further details.

Building

cargo build

Usage

If you use image-rs, usage is just:

use bmp8bit::{self, save_8bit_win};
let img: image::DynamicImage = somehow_acquired_image();
save_8bit_win(img, "out/img_8bit.bmp");

Your own raster image representation

If your have your own raster image representation implemented, you'll need to implement Colors256 trait. It has two methods:

  • samples is for converting your raster image representation to bytes vector using specified color table. This vector should contain the whole image. Use ColorTableSample::new to convert your sample to color table sample and then ColorTable::convert to acquire vector of bytes for your sample.
  • size just returns Dimensions struct which describes your image width and height.

You can find reference implementation in image_rs module.

Custom color table

Theoretically, Colors256::samples using custom color table would also generate a valid bmp image. Needs some testing. windows_color_table can be taken as an example.

License

Apache License Version 2.0

Contributing

I am not really good in Rust yet, so any issue reports, improvements, suggestions (even for code style) are appreciated.