diff options
author | pommicket <pommicket@gmail.com> | 2023-09-04 18:46:27 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-09-04 18:46:27 -0400 |
commit | 26befe536c56d0e8ff47d07bdc1d64086fdc0394 (patch) | |
tree | 9fe96174d6f82371de6e1763a6205f5cdf974c83 /README.md | |
parent | 7f7c4845e0ad01b229f30769708fad5fe7f72e1e (diff) |
adler feature, etc.
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 27 |
1 files changed, 22 insertions, 5 deletions
@@ -2,7 +2,7 @@ Tiny Rust PNG decoder. -This decoder can be used without `std` or even `alloc` by disabling the `std` feature (enabled by default). +This decoder can be used without `std` or `alloc` by disabling the `std` feature (enabled by default). ## Goals @@ -15,17 +15,19 @@ This decoder can be used without `std` or even `alloc` by disabling the `std` fe - Adam7 interlacing (interlaced PNGs are rare, and this would require additional code complexity — but if you want to add it behind a feature gate, feel free to) -- Sacrificing code size for speed (except maybe with a feature enabled) +- Sacrificing code size a lot for speed (except maybe with a feature enabled) +- Checking block CRCs (increased code complexity probably isn't worth it, + and there's already Adler32 checksums for IDAT chunks) ## Example usage -Very basic usage: +Basic usage: ```rust let mut buffer = vec![0; 1 << 20]; // hope this is big enough! let mut png = &include_bytes!("image.png")[..]; let image = tiny_png::read_png(&mut png, None, &mut buffer).expect("bad PNG"); -println!("{}x{} image", image.width(), image.height()); +println!("{}×{} image", image.width(), image.height()); let pixels = image.pixels(); println!("top-left pixel is #{:02x}{:02x}{:02x}", pixels[0], pixels[1], pixels[2]); // (^ this only makes sense for RGB 8bpc images) @@ -39,8 +41,23 @@ let header = tiny_png::read_png_header(&mut png).expect("bad PNG"); println!("need {} bytes of memory", header.required_bytes()); let mut buffer = vec![0; header.required_bytes()]; let image = tiny_png::read_png(&mut png, Some(&header), &mut buffer).expect("bad PNG"); -println!("{}x{} image", image.width(), image.height()); +println!("{}×{} image", image.width(), image.height()); let pixels = image.pixels(); println!("top-left pixel is #{:02x}{:02x}{:02x}", pixels[0], pixels[1], pixels[2]); // (^ this only makes sense for RGB 8bpc images) ``` + +## Features + +- `std` (default: enabled) — use standard library. enabling it allows you to read from `BufReader<File>` but + adds `std` as a dependency. +- `adler` (default: disabled) — check Adler-32 checksums. slightly increases code size and + slightly decreases performance but verifies integrity of PNG files. + +## Development + +A `pre-commit` git hook is provided to run `cargo fmt` and `cargo clippy`. You can install it with: + +```sh +ln -s ../../pre-commit .git/hooks/ +``` |