Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
ITexCodec Class Referenceabstract

virtual method table for TexCodecs. More...

#include <tex_codec.h>

Inheritance diagram for ITexCodec:

Public Member Functions

virtual Status decode (u8 *data, size_t size, Tex *RESTRICT t) const =0
 decode the file into a Tex structure. More...
 
virtual Status encode (Tex *RESTRICT t, DynArray *RESTRICT da) const =0
 encode the texture data into the codec's file format (in memory). More...
 
virtual Status transform (Tex *t, size_t transforms) const =0
 transform the texture's pixel format. More...
 
virtual bool is_hdr (const u8 *file) const =0
 indicate if the data appears to be an instance of this codec's header, i.e. More...
 
virtual bool is_ext (const OsPath &extension) const =0
 is the extension that of a file format supported by this codec? More...
 
virtual size_t hdr_size (const u8 *file) const =0
 return size of the file header supported by this codec. More...
 
virtual const wchar_t * get_name () const =0
 name of codec for debug purposes. More...
 
virtual ~ITexCodec ()
 

Detailed Description

virtual method table for TexCodecs.

rationale: this works in C and also allows storing name and next in vtbl. 'template method'-style interface to increase code reuse and simplify writing new codecs.

Constructor & Destructor Documentation

◆ ~ITexCodec()

virtual ITexCodec::~ITexCodec ( )
inlinevirtual

Member Function Documentation

◆ decode()

virtual Status ITexCodec::decode ( u8 data,
size_t  size,
Tex *RESTRICT  t 
) const
pure virtual

decode the file into a Tex structure.

Parameters
datainput data array (non-const, because the texture may have to be flipped in-place - see "texture orientation").
size[bytes] of data, always >= 4 (this is usually enough to compare the header's "magic" field, and no legitimate file will be smaller)
toutput texture object
Returns
Status

Implemented in TexCodecPng, TexCodecDds, TexCodecTga, and TexCodecBmp.

◆ encode()

virtual Status ITexCodec::encode ( Tex *RESTRICT  t,
DynArray *RESTRICT  da 
) const
pure virtual

encode the texture data into the codec's file format (in memory).

Parameters
tinput texture object. note: non-const because encoding may require a Tex::transform.
daoutput data array, allocated by codec. rationale: some codecs cannot calculate the output size beforehand (e.g. PNG output via libpng), so the output memory cannot be allocated by the caller.
Returns
Status

Implemented in TexCodecPng, TexCodecDds, TexCodecTga, and TexCodecBmp.

◆ get_name()

virtual const wchar_t * ITexCodec::get_name ( ) const
pure virtual

name of codec for debug purposes.

typically set via TEX_CODEC_REGISTER.

Implemented in TexCodecPng, TexCodecDds, TexCodecTga, and TexCodecBmp.

◆ hdr_size()

virtual size_t ITexCodec::hdr_size ( const u8 file) const
pure virtual

return size of the file header supported by this codec.

Parameters
filethe specific header to return length of (taking its variable-length fields into account). if NULL, return minimum guaranteed header size, i.e. the header without any variable-length fields.
Returns
size [bytes]

Implemented in TexCodecPng, TexCodecDds, TexCodecTga, and TexCodecBmp.

◆ is_ext()

virtual bool ITexCodec::is_ext ( const OsPath extension) const
pure virtual

is the extension that of a file format supported by this codec?

rationale: cannot just return the extension string and have caller compare it (-> smaller code) because a codec's file format may have several valid extensions (e.g. jpg and jpeg).

Parameters
extension(including '.')
Returns
bool

Implemented in TexCodecPng, TexCodecDds, TexCodecTga, and TexCodecBmp.

◆ is_hdr()

virtual bool ITexCodec::is_hdr ( const u8 file) const
pure virtual

indicate if the data appears to be an instance of this codec's header, i.e.

can this codec decode it?

Parameters
fileinput data; only guaranteed to be 4 bytes! (this should be enough to examine the header's 'magic' field)
Returns
bool

Implemented in TexCodecPng, TexCodecDds, TexCodecTga, and TexCodecBmp.

◆ transform()

virtual Status ITexCodec::transform ( Tex t,
size_t  transforms 
) const
pure virtual

transform the texture's pixel format.

Parameters
ttexture object
transformsOR-ed combination of TEX_* flags that are to be changed. note: the codec needs only handle situations specific to its format; generic pixel format transforms are handled by the caller.

Implemented in TexCodecPng, TexCodecDds, TexCodecTga, and TexCodecBmp.


The documentation for this class was generated from the following file: