NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches
texture.hpp File Reference

Contains structures and functions for working with in-game textures. More...

#include <math.h>
#include <cstring>
#include <map>
#include <vector>
#include "NNL/common/fixed_type.hpp"
#include "NNL/common/io.hpp"
#include "NNL/simple_asset/stexture.hpp"
#include "NNL/utility/static_vector.hpp"

Go to the source code of this file.

Classes

struct  nnl::texture::TextureData
 Structure representing image data of a texture. More...
struct  nnl::texture::Texture
 Structure representing a texture. More...
struct  nnl::texture::ConvertParam
 Structure to hold parameters for texture conversion. More...

Namespaces

namespace  nnl
namespace  nnl::texture
 Contains structures and functions for working with in-game textures.

Typedefs

using nnl::texture::TextureContainer = std::vector<Texture>
 Type alias for a container of textures.

Enumerations

enum class  nnl::texture::TextureFormat : u16 {
  nnl::texture::TextureFormat::kCLUT8 = 5 , nnl::texture::TextureFormat::kCLUT4 = 4 , nnl::texture::TextureFormat::kRGBA8888 = 3 , nnl::texture::TextureFormat::kRGBA4444 = 2 ,
  nnl::texture::TextureFormat::kRGBA5551 = 1 , nnl::texture::TextureFormat::kRGB565 = 0
}
 Enumeration of texture formats. More...
enum class  nnl::texture::ClutFormat : u8 { nnl::texture::ClutFormat::kRGBA8888 = 3 , nnl::texture::ClutFormat::kRGBA4444 = 2 , nnl::texture::ClutFormat::kRGBA5551 = 1 , nnl::texture::ClutFormat::kRGB565 = 0 }
 Enumeration of color formats used in Color Lookup Tables (CLUT). More...
enum class  nnl::texture::TextureFilter : u8 {
  nnl::texture::TextureFilter::kNearest = 0 , nnl::texture::TextureFilter::kLinear = 1 , nnl::texture::TextureFilter::kNearestMipmapNearest = 4 , nnl::texture::TextureFilter::kLinearMipmapNearest = 5 ,
  nnl::texture::TextureFilter::kNearestMipmapLinear = 6 , nnl::texture::TextureFilter::kLinearMipmapLinear = 7
}
 Enumeration of texture filtering methods. More...

Functions

std::vector< STexturennl::texture::Convert (const TextureContainer &texture_container, bool mipmaps=false)
 Converts a container of textures to a simplified representation.
TextureContainer nnl::texture::Convert (std::vector< STexture > &&images, const ConvertParam &texture_params={})
 Converts a vector of simplified textures into the in-game format.
bool nnl::texture::IsOfType (BufferView buffer)
 Tests if the provided file is a texture container.
TextureContainer nnl::texture::Import (BufferView buffer)
 Parses a binary file and converts it to a structured texture container.
Buffer nnl::texture::Export (const TextureContainer &texture_container)
 Converts a texture container to its binary file representation.
Texture nnl::texture::Convert (STexture &&image, const ConvertParam &tex_param={})
 Converts a texture from a simplified representation to the in-game format.
STexture nnl::texture::Convert (const Texture &texture, unsigned int level=0)
 Converts a texture from the in-game format to a simplified representation.
Buffer nnl::texture::ConvertRGB565ToRGBA8888 (BufferView bitmap565)
 Converts an image buffer from RGB565 format to RGBA8888 format.
Buffer nnl::texture::ConvertRGBA5551ToRGBA8888 (BufferView bitmap5551)
 Converts an image buffer from RGBA5551 format to RGBA8888 format.
Buffer nnl::texture::ConvertRGBA4444ToRGBA8888 (BufferView bitmap4444)
 Converts an image buffer from RGBA4444 format to RGBA8888 format.
Buffer nnl::texture::ConvertRGBA8888ToRGBA4444 (BufferView bitmap8888)
 Converts an image buffer from RGBA8888 format to RGBA4444 format.
Buffer nnl::texture::ConvertRGBA8888ToRGBA5551 (BufferView bitmap8888)
 Converts an image buffer from RGBA8888 format to RGBA5551 format.
Buffer nnl::texture::ConvertRGBA8888ToRGB565 (BufferView bitmap8888)
 Converts an image buffer from RGBA8888 format to RGB565 format.
Buffer nnl::texture::UnswizzleFromMem (BufferView texptr, u32 bufw, u32 height, u32 bytes_per_pixel)
 Unswizzles texture data.
Buffer nnl::texture::SwizzleFromMem (Buffer &texptr, u32 bufw, u32 height, u32 bytes_per_pixel)
 Swizzles texture data.
u32 nnl::texture::QuickTexHash (BufferView data)
 Computes a quick hash for a texture.
Buffer nnl::texture::ConvertIndexed4To8 (BufferView clut4, u32 width)
 Converts a 4-bit indexed texture to an 8-bit indexed texture.
Buffer nnl::texture::ConvertIndexed8To4 (BufferView clut8, u32 width)
 Converts an 8-bit indexed texture to a 4-bit indexed texture.
std::vector< SPixelnnl::texture::GeneratePaletteMedian (const STexture &source_image, std::size_t num_colors=256)
 Creates a color palette using the median cut algorithm.
std::vector< SPixelnnl::texture::GeneratePaletteNaive (const STexture &source_image, std::size_t num_colors=256)
 Creates a color palette by extracting the first N unique colors from the image.
std::vector< u8nnl::texture::ApplyPalette (const STexture &image, const std::vector< SPixel > &palette, bool dither=true)
 Applies a color palette to the image.
Buffer nnl::texture::AlignBufferWidth (BufferView image_buffer, unsigned int width, unsigned int height, unsigned int bpp, unsigned int buffer_width)
 Aligns the buffer width to a desired buffer width.
Buffer nnl::texture::DealignBufferWidth (BufferView image_buffer, unsigned int width, unsigned int height, unsigned int bpp, unsigned int buffer_width)
 Removes padding from an aligned image buffer.
Buffer nnl::texture::DeindexClut8ToRGBA8888 (BufferView indexed_image, BufferView palette)
 Converts an 8-bit indexed image buffer to an RGBA8888 buffer.
ConvertParam nnl::texture::GenerateConvertParam (const Texture &texture)
 Generates conversion parameters from a given texture.
std::vector< ConvertParamnnl::texture::GenerateConvertParam (const TextureContainer &texture_container)
 Generates conversion parameters from a given texture container.

Variables

constexpr unsigned int nnl::texture::kMinDimension = 1
 Minimum allowed width and height of a texture in pixels.
constexpr unsigned int nnl::texture::kMinByteBufferWidth = 16
 Minimum width of a texture buffer in bytes (as expected by the GE). The actual pixel width can be smaller than this.
constexpr unsigned int nnl::texture::kMaxDimension = 1024
 Maximum allowed width and height of a texture in pixels.
constexpr std::size_t nnl::texture::kMaxMipMapLvl = 7
 The maximum number of mipmap levels that can be used.
constexpr std::size_t nnl::texture::kMaxTextureLvl = 1 + kMaxMipMapLvl
 The maximum number of texture levels.
constexpr u32 nnl::texture::raw::kMagicBytes = 0x88'88'00'01
 Magic bytes used to identify the texture format.

Detailed Description

Contains structures and functions for working with in-game textures.

See also
nnl::texture::TextureContainer
nnl::texture::IsOfType
nnl::texture::Import
nnl::texture::Export
nnl::texture::Convert