Skip to main content

Crate heifer

Crate heifer 

Source
Expand description

Pure-Rust HEIF/HEIC image decoder and encoder.

let bytes = std::fs::read("photo.heic").unwrap();
let image = heifer::decode(&bytes).unwrap();
let rgba: Vec<u8> = image.to_rgba8();
println!("{}x{}, alpha: {}", image.width, image.height, image.has_alpha);

let heic = heifer::encode(&image, &heifer::EncodeOptions::default()).unwrap();
std::fs::write("copy.heic", heic).unwrap();

This crate ties together the container (heifer_isobmff) and the HEVC codec (heifer_hevc_dec, heifer_hevc_enc).

Re-exports§

pub use encode::EncodeOptions;
pub use encode::encode;
pub use encode::encode_hdr;
pub use encode::encode_hdr_with_metadata;
pub use encode::encode_rgb8;
pub use encode::encode_rgba8;
pub use encode::encode_with_metadata;
pub use hdr::GainMap;
pub use hdr::HdrImage;
pub use hdr::decode_hdr;
pub use hdr::read_gain_map;
pub use image::Image;
pub use image::Sample;
pub use metadata::Exif;
pub use metadata::Metadata;
pub use metadata::item_metadata;
pub use metadata::read_metadata;
pub use heifer_hevc_dec;
pub use heifer_hevc_enc;
pub use heifer_isobmff;

Modules§

color
YCbCr to RGB conversion (ITU-T H.273 matrix coefficients).
encode
Encoding of HEIC files: RGB(A) images to HEVC-coded HEIF, in 8 or 10 bits.
hdr
HDR photos with a gain map, or a PQ/HLG transfer.
image
Decoded RGBA images and the geometric transforms of HEIF (crop, rotation, mirror).
image_crate
Integration with the image crate (feature image).
metadata
Image metadata: EXIF, XMP and ICC profile, plus a minimal EXIF (TIFF) reader for the most common fields.

Structs§

Options
Decoding options.

Enums§

Error
Errors produced while decoding or encoding a HEIF file.
FileTypeResult
The result of check_file_type, matching libheif-rs’s FileTypeResult so that a caller can switch from libheif without changing its validation logic.

Functions§

check_file_type
Checks the type of a file from its leading bytes, without decoding it: the equivalent of libheif’s heif_check_filetype, for gating or validation before a full decode.
decode
Decodes the primary image of a HEIF/HEIC file, with its alpha channel if any, and applies the crop, rotation and mirror transforms stored in the file. Grid tiles are decoded in parallel on all available cores.
decode_all
Decodes every top-level image of a HEIF/HEIC file, not just the primary one.
decode_all_srgb_rgba8
Like decode_all, at 8 bits per sample and with the samples converted to sRGB, as decode_srgb_rgba8 does for the primary image. A file in a colour space heifer cannot convert (an ICC profile that is not an RGB input profile, or a PQ/HLG transfer) is refused with Error::Unsupported.
decode_all_with_options
Like decode_all, with options.
decode_item
Decodes one image item: coded (hvc1) or derived (grid, iovl, iden), then applies its transformative properties.
decode_rgba8
Like decode_with_options, at 8 bits per sample whatever the coded depth: half the memory, which counts on large photos.
decode_srgb
Like decode, with the samples converted to sRGB: from the image’s embedded ICC profile when it has one (as iPhone and many camera photos do, in Display P3), otherwise from its nclx colour information. Without either, the samples are returned as coded (as decode does).
decode_srgb_rgba8
Like decode_srgb, at 8 bits per sample whatever the coded depth: half the memory, which counts on large photos (see decode_rgba8 for the caveat on 10- and 12-bit files).
decode_srgb_with_options
Like decode_srgb, with options.
decode_thumbnail
Decodes the thumbnail of the primary image (a thmb item, such as the 320×240 preview of iPhone photos), or None if the file has none: much faster than decoding the image.
decode_with_options
Like decode, with options.