Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Macros | Typedefs | Functions
tex_codec.h File Reference
#include "tex.h"
#include "tex_internal.h"

Go to the source code of this file.

Classes

struct  TexCodecVTbl
 virtual method table for TexCodecs. More...
 

Macros

#define TEX_CODEC_REGISTER(name)
 build codec vtbl and register it. More...
 

Typedefs

typedef const u8RowPtr
 allocate an array of row pointers that point into the given texture data. More...
 

Functions

int tex_codec_register (TexCodecVTbl *c)
 add this vtbl to the codec list. More...
 
Status tex_codec_for_filename (const OsPath &extension, const TexCodecVTbl **c)
 Find codec that recognizes the desired output file extension. More...
 
Status tex_codec_for_header (const u8 *data, size_t data_size, const TexCodecVTbl **c)
 find codec that recognizes the header's magic field. More...
 
const TexCodecVTbltex_codec_next (const TexCodecVTbl *prev_codec)
 enumerate all registered codecs. More...
 
Status tex_codec_transform (Tex *t, size_t transforms)
 transform the texture's pixel format. More...
 
std::vector< RowPtrtex_codec_alloc_rows (const u8 *data, size_t h, size_t pitch, size_t src_flags, size_t dst_orientation)
 
Status tex_codec_write (Tex *t, size_t transforms, const void *hdr, size_t hdr_size, DynArray *da)
 apply transforms and then copy header and image into output buffer. More...
 

Macro Definition Documentation

#define TEX_CODEC_REGISTER (   name)
Value:
static TexCodecVTbl UID__ = \
{\
name##_decode, name##_encode, name##_transform,\
name##_is_hdr, name##_is_ext, name##_hdr_size,\
WIDEN(#name)\
};\
/*static int dummy = tex_codec_register(&vtbl);*/\
/* note: when building as a static library, pre-main initializers */\
/* will not run! as a workaround, we build an externally visible */\
/* registration function that must be called via */\
/* tex_codec_register_all - see comments there. */\
void name##_register() { tex_codec_register(&UID__); }
#define WIDEN(x)
virtual method table for TexCodecs.
Definition: tex_codec.h:39
#define UID__
int tex_codec_register(TexCodecVTbl *c)
add this vtbl to the codec list.
Definition: tex_codec.cpp:44

build codec vtbl and register it.

the codec will be queried for future texture load requests. call order is undefined, but since each codec only steps up if it can handle the given format, this is not a problem.

Parameters
nameidentifier of codec (not string!). used to bind 'member' functions prefixed with it to the vtbl, and as the TexCodecVTbl name. it should also mirror the default file extension (e.g. dds) - this is relied upon (but verified) in the self-test.

usage: at file scope within the source file containing the codec's methods.

Definition at line 137 of file tex_codec.h.

Typedef Documentation

typedef const u8* RowPtr

allocate an array of row pointers that point into the given texture data.

for texture decoders that support output via row pointers (e.g. PNG), this allows flipping the image vertically (useful when matching bottom-up textures to a global orientation) directly, which is much more efficient than transforming later via copying all pixels.

Parameters
datathe texture data into which row pointers will point. note: we don't allocate it here because this function is needed for encoding, too (where data is already present).
hheight [pixels] of texture.
pitchsize [bytes] of one texture row, i.e. width*bytes_per_pixel.
src_flagsTexFlags of source texture. used to extract its orientation.
dst_orientationdesired orientation of the output data. can be one of TEX_BOTTOM_UP, TEX_TOP_DOWN, or 0 for the "global orientation". depending on src and dst, the row array is flipped if necessary.

Definition at line 228 of file tex_codec.h.

Function Documentation

std::vector<RowPtr> tex_codec_alloc_rows ( const u8 data,
size_t  h,
size_t  pitch,
size_t  src_flags,
size_t  dst_orientation 
)

Definition at line 154 of file tex_codec.cpp.

Status tex_codec_for_filename ( const OsPath extension,
const TexCodecVTbl **  c 
)

Find codec that recognizes the desired output file extension.

Parameters
extension
c(out) vtbl of responsible codec
Returns
Status; ERR::RES_UNKNOWN_FORMAT (without warning, because this is called by tex_is_known_extension) if no codec indicates they can handle the given extension.

Definition at line 65 of file tex_codec.cpp.

Status tex_codec_for_header ( const u8 data,
size_t  data_size,
const TexCodecVTbl **  c 
)

find codec that recognizes the header's magic field.

Parameters
datatypically contents of file, but need only include the (first 4 bytes of) header.
data_size[bytes]
c(out) vtbl of responsible codec
Returns
Status; ERR::RES_UNKNOWN_FORMAT if no codec indicates they can handle the given format (header).

Definition at line 79 of file tex_codec.cpp.

const TexCodecVTbl* tex_codec_next ( const TexCodecVTbl prev_codec)

enumerate all registered codecs.

used by self-test to test each one of them in turn.

Parameters
prev_codecthe last codec returned by this function. pass 0 the first time. note: this routine is stateless and therefore reentrant.
Returns
the next codec, or 0 if all have been returned.

Definition at line 96 of file tex_codec.cpp.

int tex_codec_register ( TexCodecVTbl c)

add this vtbl to the codec list.

called at NLSO init time by the TEX_CODEC_REGISTER in each codec file. order in list is unspecified; see TEX_CODEC_REGISTER.

Parameters
cpointer to vtbl.
Returns
int (allows calling from a macro at file scope; value is not used)

Definition at line 44 of file tex_codec.cpp.

Status tex_codec_transform ( Tex t,
size_t  transforms 
)

transform the texture's pixel format.

tries each codec's transform method once, or until one indicates success.

Parameters
ttexture object
transforms,:OR-ed combination of TEX_* flags that are to be changed.
Returns
Status

Definition at line 107 of file tex_codec.cpp.

Status tex_codec_write ( Tex t,
size_t  transforms,
const void *  hdr,
size_t  hdr_size,
DynArray da 
)

apply transforms and then copy header and image into output buffer.

Parameters
tinput texture object
transformstransformations to be applied to pixel format
hdrheader data
hdr_size[bytes]
daoutput data array (will be expanded as necessary)
Returns
Status

Definition at line 176 of file tex_codec.cpp.