use crate::core::mipmap::Mipmap;
use crate::core::types::{SourceKind, TextureType, Version};
use crate::error::error::BlpError;
pub const MAX_MIPS: usize = 16;
pub const HEADER_SIZE: u64 = 156;
fn is_blp_file(buf: &[u8]) -> bool {
buf.len() >= 3 && &buf[..3] == b"BLP"
}
#[derive(Debug, Default)]
pub struct ImageBlp {
#[allow(dead_code)]
pub version: Version,
pub texture_type: TextureType,
pub compression: u8,
pub alpha_bits: u32,
pub alpha_type: u8,
pub has_mips: u8,
pub width: u32,
pub height: u32,
pub extra: u32, pub has_mipmaps: u32, pub mipmaps: Vec<Mipmap>,
pub holes: usize,
pub header_offset: usize,
pub header_length: usize,
pub source: SourceKind,
}
impl ImageBlp {
pub fn from_buf(buf: &[u8]) -> Result<Self, BlpError> {
if is_blp_file(buf) {
Self::from_buf_blp(buf)
} else {
Self::from_buf_image(buf)
}
}
pub fn from_rgba(rgba_buf: &[u8], width: u32, height: u32) -> Result<Self, BlpError> {
Self::from_rgba_impl(rgba_buf, width, height)
}
pub fn decode(&mut self, buf: &[u8], mip_visible: &[bool]) -> Result<(), BlpError> {
match self.source {
SourceKind::Blp => match self.texture_type {
TextureType::DIRECT => self.decode_direct(buf, mip_visible),
TextureType::JPEG => self.decode_jpeg(buf, mip_visible),
},
SourceKind::Image => self.decode_image(buf, mip_visible),
}
}
}