Select Git revision
semi_coherent_search_using_MCMC.py
-
Gregory Ashton authoredGregory Ashton authored
bmplib.cpp 5.29 KiB
#ifdef _WIN32
#include "boinc_win.h"
#else
#include "config.h"
#endif
#include "bmplib.h"
// Returns true for success -- false otherwise
bool DIB_BITMAP::set_size(int width, int height, int channels)
{
// If DIB_BITMAP has already been set -- clear it out first
FreeDIB_BMP();
// Create a temporary compatible device context
HDC temp_hdc = CreateCompatibleDC(NULL);
// Error Check
if(!temp_hdc)
return false;
bmp_width = width; // Set the width
bmp_height = height; // Set the height
bmp_channels = channels; // Set the channels (3 == 24-bit, 4 == 32-bit)
// Set stride -- The stride is the TRUE number of bytes in a line of pixels
// Windows makes all the .bmps DWORD aligned (divisible evenly by 4)
// So if you bitmap say was 103x103 pixels, Windows would add 1 "padding byte" to it
// so in memory it would be 104x103 pixels. The "padding bytes" do not get blit (drawn)
// to the screen, they're just there so again everything is DWORD aligned which makes
// blitting (drawing to the screen) easier for the OS
bmp_stride = bmp_width * bmp_channels;
while((bmp_stride % 4) != 0) // Ensure bmp_stride is DWORD aligned
bmp_stride++;
BITMAPINFO bmp_info = {0};
// Initialize the parameters that we care about
bmp_info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmp_info.bmiHeader.biWidth = width;
bmp_info.bmiHeader.biHeight = height;
bmp_info.bmiHeader.biPlanes = 1; // Always equal 1
bmp_info.bmiHeader.biBitCount = channels * 8;
bmp_info.bmiHeader.biCompression = BI_RGB; // No compression
bmp_info.bmiHeader.biClrUsed = 0; // Always equals 0 with a 24 or 32-bit .bmp
// Create a DIBSection -- This returns us two things, an HBITMAP handle and
// a memory pointer (pointer to the pixels) in surface_bits
hbitmap = CreateDIBSection(temp_hdc, &bmp_info, DIB_RGB_COLORS,
(void**)&surface_bits, 0, 0);
// Release our temporary HDC
DeleteDC(temp_hdc);
// Error Check -- Make sure the call to CreateDIBSection() DID NOT fail
if(!hbitmap)
return false;
return true; // We're sized :)
} // end of set_size(int width, int height, int channels)
bool DIB_BITMAP::loadBMP(const char *file_name)
{
// If DIB_BITMAP has already been set -- clear it out first
FreeDIB_BMP();
// Error Check -- Make sure they passed in a valid file name