Struct icns::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

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

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.

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.

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.

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

Reads an icon element from within an ICNS file.

Writes the icon element to within an ICNS file.

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.