Struct nutexb::NutexbFile

source ·
pub struct NutexbFile {
    pub data: Vec<u8>,
    pub layer_mipmaps: Vec<LayerMipmaps>,
    pub footer: NutexbFooter,
}
Expand description

The data stored in a nutexb file like "def_001_col.nutexb".

Fields§

§data: Vec<u8>

Combined image data for all array layer and mipmap levels.

§layer_mipmaps: Vec<LayerMipmaps>

The size of the mipmaps for each array layer.

Most nutexb files use swizzled image data, so these sizes won’t add up to the length of data.

§footer: NutexbFooter

Information about the image stored in data.

Implementations§

source§

impl NutexbFile

source

pub fn read<R: Read + Seek>(reader: &mut R) -> BinResult<Self>

Reads the NutexbFile from the specified reader.

source

pub fn read_from_file<P: AsRef<Path>>(path: P) -> Result<NutexbFile, Error>

Reads the NutexbFile from the specified path. The entire file is buffered to improve performance.

source

pub fn write<W: Write + Seek>(&self, writer: &mut W) -> Result<(), Error>

Writes the NutexbFile to the specified writer.

source

pub fn write_to_file<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>

Writes the NutexbFile to the specified path. The entire file is buffered to improve performance.

source

pub fn deswizzled_data(&self) -> Result<Vec<u8>, SwizzleError>

Deswizzles all the layers and mipmaps in data.

source

pub fn from_surface<T: AsRef<[u8]>, S: Into<String>>( image: Surface<T>, name: S ) -> Result<Self, SwizzleError>

Creates a NutexbFile from image with the nutexb string set to name. The data in image is swizzled according to the specified dimensions and format.

source

pub fn from_surface_unswizzled<T: AsRef<[u8]>, S: Into<String>>( surface: &Surface<T>, name: S ) -> Self

Creates a NutexbFile from surface with the nutexb string set to name without any swizzling. This assumes no layers or mipmaps for image. Prefer NutexbFile::from_surface for better memory access performance in most cases.

Textures created with NutexbFile::from_surface use a memory layout optimized for the Tegra X1 with better access performance in the general case. This function exists for the rare case where swizzling the image data is not desired for performance or compatibility reasons.

source

pub fn from_dds<S: Into<String>>( dds: &Dds, name: S ) -> Result<Self, ReadDdsError>

Creates a swizzled NutexbFile from dds with the Nutexb string set to name.

DDS supports all Nutexb image formats as well as array layers, mipmaps, cube maps, and 3D volume textures.

source

pub fn to_dds(&self) -> Result<Dds, SwizzleError>

Deswizzle the surface data to DDS while preserving the layers, mipmaps, and image format.

source

pub fn from_image<S: Into<String>>( image: &RgbaImage, name: S ) -> Result<Self, SwizzleError>

Creates a swizzled 2D NutexbFile from image with the Nutexb string set to name and without mipmaps.

source

pub fn optimize_size(&mut self)

Resizes the image data to the expected size based on the footer information by truncating or padding with zeros.

Calling this method is unnecessary for nutexbs created with NutexbFile::from_surface or NutexbFile::from_surface_unswizzled. These methods already calculate the appropriate image data size.

Trait Implementations§

source§

impl BinRead for NutexbFile

§

type Args<'arg> = ()

The type used for the args parameter of read_args() and read_options(). Read more
source§

fn read_options<R: Read + Seek>( reader: &mut R, _endian: Endian, _args: Self::Args<'_> ) -> BinResult<Self>

Read Self from the reader using the given Endian and arguments. Read more
source§

fn read_be<R>(reader: &mut R) -> Result<Self, Error>
where R: Read + Seek, Self::Args<'a>: for<'a> Required,

Read Self from the reader using default arguments and assuming big-endian byte order. Read more
source§

fn read_le<R>(reader: &mut R) -> Result<Self, Error>
where R: Read + Seek, Self::Args<'a>: for<'a> Required,

Read Self from the reader using default arguments and assuming little-endian byte order. Read more
source§

fn read_ne<R>(reader: &mut R) -> Result<Self, Error>
where R: Read + Seek, Self::Args<'a>: for<'a> Required,

Read T from the reader assuming native-endian byte order. Read more
source§

fn read_be_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
where R: Read + Seek,

Read Self from the reader, assuming big-endian byte order, using the given arguments. Read more
source§

fn read_le_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
where R: Read + Seek,

Read Self from the reader, assuming little-endian byte order, using the given arguments. Read more
source§

fn read_ne_args<R>(reader: &mut R, args: Self::Args<'_>) -> Result<Self, Error>
where R: Read + Seek,

Read T from the reader, assuming native-endian byte order, using the given arguments. Read more
source§

impl BinWrite for NutexbFile

§

type Args<'__binrw_generated_args_lifetime> = ()

The type used for the args parameter of write_args() and write_options(). Read more
source§

fn write_options<W: Write + Seek>( &self, __binrw_generated_var_writer: &mut W, __binrw_generated_var_endian: Endian, __binrw_generated_var_arguments: Self::Args<'_> ) -> BinResult<()>

Write Self to the writer using the given Endian and arguments. Read more
source§

fn write_be<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek, Self::Args<'a>: for<'a> Required,

Write Self to the writer assuming big-endian byte order. Read more
source§

fn write_le<W>(&self, writer: &mut W) -> Result<(), Error>
where W: Write + Seek, Self::Args<'a>: for<'a> Required,

Write Self to the writer assuming little-endian byte order. Read more
source§

fn write_be_args<W>( &self, writer: &mut W, args: Self::Args<'_> ) -> Result<(), Error>
where W: Write + Seek,

Write Self to the writer, assuming big-endian byte order, using the given arguments. Read more
source§

fn write_le_args<W>( &self, writer: &mut W, args: Self::Args<'_> ) -> Result<(), Error>
where W: Write + Seek,

Write Self to the writer, assuming little-endian byte order, using the given arguments. Read more
source§

impl Clone for NutexbFile

source§

fn clone(&self) -> NutexbFile

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for NutexbFile

source§

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

Formats the value using the given formatter. 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.