summaryrefslogtreecommitdiff
path: root/plugins/SplashScreen/src/bitmap_funcs.h
blob: 05cbabc0ce78f220313cde974c45ac76808a8a8a (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
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef __bitmap_funcs_h__
#define __bitmap_funcs_h__

// This should make bitmap manipulations much easier...
class MyBitmap
{
public:
	typedef unsigned long COLOR32;
	static inline COLOR32 RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 0xff)
	{
		return (a << 24) | (r << 16) | (g << 8) | b;
	};

private:
	HBITMAP hBmpSave = 0, hBmp = 0;
	HDC dcBmp = 0;
	COLOR32 *bits = 0;
	COLOR32 *bitsSave = 0;
	int width = 0, height = 0;

	void allocate(int w, int h);
	void free();

	void premultipleChannels();

public:
	MyBitmap();
	MyBitmap(int w, int h);
	MyBitmap(wchar_t *fn);
	~MyBitmap();

	bool loadFromFile(wchar_t *fn);

	int getWidth() { return width; }
	int getHeight() { return height; }

	HDC getDC() { return dcBmp; }
	HBITMAP getBitmap() { return hBmp; }

	
	void makeOpaque();

	void saveAlpha(int x = 0, int y = 0, int w = 0, int h = 0);
	void restoreAlpha(int x = 0, int y = 0, int w = 0, int h = 0);
	
	void DrawText(wchar_t *str, int x, int y);

	inline COLOR32 *getBits() { return bits; }
	inline COLOR32 *getRow(int row) { return bits + row * width; }
	inline COLOR32 *operator[] (int row) { return bits + row * width; }

	COLOR32 rgba(COLOR32 r, COLOR32 g, COLOR32 b, COLOR32 a)
	{
		return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff);
	}
	COLOR32 getr(COLOR32 c)
	{
		return (c >> 16) & 0xff;
	}
	COLOR32 getg(COLOR32 c)
	{
		return (c >> 8) & 0xff;
	}
	COLOR32 getb(COLOR32 c)
	{
		return c & 0xff;
	}
	COLOR32 geta(COLOR32 c)
	{
		return (c >> 24) & 0xff;
	}
};

#endif // __bitmap_funcs_h__