1use std::{collections::HashMap, hash::Hash};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
4pub enum TlgColorType {
6 Grayscale8,
8 Bgr24,
10 Bgra32,
12}
13
14#[derive(Debug, Clone)]
15pub struct Tlg {
17 pub tags: HashMap<Vec<u8>, Vec<u8>>,
19 pub version: u32,
21 pub width: u32,
23 pub height: u32,
25 pub color: TlgColorType,
27 pub data: Vec<u8>,
29}
30
31#[derive(Debug)]
32pub enum TlgError {
34 Io(std::io::Error),
36 InvalidFormat,
38 UnsupportedColorType(u8),
40 IndexOutOfRange,
42 UnsupportedCompressedMethod(u8),
44 Str(String),
46 #[cfg(feature = "encode")]
47 #[cfg_attr(docsrs, doc(cfg(feature = "encode")))]
48 EncodeError(String),
50}
51
52impl std::fmt::Display for TlgError {
53 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
54 match self {
55 TlgError::Io(e) => write!(f, "IO Error: {}", e),
56 TlgError::InvalidFormat => write!(f, "Invalid TLG format"),
57 TlgError::UnsupportedColorType(c) => write!(f, "Unsupported color type: {}", c),
58 TlgError::IndexOutOfRange => write!(f, "Index out of range"),
59 TlgError::UnsupportedCompressedMethod(m) => {
60 write!(f, "Unsupported compressed method: {}", m)
61 }
62 TlgError::Str(s) => write!(f, "{}", s),
63 #[cfg(feature = "encode")]
64 TlgError::EncodeError(s) => write!(f, "Encoding error: {}", s),
65 }
66 }
67}
68
69impl From<std::io::Error> for TlgError {
70 fn from(err: std::io::Error) -> Self {
71 TlgError::Io(err)
72 }
73}
74
75impl From<String> for TlgError {
76 fn from(err: String) -> Self {
77 TlgError::Str(err)
78 }
79}
80
81impl From<&str> for TlgError {
82 fn from(err: &str) -> Self {
83 TlgError::Str(err.to_string())
84 }
85}
86
87impl From<&String> for TlgError {
88 fn from(err: &String) -> Self {
89 TlgError::Str(err.clone())
90 }
91}
92
93impl std::error::Error for TlgError {}