libwebp/lib.rs
1//! # libwebp
2//!
3//! This is a binding to [the libwebp library](https://developers.google.com/speed/webp/download).
4//!
5//! ## Usage
6//!
7//! ### Preparation
8//!
9//! ```toml
10//! # Cargo.toml
11//!
12//! [dependencies]
13//! libwebp = { version = "0.1.2", features = ["0_6"] }
14//! ```
15//!
16//! ### Simple decoding
17//!
18//! You can use [`WebPDecodeRGBA`] or [`WebPDecodeRGBAInto`] families for
19//! simple decoding.
20//!
21//! [`WebPDecodeRGBA`]: fn.WebPDecodeRGBA.html
22//! [`WebPDecodeRGBAInto`]: fn.WebPDecodeRGBAInto.html
23//!
24//! ```rust
25//! use libwebp::WebPDecodeRGBA;
26//!
27//! let data: &[u8];
28//! # let data: &[u8] = include_bytes!("lena.webp");
29//!
30//! let (width, height, buf) = WebPDecodeRGBA(data).unwrap();
31//! # assert_eq!((width, height), (128, 128));
32//! assert_eq!(buf.len(), width as usize * height as usize * 4);
33//! eprintln!("width = {}, height = {}", width, height);
34//! eprintln!(
35//! "top-left pixel: rgba({}, {}, {}, {})",
36//! buf[0],
37//! buf[1],
38//! buf[2],
39//! buf[3] as f64 / 255.0,
40//! )
41//! ```
42//!
43//! ### Simple encoding
44//!
45//! You can use [`WebPEncodeRGBA`] or [`WebPEncodeLosslessRGBA`] families for
46//! simple encoding.
47//!
48//! [`WebPEncodeRGBA`]: fn.WebPEncodeRGBA.html
49//! [`WebPEncodeLosslessRGBA`]: fn.WebPEncodeLosslessRGBA.html
50//!
51//! ```rust
52//! use libwebp::{WebPEncodeRGBA, WebPEncodeLosslessRGBA};
53//!
54//! let buf: &[u8] = &[
55//! 255, 255, 255, 255, // white
56//! 255, 0, 0, 255, // red
57//! 0, 255, 0, 255, // green
58//! 0, 0, 255, 255, // blue
59//! ];
60//! let data = WebPEncodeRGBA(buf, 2, 2, 8, 75.0).unwrap();
61//! let lossless_data = WebPEncodeLosslessRGBA(buf, 2, 2, 8).unwrap();
62//! assert_eq!(&data[..4], b"RIFF");
63//! assert_eq!(&data[8..12], b"WEBP");
64//! assert_eq!(&lossless_data[..4], b"RIFF");
65//! assert_eq!(&lossless_data[8..12], b"WEBP");
66//! ```
67
68pub use crate::decode::*;
69pub use crate::encode::*;
70
71pub mod boxed;
72mod decode;
73mod encode;
74pub mod error;