This source file includes following definitions.
- Info
- Info
- Header
- Header
- dc
- ColSize
- InitHeader
- InitHeader
- CalcSize
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 #pragma once
35
36 #include "../../../core/ttypes.hpp"
37
38 #include <boost/shared_ptr.hpp>
39
40 namespace jmmcg { namespace NTUtils {
41
42 class BitMapInfoWrapper {
43 public:
44 explicit inline __stdcall BitMapInfoWrapper(const unsigned long size =0);
45 inline __stdcall BitMapInfoWrapper(const unsigned int width,const unsigned int height,const unsigned short colour_depth);
46 inline __stdcall BitMapInfoWrapper(const HBITMAP hbitmap,const unsigned short colour_depth);
47 inline __stdcall BitMapInfoWrapper(BitMapInfoWrapper const &bmi) noexcept(true)
48 : buff(bmi.buff) {
49 }
50 inline __stdcall ~BitMapInfoWrapper(void) noexcept(true) {
51 }
52
53 inline BitMapInfoWrapper & __fastcall operator=(BitMapInfoWrapper &bmi) noexcept(true) {
54 buff=bmi.buff;
55 return *this;
56 }
57
58 inline const BITMAPINFO * __fastcall Info(void) const noexcept(true) {
59 return reinterpret_cast<BITMAPINFO *>(buff.get());
60 }
61 inline BITMAPINFO * __fastcall Info(void) noexcept(true) {
62 return reinterpret_cast<BITMAPINFO *>(buff.get());
63 }
64 inline const BITMAPINFOHEADER * __fastcall Header(void) const noexcept(true) {
65 return reinterpret_cast<BITMAPINFOHEADER *>(buff.get());
66 }
67 inline BITMAPINFOHEADER * __fastcall Header(void) noexcept(true) {
68 return reinterpret_cast<BITMAPINFOHEADER *>(buff.get());
69 }
70
71 static inline DWORD __fastcall ColSize(const unsigned short colour_depth) noexcept(true);
72
73 private:
74 class DCWrapper {
75 public:
76 explicit inline __stdcall DCWrapper(void) noexcept(true)
77 : dc_(CreateCompatibleDC(NULL)) {
78 }
79 inline __stdcall ~DCWrapper(void) noexcept(true) {
80 DeleteDC(dc_);
81 }
82
83 inline HDC __fastcall dc(void) noexcept(true) {
84 return dc_;
85 }
86
87 private:
88 HDC dc_;
89
90 inline __stdcall DCWrapper(const DCWrapper &) noexcept(true);
91 inline DCWrapper & __fastcall operator=(const DCWrapper &) noexcept(true);
92 };
93
94 boost::shared_ptr<char> buff;
95
96 inline void __fastcall InitHeader(void) noexcept(true);
97 inline void __fastcall InitHeader(const unsigned int width,const unsigned int height,const unsigned short colour_depth) noexcept(true);
98
99 static inline DWORD __fastcall CalcSize(const unsigned int width,const unsigned int height,const unsigned short colour_depth) noexcept(true);
100 };
101
102 AFX_EXT_CLASS bool __fastcall LoadBMP(const jmmcg::tstring &BMPFile,BitMapInfoWrapper &hDIB,std::auto_ptr<CPalette> &);
103 AFX_EXT_CLASS bool __fastcall LoadBMP(CFile &,BitMapInfoWrapper &hDIB,std::auto_ptr<CPalette> &);
104 AFX_EXT_CLASS BitMapInfoWrapper __fastcall CreateBitmapInfoStruct(const CBitmap &);
105 AFX_EXT_CLASS bool __fastcall CreateBMPFile(const jmmcg::tstring &,const CBitmap &,const CDC &);
106 AFX_EXT_CLASS bool __fastcall CreateBMPFile(CFile &,const CBitmap &,const CDC &);
107
108 inline __stdcall
109 BitMapInfoWrapper::BitMapInfoWrapper(const unsigned long size)
110 : buff(new char[sizeof(BITMAPINFOHEADER)+size]) {
111 InitHeader();
112 }
113
114 inline __stdcall
115 BitMapInfoWrapper::BitMapInfoWrapper(const unsigned int width,const unsigned int height,const unsigned short colour_depth)
116 : buff(new char[CalcSize(width,height,colour_depth)]) {
117 InitHeader(width,height,colour_depth);
118 }
119
120 inline __stdcall
121 BitMapInfoWrapper::BitMapInfoWrapper(const HBITMAP hbitmap,const unsigned short colour_depth) {
122 BITMAP bitmap;
123 GetObject(hbitmap,sizeof(BITMAP),&bitmap);
124 buff=std::auto_ptr<char>(new char[CalcSize(bitmap.bmWidth,bitmap.bmHeight,colour_depth)]);
125 InitHeader(bitmap.bmWidth,bitmap.bmHeight,colour_depth);
126
127 BYTE * const lpBits=reinterpret_cast<BYTE * const>(reinterpret_cast<BITMAPINFO *>(buff.get())->bmiColors)+ColSize(colour_depth);
128 DCWrapper temp_dc;
129 GetDIBits(temp_dc.dc(),hbitmap,0,bitmap.bmHeight,lpBits,reinterpret_cast<BITMAPINFO *>(buff.get()),DIB_RGB_COLORS);
130
131 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biClrUsed=ColSize(colour_depth)/sizeof(RGBQUAD);
132 }
133
134 inline DWORD __fastcall
135 BitMapInfoWrapper::ColSize(const unsigned short colour_depth) {
136 return sizeof(RGBQUAD)*((colour_depth<= 8) ? 1<<colour_depth : 0);
137 }
138
139 inline void __fastcall
140 BitMapInfoWrapper::InitHeader(void) {
141 assert(buff.get());
142 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biSize=sizeof(BITMAPINFOHEADER);
143
144 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biCompression=BI_RGB;
145 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biXPelsPerMeter=reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biYPelsPerMeter=0;
146
147
148
149
150 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biClrImportant=0;
151 }
152
153 inline void __fastcall
154 BitMapInfoWrapper::InitHeader(const unsigned int width,const unsigned int height,const unsigned short colour_depth) {
155 InitHeader();
156 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biWidth=width;
157 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biHeight=height;
158 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biPlanes=1;
159 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biBitCount=colour_depth;
160 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biSizeImage=CalcSize(width,height,colour_depth)-sizeof(BITMAPINFOHEADER)-ColSize(colour_depth);
161 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biClrUsed=ColSize(colour_depth)/sizeof(RGBQUAD);
162 }
163
164 inline DWORD __fastcall
165 BitMapInfoWrapper::CalcSize(const unsigned int width,const unsigned int height,const unsigned short colour_depth) {
166
167
168
169
170
171 const UINT LineLen = (width*colour_depth+31)/32 * 4;
172 return sizeof(BITMAPINFOHEADER)
173 +ColSize(colour_depth)
174 +static_cast<DWORD>(LineLen)*static_cast<DWORD>(height);
175 }
176
177 } }