mod container;
mod error;
#[cfg(any(feature = "blp-decode", feature = "blp-encode"))]
mod image;
pub use container::blp1::{Blp1, Blp1Content, Blp1ContentRef, Blp1Header, Blp1Ref};
pub use container::blp2::{Blp2, Blp2Content, Blp2ContentRef, Blp2Header, Blp2Ref, DxtFormat};
pub use error::{ReadError, ReadErrorKind, WriteError};
#[cfg(feature = "blp-encode")]
pub use image::BlpEncoder;
#[cfg(feature = "blp-decode")]
pub use image::DecodeError;
#[cfg(feature = "blp-decode")]
pub use image::{register_decoding_hook, BlpDecoder};
#[cfg(feature = "blp-encode")]
pub use image::{BlpVersion, EncodeError, EncodeFormat, EncodeOptions, IndexedAlpha};
pub const MIPMAP_SLOTS: usize = 16;
pub const PALETTE_BYTES: usize = 1024;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum BlpRef<'a> {
Blp1(Blp1Ref<'a>),
Blp2(Blp2Ref<'a>),
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Blp {
Blp1(Blp1),
Blp2(Blp2),
}
impl<'a> BlpRef<'a> {
pub fn read(bytes: &'a [u8]) -> Result<Self, ReadError> {
match container::io::slice(bytes, 0, 4)? {
b"BLP1" => Blp1Ref::read(bytes).map(Self::Blp1),
b"BLP2" => Blp2Ref::read(bytes).map(Self::Blp2),
_ => Err(ReadError::new(0, ReadErrorKind::InvalidMagic)),
}
}
pub fn to_owned(&self) -> Blp {
match self {
Self::Blp1(value) => Blp::Blp1(value.to_owned()),
Self::Blp2(value) => Blp::Blp2(value.to_owned()),
}
}
pub fn write(&self) -> Result<Vec<u8>, WriteError> {
match self {
Self::Blp1(value) => value.write(),
Self::Blp2(value) => value.write(),
}
}
}
impl Blp {
pub fn as_ref(&self) -> BlpRef<'_> {
match self {
Self::Blp1(value) => BlpRef::Blp1(value.as_ref()),
Self::Blp2(value) => BlpRef::Blp2(value.as_ref()),
}
}
pub fn write(&self) -> Result<Vec<u8>, WriteError> {
self.as_ref().write()
}
}