6 releases
0.5.0-rc4 | May 12, 2024 |
---|---|
0.5.0-rc3 | Apr 22, 2024 |
0.5.0-rc0 | Apr 7, 2024 |
0.4.0 | Nov 16, 2023 |
#898 in Images
935 downloads per month
Used in 3 crates
(via zune-image)
170KB
2.5K
SLoC
zune-bmp
A lean, mean and green BMP decoder.
This crate contains a fast implemtnation of a BMP decoder with battery included support for the esoteric parts of the spec
Features
- RLE support
- 1-bit,4-bit,8-bit,16-bit,24-bit and 32-bit support
- Performant
Usage
First add the project to your library/binary
zune-bmp = "0.4" # Or use cargo add zune-bmp
Then you can toy with the other configs
use zune_bmp::BmpDecoder;
use zune_bmp::BmpDecoderErrors;
fn main()->Result<(),BmpDecodeErrors>{
let decoder:Vec<u8> = BmpDecoder::new(b"BMP").decode()?;
}
Security
The decoder is continuously fuzz tested in CI to ensure it does not crash on malicious input in case a sample causes it to crash, an issue would be welcome.
lib.rs
:
A versatile BMP decoder
This crate features a BMP decoder capable of decoding multiple BMP images fast
Features
no_std
by default withalloc
feature- Fast
- Minimal dependencies
- Very minimal internal allocation. (most paths do not allocate any more than output buffer)
Supported formats
- RLE (4 bit and 8 bit)
- Paletted images(1 bit, 2 bits, 4 bits and 8 bits)
- Masked images (16 bit and 32 bit formats)
Unsupported formats
- Embedded PNG and JPEGs
- Images with embedded color profiles. (the embedded color profile is ignored)
Features
log
: Use thelog
crate features to print image information when decodingstd
: Allow direct decoding from anything that implementsstd::io::BufRead
+std::io::Seek
Usage
It is recommended that if you have an in memory buffer you use
ZCursor
to read as it is more optimized when compared to std::io::Cursor
since it's
methods are specialized for the ZByteReaderTrait
use zune_bmp::BmpDecoder;
use zune_core::bytestream::ZCursor;
let decoder:Vec<u8> = BmpDecoder::new(ZCursor::new(b"BMP")).decode().unwrap();
You can also read directly from bmp files. This can be preferred when you don't have the file contents in memory and just want the pixels
It's recommended you wrap the file in a bufreader.
This requires the std
feature to work.
use std::fs::File;
use std::io::BufReader;
use zune_bmp::BmpDecoder;
// read from a file
let source = BufReader::new(File::open("./image.bmp").unwrap());
// only run when std is enabled, otherwise zune_core doesn't implement the ZByteReader trait
// on File since it doesn't exist in `no_std` land
#[cfg(feature = "std")]
let decoder = BmpDecoder::new(source);
Security
The decoder is continuously fuzz tested in CI to ensure it does not crash on malicious input in case a sample causes it to crash, an issue would be welcome.
Performance
BMP isn't a compute heavy image format, this crate should not be a bottleneck in any way possible, benchmark just in case you think it's slowing you down in any way.
Dependencies
~86KB