]> git.sesse.net Git - casparcg/blob - core/producer/flash/bitmap.cpp
2.0.0.2:
[casparcg] / core / producer / flash / bitmap.cpp
1 /*\r
2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
3 *\r
4 *  This file is part of CasparCG.\r
5 *\r
6 *    CasparCG is free software: you can redistribute it and/or modify\r
7 *    it under the terms of the GNU General Public License as published by\r
8 *    the Free Software Foundation, either version 3 of the License, or\r
9 *    (at your option) any later version.\r
10 *\r
11 *    CasparCG is distributed in the hope that it will be useful,\r
12 *    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14 *    GNU General Public License for more details.\r
15 \r
16 *    You should have received a copy of the GNU General Public License\r
17 *    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
18 *\r
19 */\r
20  \r
21 #include "../../StdAfx.h"\r
22 \r
23 #include "bitmap.h"\r
24 \r
25 #include <windows.h>\r
26 \r
27 namespace caspar{\r
28         \r
29 struct bitmap::implementation : boost::noncopyable\r
30 {\r
31         implementation(size_t width, size_t height) \r
32                 : size_(width*height*4), width_(width), height_(height), hdc_(CreateCompatibleDC(nullptr)), bitmap_handle_(nullptr)\r
33         {       \r
34                 if(hdc_ == nullptr)\r
35                         throw std::bad_alloc();\r
36                 \r
37                 BITMAPINFO bitmapInfo;\r
38                 bitmapInfo.bmiHeader.biBitCount = 32;\r
39                 bitmapInfo.bmiHeader.biClrImportant = 0;\r
40                 bitmapInfo.bmiHeader.biClrUsed = 0;\r
41                 bitmapInfo.bmiHeader.biCompression = BI_RGB;\r
42         #pragma warning(disable:4146)\r
43                 bitmapInfo.bmiHeader.biHeight = -height;\r
44         #pragma warning(default:4146)\r
45                 bitmapInfo.bmiHeader.biPlanes = 1;\r
46                 bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFO);\r
47                 bitmapInfo.bmiHeader.biWidth = width;\r
48                 bitmapInfo.bmiHeader.biSizeImage = 0;\r
49                 bitmapInfo.bmiHeader.biXPelsPerMeter = 0;\r
50                 bitmapInfo.bmiHeader.biYPelsPerMeter = 0;\r
51 \r
52                 bitmap_handle_ = CreateDIBSection(hdc_, &bitmapInfo, DIB_RGB_COLORS, reinterpret_cast<void**>(&bitmap_data_), NULL, 0);\r
53                 SelectObject(hdc_, bitmap_handle_);     \r
54         }\r
55         \r
56         ~implementation()\r
57         {\r
58                 if(bitmap_handle_ != nullptr) \r
59                         DeleteObject(bitmap_handle_);\r
60                 if(hdc_ != nullptr)\r
61                         DeleteDC(hdc_);\r
62         }\r
63         \r
64         const size_t size_;\r
65         const size_t width_;\r
66         const size_t height_;\r
67         unsigned char* bitmap_data_;\r
68         HDC hdc_;\r
69         HBITMAP bitmap_handle_;\r
70 };\r
71 \r
72 bitmap::bitmap(size_t width, size_t height) : impl_(new implementation(width, height)){}\r
73 size_t bitmap::size() const { return impl_->size_; }\r
74 size_t bitmap::width() const { return impl_->width_; }\r
75 size_t bitmap::height() const { return impl_->height_; }\r
76 unsigned char* bitmap::data() { return impl_->bitmap_data_; }\r
77 HDC bitmap::hdc() { return impl_->hdc_; }\r
78 \r
79 }