-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitmap.h
105 lines (80 loc) · 2.92 KB
/
bitmap.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
#if !defined(BITMAP_H)
#define BITMAP_H
#include <windows.h>
#include <tchar.h>
//-----------------------------------------------------------------------------
// 32-bit BGRA WIN32 device independent bitmap (DIB) class.
//
// Supports the loading of BMP, EMF, GIF, ICO, JPG, and WMF files using the
// WIN32 IPicture COM object.
//
// Also supports the loading of true color 24-bit and 32-bit TGA files, and
// grayscale 8-bit TGA files.
//
// Support is also provided for capturing a screen shot of the current Windows
// desktop and loading that as an image into the Bitmap class.
//
// This class stores the DIB in a top-down orientation. The pixel bytes are
// stored in the standard Windows DIB order of BGRA.
//
// All Windows DIBs are aligned to 4-byte (DWORD) memory boundaries. This means
// that each scan line is padded with extra bytes to ensure that the next scan
// line starts on a 4-byte memory boundary.
//
// To get a copy of the DIB that is BYTE (1-byte) aligned with all the extra
// padding bytes removed use the copyBytes() methods.
//-----------------------------------------------------------------------------
class Bitmap
{
public:
HDC dc;
HBITMAP hBitmap;
int width;
int height;
int pitch;
BITMAPINFO info;
Bitmap();
Bitmap(const Bitmap &bitmap);
~Bitmap();
Bitmap &operator=(const Bitmap &bitmap);
BYTE *operator[](int row) const
{ return &m_pBits[pitch * row]; }
void blt(HDC hdcDest);
void blt(HDC hdcDest, int x, int y);
void blt(HDC hdcDest, int x, int y, int w, int h);
void blt(HDC hdcDest, const RECT &rcDest, const RECT &rcSrc);
bool clone(const Bitmap &bitmap);
bool create(int widthPixels, int heightPixels);
void destroy();
void fill(int r, int g, int b, int a);
void fill(float r, float g, float b, float a);
BYTE *getPixel(int x, int y) const
{ return &m_pBits[(y * pitch) + (x * 4)]; }
BYTE *getPixels() const
{ return m_pBits; }
bool loadDesktop();
bool loadBitmap(LPCTSTR pszFilename);
bool loadPicture(LPCTSTR pszFilename);
bool loadTarga(LPCTSTR pszFilename);
bool saveBitmap(LPCTSTR pszFilename) const;
bool saveTarga(LPCTSTR pszFilename) const;
void selectObject();
void deselectObject();
void copyBytes24Bit(BYTE *pDest) const;
void copyBytes32Bit(BYTE *pDest) const;
void copyBytesAlpha8Bit(BYTE *pDest) const;
void copyBytesAlpha32Bit(BYTE *pDest) const;
void setPixels(const BYTE *pPixels, int w, int h, int bytesPerPixel);
void flipHorizontal();
void flipVertical();
void resize(int newWidth, int newHeight);
private:
DWORD createPixel(int r, int g, int b, int a) const;
DWORD createPixel(float r, float g, float b, float a) const;
static const int HIMETRIC_INCH = 2540; // matches constant in MFC CDC class
static int m_logpixelsx;
static int m_logpixelsy;
HGDIOBJ m_hPrevObj;
BYTE *m_pBits;
};
#endif