-
Notifications
You must be signed in to change notification settings - Fork 1
/
Texture.h
executable file
·98 lines (77 loc) · 3.04 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
//********************************************
// Texture.h
//********************************************
// class CTexture
//********************************************
// This object stores a bitmap image used as
// an OpenGL texture.
// Files are stored as .bmp format.
// Depth are currently 24 or 32 bits,
// Modes are : RGB, RGBA (alpha layer).
//********************************************
// Created : 17/12/97
// Modified : 18/02/98
//********************************************
#ifndef _TEXTURE_
#define _TEXTURE_
class CTexture : public CObject
{
// Members datas
private :
unsigned char *m_pData; // datas
unsigned int m_Width; // width (pixels)
unsigned int m_Height; // height (pixels)
unsigned int m_Depth; // bits per pixel
CString m_FileName; // texture image file name
BITMAPINFOHEADER m_Header; // image header (display on device context)
unsigned int m_WidthByte32; // width (in bytes, and 32 bits aligned)
public :
// Construction / destruction
CTexture();
virtual ~CTexture();
// File reading
int ReadFile(const char *filename,unsigned int width=-1,unsigned int height=-1,unsigned int depth=-1);
int ReadFileBMP(const char *filename);
int ReadFileRAW(const char *filename,unsigned int width,unsigned int height,unsigned int depth);
// File saving
int SaveFile(char *filename);
int SaveFileBMP(char *filename);
int SaveFileRAW(char *filename);
// Datas (explicit inline functions)
unsigned char *GetData(void) { return m_pData; }
unsigned int GetWidth(void) { return m_Width; }
unsigned int GetHeight(void) { return m_Height;}
unsigned int GetDepth(void) { return m_Depth; }
CString GetFileName(void) { return m_FileName; }
// Misc
int IsValid();
int SameSize(CTexture *pTexture);
int BGRtoRGB(void);
int HigherPowerOfTwo(int value);
int LowerPowerOfTwo(int value);
// Updating
void UpdateWidthByte32();
void UpdateHeader();
unsigned int WidthByte32(unsigned int width,unsigned int depth);
// Alpha
int HasAlpha() { return (m_Depth == 32); }
int AddAlphaLayer(unsigned char alpha);
int SetAlphaLayer(unsigned char alpha);
int PutAlpha(CTexture *pTexture); // Put an alpha layer from grey scale
// DuplicateMirror
int DuplicateMirror(int left=0,int top=0,int right=-1,int bottom=-1);
int DuplicateRepeatWidth(int left=0,int top=0,int right=-1,int bottom=-1);
int Extract(int left=0,int top=0,int right=-1,int bottom=-1);
// Display
int Draw(CDC *pDC,int xOffset=0,int yOffset=0, int width=-1, int height=-1);
// Buffer
int ReadBuffer(unsigned char *buffer, int width, int height, int depth);
int Grey(unsigned int x,unsigned int y);
// Memory
void Free(void);
private :
// Memory
int Alloc(unsigned int width,unsigned int height,unsigned int depth);
};
#endif // _TEXTURE_