Skip to main content

rustydemon_blp2/
error.rs

1use thiserror::Error;
2
3/// All errors that can be returned by this crate.
4#[derive(Debug, Error)]
5pub enum BlpError {
6    /// An I/O error occurred while reading the file or buffer.
7    #[error("I/O error: {0}")]
8    Io(#[from] std::io::Error),
9
10    /// The first four bytes of the file are not a recognised BLP magic number
11    /// (`BLP0`, `BLP1`, or `BLP2`).
12    #[error("invalid BLP magic number")]
13    InvalidMagic,
14
15    /// A BLP2 file declared a format version other than `1`.
16    #[error("invalid BLP2 format version: expected 1, got {0}")]
17    InvalidFormatVersion(u32),
18
19    /// The color encoding byte is not one of the five known values
20    /// (JPEG=0, Palette=1, DXT=2, ARGB8888=3, ARGB8888Dup=4).
21    #[error("unsupported color encoding: {0}")]
22    UnsupportedEncoding(u8),
23
24    /// [`BlpFile::get_pixels`] was called on a file whose mipmap offset table
25    /// contains no non-zero entries.
26    #[error("no mipmaps present")]
27    NoMipmaps,
28
29    /// A mipmap offset/size pair points outside the bounds of the file buffer,
30    /// or `offset + size` overflows `usize`.
31    #[error("mipmap data out of bounds")]
32    OutOfBounds,
33
34    /// The mipmap data slice is present but shorter than the decoded image
35    /// requires (e.g. palette indices are truncated, or alpha bytes are missing).
36    #[error("mipmap data too short for declared image dimensions")]
37    DataTooShort,
38
39    /// The declared image dimensions (`width × height × 4`) would exceed the
40    /// 256 MiB allocation ceiling, or the multiplication overflows `usize`.
41    #[error("image dimensions too large")]
42    ImageTooLarge,
43
44    /// JPEG decoding failed. The inner string contains the decoder's error message.
45    #[error("JPEG decode error: {0}")]
46    JpegDecode(String),
47}