physis/hwc.rs
1// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4use std::io::{Cursor, Read};
5
6use crate::ByteSpan;
7
8#[derive(Debug)]
9pub struct Hwc {
10 pub rgba: Vec<u8>,
11}
12
13const CURSOR_WIDTH: usize = 64;
14const CURSOR_HEIGHT: usize = 64;
15
16impl Hwc {
17 /// Reads an existing HWC file
18 pub fn from_existing(buffer: ByteSpan) -> Option<Self> {
19 let mut cursor = Cursor::new(buffer);
20
21 let mut rgba = vec![0; CURSOR_WIDTH * CURSOR_HEIGHT * 4];
22 cursor.read_exact(&mut rgba).ok()?;
23
24 Some(Self { rgba })
25 }
26}