Changeset View
Changeset View
Standalone View
Standalone View
source/lib/tex/tex_codec.h
/* Copyright (C) 2010 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
* | * | ||||
* Permission is hereby granted, free of charge, to any person obtaining | * Permission is hereby granted, free of charge, to any person obtaining | ||||
* a copy of this software and associated documentation files (the | * a copy of this software and associated documentation files (the | ||||
* "Software"), to deal in the Software without restriction, including | * "Software"), to deal in the Software without restriction, including | ||||
* without limitation the rights to use, copy, modify, merge, publish, | * without limitation the rights to use, copy, modify, merge, publish, | ||||
* distribute, sublicense, and/or sell copies of the Software, and to | * distribute, sublicense, and/or sell copies of the Software, and to | ||||
* permit persons to whom the Software is furnished to do so, subject to | * permit persons to whom the Software is furnished to do so, subject to | ||||
* the following conditions: | * the following conditions: | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | public: | ||||
* @param t input texture object. note: non-const because encoding may | * @param t input texture object. note: non-const because encoding may | ||||
* require a Tex::transform. | * require a Tex::transform. | ||||
* @param da output data array, allocated by codec. | * @param da output data array, allocated by codec. | ||||
* rationale: some codecs cannot calculate the output size beforehand | * rationale: some codecs cannot calculate the output size beforehand | ||||
* (e.g. PNG output via libpng), so the output memory cannot be allocated | * (e.g. PNG output via libpng), so the output memory cannot be allocated | ||||
* by the caller. | * by the caller. | ||||
* @return Status | * @return Status | ||||
**/ | **/ | ||||
virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const = 0; | virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da, int quality) const = 0; | ||||
/** | /** | ||||
* transform the texture's pixel format. | * transform the texture's pixel format. | ||||
* | * | ||||
* @param t texture object | * @param t texture object | ||||
* @param transforms: OR-ed combination of TEX_* flags that are to | * @param transforms: OR-ed combination of TEX_* flags that are to | ||||
* be changed. note: the codec needs only handle situations specific | * be changed. note: the codec needs only handle situations specific | ||||
* to its format; generic pixel format transforms are handled by | * to its format; generic pixel format transforms are handled by | ||||
Show All 40 Lines | public: | ||||
virtual const wchar_t* get_name() const = 0; | virtual const wchar_t* get_name() const = 0; | ||||
virtual ~ITexCodec() {} | virtual ~ITexCodec() {} | ||||
}; | }; | ||||
class TexCodecPng:ITexCodec { | class TexCodecPng:ITexCodec { | ||||
public: | public: | ||||
virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; | virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; | ||||
virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; | virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da, int quality) const; | ||||
virtual Status transform(Tex* t, size_t transforms) const; | virtual Status transform(Tex* t, size_t transforms) const; | ||||
virtual bool is_hdr(const u8* file) const; | virtual bool is_hdr(const u8* file) const; | ||||
virtual bool is_ext(const OsPath& extension) const; | virtual bool is_ext(const OsPath& extension) const; | ||||
virtual size_t hdr_size(const u8* file) const; | virtual size_t hdr_size(const u8* file) const; | ||||
virtual const wchar_t* get_name() const { | virtual const wchar_t* get_name() const { | ||||
static const wchar_t *name = L"png"; | static const wchar_t *name = L"png"; | ||||
return name; | return name; | ||||
}; | }; | ||||
}; | }; | ||||
class TexCodecJpg:ITexCodec { | |||||
public: | |||||
virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; | |||||
virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da, int quality) const; | |||||
virtual Status transform(Tex* t, size_t transforms) const; | |||||
virtual bool is_hdr(const u8* file) const; | |||||
virtual bool is_ext(const OsPath& extension) const; | |||||
virtual size_t hdr_size(const u8* file) const; | |||||
virtual const wchar_t* get_name() const { | |||||
static const wchar_t *name = L"jpg"; | |||||
return name; | |||||
}; | |||||
}; | |||||
class TexCodecDds:ITexCodec { | class TexCodecDds:ITexCodec { | ||||
public: | public: | ||||
virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; | virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; | ||||
virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; | virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da, int quality) const; | ||||
virtual Status transform(Tex* t, size_t transforms) const; | virtual Status transform(Tex* t, size_t transforms) const; | ||||
virtual bool is_hdr(const u8* file) const; | virtual bool is_hdr(const u8* file) const; | ||||
virtual bool is_ext(const OsPath& extension) const; | virtual bool is_ext(const OsPath& extension) const; | ||||
virtual size_t hdr_size(const u8* file) const; | virtual size_t hdr_size(const u8* file) const; | ||||
virtual const wchar_t* get_name() const { | virtual const wchar_t* get_name() const { | ||||
static const wchar_t *name = L"dds"; | static const wchar_t *name = L"dds"; | ||||
return name; | return name; | ||||
}; | }; | ||||
}; | }; | ||||
class TexCodecTga:ITexCodec { | class TexCodecTga:ITexCodec { | ||||
public: | public: | ||||
virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; | virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; | ||||
virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; | virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da, int quality) const; | ||||
virtual Status transform(Tex* t, size_t transforms) const; | virtual Status transform(Tex* t, size_t transforms) const; | ||||
virtual bool is_hdr(const u8* file) const; | virtual bool is_hdr(const u8* file) const; | ||||
virtual bool is_ext(const OsPath& extension) const; | virtual bool is_ext(const OsPath& extension) const; | ||||
virtual size_t hdr_size(const u8* file) const; | virtual size_t hdr_size(const u8* file) const; | ||||
virtual const wchar_t* get_name() const { | virtual const wchar_t* get_name() const { | ||||
static const wchar_t *name = L"tga"; | static const wchar_t *name = L"tga"; | ||||
return name; | return name; | ||||
}; | }; | ||||
}; | }; | ||||
class TexCodecBmp:ITexCodec { | class TexCodecBmp:ITexCodec { | ||||
public: | public: | ||||
virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; | virtual Status decode(u8* data, size_t size, Tex* RESTRICT t) const; | ||||
virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da) const; | virtual Status encode(Tex* RESTRICT t, DynArray* RESTRICT da, int quality) const; | ||||
virtual Status transform(Tex* t, size_t transforms) const; | virtual Status transform(Tex* t, size_t transforms) const; | ||||
virtual bool is_hdr(const u8* file) const; | virtual bool is_hdr(const u8* file) const; | ||||
virtual bool is_ext(const OsPath& extension) const; | virtual bool is_ext(const OsPath& extension) const; | ||||
virtual size_t hdr_size(const u8* file) const; | virtual size_t hdr_size(const u8* file) const; | ||||
virtual const wchar_t* get_name() const { | virtual const wchar_t* get_name() const { | ||||
static const wchar_t *name = L"bmp"; | static const wchar_t *name = L"bmp"; | ||||
return name; | return name; | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator