Repository navigation
Expand file tree
/
Copy pathlogo.rs
More file actions
113 lines (100 loc) · 3.76 KB
/
Copy pathlogo.rs
File metadata and controls
113 lines (100 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// SPDX-License-Identifier: Apache-2.0
use image::RgbaImage;
const GRID: u32 = 16;
const SCALE: u32 = 8;
// 0=transparent, 1=lavender purple, 2=dark indigo, 3=white, 4=pink
const PALETTE: [[u8; 4]; 5] = [
[0, 0, 0, 0], // 0: transparent
[155, 143, 232, 255], // 1: lavender purple (#9B8FE8)
[45, 27, 105, 255], // 2: dark indigo (#2D1B69)
[255, 255, 255, 255], // 3: white (eye highlight)
[255, 145, 176, 255], // 4: warm pink (#FF91B0)
];
const _: () = assert!(PALETTE.len() >= 5);
// 16x16 pixel-art kitten — compiler checks both dimensions
// Kitten proportions: tall ears, big eyes, prominent blush
#[rustfmt::skip]
const LOGO: [[u8; 16]; 16] = [
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
[0,0,0,2,0,0,0,0,0,0,0,0,2,0,0,0], // 0 ear tips
[0,0,2,4,2,0,0,0,0,0,0,2,4,2,0,0], // 1 ears (pink inner)
[0,2,1,4,2,0,0,0,0,0,0,2,4,1,2,0], // 2 ears wider (pink inner)
[0,2,1,1,2,2,2,2,2,2,2,2,1,1,2,0], // 3 ears → head
[0,2,1,1,1,1,1,1,1,1,1,1,1,1,2,0], // 4 forehead
[0,2,1,2,3,2,1,1,1,1,2,3,2,1,2,0], // 5 eyes (D·W·D / D·W·D)
[0,2,1,2,2,2,1,1,1,1,2,2,2,1,2,0], // 6 eyes (D·D·D / D·D·D)
[0,2,1,4,4,1,1,1,1,1,1,4,4,1,2,0], // 7 blush (2px per cheek)
[0,2,1,1,1,1,1,4,4,1,1,1,1,1,2,0], // 8 nose
[0,2,1,1,1,1,2,1,1,2,1,1,1,1,2,0], // 9 mouth (ω top)
[0,2,1,1,1,1,1,2,2,1,1,1,1,1,2,0], // 10 mouth (ω bottom)
[0,0,2,1,1,1,1,1,1,1,1,1,1,2,0,0], // 11 chin narrows
[0,0,0,2,1,1,1,1,1,1,1,1,2,0,0,0], // 12 lower chin
[0,0,0,0,2,2,2,2,2,2,2,2,0,0,0,0], // 13 bottom edge
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], // 14 blank
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], // 15 blank
];
/// Generate the built-in kittyview kitten logo as PNG bytes.
pub fn generate_logo_png() -> Vec<u8> {
let size = GRID * SCALE;
let mut img = RgbaImage::new(size, size);
for (y, row) in LOGO.iter().enumerate() {
for (x, &idx) in row.iter().enumerate() {
let color = image::Rgba(PALETTE[idx as usize]);
for dy in 0..SCALE {
for dx in 0..SCALE {
img.put_pixel(x as u32 * SCALE + dx, y as u32 * SCALE + dy, color);
}
}
}
}
let mut buf = std::io::Cursor::new(Vec::new());
img.write_to(&mut buf, image::ImageFormat::Png)
.expect("PNG encoding of logo failed");
buf.into_inner()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn logo_produces_valid_png() {
let png = generate_logo_png();
// PNG magic bytes
assert_eq!(&png[..8], b"\x89PNG\r\n\x1a\n");
}
#[test]
fn logo_dimensions_are_128x128() {
let png = generate_logo_png();
let img = image::load_from_memory(&png).unwrap();
assert_eq!(img.width(), GRID * SCALE);
assert_eq!(img.height(), GRID * SCALE);
assert_eq!(img.width(), 128);
}
#[test]
fn logo_palette_indices_in_range() {
for (y, row) in LOGO.iter().enumerate() {
for (x, &idx) in row.iter().enumerate() {
assert!(
(idx as usize) < PALETTE.len(),
"LOGO[{y}][{x}] = {idx} is out of palette range"
);
}
}
}
#[test]
fn logo_is_horizontally_symmetric() {
for (y, row) in LOGO.iter().enumerate() {
let w = row.len();
for x in 0..w / 2 {
let left = row[x];
let right = row[w - 1 - x];
// Outline (2) and transparent (0) must be symmetric
if left == 0 || left == 2 {
assert_eq!(
left, right,
"row {y}: outline/transparent asymmetry at x={x}"
);
}
}
}
}
}