Struct tauri_icns::IconElement
source · [−]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
sourceimpl IconElement
impl IconElement
sourcepub fn new(ostype: OSType, data: Vec<u8>) -> IconElement
pub fn new(ostype: OSType, data: Vec<u8>) -> IconElement
Creates an icon element with the given OSType and data payload.
sourcepub fn encode_image_with_type(
image: &Image,
icon_type: IconType
) -> Result<IconElement>
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.
sourcepub fn decode_image(&self) -> Result<Image>
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.
sourcepub fn decode_image_with_mask(&self, mask: &IconElement) -> Result<Image>
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.
sourcepub fn icon_type(&self) -> Option<IconType>
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.
sourcepub fn read<R: Read>(reader: R) -> Result<IconElement>
pub fn read<R: Read>(reader: R) -> Result<IconElement>
Reads an icon element from within an ICNS file.
sourcepub fn write<W: Write>(&self, writer: W) -> Result<()>
pub fn write<W: Write>(&self, writer: W) -> Result<()>
Writes the icon element to within an ICNS file.
sourcepub fn total_length(&self) -> u32
pub fn total_length(&self) -> u32
Returns the encoded length of the element, in bytes, including the length of the header.
Auto Trait Implementations
impl RefUnwindSafe for IconElement
impl Send for IconElement
impl Sync for IconElement
impl Unpin for IconElement
impl UnwindSafe for IconElement
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more