Example #1
0
//
// DIBを作成する
//
BOOL CDib::Create(int width, int height, int depth)
{
	W = width;
	H = height;
	D = depth;

	bytes_per_line = ScanBytes(width, depth);
	bytes_per_pixel = PixelBytes(depth);

	long	bitsAlloc = bytes_per_line * height;
	long	headerSize = sizeof(BITMAPINFOHEADER);
	if (depth == 8)
		headerSize += sizeof(RGBQUAD) * 256;

	if ((hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, bitsAlloc + headerSize)) == 0)
		return FALSE;

	Info = (BITMAPINFO *)::GlobalLock(hGlobal);
	Bits = (void *)((char *)Info + headerSize);

	Info->bmiHeader.biSize			= sizeof(BITMAPINFOHEADER);
	Info->bmiHeader.biWidth			= width;
	Info->bmiHeader.biHeight		= height;
	Info->bmiHeader.biBitCount		= (unsigned short)depth;
	Info->bmiHeader.biPlanes		= 1;
	Info->bmiHeader.biXPelsPerMeter	= 0;
	Info->bmiHeader.biYPelsPerMeter	= 0;
	Info->bmiHeader.biClrUsed		= 0;
	Info->bmiHeader.biClrImportant	= 0;
	Info->bmiHeader.biCompression	= BI_RGB;
	Info->bmiHeader.biSizeImage		= bitsAlloc;

	return TRUE;
}
Example #2
0
void PixelFormat::SetPixel(BYTE* pb, Pixel pixel) const
{
    switch (PixelBytes()) {
        case 1:         *pb = (BYTE)(pixel.Value()); break;
        case 2:  *(WORD*)pb = (WORD)(pixel.Value()); break;
        case 3:
            pb[0] = (BYTE)(((pixel.Value()) >>  0) & 0xff);
            pb[1] = (BYTE)(((pixel.Value()) >>  8) & 0xff);
            pb[2] = (BYTE)(((pixel.Value()) >> 16) & 0xff);
            break;
        case 4: *(DWORD*)pb = (pixel.Value()); break;
    }
}
Example #3
0
Pixel PixelFormat::GetPixel(const BYTE* pb) const
{
    switch (PixelBytes()) {
        case 1: return Pixel::Create(*pb);
        case 2: return Pixel::Create(*(WORD*)pb);
        case 3:
            return
                Pixel::Create(
                      (DWORD(pb[0]) <<  0)
                    | (DWORD(pb[1]) <<  8)
                    | (DWORD(pb[2]) << 16)
                );
        case 4: return Pixel::Create(*(DWORD*)pb);
    }

    return Pixel::Create(0);
}