[][src]Crate libwebp

libwebp

This is a binding to the libwebp library.

Usage

Preparation

# Cargo.toml

[dependencies]
libwebp = { version = "0.1.2", features = ["0_6"] }

Simple decoding

You can use WebPDecodeRGBA or WebPDecodeRGBAInto families for simple decoding.

use libwebp::WebPDecodeRGBA;

let data: &[u8];

let (width, height, buf) = WebPDecodeRGBA(data).unwrap();
assert_eq!(buf.len(), width as usize * height as usize * 4);
eprintln!("width = {}, height = {}", width, height);
eprintln!(
    "top-left pixel: rgba({}, {}, {}, {})",
    buf[0],
    buf[1],
    buf[2],
    buf[3] as f64 / 255.0,
)

Simple encoding

You can use WebPEncodeRGBA or WebPEncodeLosslessRGBA families for simple encoding.

use libwebp::{WebPEncodeRGBA, WebPEncodeLosslessRGBA};

let buf: &[u8] = &[
    255, 255, 255, 255, // white
    255, 0, 0, 255, // red
    0, 255, 0, 255, // green
    0, 0, 255, 255, // blue
];
let data = WebPEncodeRGBA(buf, 2, 2, 8, 75.0).unwrap();
let lossless_data = WebPEncodeLosslessRGBA(buf, 2, 2, 8).unwrap();
assert_eq!(&data[..4], b"RIFF");
assert_eq!(&data[8..12], b"WEBP");
assert_eq!(&lossless_data[..4], b"RIFF");
assert_eq!(&lossless_data[8..12], b"WEBP");

Modules

boxed

Safe RAII wrappers for WebPFree.

error

Error type definitions.

Structs

WebPIDecGetRGBResult
WebPIDecGetYUVAResult
WebPIDecoder

Enums

VP8StatusCode
WEBP_CSP_MODE

Functions

WebPDecodeARGB

Same as WebPDecodeRGBA, but returning A, R, G, B, A, R, G, B... ordered data.

WebPDecodeARGBInto

Same as WebPDecodeRGBAInto, but returning A, R, G, B, A, R, G, B... ordered data.

WebPDecodeBGR

Same as WebPDecodeRGBA, but returning B, G, R, B, G, R... ordered data.

WebPDecodeBGRA

Same as WebPDecodeRGBA, but returning B, G, R, A, B, G, R, A... ordered data.

WebPDecodeBGRAInto

Same as WebPDecodeRGBAInto, but returning B, G, R, A, B, G, R, A... ordered data.

WebPDecodeBGRInto

Same as WebPDecodeRGBAInto, but returning B, G, R, B, G, R... ordered data.

WebPDecodeRGB

Same as WebPDecodeRGBA, but returning R, G, B, R, G, B... ordered data.

WebPDecodeRGBA

Decodes WebP images pointed to by data and returns RGBA samples, along with the dimensions (width and height).

WebPDecodeRGBAInto

Decodes WebP images pointed to by data and writes RGBA samples to output_buffer.

WebPDecodeRGBInto

Same as WebPDecodeRGBAInto, but returning R, G, B, R, G, B... ordered data.

WebPDecodeYUV

Decodes WebP images pointed to by data to Y'UV format1.

WebPDecodeYUVInto

A variant of WebPDecodeYUVInto that operates directly into pre-allocated buffers.

WebPEncodeBGR

Same as WebPEncodeRGBA, but expecting B, G, R, B, G, R... ordered data.

WebPEncodeBGRA

Same as WebPEncodeRGBA, but expecting B, G, R, A, B, G, R, A... ordered data.

WebPEncodeLosslessBGR

Same as WebPEncodeLosslessRGBA, but expecting B, G, R, B, G, R... ordered data.

WebPEncodeLosslessBGRA

Same as WebPEncodeLosslessRGBA, but expecting B, G, R, A, B, G, R, A... ordered data.

WebPEncodeLosslessRGB

Same as WebPEncodeLosslessRGBA, but expecting R, G, B, R, G, B... ordered data.

WebPEncodeLosslessRGBA

Encodes images pointed to by rgba and returns the WebP binary data.

WebPEncodeRGB

Same as WebPEncodeRGBA, but expecting R, G, B, R, G, B... ordered data.

WebPEncodeRGBA

Encodes images pointed to by rgba and returns the WebP binary data.

WebPGetDecoderVersion

Return the decoder's version number, packed in hexadecimal using 8bits for each of major/minor/revision.

WebPGetEncoderVersion

Return the encoder's version number, packed in hexadecimal using 8bits for each of major/minor/revision.

WebPGetInfo

Retrieve basic header information: width, height.

WebPIAppend
WebPIDecGetRGB
WebPIDecGetYUVA
WebPINewDecoder
WebPINewRGB
WebPINewYUVA
WebPIsAlphaMode
WebPIsPremultipliedMode
WebPIsRGBMode