-
Notifications
You must be signed in to change notification settings - Fork 0
/
ltga.h
107 lines (91 loc) · 4.29 KB
/
ltga.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
/* ----------------------------------------------------------------------------
Copyright (c) 1999-2002, Lev Povalahev
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* The name of the author may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
------------------------------------------------------------------------------*/
#ifndef LTGA_H
#define LTGA_H
//------------------------------------------------
#include <string>
//------------------------------------------------
typedef unsigned char byte;
typedef unsigned int uint;
enum LImageType {itUndefined, itRGB, itRGBA, itGreyscale};
const char *const LImageTypeString[] = { "Undefined", "RGB", "RGBA", "Greyscale" };
//------------------------------------------------
class LTGA
{
public:
// default constructor, does nothing
LTGA();
// constructs the object and loads the given tga file
LTGA(const std::string &filename);
// constructor from sizes, IG added this.
LTGA(uint _width, uint _height);
// the destructor, cleans up the memory
virtual ~LTGA();
// this method loads a tga file. It clears all the data
// if needed.
bool LoadFromFile(const std::string &filename);
// this method clears the data, calling it is not nessesary, since it is
// automatically called by the destructor
void Clear();
// this method retursn the depth of the alpha bitplane in the image
// it can be either 0 or 8.
uint GetAlphaDepth();
// this method returns the width of the image.
uint GetImageWidth();
// this method returns the height of the image.
uint GetImageHeight();
// this method returns the pixel depth of the image. i.e. color
// depth. Can be 0 (no image loaded), 8 or 24. 16 bit images are not supported.
uint GetPixelDepth();
// this function returns the pointer to the image data. This pointer can be used
// for glTexImage2D, for example.
byte* GetPixels();
// this function returns an image type. Imagetype can be either itUndefined (when
// no tga file has been loaded, itRGB (when GetAlphaDepth returns 0 and GetPixelDepth
// returns 24, itRGBA (when GetAlphaDepth returns 8 and GetPixelDepth returns 24), or
// itGreyscale (when GetAlphaDepth returns 0 and GetPixelDepth returns 8).
LImageType GetImageType();
// Returns true if an image has been loaded
bool IsLoaded(void) const { return m_loaded; }
void SwapRB();
// IG added this -- may not work for every little file you got.
void WriteToFile(const std::string& name);
protected:
// this is the pixel buffer -> the image
byte *m_pixels;
// the pixel depth of the image, including the alpha bits
uint m_pixelDepth;
// the depth of the alpha bitplane
uint m_alphaDepth;
// the image height
uint m_height;
// the width of the image
uint m_width;
// image type, either rgb, rgba or greyscale
LImageType m_type;
// m_loaded is true if a file has been loaded
bool m_loaded;
};
//------------------------------------------------
#endif // LTGA_H