void Bitmap::create(int w, int h, bool _alpha) { free(); checkSize(w, h); BITMAPINFO bmi; ZeroMemory(&bmi, sizeof(BITMAPINFO)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = w; bmi.bmiHeader.biHeight = h; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = bmi.bmiHeader.biWidth * bmi.bmiHeader.biHeight * 4; DCDisplay dcd; DCCompatible cdc(dcd.hdc); ptr32 = 0; handle = CreateDIBSection(cdc.hdc, &bmi, DIB_RGB_COLORS, &ptr32, NULL, 0x0); if(handle==0) raise_os(_T("Bitmap.create: CreateDIBSection")); if(ptr32==0) { DeleteObject(handle); handle=0; raise(_T("Bitmap.create: CreateDIBSection ptr32=0")); } BEGIN_NO_EXCEPTION width = w; height = h; alpha = _alpha; END_NO_EXCEPTION }
int main(const char*) { Gdiplus::GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); bmp2 = new Gdiplus::Bitmap(192, 102); WNDCLASS wnd; memset(&wnd, 0, sizeof(wnd)); WNDCLASS wndclass; memset(&wndclass, 0, sizeof(wndclass)); wndclass.style = CS_VREDRAW|CS_HREDRAW|CS_DBLCLKS|CS_SAVEBITS; wndclass.hInstance = GetModuleHandle(0); wndclass.hIcon = LoadIcon(0, IDI_APPLICATION); wndclass.hCursor = LoadCursor(0, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)COLOR_WINDOW; wndclass.lpfnWndProc = wndProc; wndclass.lpszClassName = "WNDPROC"; if(!RegisterClass(&wndclass)) raise_os(_T("RegisterClass")); HWND h = CreateWindow("WNDPROC", "Apogey Color Test", WS_OVERLAPPEDWINDOW|WS_VISIBLE, 100, 100, 640, 480, 0, 0, GetModuleHandle(0), 0); if(!h) raise("CreateWindow"); SetTimer(h, 1, 1000, 0); while(true) { MSG msg; bool r=GetMessage(&msg, NULL, 0, 0)!=0; if(!r) break; TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }
void Bitmap::loadRGB(const void* data, int size, int bpp) { BITMAPINFO h; memset(&h, 0, sizeof(h)); h.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); h.bmiHeader.biWidth = width; h.bmiHeader.biHeight = height; h.bmiHeader.biPlanes = 1; h.bmiHeader.biBitCount = bpp; h.bmiHeader.biSizeImage = size; h.bmiHeader.biXPelsPerMeter = 1; h.bmiHeader.biYPelsPerMeter = 1; DCDisplay dcd; if(!SetDIBits(dcd.hdc, handle, 0, height, data, &h, DIB_RGB_COLORS)) raise_os(_T("SetBitmapBits")); }
void Bitmap::saveRGB32(std::vector<char>& data) const { data.resize(width * height * 4); // Быстрое копирование if(ptr32) { memcpy(&(data[0]), ptr32, data.size()); return; } BITMAPINFO info; info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); info.bmiHeader.biWidth = width; info.bmiHeader.biHeight = height; info.bmiHeader.biPlanes = 1; info.bmiHeader.biBitCount = 32; info.bmiHeader.biSizeImage = data.size(); info.bmiHeader.biXPelsPerMeter = 1; info.bmiHeader.biYPelsPerMeter = 1; DCDisplay dcd; if(GetDIBits(dcd.hdc, handle, 0, height, &(data[0]), &info, DIB_RGB_COLORS)==0) raise_os(_T("GetDIBits")); }
void DNSHandler::worker () { // FD sets used for selecting fd_set readable; fd_set writeable; // Maximum file descriptor to pass // to select int nfds; // The timeout for select struct timeval tv; // Loop until shutdown for (;;) { // Zero FDs FD_ZERO(&readable); FD_ZERO(&writeable); if (lock.Execute([&] () mutable { // Wait for there to be something actionable, // either pending queries, or a shutdown command while (!stop && (queries.size()==0)) wait.Sleep(lock); // If the command to shutdown has been given, // do that at once if (stop) return true; // Get the file descriptors from libcares nfds=ares_fds( channel, &readable, &writeable ); // Get the timeout from libcares ares_timeout( channel, nullptr, &tv ); return false; })) break; // If there's a message pending on // the worker end of the socket pair, // we want to be woken up, so // If there's a message pending // on the worker end of the socket // pair, we want to be woken up, // so we're checking for readability nfds=control.Add(readable,nfds); // Wait for something to happen if (select( nfds, &readable, &writeable, nullptr, &tv )== #ifdef ENVIRONMENT_WINDOWS SOCKET_ERROR #else -1 #endif ) raise_os(); // Did something happen with the // control socket? if (control.Is(readable)) { // Check to see if a shutdown command // is coming through the control socket, // if so end at once if (should_stop()) break; // Remove it in case it matters to // libcares what's in the fd_set control.Clear(readable); } // Call libcares lock.Execute([&] () mutable { ares_process( channel, &readable, &writeable ); }); } }