34 #include "../../../core/ttypes.hpp"
36 #include <boost/shared_ptr.hpp>
43 inline __stdcall BitMapInfoWrapper(
const unsigned int width,
const unsigned int height,
const unsigned short colour_depth);
44 inline __stdcall BitMapInfoWrapper(
const HBITMAP hbitmap,
const unsigned short colour_depth);
57 return reinterpret_cast<BITMAPINFO *>(buff.get());
60 return reinterpret_cast<BITMAPINFO *>(buff.get());
63 return reinterpret_cast<BITMAPINFOHEADER *>(buff.get());
66 return reinterpret_cast<BITMAPINFOHEADER *>(buff.get());
74 explicit inline __stdcall DCWrapper(
void)
noexcept(
true)
75 : dc_(CreateCompatibleDC(NULL)) {
77 inline __stdcall ~DCWrapper(
void)
noexcept(
true) {
81 inline HDC
__fastcall dc(
void)
noexcept(
true) {
88 inline __stdcall DCWrapper(
const DCWrapper &)
noexcept(
true);
89 inline DCWrapper &
__fastcall operator=(
const DCWrapper &)
noexcept(
true);
92 boost::shared_ptr<
char> buff;
94 inline void __fastcall InitHeader(
void)
noexcept(
true);
95 inline void __fastcall InitHeader(
const unsigned int width,
const unsigned int height,
const unsigned short colour_depth)
noexcept(
true);
97 static inline DWORD
__fastcall CalcSize(
const unsigned int width,
const unsigned int height,
const unsigned short colour_depth)
noexcept(
true);
115 InitHeader(width,height,colour_depth);
121 GetObject(hbitmap,
sizeof(BITMAP),&bitmap);
122 buff=std::auto_ptr<
char>(
new char[CalcSize(bitmap.bmWidth,bitmap.bmHeight,colour_depth)]);
123 InitHeader(bitmap.bmWidth,bitmap.bmHeight,colour_depth);
125 BYTE *
const lpBits=
reinterpret_cast<BYTE *
const>(
reinterpret_cast<BITMAPINFO *>(buff.get())->bmiColors)+ColSize(colour_depth);
127 GetDIBits(temp_dc.dc(),hbitmap,0,bitmap.bmHeight,lpBits,
reinterpret_cast<BITMAPINFO *>(buff.get()),DIB_RGB_COLORS);
129 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biClrUsed=ColSize(colour_depth)/
sizeof(RGBQUAD);
132 inline DWORD
__fastcall
134 return sizeof(RGBQUAD)*((colour_depth<= 8) ? 1<<colour_depth : 0);
137 inline void __fastcall
140 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biSize=
sizeof(BITMAPINFOHEADER);
142 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biCompression=BI_RGB;
143 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biXPelsPerMeter=
reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biYPelsPerMeter=0;
148 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biClrImportant=0;
151 inline void __fastcall
152 BitMapInfoWrapper::InitHeader(
const unsigned int width,
const unsigned int height,
const unsigned short colour_depth) {
154 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biWidth=width;
155 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biHeight=height;
156 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biPlanes=1;
157 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biBitCount=colour_depth;
158 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biSizeImage=CalcSize(width,height,colour_depth)-
sizeof(BITMAPINFOHEADER)-ColSize(colour_depth);
159 reinterpret_cast<BITMAPINFOHEADER *>(buff.get())->biClrUsed=ColSize(colour_depth)/
sizeof(RGBQUAD);
162 inline DWORD
__fastcall
163 BitMapInfoWrapper::CalcSize(
const unsigned int width,
const unsigned int height,
const unsigned short colour_depth) {
169 const UINT LineLen = (width*colour_depth+31)/32 * 4;
170 return sizeof(BITMAPINFOHEADER)
171 +ColSize(colour_depth)
172 +
static_cast<DWORD>(LineLen)*
static_cast<DWORD>(height);