pub struct Container<'d> { /* private fields */ }Expand description
The container of a WebP file: its metadata chunks and the canvas and
animation parameters, through libwebp’s demuxer (C: WebPDemuxer).
It borrows the file’s bytes; the chunk payloads borrow the container.
§Examples
use webp::api::decode::Container;
// `file` is an extended 2 by 2 WebP file with an ICC profile and EXIF data.
let container = Container::new(&file)?;
assert_eq!((container.canvas_width(), container.canvas_height()), (2, 2));
assert_eq!(container.icc_profile(), Some(&b"profile"[..]));
assert_eq!(container.exif(), Some(&b"Exif\0\0MM"[..]));
assert_eq!(container.xmp(), None);Implementations§
Source§impl<'d> Container<'d>
impl<'d> Container<'d>
Sourcepub fn new(data: &'d [u8]) -> Result<Self, DecodeError>
pub fn new(data: &'d [u8]) -> Result<Self, DecodeError>
Parses a complete WebP file (C: WebPDemux).
§Errors
The error of Features::parse for data that is not a WebP file or
ends inside its header; then DecodeError::NotEnoughData for a file
that ends early and DecodeError::BitstreamError for one that does
not parse.
§Examples
use webp::api::decode::{Container, DecodeError};
assert!(Container::new(&file)?.is_complete());
assert_eq!(Container::new(&file[..file.len() - 2]).unwrap_err(), DecodeError::NotEnoughData);
assert_eq!(Container::new(b"not a WebP file").unwrap_err(), DecodeError::BitstreamError);Sourcepub fn partial(data: &'d [u8]) -> Result<Self, DecodeError>
pub fn partial(data: &'d [u8]) -> Result<Self, DecodeError>
Parses the start of a WebP file (C: WebPDemuxPartial); the chunks
and frames that the data reaches are available, which is enough for an
ICCP chunk, which precedes the image data.
§Errors
DecodeError::NotEnoughData when the data ends inside the file
header, DecodeError::BitstreamError when it does not parse; as for
Container::new, the error of Features::parse comes first.
§Examples
use webp::api::decode::Container;
let container = Container::partial(&file[..file.len() - 2])?;
assert!(!container.is_complete());Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Whether the whole file was parsed (C: WEBP_DEMUX_DONE).
§Examples
use webp::api::decode::Container;
assert!(Container::partial(&file)?.is_complete());Sourcepub fn canvas_width(&self) -> u32
pub fn canvas_width(&self) -> u32
The canvas width in pixels: the image’s for a simple file.
§Examples
use webp::api::decode::Container;
assert_eq!(Container::new(&file)?.canvas_width(), 3);Sourcepub fn canvas_height(&self) -> u32
pub fn canvas_height(&self) -> u32
The canvas height in pixels: the image’s for a simple file.
§Examples
use webp::api::decode::Container;
assert_eq!(Container::new(&file)?.canvas_height(), 2);Sourcepub fn has_alpha(&self) -> bool
pub fn has_alpha(&self) -> bool
Whether the file declares alpha (C: ALPHA_FLAG of
WEBP_FF_FORMAT_FLAGS, which the demuxer also sets for a simple
file whose image has alpha).
§Examples
use webp::api::decode::Container;
assert!(Container::new(&file)?.has_alpha());Sourcepub fn has_animation(&self) -> bool
pub fn has_animation(&self) -> bool
Whether the file is an animation (C: ANIMATION_FLAG of
WEBP_FF_FORMAT_FLAGS).
§Examples
use webp::api::decode::Container;
assert!(!Container::new(&file)?.has_animation());Sourcepub fn loop_count(&self) -> u32
pub fn loop_count(&self) -> u32
The number of times an animation loops, 0 for forever (C:
WEBP_FF_LOOP_COUNT); a still image reports 1, the demuxer’s default.
§Examples
use webp::api::decode::Container;
assert_eq!(Container::new(&file)?.loop_count(), 1);Sourcepub fn background_color(&self) -> u32
pub fn background_color(&self) -> u32
The background color of an animation as 0xAARRGGBB: the ANIM
chunk’s bytes (blue, green, red, alpha) read as a little-endian u32
(C: WEBP_FF_BACKGROUND_COLOR). It is reported, not applied: the
canvas of AnimationDecoder starts transparent black. A still image
reports 0xFFFFFFFF.
§Examples
use webp::api::decode::Container;
assert_eq!(Container::new(&file)?.background_color(), 0xFFFF_FFFF);Sourcepub fn frame_count(&self) -> u32
pub fn frame_count(&self) -> u32
The number of frames: 1 for a still image (C: WEBP_FF_FRAME_COUNT);
the frames parsed so far for a partial container.
§Examples
use webp::api::decode::Container;
assert_eq!(Container::new(&file)?.frame_count(), 1);Sourcepub fn icc_profile(&self) -> Option<&[u8]>
pub fn icc_profile(&self) -> Option<&[u8]>
The raw ICC profile: the payload of the first ICCP chunk, which the
demuxer keeps when the VP8X flags announce it.
§Examples
use webp::api::decode::Container;
// A simple file has no metadata; readers then assume sRGB.
assert_eq!(Container::new(&file)?.icc_profile(), None);Sourcepub fn exif(&self) -> Option<&[u8]>
pub fn exif(&self) -> Option<&[u8]>
The raw EXIF data: the payload of the first EXIF chunk, unparsed
(the orientation, if any, is in it).
§Examples
use webp::api::decode::Container;
assert_eq!(Container::new(&file)?.exif(), None);Sourcepub fn xmp(&self) -> Option<&[u8]>
pub fn xmp(&self) -> Option<&[u8]>
The raw XMP packet: the payload of the first XMP chunk.
§Examples
use webp::api::decode::Container;
assert_eq!(Container::new(&file)?.xmp(), None);Sourcepub fn chunks(&self, fourcc: [u8; 4]) -> Chunks<'_> ⓘ
pub fn chunks(&self, fourcc: [u8; 4]) -> Chunks<'_> ⓘ
The payloads of every chunk with fourcc that the demuxer keeps
(ICCP, EXIF, XMP and unknown chunks), in file order (C:
WebPDemuxGetChunk and WebPDemuxNextChunk).
§Examples
use webp::api::decode::Container;
assert_eq!(Container::new(&file)?.chunks(*b"EXIF").count(), 0);