[][src]Struct icns::IconElement

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

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

impl IconElement[src]

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

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

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

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.

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

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.

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

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.

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

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

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

Reads an icon element from within an ICNS file.

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

Writes the icon element to within an ICNS file.

pub fn total_length(&self) -> u32[src]

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

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.