use std::{collections::HashMap, hash::Hash};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum TlgColorType {
Grayscale8,
Bgr24,
Bgra32,
}
#[derive(Debug, Clone)]
pub struct Tlg {
pub tags: HashMap<Vec<u8>, Vec<u8>>,
pub version: u32,
pub width: u32,
pub height: u32,
pub color: TlgColorType,
pub data: Vec<u8>,
}
#[derive(Debug)]
pub enum TlgError {
Io(std::io::Error),
InvalidFormat,
UnsupportedColorType(u8),
IndexOutOfRange,
UnsupportedCompressedMethod(u8),
Str(String),
#[cfg(feature = "encode")]
#[cfg_attr(docsrs, doc(cfg(feature = "encode")))]
EncodeError(String),
}
impl std::fmt::Display for TlgError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TlgError::Io(e) => write!(f, "IO Error: {}", e),
TlgError::InvalidFormat => write!(f, "Invalid TLG format"),
TlgError::UnsupportedColorType(c) => write!(f, "Unsupported color type: {}", c),
TlgError::IndexOutOfRange => write!(f, "Index out of range"),
TlgError::UnsupportedCompressedMethod(m) => {
write!(f, "Unsupported compressed method: {}", m)
}
TlgError::Str(s) => write!(f, "{}", s),
#[cfg(feature = "encode")]
TlgError::EncodeError(s) => write!(f, "Encoding error: {}", s),
}
}
}
impl From<std::io::Error> for TlgError {
fn from(err: std::io::Error) -> Self {
TlgError::Io(err)
}
}
impl From<String> for TlgError {
fn from(err: String) -> Self {
TlgError::Str(err)
}
}
impl From<&str> for TlgError {
fn from(err: &str) -> Self {
TlgError::Str(err.to_string())
}
}
impl From<&String> for TlgError {
fn from(err: &String) -> Self {
TlgError::Str(err.clone())
}
}
impl std::error::Error for TlgError {}