-
Notifications
You must be signed in to change notification settings - Fork 0
/
TargaImage.h
99 lines (83 loc) · 2.09 KB
/
TargaImage.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
#ifndef __TARGA_LIB
#define __TARGA_LIB
enum TGATypes
{
TGA_NODATA = 0,
TGA_INDEXED = 1,
TGA_RGB = 2,
TGA_GRAYSCALE = 3,
TGA_INDEXED_RLE = 9,
TGA_RGB_RLE = 10,
TGA_GRAYSCALE_RLE = 11
};
// Image Data Formats
#define IMAGE_RGB 0
#define IMAGE_RGBA 1
#define IMAGE_LUMINANCE 2
// Image data types
#define IMAGE_DATA_UNSIGNED_BYTE 0
// Pixel data transfer from file to screen:
// These masks are AND'd with the imageDesc in the TGA header,
// bit 4 is left-to-right ordering
// bit 5 is top-to-bottom
#define BOTTOM_LEFT 0x00 // first pixel is bottom left corner
#define BOTTOM_RIGHT 0x10 // first pixel is bottom right corner
#define TOP_LEFT 0x20 // first pixel is top left corner
#define TOP_RIGHT 0x30 // first pixel is top right corner
// TGA header
struct tgaheader_t
{
unsigned char idLength;
unsigned char colorMapType;
unsigned char imageTypeCode;
unsigned char colorMapSpec[5];
unsigned short xOrigin;
unsigned short yOrigin;
unsigned short width;
unsigned short height;
unsigned char bpp;
unsigned char imageDesc;
};
struct rgba_t
{
unsigned char r;
unsigned char g;
unsigned char b;
unsigned char a;
};
struct rgb_t
{
unsigned char r;
unsigned char g;
unsigned char b;
};
class TargaImage
{
private:
unsigned char m_colorDepth;
unsigned char m_imageDataType;
unsigned char m_imageDataFormat;
unsigned char *m_pImageData;
unsigned short m_width;
unsigned short m_height;
unsigned long m_imageSize;
// swap the red and blue components in the image data
void SwapRedBlue();
public:
TargaImage();
virtual ~TargaImage();
// loading and unloading
bool Load(const char *filename);
void Release();
// flips image vertically
bool FlipVertical();
unsigned short GetWidth() { return m_width; }
unsigned short GetHeight() { return m_height; }
unsigned char GetImageFormat() { return m_imageDataFormat; }
// converts RGB format to RGBA format and vice versa
bool ConvertRGBAToRGB();
bool ConvertRGBToRGBA(unsigned char alphaValue);
// returns the current image data
unsigned char *GetImage() { return m_pImageData; }
};
#endif