#![cfg(windows)]
mod base64;
mod error;
mod extract;
mod resource;
mod stock;
#[cfg(feature = "webp")]
mod encode;
#[cfg(feature = "png")]
mod png;
#[cfg(feature = "cache")]
mod cache;
pub use base64::{encode_base64, decode_base64, decode_image_base64};
pub use error::IconError;
pub use extract::IconData;
pub use resource::{get_max_icon_size, get_max_icon_size_wide};
pub use stock::StockIcon;
#[cfg(feature = "webp")]
pub use encode::WebPOptions;
#[cfg(feature = "cache")]
pub use cache::{CacheStats, IconCache};
#[cfg(all(feature = "cache", any(feature = "webp", feature = "png")))]
pub use cache::ImageFormat;
pub fn extract_icon(path: &str) -> Result<IconData, IconError> {
extract::extract_icon(path)
}
pub fn extract_icon_at(path: &str, index: u32) -> Result<IconData, IconError> {
extract::extract_icon_at(path, index)
}
pub fn extract_icon_with_size(path: &str, size: u32) -> Result<IconData, IconError> {
extract::extract_icon_with_size(path, size)
}
#[cfg(feature = "webp")]
pub fn encode_webp(rgba: &[u8], width: u32, height: u32) -> Result<Vec<u8>, IconError> {
encode::encode_webp(rgba, width, height)
}
#[cfg(feature = "webp")]
pub fn encode_webp_with(
rgba: &[u8], width: u32, height: u32, opts: &WebPOptions,
) -> Result<Vec<u8>, IconError> {
encode::encode_webp_with(rgba, width, height, opts)
}
#[cfg(feature = "webp")]
pub fn extract_icon_webp(path: &str) -> Result<Vec<u8>, IconError> {
let data = extract::extract_icon(path)?;
encode::encode_webp(&data.rgba, data.width, data.height)
}
#[cfg(feature = "png")]
pub use png::{PngFilter, PngOptions};
#[cfg(feature = "png")]
pub fn encode_png(rgba: &[u8], width: u32, height: u32) -> Result<Vec<u8>, IconError> {
png::encode_png(rgba, width, height)
}
#[cfg(feature = "png")]
pub fn encode_png_with(
rgba: &[u8], width: u32, height: u32, opts: &PngOptions,
) -> Result<Vec<u8>, IconError> {
png::encode_png_with(rgba, width, height, opts)
}
#[cfg(feature = "png")]
pub fn extract_icon_png(path: &str) -> Result<Vec<u8>, IconError> {
let data = extract::extract_icon(path)?;
png::encode_png(&data.rgba, data.width, data.height)
}
#[cfg(feature = "bulk")]
pub fn extract_icons_bulk(
paths: &[&str],
) -> std::collections::HashMap<String, Result<IconData, IconError>> {
use rayon::prelude::*;
paths
.par_iter()
.map(|&p| (p.to_string(), extract::extract_icon(p)))
.collect()
}
pub fn icon_count(path: &str) -> u32 {
extract::icon_count(path)
}
pub fn extract_icon_for_extension(ext: &str) -> Result<IconData, IconError> {
extract::extract_icon_for_extension(ext)
}
pub fn extract_stock_icon(icon: StockIcon) -> Result<IconData, IconError> {
stock::extract_stock_icon(icon)
}
pub fn extract_stock_icon_sized(icon: StockIcon, size: u32) -> Result<IconData, IconError> {
stock::extract_stock_icon_sized(icon, size as i32)
}
#[cfg(feature = "webp")]
pub fn extract_icon_webp_base64(path: &str) -> Result<String, IconError> {
let bytes = extract_icon_webp(path)?;
Ok(encode_base64(&bytes))
}
#[cfg(feature = "png")]
pub fn extract_icon_png_base64(path: &str) -> Result<String, IconError> {
let bytes = extract_icon_png(path)?;
Ok(encode_base64(&bytes))
}