use crate::prelude::RGB;
use byteorder::{ReadBytesExt, WriteBytesExt};
use std::io;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct XpColor {
pub r: u8,
pub g: u8,
pub b: u8,
}
impl From<RGB> for XpColor {
fn from(rgb: RGB) -> Self {
rgb.to_xp()
}
}
impl XpColor {
pub const BLACK: Self = Self { r: 0, g: 0, b: 0 };
pub const TRANSPARENT: Self = Self {
r: 255,
g: 0,
b: 255,
};
#[inline]
#[must_use]
pub const fn new(r: u8, g: u8, b: u8) -> Self {
Self { r, g, b }
}
#[inline]
#[must_use]
pub fn is_transparent(self) -> bool {
self == Self::TRANSPARENT
}
#[inline]
pub fn read<T: ReadBytesExt>(rdr: &mut T) -> io::Result<Self> {
let r = rdr.read_u8()?;
let g = rdr.read_u8()?;
let b = rdr.read_u8()?;
Ok(Self { r, g, b })
}
#[inline]
pub fn write<T: WriteBytesExt>(self, wr: &mut T) -> io::Result<()> {
wr.write_u8(self.r)?;
wr.write_u8(self.g)?;
wr.write_u8(self.b)?;
Ok(())
}
}
impl From<XpColor> for RGB {
fn from(xp: XpColor) -> Self {
RGB::from_xp(xp)
}
}