summaryrefslogtreecommitdiff
path: root/public/mxtk/mximage.h
blob: 46b7f0d4963514bbb4c08e02ba997ae03c6d37f7 (plain) (blame)
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
//
//                 mxToolKit (c) 1999 by Mete Ciragan
//
// file:           mxImage.h
// implementation: all
// last modified:  Apr 15 1999, Mete Ciragan
// copyright:      The programs and associated files contained in this
//                 distribution were developed by Mete Ciragan. The programs
//                 are not in the public domain, but they are freely
//                 distributable without licensing fees. These programs are
//                 provided without guarantee or warrantee expressed or
//                 implied.
//
#ifndef INCLUDED_MXIMAGE
#define INCLUDED_MXIMAGE



#ifndef byte
typedef unsigned char byte;
#endif // byte

#ifndef word
typedef unsigned short word;
#endif // word



class mxImage
{
public:
	int width;
	int height;
	int bpp;
	void *data;
	void *palette;

	// CREATORS
	mxImage () : width (0), height (0), bpp (0), data (0), palette (0)
	{
	}

	mxImage (int w, int h, int bpp)
	{
		create (w, h, bpp);
	}

	virtual ~mxImage ()
	{
		destroy ();
	}

	// MANIPULATORS
	bool create (int w, int h, int pixelSize)
	{
		if (data)
			delete[] data;

		if (palette)
			delete[] palette;

		data = new byte[w * h * pixelSize / 8];
		if (!data)
			return false;

		// allocate a palette for 8-bit images
		if (pixelSize == 8)
		{
			palette = new byte[768];
			if (!palette)
			{
				delete[] data;
				return false;
			}
		}
		else
			palette = 0;

		width = w;
		height = h;
		bpp = pixelSize;

		return true;
	}

	void destroy ()
	{
		if (data)
			delete[] data;

		if (palette)
			delete[] palette;

		data = palette = 0;
		width = height = bpp = 0;
	}

private:
	// NOT IMPLEMENTED
	mxImage (const mxImage&);
	mxImage& operator= (const mxImage&);
};



#endif // INCLUDED_MXIMAGE