Skip to main content

ravenrs_sheet/base/
color.rs

1//! Shared legacy indexed colours used by XLSX and number-format rendering.
2
3/// The 64-entry legacy indexed colour palette, stored as `RRGGBB`.
4pub const INDEXED: [u32; 64] = [
5    0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0xFF00FF, 0x00FFFF, 0x000000, 0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00,
6    0xFF00FF, 0x00FFFF, 0x800000, 0x008000, 0x000080, 0x808000, 0x800080, 0x008080, 0xC0C0C0, 0x808080, 0x9999FF, 0x993366, 0xFFFFCC, 0xCCFFFF,
7    0x660066, 0xFF8080, 0x0066CC, 0xCCCCFF, 0x000080, 0xFF00FF, 0xFFFF00, 0x00FFFF, 0x800080, 0x800000, 0x008080, 0x0000FF, 0x00CCFF, 0xCCFFFF,
8    0xCCFFCC, 0xFFFF99, 0x99CCFF, 0xFF99CC, 0xCC99FF, 0xFFCC99, 0x3366FF, 0x33CCCC, 0x99CC00, 0xFFCC00, 0xFF9900, 0xFF6600, 0x666699, 0x969696,
9    0x003366, 0x339966, 0x003300, 0x333300, 0x993300, 0x993366, 0x333399, 0x333333,
10];
11
12/// Resolve an Excel number-format color index (`Color1` through `Color56`).
13pub fn indexed_color(index: u8) -> Option<[u8; 3]> {
14    if !(1..=56).contains(&index) {
15        return None;
16    }
17    let slot = index.checked_add(7)?;
18    let rgb = *INDEXED.get(slot as usize)?;
19    Some([(rgb >> 16) as u8, (rgb >> 8) as u8, rgb as u8])
20}