forked from graphitemaster/neothyne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
texture.h
121 lines (97 loc) · 3.02 KB
/
texture.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef TEXTURE_HDR
#define TEXTURE_HDR
#include "u_string.h"
#include "u_optional.h"
#include "u_vector.h"
enum {
kTexFlagNormal = 1 << 0,
kTexFlagGrey = 1 << 1,
kTexFlagDisk = 1 << 2,
kTexFlagPremul = 1 << 3,
kTexFlagNoCompress = 1 << 4,
kTexFlagCompressed = 1 << 5
};
enum textureFormat {
kTexFormatRGB,
kTexFormatRGBA,
kTexFormatBGR,
kTexFormatBGRA,
kTexFormatRG,
kTexFormatLuminance,
kTexFormatDXT1,
kTexFormatDXT3,
kTexFormatDXT5,
kTexFormatBC4U, // Also ATI1
kTexFormatBC4S,
kTexFormatBC5U, // also ATI2
kTexFormatBC5S
};
enum saveFormat {
kSaveBMP,
kSaveTGA,
kSavePNG
};
struct texture {
texture()
: m_width(0)
, m_height(0)
, m_bpp(0)
, m_pitch(0)
, m_mips(0)
, m_flags(0)
, m_format(kTexFormatLuminance)
{
}
texture(const unsigned char *const data, size_t length, size_t width,
size_t height, bool normal, textureFormat format);
bool load(const u::string &file, float quality = 1.0f);
bool from(const unsigned char *const data, size_t length, size_t width,
size_t height, bool normal, textureFormat format);
bool save(const u::string &file, saveFormat save = kSaveBMP, float quality = 1.0f);
void colorize(uint32_t color);
template <size_t S>
static void halve(unsigned char *src, size_t sw, size_t sh, size_t stride,
unsigned char *dst);
template <size_t S>
static void shift(unsigned char *src, size_t sw, size_t sh, size_t stride,
unsigned char *dst, size_t dw, size_t dh);
template <size_t S>
static void scale(unsigned char *src, size_t sw, size_t sh, size_t stride,
unsigned char *dst, size_t dw, size_t dh);
static void scale(unsigned char *src, size_t sw, size_t sh, size_t bpp,
size_t pitch, unsigned char *dst, size_t dw, size_t dh);
static void reorient(unsigned char *src, size_t sw, size_t sh, size_t bpp,
size_t stride, unsigned char *dst, bool flipx, bool flipy, bool swapxy);
void resize(size_t width, size_t height);
template <textureFormat F>
void convert();
size_t width() const;
size_t height() const;
textureFormat format() const;
const unsigned char *data() const;
size_t size() const;
size_t bpp() const;
size_t pitch() const;
size_t mips() const;
const u::string &hashString() const;
int flags() const;
void unload();
private:
void writeTGA(u::vector<unsigned char> &outData);
void writeBMP(u::vector<unsigned char> &outData);
void writePNG(u::vector<unsigned char> &outData);
u::optional<u::string> find(const u::string &file);
template <typename T>
bool decode(const u::vector<unsigned char> &data, const char *fileName,
float quality = 1.0f);
u::string m_hashString;
u::vector<unsigned char> m_data;
size_t m_width;
size_t m_height;
size_t m_bpp;
size_t m_pitch;
size_t m_mips;
int m_flags;
textureFormat m_format;
};
#endif