summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-09-04 13:54:53 -0400
committerpommicket <pommicket@gmail.com>2023-09-04 14:01:49 -0400
commit7f7c4845e0ad01b229f30769708fad5fe7f72e1e (patch)
treeca784c3c45c1a61aa3276f76422e04e59095f95e /examples
parent36cc87543dd8a90342aa9d922d9f9fef852df91c (diff)
more tests
Diffstat (limited to 'examples')
-rw-r--r--examples/alloc_correct.rs14
-rw-r--r--examples/image.pngbin0 -> 465986 bytes
-rw-r--r--examples/small.pngbin233 -> 0 bytes
-rw-r--r--examples/small.rs7
-rw-r--r--examples/very_basic.rs12
5 files changed, 26 insertions, 7 deletions
diff --git a/examples/alloc_correct.rs b/examples/alloc_correct.rs
new file mode 100644
index 0000000..6711a1c
--- /dev/null
+++ b/examples/alloc_correct.rs
@@ -0,0 +1,14 @@
+fn main() {
+ let mut png = &include_bytes!("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");
+ println!("{}x{} 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)
+}
diff --git a/examples/image.png b/examples/image.png
new file mode 100644
index 0000000..5452484
--- /dev/null
+++ b/examples/image.png
Binary files differ
diff --git a/examples/small.png b/examples/small.png
deleted file mode 100644
index 47226a2..0000000
--- a/examples/small.png
+++ /dev/null
Binary files differ
diff --git a/examples/small.rs b/examples/small.rs
deleted file mode 100644
index e6af172..0000000
--- a/examples/small.rs
+++ /dev/null
@@ -1,7 +0,0 @@
-fn main() {
- let mut data = &include_bytes!("small.png")[..];
- let header = tiny_png::read_png_header(&mut data).unwrap();
- let mut buf = vec![0; header.required_bytes()];
- let result = tiny_png::read_png(&mut data, Some(&header), &mut buf);
- println!("{result:?}");
-}
diff --git a/examples/very_basic.rs b/examples/very_basic.rs
new file mode 100644
index 0000000..33043b6
--- /dev/null
+++ b/examples/very_basic.rs
@@ -0,0 +1,12 @@
+fn main() {
+ let mut my_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 my_buffer).expect("bad PNG");
+ println!("{}x{} 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)
+}