pub struct HeifContext<'a> { /* private fields */ }Implementations§
Source§impl HeifContext<'static>
impl HeifContext<'static>
Sourcepub fn new() -> Result<HeifContext<'static>>
pub fn new() -> Result<HeifContext<'static>>
Create a new empty context.
Sourcepub fn read_from_file(name: &str) -> Result<HeifContext<'static>>
pub fn read_from_file(name: &str) -> Result<HeifContext<'static>>
Create a new context from a file.
Source§impl<'a> HeifContext<'a>
impl<'a> HeifContext<'a>
Sourcepub fn read_reader(&mut self, reader: Box<dyn Reader + 'a>) -> Result<()>
pub fn read_reader(&mut self, reader: Box<dyn Reader + 'a>) -> Result<()>
Read a HEIF file from the reader.
Sourcepub fn read_from_reader(reader: Box<dyn Reader + 'a>) -> Result<HeifContext<'a>>
pub fn read_from_reader(reader: Box<dyn Reader + 'a>) -> Result<HeifContext<'a>>
Create a new context from the reader.
Sourcepub fn read_from_bytes(bytes: &[u8]) -> Result<HeifContext<'_>>
pub fn read_from_bytes(bytes: &[u8]) -> Result<HeifContext<'_>>
Create a new context from bytes.
The provided memory buffer is not copied. That means you will have to keep the memory buffer alive as long as you use the context.
Sourcepub fn read_bytes<'b: 'a>(&mut self, bytes: &'b [u8]) -> Result<()>
pub fn read_bytes<'b: 'a>(&mut self, bytes: &'b [u8]) -> Result<()>
Read a HEIF file from bytes.
The provided memory buffer is not copied. That means you will have to keep the memory buffer alive as long as you use the context.
pub fn write_to_bytes(&self) -> Result<Vec<u8>>
pub fn write_to_file(&self, name: &str) -> Result<()>
Sourcepub fn number_of_top_level_images(&self) -> usize
👎Deprecated since 2.7.0: use ‘image_ids’ method instead.
pub fn number_of_top_level_images(&self) -> usize
Number of top-level images in the HEIF file.
This does not include the thumbnails or the tile images that are composed to an image grid. You can get access to the thumbnails via the main image handle.
Sourcepub fn top_level_image_ids(&self, item_ids: &mut [ItemId]) -> usize
👎Deprecated since 2.7.0: use ‘image_ids’ method instead.
pub fn top_level_image_ids(&self, item_ids: &mut [ItemId]) -> usize
Fills in image IDs into the user-supplied preallocated array ‘ID_array’.
Method returns the total number of IDs filled into the array.
Sourcepub fn image_handle(&self, item_id: ItemId) -> Result<ImageHandle>
pub fn image_handle(&self, item_id: ItemId) -> Result<ImageHandle>
Get the image handle for a known image ID.
Sourcepub fn primary_image_handle(&self) -> Result<ImageHandle>
pub fn primary_image_handle(&self) -> Result<ImageHandle>
Get a handle to the primary image of the HEIF file.
This is the image that should be displayed primarily when there are several images in the file.
Sourcepub fn top_level_image_handles(&self) -> Vec<ImageHandle>
pub fn top_level_image_handles(&self) -> Vec<ImageHandle>
Returns a vector with top level image handles.
Sourcepub fn encode_image(
&mut self,
image: &Image,
encoder: &mut Encoder<'_>,
encoding_options: Option<EncodingOptions>,
) -> Result<ImageHandle>
pub fn encode_image( &mut self, image: &Image, encoder: &mut Encoder<'_>, encoding_options: Option<EncodingOptions>, ) -> Result<ImageHandle>
Compress the input image.
The first image added to the context is also automatically set as the primary image, but
you can change the primary image later with HeifContext::set_primary_image method.
Sourcepub fn encode_thumbnail(
&mut self,
image: &Image,
master_image_handle: &ImageHandle,
bbox_size: u32,
encoder: &mut Encoder<'_>,
encoding_options: Option<EncodingOptions>,
) -> Result<Option<ImageHandle>>
pub fn encode_thumbnail( &mut self, image: &Image, master_image_handle: &ImageHandle, bbox_size: u32, encoder: &mut Encoder<'_>, encoding_options: Option<EncodingOptions>, ) -> Result<Option<ImageHandle>>
Encode the image as a scaled down thumbnail image.
The image is scaled down to fit into a square area of width bbox_size.
If the input image is already so small that it fits into this bounding
box, no thumbnail image is encoded and Ok(None) is returned.
No error is returned in this case.
The encoded thumbnail is automatically assigned to the
master_image_handle. Hence, you do not have to call
HeifContext::assign_thumbnail() method.
Sourcepub fn encode_grid(
&mut self,
tiles: &[Image],
rows: NonZeroU16,
encoder: &mut Encoder<'_>,
encoding_options: Option<EncodingOptions>,
) -> Result<Option<ImageHandle>>
Available on crate feature v1_18 only.
pub fn encode_grid( &mut self, tiles: &[Image], rows: NonZeroU16, encoder: &mut Encoder<'_>, encoding_options: Option<EncodingOptions>, ) -> Result<Option<ImageHandle>>
v1_18 only.Encodes an array of images into a grid.
§Arguments
tiles- User allocated array of images that will form the grid.rows- The number of rows in the grid. The number of columns will be calculated from the size oftiles.encoder- Defines the encoder to use. See LibHeif::encoder_for_format().encoding_options- Optional, may be None.
Returns an error if tiles slice is empty.
Sourcepub fn assign_thumbnail(
&mut self,
master_image_handle: &ImageHandle,
thumbnail_image_handle: &ImageHandle,
) -> Result<()>
pub fn assign_thumbnail( &mut self, master_image_handle: &ImageHandle, thumbnail_image_handle: &ImageHandle, ) -> Result<()>
Assign master_image_handle as the thumbnail image of thumbnail_image_handle.
pub fn set_primary_image( &mut self, image_handle: &mut ImageHandle, ) -> Result<()>
Sourcepub fn add_generic_metadata<T>(
&mut self,
image_handle: &ImageHandle,
data: &[u8],
item_type: T,
content_type: Option<&str>,
) -> Result<()>
pub fn add_generic_metadata<T>( &mut self, image_handle: &ImageHandle, data: &[u8], item_type: T, content_type: Option<&str>, ) -> Result<()>
Add generic, proprietary metadata to an image.
You have to specify an item_type that will identify your metadata.
content_type can be an additional type.
For example, this function can be used to add IPTC metadata
(IIM stream, not XMP) to an image. Although not standard, we propose
to store IPTC data with item_type=b"iptc" and content_type=None.
Sourcepub fn add_exif_metadata(
&mut self,
master_image: &ImageHandle,
data: &[u8],
) -> Result<()>
pub fn add_exif_metadata( &mut self, master_image: &ImageHandle, data: &[u8], ) -> Result<()>
Add EXIF metadata to an image.
Sourcepub fn add_xmp_metadata(
&mut self,
master_image: &ImageHandle,
data: &[u8],
) -> Result<()>
pub fn add_xmp_metadata( &mut self, master_image: &ImageHandle, data: &[u8], ) -> Result<()>
Add XMP metadata to an image.
Sourcepub fn set_max_decoding_threads(&mut self, max_threads: u32)
pub fn set_max_decoding_threads(&mut self, max_threads: u32)
If the maximum threads number is set to 0, the image tiles are decoded in the main thread. This is different from setting it to 1, which will generate a single background thread to decode the tiles.
Note that this setting only affects libheif itself. The codecs itself
may still use multi-threaded decoding. You can use it, for example,
in cases where you are decoding several images in parallel anyway you
thus want to minimize parallelism in each decoder.
Sourcepub fn security_limits(&self) -> SecurityLimits
Available on crate feature v1_19 only.
pub fn security_limits(&self) -> SecurityLimits
v1_19 only.Returns the security limits for a context.
By default, the limits are set to the global limits,
but you can change them with the help of HeifContext::set_security_limits() method.
Sourcepub fn set_security_limits(&mut self, limits: &SecurityLimits) -> Result<()>
Available on crate feature v1_19 only.
pub fn set_security_limits(&mut self, limits: &SecurityLimits) -> Result<()>
v1_19 only.Overwrites the security limits of a context.
Sourcepub fn has_sequence(&self) -> bool
Available on crate feature v1_20 only.
pub fn has_sequence(&self) -> bool
v1_20 only.Check whether there is an image sequence in the HEIF file.
Sourcepub fn sequence_timescale(&self) -> u32
Available on crate feature v1_20 only.
pub fn sequence_timescale(&self) -> u32
v1_20 only.Get the timescale (clock ticks per second) for timing values in the sequence.
Each track may have its independent timescale.
Returns 0 if there is no sequence in the file.
Sourcepub fn sequence_duration(&self) -> u64
Available on crate feature v1_20 only.
pub fn sequence_duration(&self) -> u64
v1_20 only.Get the total duration of the sequence in timescale clock ticks.
Use [sequence_timescale] method to get the clock ticks per second.
Returns 0 if there is no sequence in the file.
Sourcepub fn track_ids(&self) -> Vec<u32>
Available on crate feature v1_20 only.
pub fn track_ids(&self) -> Vec<u32>
v1_20 only.Returns a vector with IDs for each of the tracks stored in the HEIF file.
Sourcepub fn track(&self, id: u32) -> Option<Track>
Available on crate feature v1_20 only.
pub fn track(&self, id: u32) -> Option<Track>
v1_20 only.Get the Track object for the given track ID.
If you pass id=0, the first visual track will be returned.
If there is no track with the given ID or if 0 is passed and
there is no visual track, None will be returned.
Tracks never have a zero ID. This is why we can use this as a special value to find the first visual track.