2 * copyright (c) 2010 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG.
\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
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
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
21 #include "../../StdAfx.h"
\r
25 #include <windows.h>
\r
29 struct bitmap::implementation : boost::noncopyable
\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
35 throw std::bad_alloc();
\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
52 bitmap_handle_ = CreateDIBSection(hdc_, &bitmapInfo, DIB_RGB_COLORS, reinterpret_cast<void**>(&bitmap_data_), NULL, 0);
\r
53 SelectObject(hdc_, bitmap_handle_);
\r
58 if(bitmap_handle_ != nullptr)
\r
59 DeleteObject(bitmap_handle_);
\r
65 const size_t width_;
\r
66 const size_t height_;
\r
67 unsigned char* bitmap_data_;
\r
69 HBITMAP bitmap_handle_;
\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