Pyrogenesis trunk
Classes | Macros | Functions | Variables
tex.cpp File Reference
#include "precompiled.h"
#include "tex.h"
#include "lib/allocators/shared_ptr.h"
#include "lib/bits.h"
#include "lib/sysdep/cpu.h"
#include "lib/tex/tex_codec.h"
#include "lib/timer.h"
#include <algorithm>
#include <cmath>
#include <cstdlib>
Include dependency graph for tex.cpp:

Classes

struct  CreateLevelData
 

Macros

#define CHECK_TEX(t)   RETURN_STATUS_IF_ERR((t->validate()))
 

Functions

 STATUS_ADD_DEFINITIONS (texStatusDefinitions)
 
Status tex_validate_plain_format (size_t bpp, size_t flags)
 check if the given texture format is acceptable: 8bpp grey, 24bpp color or 32bpp color+alpha (BGR / upside down are permitted). More...
 
void tex_util_foreach_mipmap (size_t w, size_t h, size_t bpp, const u8 *pixels, int levels_to_skip, size_t data_padding, MipmapCB cb, void *RESTRICT cbData)
 for a series of mipmaps stored from base to highest, call back for each level. More...
 
static void create_level (size_t level, size_t level_w, size_t level_h, const u8 *RESTRICT level_data, size_t level_dataSize, void *RESTRICT cbData)
 
static Status add_mipmaps (Tex *t, size_t w, size_t h, size_t bpp, void *newData, size_t dataSize)
 
 TIMER_ADD_CLIENT (tc_plain_transform)
 
static Status plain_transform (Tex *t, size_t transforms)
 
 TIMER_ADD_CLIENT (tc_transform)
 
void tex_set_global_orientation (int o)
 Set the orientation to which all loaded images will automatically be converted (excepting file formats that don't specify their orientation, i.e. More...
 
static void flip_to_global_orientation (Tex *t)
 
bool tex_orientations_match (size_t src_flags, size_t dst_orientation)
 indicate if the two vertical orientations match. More...
 
bool tex_is_known_extension (const VfsPath &pathname)
 Is the file's extension that of a texture format supported by tex_load? More...
 
static void add_level_size (size_t level, size_t level_w, size_t level_h, const u8 *RESTRICT level_data, size_t level_dataSize, void *RESTRICT cbData)
 
size_t tex_hdr_size (const VfsPath &filename)
 return the minimum header size (i.e. More...
 

Variables

static const StatusDefinition texStatusDefinitions []
 
static int global_orientation = TEX_TOP_DOWN
 

Macro Definition Documentation

◆ CHECK_TEX

#define CHECK_TEX (   t)    RETURN_STATUS_IF_ERR((t->validate()))

Function Documentation

◆ add_level_size()

static void add_level_size ( size_t  level,
size_t  level_w,
size_t  level_h,
const u8 *RESTRICT  level_data,
size_t  level_dataSize,
void *RESTRICT  cbData 
)
static

◆ add_mipmaps()

static Status add_mipmaps ( Tex t,
size_t  w,
size_t  h,
size_t  bpp,
void *  newData,
size_t  dataSize 
)
static

◆ create_level()

static void create_level ( size_t  level,
size_t  level_w,
size_t  level_h,
const u8 *RESTRICT  level_data,
size_t  level_dataSize,
void *RESTRICT  cbData 
)
static

◆ flip_to_global_orientation()

static void flip_to_global_orientation ( Tex t)
static

◆ plain_transform()

static Status plain_transform ( Tex t,
size_t  transforms 
)
static

◆ STATUS_ADD_DEFINITIONS()

STATUS_ADD_DEFINITIONS ( texStatusDefinitions  )

◆ tex_hdr_size()

size_t tex_hdr_size ( const VfsPath filename)

return the minimum header size (i.e.

offset to pixel data) of the file format corresponding to the filename.

rationale: this can be used to optimize calls to tex_write: when allocating the buffer that will hold the image, allocate this much extra and pass the pointer as base+hdr_size. this allows writing the header directly into the output buffer and makes for zero-copy IO.

Parameters
filenameFilename; only the extension (that after '.') is used. case-insensitive.
Returns
size [bytes] or 0 on error (i.e. no codec found).

◆ tex_is_known_extension()

bool tex_is_known_extension ( const VfsPath pathname)

Is the file's extension that of a texture format supported by tex_load?

Rationale: tex_load complains if the given file is of an unsupported type. this API allows users to preempt that warning (by checking the filename themselves), and also provides for e.g. enumerating only images in a file picker. an alternative might be a flag to suppress warning about invalid files, but this is open to misuse.

Parameters
pathnameOnly the extension (starting with '.') is used. case-insensitive.
Returns
bool

◆ tex_orientations_match()

bool tex_orientations_match ( size_t  src_flags,
size_t  dst_orientation 
)

indicate if the two vertical orientations match.

used by tex_codec.

Parameters
src_flagsTexFlags, used to extract the orientation. we ask for this instead of src_orientation so callers don't have to mask off TEX_ORIENTATION.
dst_orientationorientation to compare against. can be one of TEX_BOTTOM_UP, TEX_TOP_DOWN, or 0 for the "global orientation".
Returns
bool

◆ tex_set_global_orientation()

void tex_set_global_orientation ( int  orientation)

Set the orientation to which all loaded images will automatically be converted (excepting file formats that don't specify their orientation, i.e.

DDS). See "Default Orientation" in docs.

Parameters
orientationEither TEX_BOTTOM_UP or TEX_TOP_DOWN.

◆ tex_util_foreach_mipmap()

void tex_util_foreach_mipmap ( size_t  w,
size_t  h,
size_t  bpp,
const u8 data,
int  levels_to_skip,
size_t  data_padding,
MipmapCB  cb,
void *RESTRICT  cbData 
)

for a series of mipmaps stored from base to highest, call back for each level.

Parameters
w,hPixel dimensions.
bppBits per pixel.
dataSeries of mipmaps.
levels_to_skipNumber of levels (counting from base) to skip, or TEX_BASE_LEVEL_ONLY to only call back for the base image. Rationale: this avoids needing to special case for images with or without mipmaps.
data_paddingMinimum pixel dimensions of mipmap levels. This is used in S3TC images, where each level is actually stored in 4x4 blocks. usually 1 to indicate levels are consecutive.
cbMipmapCB to call.
cbDataExtra data to pass to cb.

◆ tex_validate_plain_format()

Status tex_validate_plain_format ( size_t  bpp,
size_t  flags 
)

check if the given texture format is acceptable: 8bpp grey, 24bpp color or 32bpp color+alpha (BGR / upside down are permitted).

basically, this is the "plain" format understood by all codecs and tex_codec_plain_transform.

Parameters
bppbits per pixel
flagsTexFlags
Returns
Status

◆ TIMER_ADD_CLIENT() [1/2]

TIMER_ADD_CLIENT ( tc_plain_transform  )

◆ TIMER_ADD_CLIENT() [2/2]

TIMER_ADD_CLIENT ( tc_transform  )

Variable Documentation

◆ global_orientation

int global_orientation = TEX_TOP_DOWN
static

◆ texStatusDefinitions

const StatusDefinition texStatusDefinitions[]
static
Initial value:
=
{
{ ERR::TEX_UNKNOWN_FORMAT, L"Unknown texture format" },
{ ERR::TEX_FMT_INVALID, L"Invalid/unsupported texture format" },
{ ERR::TEX_INVALID_COLOR_TYPE, L"Invalid color type" },
{ ERR::TEX_NOT_8BIT_PRECISION, L"Not 8-bit channel precision" },
{ ERR::TEX_INVALID_LAYOUT, L"Unsupported texel layout, e.g. right-to-left" },
{ ERR::TEX_COMPRESSED, L"Unsupported texture compression" },
{ WARN::TEX_INVALID_DATA, L"Warning: invalid texel data encountered" },
{ ERR::TEX_INVALID_SIZE, L"Texture size is incorrect" },
{ INFO::TEX_CODEC_CANNOT_HANDLE, L"Texture codec cannot handle the given format" }
}
const Status TEX_NOT_8BIT_PRECISION
Definition: tex.h:119
const Status TEX_INVALID_LAYOUT
Definition: tex.h:120
const Status TEX_INVALID_SIZE
Definition: tex.h:122
const Status TEX_UNKNOWN_FORMAT
Definition: tex.h:115
const Status TEX_INVALID_COLOR_TYPE
Definition: tex.h:118
const Status TEX_COMPRESSED
Definition: tex.h:121
const Status TEX_FMT_INVALID
Definition: tex.h:117
const Status TEX_CODEC_CANNOT_HANDLE
Definition: tex.h:132
const Status TEX_INVALID_DATA
Definition: tex.h:127