Struct IconElement

Source
pub struct IconElement {
    pub ostype: OSType,
    pub data: Vec<u8>,
}
Expand description

One data block in an ICNS file. Depending on the resource type, this may represent an icon, or part of an icon (such as an alpha mask, or color data without the mask).

Fields§

§ostype: OSType

The OSType for this element (e.g. it32 or t8mk).

§data: Vec<u8>

The raw data payload for this element.

Implementations§

Source§

impl IconElement

Source

pub fn new(ostype: OSType, data: Vec<u8>) -> IconElement

Creates an icon element with the given OSType and data payload.

Source

pub fn encode_image_with_type( image: &Image, icon_type: IconType, ) -> Result<IconElement>

Creates an icon element that encodes the given image as the given icon type. Image color channels that aren’t relevant to the specified icon type will be ignored (e.g. if the icon type is a mask, then only the alpha channel of the image will be used). Returns an error if the image dimensions don’t match the icon type.

Note that if icon_type has an associated mask type, this method will not encode the mask, and will in fact ignore any alpha channel in the image; you’ll need to encode a second IconElement with the mask type. For a higher-level interface that will encode both elements at once, see the IconFamily.add_icon_with_type method.

Source

pub fn decode_image(&self) -> Result<Image>

Decodes the icon element into an image. Returns an error if this element does not represent an icon type supported by this library, or if the data is malformed.

Note that if the element’s icon type has an associated mask type, this method will simply produce an image with no alpha channel (since the mask lives in a separate IconElement). To decode image and mask together into a single image, you can either use the decode_image_with_mask method, or the higher-level IconFamily.get_icon_with_type method.

Source

pub fn decode_image_with_mask(&self, mask: &IconElement) -> Result<Image>

Decodes this element, together with a separate mask element, into a single image with alpha channel. Returns an error if this element does not represent an icon type supported by this library, or if the given mask element does not represent the correct mask type for this element, or if any of the data is malformed.

For a more convenient alternative to this method, consider using the higher-level IconFamily.get_icon_with_type method instead.

Source

pub fn icon_type(&self) -> Option<IconType>

Returns the type of icon encoded by this element, or None if this element does not encode a supported icon type.

Source

pub fn read<R: Read>(reader: R) -> Result<IconElement>

Reads an icon element from within an ICNS file.

Source

pub fn write<W: Write>(&self, writer: W) -> Result<()>

Writes the icon element to within an ICNS file.

Source

pub fn total_length(&self) -> u32

Returns the encoded length of the element, in bytes, including the length of the header.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.