tauri_icns

Enum IconType

Source
pub enum IconType {
Show 19 variants RGB24_16x16, Mask8_16x16, RGB24_32x32, Mask8_32x32, RGB24_48x48, Mask8_48x48, RGB24_128x128, Mask8_128x128, RGBA32_16x16, RGBA32_16x16_2x, RGBA32_32x32, RGBA32_32x32_2x, RGBA32_64x64, RGBA32_128x128, RGBA32_128x128_2x, RGBA32_256x256, RGBA32_256x256_2x, RGBA32_512x512, RGBA32_512x512_2x,
}
Expand description

Types of icon elements that can be decoded as images or masks.

This type enumerates the kinds of IconElement that can be decoded by this library; each IconType corresponds to a particular OSType. The non-mask IconType values can also be used with the higher-level IconFamily methods to encode and decode complete icons that consist of multiple IconElements.

Variants§

§

RGB24_16x16

16x16 24-bit icon (without alpha).

§

Mask8_16x16

16x16 8-bit alpha mask.

§

RGB24_32x32

32x32 24-bit icon (without alpha).

§

Mask8_32x32

32x32 8-bit alpha mask.

§

RGB24_48x48

48x48 24-bit icon (without alpha).

§

Mask8_48x48

48x48 8-bit alpha mask.

§

RGB24_128x128

128x128 24-bit icon (without alpha).

§

Mask8_128x128

128x128 8-bit alpha mask.

§

RGBA32_16x16

16x16 32-bit icon.

§

RGBA32_16x16_2x

16x16 32-bit icon at 2x “retina” density (so, 32 by 32 pixels).

§

RGBA32_32x32

32x32 32-bit icon.

§

RGBA32_32x32_2x

32x32 32-bit icon at 2x “retina” density (so, 64 by 64 pixels).

§

RGBA32_64x64

64x64 32-bit icon. (For whatever reason, the ICNS format has no corresponding type for a 64x64 icon at 2x “retina” density.)

§

RGBA32_128x128

128x128 32-bit icon.

§

RGBA32_128x128_2x

128x128 32-bit icon at 2x “retina” density (so, 256 by 256 pixels).

§

RGBA32_256x256

256x256 32-bit icon.

§

RGBA32_256x256_2x

256x256 32-bit icon at 2x “retina” density (so, 512 by 512 pixels).

§

RGBA32_512x512

512x512 32-bit icon.

§

RGBA32_512x512_2x

512x512 32-bit icon at 2x “retina” density (so, 1024 by 1024 pixels).

Implementations§

Source§

impl IconType

Source

pub fn from_ostype(ostype: OSType) -> Option<IconType>

Get the icon type associated with the given OSType, if any.

Examples found in repository?
examples/png2icns.rs (line 47)
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
fn main() {
    let num_args = env::args().count();
    if num_args < 2 || num_args > 3 {
        println!("Usage: png2icns <path> [<ostype>]");
        return;
    }
    let png_path = env::args().nth(1).unwrap();
    let png_path = Path::new(&png_path);
    let png_file = BufReader::new(File::open(png_path).expect("failed to open PNG file"));
    let image = Image::read_png(png_file).expect("failed to read PNG file");
    let mut family = IconFamily::new();
    let icns_path = if num_args == 3 {
        let ostype = OSType::from_str(&env::args().nth(2).unwrap()).unwrap();
        let icon_type = IconType::from_ostype(ostype).expect("unsupported ostype");
        family
            .add_icon_with_type(&image, icon_type)
            .expect("failed to encode image");
        png_path.with_extension(format!("{}.icns", ostype))
    } else {
        family.add_icon(&image).expect("failed to encode image");
        png_path.with_extension("icns")
    };
    let icns_file = BufWriter::new(File::create(icns_path).expect("failed to create ICNS file"));
    family.write(icns_file).expect("failed to write ICNS file");
}
More examples
Hide additional examples
examples/icns2png.rs (line 43)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
fn main() {
    let num_args = env::args().count();
    if num_args < 2 || num_args > 3 {
        println!("Usage: icns2png <path> [<ostype>]");
        return;
    }
    let icns_path = env::args().nth(1).unwrap();
    let icns_path = Path::new(&icns_path);
    let icns_file = BufReader::new(File::open(icns_path).expect("failed to open ICNS file"));
    let family = IconFamily::read(icns_file).expect("failed to read ICNS file");
    let (icon_type, png_path) = if num_args == 3 {
        let ostype = OSType::from_str(&env::args().nth(2).unwrap()).unwrap();
        let icon_type = IconType::from_ostype(ostype).expect("unsupported ostype");
        let png_path = icns_path.with_extension(format!("{}.png", ostype));
        (icon_type, png_path)
    } else {
        // If no OSType is specified, extract the highest-resolution icon.
        let &icon_type = family
            .available_icons()
            .iter()
            .max_by_key(|icon_type| icon_type.pixel_width() * icon_type.pixel_height())
            .expect("ICNS file contains no icons");
        let png_path = icns_path.with_extension("png");
        (icon_type, png_path)
    };
    let image = family
        .get_icon_with_type(icon_type)
        .expect("ICNS file does not contain that icon type");
    let png_file = BufWriter::new(File::create(png_path).expect("failed to create PNG file"));
    image.write_png(png_file).expect("failed to write PNG file");
}
Source

pub fn from_pixel_size(width: u32, height: u32) -> Option<IconType>

Return a (non-mask) icon type that has the given pixel width/height, if any.

§Examples
use tauri_icns::IconType;
assert_eq!(IconType::from_pixel_size(48, 48),
           Some(IconType::RGB24_48x48));
assert_eq!(IconType::from_pixel_size(256, 256),
           Some(IconType::RGBA32_256x256));
assert_eq!(IconType::from_pixel_size(1024, 1024),
           Some(IconType::RGBA32_512x512_2x));
Source

pub fn from_pixel_size_and_density( width: u32, height: u32, density: u32, ) -> Option<IconType>

Return a (non-mask) icon type that has the given pixel width/height and pixel density, if any.

§Examples
use tauri_icns::IconType;
assert_eq!(IconType::from_pixel_size_and_density(48, 48, 1),
           Some(IconType::RGB24_48x48));
assert_eq!(IconType::from_pixel_size_and_density(256, 256, 1),
           Some(IconType::RGBA32_256x256));
assert_eq!(IconType::from_pixel_size_and_density(256, 256, 2),
           Some(IconType::RGBA32_128x128_2x));
Source

pub fn ostype(self) -> OSType

Get the OSType that represents this icon type.

Source

pub fn is_mask(self) -> bool

Returns true if this is icon type is a mask for some other icon type.

§Examples
use tauri_icns::IconType;
assert!(!IconType::RGB24_16x16.is_mask());
assert!(IconType::Mask8_16x16.is_mask());
assert!(!IconType::RGBA32_16x16.is_mask());
Source

pub fn mask_type(self) -> Option<IconType>

If this icon type has an associated mask type, returns that mask type; if this is a mask icon type, or a non-mask icon type that has no associated mask type, returns None.

§Examples
use tauri_icns::IconType;
assert_eq!(IconType::RGB24_16x16.mask_type(),
           Some(IconType::Mask8_16x16));
assert_eq!(IconType::Mask8_16x16.mask_type(), None);
assert_eq!(IconType::RGBA32_16x16.mask_type(), None);
Source

pub fn pixel_width(self) -> u32

Returns the pixel data width of this icon type. Normally this is the same as the screen width, but for 2x “retina” density icons, this will be twice that value.

§Examples
use tauri_icns::IconType;
assert_eq!(IconType::Mask8_128x128.pixel_width(), 128);
assert_eq!(IconType::RGBA32_256x256.pixel_width(), 256);
assert_eq!(IconType::RGBA32_256x256_2x.pixel_width(), 512);
Examples found in repository?
examples/icns2png.rs (line 51)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
fn main() {
    let num_args = env::args().count();
    if num_args < 2 || num_args > 3 {
        println!("Usage: icns2png <path> [<ostype>]");
        return;
    }
    let icns_path = env::args().nth(1).unwrap();
    let icns_path = Path::new(&icns_path);
    let icns_file = BufReader::new(File::open(icns_path).expect("failed to open ICNS file"));
    let family = IconFamily::read(icns_file).expect("failed to read ICNS file");
    let (icon_type, png_path) = if num_args == 3 {
        let ostype = OSType::from_str(&env::args().nth(2).unwrap()).unwrap();
        let icon_type = IconType::from_ostype(ostype).expect("unsupported ostype");
        let png_path = icns_path.with_extension(format!("{}.png", ostype));
        (icon_type, png_path)
    } else {
        // If no OSType is specified, extract the highest-resolution icon.
        let &icon_type = family
            .available_icons()
            .iter()
            .max_by_key(|icon_type| icon_type.pixel_width() * icon_type.pixel_height())
            .expect("ICNS file contains no icons");
        let png_path = icns_path.with_extension("png");
        (icon_type, png_path)
    };
    let image = family
        .get_icon_with_type(icon_type)
        .expect("ICNS file does not contain that icon type");
    let png_file = BufWriter::new(File::create(png_path).expect("failed to create PNG file"));
    image.write_png(png_file).expect("failed to write PNG file");
}
Source

pub fn pixel_height(self) -> u32

Returns the pixel data height of this icon type. Normally this is the same as the screen height, but for 2x “retina” density icons, this will be twice that value.

§Examples
use tauri_icns::IconType;
assert_eq!(IconType::Mask8_128x128.pixel_height(), 128);
assert_eq!(IconType::RGBA32_256x256.pixel_height(), 256);
assert_eq!(IconType::RGBA32_256x256_2x.pixel_height(), 512);
Examples found in repository?
examples/icns2png.rs (line 51)
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
fn main() {
    let num_args = env::args().count();
    if num_args < 2 || num_args > 3 {
        println!("Usage: icns2png <path> [<ostype>]");
        return;
    }
    let icns_path = env::args().nth(1).unwrap();
    let icns_path = Path::new(&icns_path);
    let icns_file = BufReader::new(File::open(icns_path).expect("failed to open ICNS file"));
    let family = IconFamily::read(icns_file).expect("failed to read ICNS file");
    let (icon_type, png_path) = if num_args == 3 {
        let ostype = OSType::from_str(&env::args().nth(2).unwrap()).unwrap();
        let icon_type = IconType::from_ostype(ostype).expect("unsupported ostype");
        let png_path = icns_path.with_extension(format!("{}.png", ostype));
        (icon_type, png_path)
    } else {
        // If no OSType is specified, extract the highest-resolution icon.
        let &icon_type = family
            .available_icons()
            .iter()
            .max_by_key(|icon_type| icon_type.pixel_width() * icon_type.pixel_height())
            .expect("ICNS file contains no icons");
        let png_path = icns_path.with_extension("png");
        (icon_type, png_path)
    };
    let image = family
        .get_icon_with_type(icon_type)
        .expect("ICNS file does not contain that icon type");
    let png_file = BufWriter::new(File::create(png_path).expect("failed to create PNG file"));
    image.write_png(png_file).expect("failed to write PNG file");
}
Source

pub fn pixel_density(self) -> u32

Returns the pixel density for this icon type – that is, 2 for 2x “retina” density icons, or 1 for other icon types.

§Examples
use tauri_icns::IconType;
assert_eq!(IconType::Mask8_128x128.pixel_density(), 1);
assert_eq!(IconType::RGBA32_256x256.pixel_density(), 1);
assert_eq!(IconType::RGBA32_256x256_2x.pixel_density(), 2);
Source

pub fn screen_width(self) -> u32

Returns the screen width of this icon type. Normally this is the same as the pixel width, but for 2x “retina” density icons, this will be half that value.

§Examples
use tauri_icns::IconType;
assert_eq!(IconType::Mask8_128x128.screen_width(), 128);
assert_eq!(IconType::RGBA32_256x256.screen_width(), 256);
assert_eq!(IconType::RGBA32_256x256_2x.screen_width(), 256);
Source

pub fn screen_height(self) -> u32

Returns the screen height of this icon type. Normally this is the same as the pixel height, but for 2x “retina” density icons, this will be half that value.

§Examples
use tauri_icns::IconType;
assert_eq!(IconType::Mask8_128x128.screen_height(), 128);
assert_eq!(IconType::RGBA32_256x256.screen_height(), 256);
assert_eq!(IconType::RGBA32_256x256_2x.screen_height(), 256);
Source

pub fn encoding(self) -> Encoding

Returns the encoding used within an ICNS file for this icon type.

Trait Implementations§

Source§

impl Clone for IconType

Source§

fn clone(&self) -> IconType

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IconType

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for IconType

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for IconType

Source§

fn eq(&self, other: &IconType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for IconType

Source§

impl Eq for IconType

Source§

impl StructuralPartialEq for IconType

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.