summaryrefslogtreecommitdiff
path: root/includes/Image.h
blob: fc94a127b0a101e0aa181b22d24f4c6574234282 (plain)
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
#ifndef __IMAGE_H__
#define __IMAGE_H__
#ifdef __cplusplus

#include <Buffer.h>
#include <generic.h>

enum {
    FORMAT_TGA_BASIC
} format_t;

struct Color {
      Color(unsigned char aR, unsigned char aG, unsigned char aB, unsigned char aA = 255) :
        R(aR), G(aG), B(aB), A(aA) { }
    unsigned char R, G, B, A;
};

class Image : public Buffer {
  public:
      Image(unsigned int, unsigned int);
      virtual ~Image();
    Color GetPixel(unsigned int, unsigned int);
    void SetPixel(unsigned int, unsigned int, Color);
    bool Prepare(unsigned int = FORMAT_TGA_BASIC);
    void Fill(Color = Color(0, 0, 0));
    virtual String GetName();
    virtual bool CanWrite();
    
  private:
    typedef unsigned char Byte;
    typedef unsigned short int Word;
    typedef unsigned long int DWord;
    struct TGAHeader {
	Byte IDLength;
	Byte ColorMapType;
	Byte ImageType;
	Word CM_FirstEntry;
	Word CM_Length;
	Byte CM_EntrySize;
	Word IS_XOrigin;
	Word IS_YOrigin;
	Word IS_Width;
	Word IS_Height;
	Byte IS_Depth;
	Byte IS_Descriptor;
    } PACKED;
    
    struct TGAFooter {
	DWord ExtOffset;
	DWord DevOffset;
	char Sig[18];
    } PACKED;
    
    unsigned int x, y;
    bool r;
    Color * img;
};

#else
#error This only works with a C++ compiler
#endif
#endif