summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md19
1 files changed, 10 insertions, 9 deletions
diff --git a/README.md b/README.md
index 0176d95..746d3b8 100644
--- a/README.md
+++ b/README.md
@@ -6,19 +6,19 @@ This decoder can be used without `std` or `alloc` by disabling the `std` feature
## Goals
-- Correctly decode all non-interlaced PNG files (if a non-interlaced PNG is decoded incorrectly, please report it as a bug)
+- Correctly decode all valid non-interlaced PNG files which can fit in memory.
- Small code size
- No dependencies other than `core`.
-- No panics (if any function panics, please report it as a bug).
-- No unsafe code
+- No panics.
+- Minimal if any unsafe code
## Non-goals
- 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 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)
+- Significantly sacrificing code size for speed (except maybe with a feature enabled)
+- Checking block CRCs (increases code complexity
+ and there’s already Adler32 checksums for IDAT chunks)
## Example usage
@@ -26,8 +26,9 @@ Basic usage:
```rust
let mut buffer = vec![0; 1 << 20]; // hope this is big enough!
-let mut png = &include_bytes!("image.png")[..];
+let mut png = &include_bytes!("../examples/image.png")[..];
let image = tiny_png::read_png(&mut png, None, &mut buffer).expect("bad PNG");
+assert!(png.is_empty(), "extra data after PNG image end");
println!("{}×{} image", image.width(), image.height());
let pixels = image.pixels();
println!("top-left pixel is #{:02x}{:02x}{:02x}", pixels[0], pixels[1], pixels[2]);
@@ -37,11 +38,11 @@ println!("top-left pixel is #{:02x}{:02x}{:02x}", pixels[0], pixels[1], pixels[2
Allocate the right number of bytes:
```rust
-let mut png = &include_bytes!("image.png")[..];
+let mut png = &include_bytes!("../examples/image.png")[..];
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");
+assert!(png.is_empty(), "extra data after PNG image end");
println!("{}×{} image", image.width(), image.height());
let pixels = image.pixels();
println!("top-left pixel is #{:02x}{:02x}{:02x}", pixels[0], pixels[1], pixels[2]);