コード例 #1
0
ファイル: gfx.cpp プロジェクト: Seldom/miranda-ng
void Gfx::setBitmapAlpha(HBITMAP hBitmap, BYTE bAlpha)
{
	BITMAP bmp;
	DWORD dwLen;
	int x, y;

	GetObject(hBitmap, sizeof(bmp), &bmp);

	if (bmp.bmBitsPixel != 32)
		return;

	dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
	if (dwLen > m_sAllocated) {
		m_p = (BYTE *)realloc(m_p, dwLen);
		m_sAllocated = dwLen;
	}
	memset(m_p, 0, dwLen);

	GetBitmapBits(hBitmap, dwLen, m_p);

	for (y = 0; y < bmp.bmHeight; ++y) {
		BYTE *px = m_p + bmp.bmWidth * 4 * y;

		for (x = 0; x < bmp.bmWidth; ++x) {
			px[3] = bAlpha;
			px += 4;
		}
	}
	SetBitmapBits(hBitmap, bmp.bmWidth * bmp.bmHeight * 4, m_p);
}
コード例 #2
0
ファイル: gfx.cpp プロジェクト: Seldom/miranda-ng
void Gfx::preMultiply(HBITMAP hBitmap, int mode)
{
	DWORD dwLen;
    int width, height, x, y;
    BITMAP bmp;
    BYTE alpha;

	GetObject(hBitmap, sizeof(bmp), &bmp);
    width = bmp.bmWidth;
	height = bmp.bmHeight;
	dwLen = width * height * 4;
	if (dwLen > m_sAllocated) {
		m_p = (BYTE *)realloc(m_p, dwLen);
		m_sAllocated = dwLen;
	}
    if(m_p) {
        GetBitmapBits(hBitmap, dwLen, m_p);
        for (y = 0; y < height; ++y) {
            BYTE *px = m_p + width * 4 * y;

            for (x = 0; x < width; ++x) {
                if(mode) {
                    alpha = px[3];
                    px[0] = px[0] * alpha/255;
                    px[1] = px[1] * alpha/255;
                    px[2] = px[2] * alpha/255;
                }
                else
                    px[3] = 255;
                px += 4;
            }
        }
        dwLen = SetBitmapBits(hBitmap, dwLen, m_p);
    }
}
コード例 #3
0
picture* load_picture(const char* name)
{
    HBITMAP hbmp;
    picture* pic;
    ps_image * img;
    BITMAP* nb;
    unsigned size;
    char* pname;

    if (!name || !strlen(name))
        return NULL;

    pname = (char*)malloc(strlen(name)+5);
    sprintf(pname, "%s.bmp", name);

    nb = (BITMAP*)malloc(sizeof(BITMAP)); 
    hbmp = (HBITMAP)LoadImageA(hInst, pname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTCOLOR);
    GetObject(hbmp, sizeof(BITMAP), (LPVOID)nb);

    size = nb->bmWidthBytes * nb->bmHeight; 
    nb->bmBits = calloc(1, size);
    GetBitmapBits(hbmp, size, nb->bmBits);
    DeleteObject(hbmp);
    free(pname);
    img = ps_image_create_with_data(nb->bmBits, fmt, nb->bmWidth, nb->bmHeight, nb->bmWidthBytes);

    pic = (picture*)malloc(sizeof(picture));
    pic->width = nb->bmWidth;
    pic->height = nb->bmHeight;
    pic->native = nb;
    pic->image = img;

    return pic;
}
コード例 #4
0
ファイル: bitmap_func.cpp プロジェクト: 0xmono/miranda-ng
BOOL IsAlphaTransparent(HBITMAP hBitmap)
{
    BITMAP bmp;
    GetObject(hBitmap, sizeof(bmp), &bmp);
    if (bmp.bmBitsPixel != 32)
        return FALSE;

    DWORD dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
    BYTE *p = (BYTE *)mir_calloc(dwLen);
    if (p == NULL)
        return FALSE;

    GetBitmapBits(hBitmap, dwLen, p);

    for (int y = 0; y < bmp.bmHeight; y++) {
        BYTE *px = p + bmp.bmWidth * 4 * y;
        for (int x = 0; x < bmp.bmWidth; x++) {
            if (px[3] != 0) {
                mir_free(p);
                return TRUE;
            }

            px += 4;
        }
    }

    mir_free(p);
    return FALSE;
}
コード例 #5
0
ファイル: EmoticonsManager.cpp プロジェクト: strogo/StrongDC
Emoticon::Emoticon(const tstring& _emoticonText, const string& _imagePath) : 
	emoticonText(_emoticonText), imagePath(_imagePath)
{
	emoticonBitmap = (HBITMAP) ::LoadImage(0, Text::toT(imagePath).c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
	if(!emoticonBitmap)
		return;
	
	BITMAP bm = { 0 };
	GetObject(emoticonBitmap, sizeof(bm), &bm);
	
	if(bm.bmBitsPixel == 32) {
		BYTE *pBits = new BYTE[bm.bmWidth * bm.bmHeight * 4];
		GetBitmapBits(emoticonBitmap, bm.bmWidth * bm.bmHeight * 4, pBits);
		
		// fix alpha channel	
		for (int y = 0; y < bm.bmHeight; y++) {
			BYTE * pPixel = (BYTE *) pBits + bm.bmWidth * 4 * y;

			for (int x = 0; x < bm.bmWidth; x++) {
				pPixel[0] = pPixel[0] * pPixel[3] / 255; 
				pPixel[1] = pPixel[1] * pPixel[3] / 255; 
				pPixel[2] = pPixel[2] * pPixel[3] / 255; 

				pPixel += 4;
			}
		}
		SetBitmapBits(emoticonBitmap, bm.bmWidth * bm.bmHeight * 4, pBits);
	    
		delete[] pBits;
	}
}
コード例 #6
0
ファイル: HandleCache.cpp プロジェクト: jamesbascle/YoloMouse
    // private
    //-------------------------------------------------------------------------
    Hash HandleCache::_CalculateHash( HCURSOR hcursor )
    {
        static const ULong HASH_BUFFER_LIMIT = KILOBYTES(8);
    
        ICONINFO    iconinfo = {0};
        LONG        count;
        Byte        buffer[HASH_BUFFER_LIMIT];

        // require valid
        if( hcursor == NULL )
            return 0;

        // get icon info
        if( GetIconInfo(hcursor, &iconinfo) == FALSE )
            return 0;

        // get icon bitmap buffer
        count = GetBitmapBits( iconinfo.hbmColor ? iconinfo.hbmColor : iconinfo.hbmMask, sizeof(buffer), buffer );

        // iconinfo cleanup 
        if( iconinfo.hbmColor )
            DeleteObject(iconinfo.hbmColor);
        if( iconinfo.hbmMask )
            DeleteObject(iconinfo.hbmMask);

        // fail if no bits read
        if(count == 0)
            return 0;

        // generate hash
        return Tools::Fnv164Hash(buffer, count);
    }
コード例 #7
0
ファイル: 44479.cpp プロジェクト: Simon0105/exploit-database
static
BOOL xxRetrieveBitmapBits(VOID)
{
    pBmpHunted = static_cast<PDWORD>(malloc(0x1000));
    ZeroMemory(pBmpHunted, 0x1000);
    LONG index = -1;
    LONG iLeng = -1;
    POCDEBUG_BREAK();
    for (LONG i = 0; i < maxTimes; i++)
    {
        iLeng = GetBitmapBits(hbitmap[i], 0x1000, pBmpHunted);
        if (iLeng < 0xCA0)
        {
            continue;
        }
        index = i;
        std::cout << "LOCATE: " << '[' << i << ']' << hbitmap[i] << std::endl;
        hBmpHunted = hbitmap[i];
        break;
    }
    if (index == -1)
    {
        std::cout << "FAILED: " << (PVOID)(-1) << std::endl;
        return FALSE;
    }
    return TRUE;
}
コード例 #8
0
ファイル: images.cpp プロジェクト: aventado/secureimplugin
void HalfBitmap32Alpha(HBITMAP hBitmap)
{
	BITMAP bmp;
	DWORD dwLen;
	BYTE *p;
	int x, y;

	GetObject(hBitmap, sizeof(bmp), &bmp);

	if (bmp.bmBitsPixel != 32)
		return;

	dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
	p = (BYTE *)malloc(dwLen);
	if (p == NULL)
		return;
	memset(p, 0, dwLen);

	GetBitmapBits(hBitmap, dwLen, p);

	for (y = 0; y < bmp.bmHeight; ++y) {
        BYTE *px = p + bmp.bmWidth * 4 * y;

        for (x = 0; x < bmp.bmWidth; ++x) 
		{
			px[3]>>=1;
			px += 4;
		}
	}

	SetBitmapBits(hBitmap, dwLen, p);

	free(p);
}
コード例 #9
0
ファイル: ScreenShot.cpp プロジェクト: gao19920804/ScreenShot
void CovertToGrayBitmap(HBITMAP hSourceBmp, HDC sourceDc)
{
	HBITMAP retBmp = hSourceBmp;
	BITMAPINFO bmpInfo;
	ZeroMemory(&bmpInfo, sizeof(BITMAPINFO));
	bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	GetDIBits(sourceDc, retBmp, 0, 0, NULL, &bmpInfo, DIB_RGB_COLORS);

	BYTE* bits = new BYTE[bmpInfo.bmiHeader.biSizeImage];
	GetBitmapBits(retBmp, bmpInfo.bmiHeader.biSizeImage, bits);

	int bytePerPixel = 4;//默认32位
	if (bmpInfo.bmiHeader.biBitCount == 24)
	{
		bytePerPixel = 3;
	}
	for (DWORD i = 0; i < bmpInfo.bmiHeader.biSizeImage; i += bytePerPixel)
	{
		BYTE r = *(bits + i);
		BYTE g = *(bits + i + 1);
		BYTE b = *(bits + i + 2);
		*(bits + i) = *(bits + i + 1) = *(bits + i + 2) = (r + b + g) / 3;
	}
	SetBitmapBits(hSourceBmp, bmpInfo.bmiHeader.biSizeImage, bits);
	delete[] bits;
}
コード例 #10
0
static LONG ReadMemory(HBITMAP hManager, HBITMAP hWorker, PVOID src, PVOID dest, DWORD len) {
	
	if (SetBitmapBits(hManager, sizeof(PVOID), &src) == 0) {
		LOG("[-] Unable To Set Source Address: 0x%p\n", src);
		return FALSE;
	}
	
	return GetBitmapBits(hWorker, len, dest) ? TRUE : FALSE;
}
コード例 #11
0
ファイル: shell.c プロジェクト: AlexSteel/wine
static HICON16 convert_icon_to_16( HINSTANCE16 inst, HICON icon )
{
    static HICON16 (WINAPI *pCreateIcon16)(HINSTANCE16,INT16,INT16,BYTE,BYTE,LPCVOID,LPCVOID);
    ICONINFO info;
    BITMAP bm;
    UINT and_size, xor_size;
    void *xor_bits = NULL, *and_bits;
    HICON16 handle = 0;

    if (!pCreateIcon16 &&
        !(pCreateIcon16 = (void *)GetProcAddress( GetModuleHandleA("user.exe16"), "CreateIcon16" )))
        return 0;

    if (!(GetIconInfo( icon, &info ))) return 0;
    GetObjectW( info.hbmMask, sizeof(bm), &bm );
    and_size = bm.bmHeight * bm.bmWidthBytes;
    if (!(and_bits = HeapAlloc( GetProcessHeap(), 0, and_size ))) goto done;
    GetBitmapBits( info.hbmMask, and_size, and_bits );
    if (info.hbmColor)
    {
        GetObjectW( info.hbmColor, sizeof(bm), &bm );
        xor_size = bm.bmHeight * bm.bmWidthBytes;
        if (!(xor_bits = HeapAlloc( GetProcessHeap(), 0, xor_size ))) goto done;
        GetBitmapBits( info.hbmColor, xor_size, xor_bits );
    }
    else
    {
        bm.bmHeight /= 2;
        xor_bits = (char *)and_bits + and_size / 2;
    }
    handle = pCreateIcon16( inst, bm.bmWidth, bm.bmHeight, bm.bmPlanes, bm.bmBitsPixel,
                            and_bits, xor_bits );
done:
    HeapFree( GetProcessHeap(), 0, and_bits );
    if (info.hbmColor)
    {
        HeapFree( GetProcessHeap(), 0, xor_bits );
        DeleteObject( info.hbmColor );
    }
    DeleteObject( info.hbmMask );
    DestroyIcon( icon );
    return handle;
}
コード例 #12
0
ファイル: v4l.c プロジェクト: bilboed/wine
static void Resize(const Capture * capBox, LPBYTE output, const BYTE *input)
{
    /* the whole image needs to be reversed,
       because the dibs are messed up in windows */
    if (!capBox->swresize)
    {
        int depth = capBox->bitDepth / 8;
        int inoffset = 0, outoffset = capBox->height * capBox->width * depth;
        int ow = capBox->width * depth;
        while (outoffset > 0)
        {
            int x;
            outoffset -= ow;
            for (x = 0; x < ow; x++)
                output[outoffset + x] = input[inoffset + x];
            inoffset += ow;
        }
    }
    else
    {
        HDC dc_s, dc_d;
        HBITMAP bmp_s, bmp_d;
        int depth = capBox->bitDepth / 8;
        int inoffset = 0, outoffset = (capBox->outputheight) * capBox->outputwidth * depth;
        int ow = capBox->outputwidth * depth;
        LPBYTE myarray;

        /* FIXME: Improve software resizing: add error checks and optimize */

        myarray = CoTaskMemAlloc(capBox->outputwidth * capBox->outputheight * depth);
        dc_s = CreateCompatibleDC(NULL);
        dc_d = CreateCompatibleDC(NULL);
        bmp_s = CreateBitmap(capBox->width, capBox->height, 1, capBox->bitDepth, input);
        bmp_d = CreateBitmap(capBox->outputwidth, capBox->outputheight, 1, capBox->bitDepth, NULL);
        SelectObject(dc_s, bmp_s);
        SelectObject(dc_d, bmp_d);
        StretchBlt(dc_d, 0, 0, capBox->outputwidth, capBox->outputheight,
                   dc_s, 0, 0, capBox->width, capBox->height, SRCCOPY);
        GetBitmapBits(bmp_d, capBox->outputwidth * capBox->outputheight * depth, myarray);
        while (outoffset > 0)
        {
            int i;

            outoffset -= ow;
            for (i = 0; i < ow; i++)
                output[outoffset + i] = myarray[inoffset + i];
            inoffset += ow;
        }
        CoTaskMemFree(myarray);
        DeleteObject(dc_s);
        DeleteObject(dc_d);
        DeleteObject(bmp_s);
        DeleteObject(bmp_d);
    }
}
コード例 #13
0
ファイル: bitmap.c プロジェクト: ABratovic/open-watcom-v2
/*
 * __GetBitmapBits - make sure to get alias right for bits
 */
LONG FAR PASCAL __GetBitmapBits( HBITMAP bm, DWORD dw, LPSTR bits )
{
    DWORD       alias;
    LONG        rc;

    DPMIGetHugeAlias( (DWORD) bits, &alias, dw );
    rc = GetBitmapBits( bm, dw, (LPSTR) alias );
    DPMIFreeHugeAlias( alias, dw );
    return( rc );

} /* __GetBitmapBits */
コード例 #14
0
ファイル: Window.cpp プロジェクト: artemcpp/winControls
int WinGui::Window::setRgn(char* path){
	BITMAP bi;
	BYTE bpp;
	DWORD delPxl;
	DWORD pixel;
	int startx;
	int i, j;
	int arraySize;

	HRGN Rgn, ResRgn = CreateRectRgn(0, 0, 0, 0);

	hbtmp = (HBITMAP)LoadImage(NULL, path, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	//hbtmp = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(path), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
	if(hbtmp == NULL)
		return -1;

	GetObject(hbtmp, sizeof(BITMAP), &bi);
	bpp = bi.bmBitsPixel >> 3;
	arraySize = bi.bmWidth * bi.bmHeight * bpp;

	BYTE *pBits = new BYTE[arraySize];

	int p = GetBitmapBits(hbtmp, arraySize, pBits);

	delPxl = *(DWORD*)pBits;
	delPxl <<= 32 - bi.bmBitsPixel;

	for (i = 0; i < bi.bmHeight; i++){
		startx = -1;
		for (j = 0; j < bi.bmWidth; j++){
			pixel = *(DWORD*)(pBits + (i * bi.bmWidth + j) * bpp) << (32 - bi.bmBitsPixel);
			if (pixel != delPxl){
				if (startx < 0){
					startx = j;
				}else if(j == (bi.bmWidth - 1)){
					Rgn = CreateRectRgn(startx, i, j, i + 1);
					CombineRgn(ResRgn, ResRgn, Rgn, RGN_OR);
					startx = -1;
				}
			}else if (startx >= 0){
				Rgn = CreateRectRgn(startx, i, j, i + 1);
				CombineRgn(ResRgn, ResRgn, Rgn, RGN_OR);
				startx = -1;
			}
		}
	}

	SetWindowRgn(hWnd, ResRgn, true);
	InvalidateRect(hWnd, 0, false);

	delete pBits;

	return 0;
}
コード例 #15
0
//截屏函数
void CopyScreenToBitmap()
{
	int right=GetSystemMetrics(SM_CXSCREEN),left=0,top=0,bottom=GetSystemMetrics(SM_CYSCREEN);//定义截屏范围此处设为全屏

	int nWidth, nHeight;

	HDC hSrcDC = NULL, hMemDC = NULL;
	HBITMAP hBitmap = NULL, hOldBitmap = NULL;

	hSrcDC = CreateDC(L"DISPLAY", NULL, NULL, NULL);
	hMemDC = CreateCompatibleDC(hSrcDC);

	nWidth = right - left;
	nHeight = bottom - top;

	hBitmap = CreateCompatibleBitmap(hSrcDC, nWidth, nHeight);
	hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);

	BitBlt(hMemDC, 0, 0, nWidth, nHeight, hSrcDC, left, top , SRCCOPY);
	hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap);

	BITMAP bmp;
	int nChannels,depth;
	BYTE *pBuffer;

	GetObject(hBitmap,sizeof(BITMAP),&bmp);

	image_nchannels = bmp.bmBitsPixel == 1 ? 1 : bmp.bmBitsPixel/8 ;
	image_depth = bmp.bmBitsPixel == 1 ? IPL_DEPTH_1U : IPL_DEPTH_8U;
	image_width=bmp.bmWidth;
	image_height=bmp.bmHeight;

	if(flag==0)
	{
		screemImage=cvCreateImage(cvSize(image_width,image_height),image_depth,image_nchannels);
		flag=1;
	}

	pBuffer = new BYTE[image_width*image_height*image_nchannels];
	GetBitmapBits(hBitmap,image_height*image_width*image_nchannels,pBuffer);
	memcpy(screemImage->imageData,pBuffer,image_height*image_width*image_nchannels);

	delete pBuffer;

	SelectObject(hMemDC,hOldBitmap);
	DeleteObject(hOldBitmap);
	DeleteDC(hMemDC);

	SelectObject(hSrcDC,hBitmap);
	DeleteObject(hBitmap);
	DeleteDC(hSrcDC);
	
}
コード例 #16
0
ファイル: XYTexture.cpp プロジェクト: Mhandxy/Raytracing
XYTexture::XYTexture(LPWSTR lpFileName)
{
    hbitmap=(HBITMAP)LoadImage(0,lpFileName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
    BITMAP bitmap;
    GetObject(hbitmap,sizeof(BITMAP),&bitmap);
    bheight=bitmap.bmHeight;
    bwidth=bitmap.bmWidth;
    bit=bitmap.bmBitsPixel/8;
    DWORD dwSize=bitmap.bmHeight*bitmap.bmWidthBytes;
    pBits=new BYTE[dwSize];
    GetBitmapBits(hbitmap,dwSize,pBits);
    DeleteObject(hbitmap);
}
コード例 #17
0
ファイル: gfx.cpp プロジェクト: Seldom/miranda-ng
void Gfx::deSaturate(HBITMAP hBitmap, bool fReduceContrast)
{
	BITMAP 	bmp;
	DWORD 	dwLen;
	BYTE	bMin = 255, bMax = 0, bRamp = 0, bMaxAdjust, bMinAdjust;

	int 	x, y;

	GetObject(hBitmap, sizeof(bmp), &bmp);

	if (bmp.bmBitsPixel != 32)
		return;

	dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
	if (dwLen > m_sAllocated) {
		m_p = (BYTE *)realloc(m_p, dwLen);
		m_sAllocated = dwLen;
	}
	memset(m_p, 0, dwLen);

	GetBitmapBits(hBitmap, dwLen, m_p);

	if(fReduceContrast) {
		for (y = 0; y < bmp.bmHeight; ++y) {
			BYTE *px = m_p + bmp.bmWidth * 4 * y;

			for (x = 0; x < bmp.bmWidth; ++x) {
				BYTE avg = (px[0] + px[1] + px[2]) / 3;
				bMin = min(avg, bMin);
				bMax = max(avg, bMax);
				px += 4;
			}
		}
		bRamp = (bMax + bMin) / 2;
		bMaxAdjust = (bMax - bRamp) / 2;
		bMinAdjust = (bRamp - bMin) / 2;
	}
	for (y = 0; y < bmp.bmHeight; ++y) {
		BYTE *px = m_p + bmp.bmWidth * 4 * y;

		for (x = 0; x < bmp.bmWidth; ++x) {
			BYTE avg = (px[0] + px[1] + px[2]) / 3;
			//if(fReduceContrast)
			//	avg = (avg < bRamp ? avg + bMinAdjust : avg - bMaxAdjust);
			px[0] = px[1] = px[2] = avg;
			px += 4;
		}
	}
	SetBitmapBits(hBitmap, bmp.bmWidth * bmp.bmHeight * 4, m_p);
}
コード例 #18
0
ファイル: OBSApi.cpp プロジェクト: Demiguise/OBS
static LPBYTE GetBitmapData(HBITMAP hBmp, BITMAP &bmp)
{
    if (!hBmp)
        return NULL;

    if (GetObject(hBmp, sizeof(bmp), &bmp) != 0) {
        UINT bitmapDataSize = bmp.bmHeight*bmp.bmWidth*bmp.bmBitsPixel;
        bitmapDataSize >>= 3;

        LPBYTE lpBitmapData = (LPBYTE)Allocate(bitmapDataSize);
        GetBitmapBits(hBmp, bitmapDataSize, lpBitmapData);

        return lpBitmapData;
    }
コード例 #19
0
ファイル: image_utils.cpp プロジェクト: tweimer/miranda-ng
HBITMAP CopyBitmapTo32(HBITMAP hBitmap)
{
	BITMAP bmp;
	GetObject(hBitmap, sizeof(bmp), &bmp);

	DWORD dwLen = bmp.bmWidth * bmp.bmHeight * 4;
	BYTE *p = (BYTE *)malloc(dwLen);
	if (p == nullptr)
		return nullptr;

	// Create bitmap
	BITMAPINFO RGB32BitsBITMAPINFO;
	memset(&RGB32BitsBITMAPINFO, 0, sizeof(BITMAPINFO));
	RGB32BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	RGB32BitsBITMAPINFO.bmiHeader.biWidth = bmp.bmWidth;
	RGB32BitsBITMAPINFO.bmiHeader.biHeight = bmp.bmHeight;
	RGB32BitsBITMAPINFO.bmiHeader.biPlanes = 1;
	RGB32BitsBITMAPINFO.bmiHeader.biBitCount = 32;

	BYTE *ptPixels;
	HBITMAP hDirectBitmap = CreateDIBSection(nullptr, (BITMAPINFO *)&RGB32BitsBITMAPINFO, DIB_RGB_COLORS, (void **)&ptPixels, nullptr, 0);

	// Copy data
	if (bmp.bmBitsPixel != 32) {
		HDC hdcOrig = CreateCompatibleDC(nullptr);
		HBITMAP oldOrig = (HBITMAP)SelectObject(hdcOrig, hBitmap);

		HDC hdcDest = CreateCompatibleDC(nullptr);
		HBITMAP oldDest = (HBITMAP)SelectObject(hdcDest, hDirectBitmap);

		BitBlt(hdcDest, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcOrig, 0, 0, SRCCOPY);

		SelectObject(hdcDest, oldDest);
		DeleteObject(hdcDest);
		SelectObject(hdcOrig, oldOrig);
		DeleteObject(hdcOrig);

		// Set alpha
		FreeImage_CorrectBitmap32Alpha(hDirectBitmap, FALSE);
	}
	else {
		GetBitmapBits(hBitmap, dwLen, p);
		SetBitmapBits(hDirectBitmap, dwLen, p);
	}

	free(p);

	return hDirectBitmap;
}
コード例 #20
0
ファイル: images.cpp プロジェクト: aventado/secureimplugin
// Correct alpha from bitmaps loaded without it (it cames with 0 and should be 255)
void CorrectBitmap32Alpha(HBITMAP hBitmap, BOOL force)
{
	BITMAP bmp;
	DWORD dwLen;
	BYTE *p;
	int x, y;
	BOOL fixIt;

	GetObject(hBitmap, sizeof(bmp), &bmp);

	if (bmp.bmBitsPixel != 32)
		return;

	dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
	p = (BYTE *)malloc(dwLen);
	if (p == NULL)
		return;
	memset(p, 0, dwLen);

	GetBitmapBits(hBitmap, dwLen, p);

	fixIt = TRUE;
	for (y = 0; fixIt && y < bmp.bmHeight; ++y) {
        BYTE *px = p + bmp.bmWidth * 4 * y;

        for (x = 0; fixIt && x < bmp.bmWidth; ++x) 
		{
			if (px[3] != 0 && !force) 
			{
				fixIt = FALSE;
			}
			else
			{
				if (px[0] != 0 || px[1] != 0 || px[2] != 0)
					px[3] = 255;
			}

			px += 4;
		}
	}

	if (fixIt)
		SetBitmapBits(hBitmap, dwLen, p);

	free(p);
}
コード例 #21
0
/**********************************************************************
 *		BITMAP_CopyBitmap
 *
 */
HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
{
    HBITMAP res = 0;
    BITMAP bm;

    if (!GetObjectW( hbitmap, sizeof(bm), &bm )) return 0;
    res = CreateBitmapIndirect(&bm);

    if(res) {
        char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
			       bm.bmHeight );
        GetBitmapBits (hbitmap, bm.bmWidthBytes * bm.bmHeight, buf);
	SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
	HeapFree( GetProcessHeap(), 0, buf );
    }
    return res;
}
コード例 #22
0
ファイル: test.cpp プロジェクト: my12doom/personalProjects
int matrix()
{
	int tbl[9] = {1,3,5,7,9,2,4,6,8};
	RGBQUAD *color_table[9];
	for(int i=0; i<9; i++)
	{
		color_table[i] = (RGBQUAD*)malloc(sizeof(RGBQUAD) * 1920 * 1080);

		char tmp[MAX_PATH];
		sprintf(tmp, "Z:\\1\\%d_µ÷Õû´óС.bmp", i+1);
		HBITMAP bm = (HBITMAP)LoadImageA(0, tmp, IMAGE_BITMAP, 1920, 1080, LR_LOADFROMFILE);
		GetBitmapBits(bm, 1920*1080*4, color_table[i]);
		DeleteObject(bm);
	}
	RGBQUAD *out = (RGBQUAD*)malloc(sizeof(RGBQUAD) * 1920 * 1080);
	FILE * f = fopen("Z:\\matrix.txt", "wb");
	for(int y=0; y<1080; y++)
	{
		for(int x=0; x<1920; x++)
		{
			int r = tbl[(y*4+x*3+0)%9]-1;
			int g = tbl[(y*4+x*3+1)%9]-1;
			int b = tbl[(y*4+x*3+2)%9]-1;

			RGBQUAD *o = &out[y*1920+x];
			o->rgbRed   = color_table[r][y*1920+x].rgbRed;
			o->rgbGreen = color_table[g][y*1920+x].rgbGreen;
			o->rgbBlue  = color_table[b][y*1920+x].rgbBlue;

			fprintf(f, "%d%d%d", r,g,b);
		}
		fprintf(f, "\r\n");
	}


	save_bitmap((DWORD*)out, L"Z:\\out.bmp", 1920, 1080);

	for(int i=0; i<9; i++)
		free(color_table[i]);
	free(out);


	return 0;
}
コード例 #23
0
ファイル: BitmapUtil.cpp プロジェクト: killbug2004/WSProf
std::vector<CStdStringA> BitmapUtil::GetLineCheckSum(LPCTSTR pszFileName)
{
	std::vector<CStdStringA> vLineCheckSum;
	int i(0);

	CStdString sPartialFile;
	if (_taccess(pszFileName, 6) != -1)
	{
		sPartialFile = pszFileName;
	}
	else
	{
		sPartialFile.Format(_T("%s%2.2d.bmp"), pszFileName, 0);
	}

	while (_taccess(sPartialFile.c_str(), 6) != -1)
	{
		BitmapUtil bmp;
		bmp.LoadIt(sPartialFile.c_str());

		if (bmp == NULL)
			return vLineCheckSum;
		BITMAP bmpInfo;
		if (::GetObject(bmp, sizeof(BITMAP), &bmpInfo) == 0)
			return vLineCheckSum;
		unsigned int byteSize = (bmpInfo.bmWidthBytes * bmpInfo.bmHeight);
		
		BYTE* buf = new BYTE [byteSize];
		int iBufSizeGetBitmapBits = GetBitmapBits(bmp, byteSize, buf);

		for (int j = 0; j < bmpInfo.bmHeight; ++j)
		{
			CString sMD5 = CMD5Checksum::GetMD5((BYTE*)&buf[j*bmpInfo.bmWidthBytes], bmpInfo.bmWidthBytes);
			vLineCheckSum.push_back(CStdString(sMD5));
		}

		delete [] buf;

		++i;
		sPartialFile.Format(_T("%s%2.2d.bmp"), pszFileName, i);
	}

	return vLineCheckSum;
}
コード例 #24
0
ファイル: images.cpp プロジェクト: aventado/secureimplugin
BOOL MakeGrayscale(HBITMAP *hBitmap)
{
	BYTE *p = NULL;
	BYTE *p1;
	DWORD dwLen;
    int width, height, x, y;
    BITMAP bmp;

	GetObject(*hBitmap, sizeof(bmp), &bmp);
    width = bmp.bmWidth;
	height = bmp.bmHeight;

	dwLen = width * height * 4;
	p = (BYTE *)malloc(dwLen);
    if (p == NULL) 
	{
		return FALSE;
	}

	if (bmp.bmBitsPixel != 32)
	{
		// Convert to 32 bpp
		HBITMAP hBmpTmp = CopyBitmapTo32(*hBitmap);
		DeleteObject(*hBitmap);
		*hBitmap = hBmpTmp;
	} 
	GetBitmapBits(*hBitmap, dwLen, p);

	// Make grayscale
	for (y = 0 ; y < height ; y++)
	{
		for (x = 0 ; x < width ; x++)
		{
			p1 = GET_PIXEL(p, x, y);
			p1[0] = p1[1] = p1[2] = ( p1[0] + p1[1] + p1[2] ) / 3;
		}
	}

    dwLen = SetBitmapBits(*hBitmap, dwLen, p);
    free(p);

	return TRUE;
}
コード例 #25
0
void GetRTFFor(Buffer<char> *buffer, HBITMAP hBitmap)
{
	BITMAP bmp;
	GetObject(hBitmap, sizeof(bmp), &bmp);

	DWORD dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
	BYTE *p = (BYTE *) malloc(dwLen);
	if (p == NULL)
		return;

	dwLen = GetBitmapBits(hBitmap, dwLen, p);

	buffer->appendPrintf("{\\pict\\wbitmap0\\wbmbitspixel%u\\wbmplanes%u\\wbmwidthbytes%u\\picw%u\\pich%u ", 
				bmp.bmBitsPixel, bmp.bmPlanes, bmp.bmWidthBytes, bmp.bmWidth, bmp.bmHeight);

	for (DWORD i = 0; i < dwLen; i++)
		buffer->appendPrintf("%02X", p[i]);

	buffer->append('}');


/*	
	BITMAPINFOHEADER bih = { 0 };
	HDC hdc = GetDC(NULL);
	GetDIBits(hdc, hBitmap, 0, bmp.bmHeight, p, (BITMAPINFO *) & bih, DIB_RGB_COLORS);

	buffer->appendPrintf("{\\pict\\wbitmap0\\wbmbitspixel%u\\wbmplanes%u\\wbmwidthbytes%u\\picw%u\\pich%u ", 
				bmp.bmBitsPixel, bmp.bmPlanes, bmp.bmWidthBytes, bmp.bmWidth, bmp.bmHeight);

	DWORD i;
	for (i = 0; i < sizeof(BITMAPINFOHEADER); i++)
		buffer->appendPrintf("%02X", ((PBYTE) & bih)[i]);

	for (i = 0; i < dwLen; i++)
		buffer->appendPrintf("%02X", p[i]);

	buffer->append('}');
*/

	free(p);
}
コード例 #26
0
ファイル: bitmap.c プロジェクト: mikekap/wine
/**********************************************************************
 *		BITMAP_CopyBitmap
 *
 */
HBITMAP BITMAP_CopyBitmap(HBITMAP hbitmap)
{
    HBITMAP res;
    DIBSECTION dib;
    DWORD size;

    if (!(size = GetObjectW( hbitmap, sizeof(dib), &dib ))) return 0;

    if (size == sizeof(DIBSECTION))
    {
        void *bits;
        BITMAPINFO *bi;
        HDC dc = CreateCompatibleDC( NULL );

        if (!dc) return 0;
        if (!(bi = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO, bmiColors[256] ))))
        {
            DeleteDC( dc );
            return 0;
        }
        bi->bmiHeader = dib.dsBmih;

        /* Get the color table or the color masks */
        GetDIBits( dc, hbitmap, 0, 0, NULL, bi, DIB_RGB_COLORS );

        res = CreateDIBSection( dc, bi, DIB_RGB_COLORS, &bits, NULL, 0 );
        if (res) SetDIBits( dc, res, 0, dib.dsBm.bmHeight, dib.dsBm.bmBits, bi, DIB_RGB_COLORS );
        HeapFree( GetProcessHeap(), 0, bi );
        DeleteDC( dc );
        return res;
    }

    res = CreateBitmapIndirect( &dib.dsBm );
    if(res) {
        char *buf = HeapAlloc( GetProcessHeap(), 0, dib.dsBm.bmWidthBytes * dib.dsBm.bmHeight );
        GetBitmapBits (hbitmap, dib.dsBm.bmWidthBytes * dib.dsBm.bmHeight, buf);
        SetBitmapBits (res, dib.dsBm.bmWidthBytes * dib.dsBm.bmHeight, buf);
	HeapFree( GetProcessHeap(), 0, buf );
    }
    return res;
}
コード例 #27
0
ファイル: image_utils.cpp プロジェクト: tweimer/miranda-ng
DWORD GetImgHash(HBITMAP hBitmap)
{
	BITMAP bmp;
	GetObject(hBitmap, sizeof(bmp), &bmp);

	DWORD dwLen = bmp.bmWidth * bmp.bmHeight * (bmp.bmBitsPixel / 8);
	WORD *p = (WORD *)malloc(dwLen);
	if (p == nullptr)
		return 0;
	memset(p, 0, dwLen);

	GetBitmapBits(hBitmap, dwLen, p);

	DWORD ret = 0;
	for (DWORD i = 0; i < dwLen / 2; i++)
		ret += p[i];

	free(p);

	return ret;
}
コード例 #28
0
ファイル: WindowBitmap.cpp プロジェクト: wuyao721/gopuls
WindowBitmap::WindowBitmap(HWND hWnd, bool directx):
   _hWnd(hWnd),
   m_bits(NULL)
{
   HDC hdcWindow = GetWindowDC(hWnd);
   HDC hdcBuffer = CreateCompatibleDC(hdcWindow);

   RECT windowRect;
   int windowWidth, windowHeight;

   GetWindowRect(hWnd, &windowRect);
   windowWidth = windowRect.right - windowRect.left;
   windowHeight = windowRect.bottom - windowRect.top;

   _hBitmap = CreateCompatibleBitmap(hdcWindow, windowWidth, windowHeight);
   HBITMAP hBitTemp = (HBITMAP) SelectObject(hdcBuffer, _hBitmap);

   if(directx){
      BitBlt(hdcBuffer, 0, 0, windowWidth, windowHeight, hdcWindow, 0, 0, SRCCOPY);
   }else{
      PrintWindow(hWnd, hdcBuffer, 0);  
   }

   _hBitmap = (HBITMAP) SelectObject(hdcBuffer, hBitTemp);
   //WindowBitmap::saveHBitmap2File(_hBitmap, "my.bmp");

   GetObject( _hBitmap, sizeof(BITMAP), &m_bmp);
   
   LONG bytes = m_bmp.bmWidthBytes * m_bmp.bmHeight;
   m_bits = new BYTE[bytes];

   GetBitmapBits( _hBitmap, bytes, m_bits );

   //WindowBitmap::saveHBitmap2File(_hBitmap, "my.bmp");

   DeleteObject(hBitTemp);
   DeleteDC(hdcBuffer);
   ReleaseDC(hWnd, hdcWindow);
}
コード例 #29
0
ファイル: main.cpp プロジェクト: Seldom/miranda-ng
/*
* needed for per pixel transparent images. Such images should then be rendered by
* using AlphaBlend() with AC_SRC_ALPHA
* dwFlags will be set to AVS_PREMULTIPLIED
* return TRUE if the image has at least one pixel with transparency
*/
static BOOL FreeImage_PreMultiply(HBITMAP hBitmap)
{
	BOOL transp = FALSE;

	BITMAP bmp;
	GetObject(hBitmap, sizeof(bmp), &bmp);
	if (bmp.bmBitsPixel == 32) {
		int width = bmp.bmWidth;
		int height = bmp.bmHeight;
		int dwLen = width * height * 4;
		BYTE *p = (BYTE *)malloc(dwLen);
		if (p != NULL) {
			GetBitmapBits(hBitmap, dwLen, p);

			for (int y = 0; y < height; ++y) {
				BYTE *px = p + width * 4 * y;
				for (int x = 0; x < width; ++x) {
					BYTE alpha = px[3];
					if (alpha < 255) {
						transp = TRUE;

						px[0] = px[0] * alpha/255;
						px[1] = px[1] * alpha/255;
						px[2] = px[2] * alpha/255;
					}

					px += 4;
				}
			}

			if (transp)
				dwLen = SetBitmapBits(hBitmap, dwLen, p);
			free(p);
		}
	}

	return transp;
}
コード例 #30
0
ファイル: BitmapUtil.cpp プロジェクト: killbug2004/WSProf
std::string BitmapUtil::CheckSum(HBITMAP hBitmap)
{
	if (hBitmap == NULL)
		return "";
	BITMAP bmpInfo;
	if (::GetObject(hBitmap, sizeof(BITMAP), &bmpInfo) == 0)
		return "";
	unsigned int byteSize = (bmpInfo.bmWidthBytes * bmpInfo.bmHeight);
	
	BYTE* buf = new BYTE [byteSize];
	try
	{
		GetBitmapBits(hBitmap, byteSize, buf);
		CStringA sMD5 = CMD5Checksum::GetMD5((BYTE*)buf, byteSize);
		delete [] buf;
		return sMD5.GetString();
	}
	catch(...)
	{
		delete [] buf;
		throw;
	}
}