summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-09-05 12:11:22 -0400
committerpommicket <pommicket@gmail.com>2023-09-05 12:11:22 -0400
commit037d3dd675eba2ebee9fce7a79eaebc7c7442d73 (patch)
tree4403607fb1ab8a89d96c81b05a474d1f5f40d973 /README.md
parent08db1dc9428ea5bc9604b229d686af1414d461af (diff)
wrote conversion function, but it's failing some tests
Diffstat (limited to 'README.md')
-rw-r--r--README.md54
1 files changed, 25 insertions, 29 deletions
diff --git a/README.md b/README.md
index 15c3360..c3e7e62 100644
--- a/README.md
+++ b/README.md
@@ -8,16 +8,16 @@ Also it has tiny code size (e.g. 5x smaller `.wasm.gz` size compared to the `png
## Goals
-- Correctly decode all valid non-interlaced PNG files which can fit in memory.
-- Small code size
-- No dependencies other than `core`.
-- No panics.
+- Correctly decode all valid non-interlaced PNG files (on 32-bit platforms, some very large images
+ might fail because of `usize::MAX`).
+- Small code size &amp; complexity
+- No dependencies other than `core`
+- 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)
+- Adam7 interlacing (increases code complexity and interlaced PNGs are rare anyways)
- 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)
@@ -30,25 +30,24 @@ Basic usage:
let mut buffer = vec![0; 1 << 20]; // hope this is big enough!
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]);
// (^ this only makes sense for RGB 8bpc images)
```
-Allocate the right number of bytes:
+More complex example that allocates the right number of bytes:
```rust
let mut png = &include_bytes!("../examples/image.png")[..];
let header = tiny_png::read_png_header(&mut png).expect("bad PNG");
-let mut buffer = vec![0; header.required_bytes()];
-let image = tiny_png::read_png(&mut png, Some(&header), &mut buffer).expect("bad PNG");
+let mut buffer = vec![0; header.required_bytes_rgba8bpc()];
+let mut image = tiny_png::read_png(&mut png, Some(&header), &mut buffer).expect("bad PNG");
+image.convert_to_rgba8bpc();
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]);
-// (^ this only makes sense for RGB 8bpc images)
+println!("top-left pixel is #{:02x}{:02x}{:02x}{:02x}", pixels[0], pixels[1], pixels[2], pixels[3]);
```
## Features
@@ -68,20 +67,17 @@ ln -s ../../pre-commit .git/hooks/
## License
-```text
-Zero-Clause BSD
-=============
-
-Permission to use, copy, modify, and/or distribute this software for
-any purpose with or without fee is hereby granted.
-
-THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL
-WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
-OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
-FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
-DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
-AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
-OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-```
-
-Note: all the test PNG images are either in the U.S. public domain or are CC0-licensed.
+> Zero-Clause BSD
+>
+> Permission to use, copy, modify, and/or distribute this software for
+> any purpose with or without fee is hereby granted.
+>
+> THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL
+> WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+> OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
+> FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
+> DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+> AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+> OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+(Note: all the test PNG images are either in the U.S. public domain or CC0-licensed.)