Skip to main content

ImageBlp

Struct ImageBlp 

Source
pub struct ImageBlp {
Show 15 fields 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,
}

Fields§

§version: Version§texture_type: TextureType§compression: u8§alpha_bits: u32§alpha_type: u8§has_mips: u8§width: u32§height: u32§extra: u32§has_mipmaps: u32§mipmaps: Vec<Mipmap>§holes: usize§header_offset: usize§header_length: usize§source: SourceKind

Implementations§

Source§

impl ImageBlp

Source

pub fn from_buf(buf: &[u8]) -> Result<Self, BlpError>

Source

pub fn from_rgba( rgba_buf: &[u8], width: u32, height: u32, ) -> Result<Self, BlpError>

Create BLP from raw RGBA buffer. Buffer must be in RGBA format (4 bytes per pixel). Width and height must match the buffer size.

Source

pub fn decode( &mut self, buf: &[u8], mip_visible: &[bool], ) -> Result<(), BlpError>

Top-level decode entry.

mip_visible[i] == false → skip decoding for mip i. Missing indices are treated as true.

Source§

impl ImageBlp

Source

pub fn from_buf_image(buf: &[u8]) -> Result<Self, BlpError>

Lightweight path for “arbitrary image”: layout only without RGBA. Supports both regular image formats (via image library), and Adobe Photoshop (PSD) files with automatic signature detection.

  1. Read source dimensions (without full decoding)
  2. Choose target frame (W*,H*) — powers of two by “minimum upscale” and “minimum crop” rule
  3. Form mipmap chain (only width/height), image=None Tail after 1×1 filled with 0×0 (not 1×1).
Source

pub fn from_rgba_impl( rgba_buf: &[u8], width: u32, height: u32, ) -> Result<Self, BlpError>

Create BLP from raw RGBA buffer. Buffer must be in RGBA format (4 bytes per pixel). Width and height must match the buffer size.

Source§

impl ImageBlp

Source

pub fn decode_direct( &mut self, buf: &[u8], mip_visible: &[bool], ) -> Result<(), BlpError>

DIRECT (paletted) decoding.

Reads palette from the header area and, for each mipmap, reads indices + alpha, then reconstructs RGBA images.

  • mip_visible[i] == false → skip decoding for that mipmap (image stays None).
  • If mip_visible has no entry for index i, we treat it as true.
Source§

impl ImageBlp

Source

pub fn decode_jpeg( &mut self, buf: &[u8], mip_visible: &[bool], ) -> Result<(), BlpError>

JPEG path:

  • Takes a shared JPEG header from [header_offset .. header_offset+header_length).
  • For each mip, concatenates [header][tail] → full JPEG, then decodes it.
  • Respects mip_visible: if mip_visible[i] == false, the mip is skipped (image stays None). Missing indices in mip_visible are treated as true.
Source§

impl ImageBlp

Source

pub fn decode_image( &mut self, buf: &[u8], mip_visible: &[bool], ) -> Result<(), BlpError>

External image path:

  1. Scale-to-cover without aspect distortion to (target_w, target_h).
  2. Center-crop to exactly (target_w, target_h).
  3. Generate mip chain, honoring mip_visible flags:
    • If mip_visible[i] == false → we do NOT materialize pixels for mip i (image stays None).
    • Missing indices in mip_visible are treated as true.
Source§

impl ImageBlp

Source

pub fn encode_blp( &self, quality: u8, mip_visible: &[bool], ) -> Result<Ctx, BlpError>

Source§

impl ImageBlp

Source

pub fn export_blp( &self, out_path: &Path, quality: u8, mip_visible: &[bool], ) -> Result<(), BlpError>

Source§

impl ImageBlp

Source

pub fn export_png(&self, mip: &Mipmap, out_path: &Path) -> Result<(), BlpError>

Сохранить переданный мип как PNG в out_path. Требуется, чтобы в мипе уже было image: Some(RgbaImage).

Source§

impl ImageBlp

Source

pub fn export_jpg( &self, mip: &Mipmap, buf: &[u8], out_path: &Path, ) -> Result<(), BlpError>

Экспортирует данный мип как “сырой” JPEG: склеивает общий JPEG header из файла с хвостом этого мипа и записывает в out_path. Требуется исходный буфер buf с .blp данными (тот же, что парсили).

Trait Implementations§

Source§

impl Debug for ImageBlp

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ImageBlp

Source§

fn default() -> ImageBlp

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.