euv-ui 0.48.6

Cross-platform UI component library and 17-scheme design system for the euv framework with pixel-consistent rendering across Web, Android, iOS, iPadOS, macOS, Windows, and Linux.
Documentation
use super::*;

/// Returns a cached zero-allocation `&'static ImageBuffer` for the canonical 96x96 transparent RGBA8 Euv brand logo.
///
/// # Returns
///
/// - `&'static ImageBuffer` - Process-wide cached RGBA8 brand logo reference.
#[must_use]
pub fn euv_brand_logo_image_ref() -> &'static ImageBuffer {
    EUV_BRAND_LOGO_CACHE.get_or_init(decode_euv_brand_logo)
}

/// Decodes and caches the canonical 96x96 transparent RGBA8 Euv brand logo image derived from `https://devhub.vip/pages/docs/img/euv.png`.
///
/// # Returns
///
/// - `ImageBuffer` - Zero-copy shared handle to the cached RGBA8 brand logo image buffer.
#[must_use]
pub fn euv_brand_logo_image() -> ImageBuffer {
    euv_brand_logo_image_ref().clone()
}

/// Decodes the embedded palette-indexed RLE brand logo payload into a flat RGBA8 `ImageBuffer`.
///
/// # Returns
///
/// - `ImageBuffer` - Decoded 96x96 RGBA8 pixel buffer.
fn decode_euv_brand_logo() -> ImageBuffer {
    let pixel_count: usize =
        (EUV_BRAND_LOGO_SIZE as usize).saturating_mul(EUV_BRAND_LOGO_SIZE as usize);
    let mut pixels: Vec<u8> = Vec::with_capacity(pixel_count.saturating_mul(4));
    let mut cursor: usize = 0;
    let total_bytes: usize = EUV_BRAND_LOGO_RLE.len();
    while cursor < total_bytes {
        let header: u8 = EUV_BRAND_LOGO_RLE[cursor];
        cursor += 1;
        if (header & EUV_BRAND_LOGO_RLE_RUN_FLAG) != 0 {
            if cursor >= total_bytes {
                break;
            }
            let count: usize =
                usize::from(header & EUV_BRAND_LOGO_RLE_RUN_MASK) + EUV_BRAND_LOGO_RLE_RUN_MIN;
            let palette_idx: usize = usize::from(EUV_BRAND_LOGO_RLE[cursor]);
            cursor += 1;
            let rgba: [u8; 4] = EUV_BRAND_LOGO_PALETTE[palette_idx];
            for _ in 0..count {
                pixels.extend_from_slice(&rgba);
            }
        } else {
            let count: usize = usize::from(header) + 1;
            let end: usize = cursor.saturating_add(count).min(total_bytes);
            for &idx in &EUV_BRAND_LOGO_RLE[cursor..end] {
                let rgba: [u8; 4] = EUV_BRAND_LOGO_PALETTE[usize::from(idx)];
                pixels.extend_from_slice(&rgba);
            }
            cursor = end;
        }
    }
    pixels.resize(pixel_count.saturating_mul(4), 0);
    ImageBuffer::new(EUV_BRAND_LOGO_SIZE, EUV_BRAND_LOGO_SIZE, pixels)
}