3 releases

0.1.2 Mar 15, 2020
0.1.1 Mar 7, 2020
0.1.0 Mar 1, 2020

#486 in Images

Download history 37/week @ 2023-11-20 49/week @ 2023-11-27 40/week @ 2023-12-04 27/week @ 2023-12-11 36/week @ 2023-12-18 27/week @ 2023-12-25 33/week @ 2024-01-01 39/week @ 2024-01-08 41/week @ 2024-01-15 63/week @ 2024-01-22 30/week @ 2024-01-29 34/week @ 2024-02-05 37/week @ 2024-02-12 66/week @ 2024-02-19 117/week @ 2024-02-26 62/week @ 2024-03-04

287 downloads per month
Used in 4 crates (3 directly)

BSD-3-Clause

66KB
1.5K SLoC

libwebp

This is a binding to the libwebp library.

Usage

Preparation

# Cargo.toml

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

Simple decoding

use libwebp::WebPDecodeRGBA;

let data: &[u8];

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

Simple encoding

use libwebp::WebPEncodeRGBA;

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();

Minimum Supported Rust Version (MSRV)

Rust 1.31.0

Features

  • demux ... enables libwebpdemux functions.
  • mux ... enables libwebpmux functions.
  • 0_5 ... enables functions introduced in libwebp 0.5.0.
  • 0_6 ... enables functions introduced in libwebp 0.6.0.
  • 1_1 ... enables functions introduced in libwebp 1.1.0.
  • static ... statically link against the bundled libwebp.
  • extern-types ... enables #![feature(extern_types)].

Linking

If libwebp is found in the system, it links against the library. Otherwise it builds and links against the bundled libwebp.

In these cases, static link is preferred:

  • For musl target.
  • When cross-compiling.
  • static feature is turned on.
  • LIBWEBP_SYS_STATIC environment variable is set to 1 when building.

Completeness

  • types.h
    • WebPMalloc
    • WebPFree
  • decode.h
    • WebPGetDecoderVersion
    • WebPGetInfo
    • WebPDecode*
    • WebPDecodeYUV
    • WebPDecode*Into
    • WebPDecodeYUVInto
    • WEBP_CSP_MODE
    • WebPIsPremultipliedMode
    • WebPIsAlphaMode
    • WebPIsRGBMode
    • WebPRGBABuffer
    • WebPYUVABuffer
    • WebPDecBuffer
    • WebPInitDecBuffer
    • WebPFreeDecBuffer
    • VP8StatusCode
    • WebPIDecoder (internal memory)
    • WebPIDecoder (external memory)
    • WebPINewDecoder (internal memory)
    • WebPINewDecoder (external memory)
    • WebPINewRGB (internal memory)
    • WebPINewRGB (external memory)
    • WebPINewYUVA (internal memory)
    • WebPINewYUVA (external memory)
    • WebPIDelete
    • WebPIAppend
    • WebPIUpdate
    • WebPIDecGetRGB
    • WebPIDecGetYUVA
    • WebPIDecodedArea
    • WebPBitstreamFeatures
    • WebPGetFeatures
    • WebPDecoderOptions
    • WebPDecoderConfig
    • WebPInitDecoderConfig
    • WebPIDecode
    • WebPDecode
  • encode.h
    • WebPGetEncoderVersion
    • WebPEncode*
    • WebPEncodeLossless*
    • WebPImageHint
    • WebPConfig
    • WebPPreset
    • WebPConfigInit
    • WebPConfigPreset
    • WebPConfigLosslessPreset
    • WebPValidateConfig
    • WebPAuxStats
    • WebPWriterFunction
    • WebPMemoryWriter
    • WebPMemoryWriterInit
    • WebPMemoryWriterClear
    • WebPMemoryWrite
    • WebPProgressHook
    • WebPEncCSP
    • WebPEncodingError
    • WEBP_MAX_DIMENSION
    • WebPPicture
    • WebPPictureInit
    • WebPPictureAlloc
    • WebPPictureFree
    • WebPPictureCopy
    • WebPPlaneDistortion
    • WebPPictureDistortion
    • WebPPictureCrop
    • WebPPictureView
    • WebPPictureIsView
    • WebPPictureRescale
    • WebPPictureImportRGB
    • WebPPictureImportRGBA
    • WebPPictureImportRGBX
    • WebPPictureImportBGR
    • WebPPictureImportBGRA
    • WebPPictureImportBGRX
    • WebPPictureARGBToYUVA
    • WebPPictureARGBToYUVADithered
    • WebPPictureSharpARGBToYUVA
    • WebPPictureSmartARGBToYUVA
    • WebPPictureYUVAToARGB
    • WebPCleanupTransparentArea
    • WebPPictureHasTransparency
    • WebPBlendAlpha
    • WebPEncode
  • mux_types.h
    • Not at all
  • demux.h
    • Not at all
  • mux.h
    • Not at all

Dependencies

~4MB
~72K SLoC