Example #1
0
void CBC_TwoDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap,
                                          int32_t& e) {
  if (m_bFixedSize) {
    pOutBitmap = CreateDIBitmap(m_Width, m_Height);
  } else {
    pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight());
  }
  if (!pOutBitmap) {
    e = BCExceptionFailToCreateBitmap;
    return;
  }
  pOutBitmap->Clear(m_backgroundColor);
  int32_t leftPos = 0;
  int32_t topPos = 0;
  if (m_bFixedSize) {
    leftPos = (m_Width - m_output->GetWidth()) / 2;
    topPos = (m_Height - m_output->GetHeight()) / 2;
  }
  for (int32_t x = 0; x < m_output->GetWidth(); x++) {
    for (int32_t y = 0; y < m_output->GetHeight(); y++) {
      if (m_output->Get(x, y)) {
        pOutBitmap->SetPixel(leftPos + x, topPos + y, m_barColor);
      }
    }
  }
  if (!m_bFixedSize) {
    CFX_DIBitmap* pStretchBitmap = pOutBitmap->StretchTo(m_Width, m_Height);
    delete pOutBitmap;
    pOutBitmap = pStretchBitmap;
  }
}
Example #2
0
HICON
image_make_icon_handle( Handle img, Point size, Point * hotSpot)
{
   PIcon i = ( PIcon) img;
   HICON    r;
   ICONINFO ii;
   int    bpp = i-> type & imBPP;
   Bool  noSZ   = i-> w != size. x || i-> h != size. y;
   Bool  noBPP  = bpp != 1 && bpp != 4 && bpp != 8 && bpp != 24;
   HDC dc;
   XBITMAPINFO bi;
   Bool notAnIcon = !kind_of( img, CIcon);

   ii. fIcon = hotSpot ? false : true;
   ii. xHotspot = hotSpot ? hotSpot-> x : 0;
   ii. yHotspot = hotSpot ? hotSpot-> y : 0;

   if ( noSZ || noBPP) {
      i = ( PIcon)( i-> self-> dup( img));

      if ( noSZ)
         i-> self-> set_size(( Handle) i, size);
      if ( noBPP)
         i-> self-> set_type(( Handle) i,
             ( bpp < 4) ? 1 :
             (( bpp < 8) ? 4 :
             (( bpp < 24) ? 8 : 24))
      );
   }

   if (!( dc = dc_alloc())) {
      if (( Handle) i != img) Object_destroy(( Handle) i);
      return NULL;
   }
   image_get_binfo(( Handle)i, &bi);
   if ( bi. bmiHeader. biClrUsed > 0)
      bi. bmiHeader. biClrUsed = bi. bmiHeader. biClrImportant = i-> palSize;

   if ( !( ii. hbmColor = CreateDIBitmap( dc, &bi. bmiHeader, CBM_INIT,
       i-> data, ( BITMAPINFO*) &bi, DIB_RGB_COLORS))) apiErr;
   bi. bmiHeader. biBitCount = bi. bmiHeader. biPlanes = 1;
   bi. bmiColors[ 0]. rgbRed = bi. bmiColors[ 0]. rgbGreen = bi. bmiColors[ 0]. rgbBlue = 0;
   bi. bmiColors[ 1]. rgbRed = bi. bmiColors[ 1]. rgbGreen = bi. bmiColors[ 1]. rgbBlue = 255;

   if ( !( ii. hbmMask  = CreateDIBitmap( dc, &bi. bmiHeader, CBM_INIT,
      notAnIcon ? NULL : i-> mask, ( BITMAPINFO*) &bi, DIB_RGB_COLORS))) apiErr;
   
   dc_free();

   if ( !( r = CreateIconIndirect( &ii))) apiErr;

   DeleteObject( ii. hbmColor);
   DeleteObject( ii. hbmMask);
   if (( Handle) i != img) Object_destroy(( Handle) i);
   return r;
}
Example #3
0
HBITMAP LoadResourceBitmap(HINSTANCE hInstance, LPCTSTR lpString, HPALETTE& rhPalette)
{
  // Pre initialize in case of error
  rhPalette = NULL;

  HRSRC hRsrc = FindResource(hInstance, lpString, RT_BITMAP);
  if (hRsrc == NULL)
    return NULL;
  HGLOBAL hGlobal = LoadResource(hInstance, hRsrc);
  if (hGlobal == NULL)
    return NULL;
  LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)LockResource(hGlobal);
  if (lpbi == NULL)
    return NULL;

  HDC hdc = GetDC(NULL);
  int iNumColors;
  rhPalette =  CreateDIBPalette ((LPBITMAPINFO)lpbi, iNumColors);
  if (rhPalette) {
    SelectPalette(hdc, rhPalette, FALSE);
    RealizePalette(hdc);
  }
  HBITMAP hBitmapFinal = CreateDIBitmap(hdc,
                                        (LPBITMAPINFOHEADER)lpbi,
                                        (LONG)CBM_INIT,
                                        (LPSTR)lpbi + lpbi->biSize + iNumColors * sizeof(RGBQUAD), 
                                        (LPBITMAPINFO)lpbi,
                                        DIB_RGB_COLORS );
  ReleaseDC(NULL,hdc);
  
  return (hBitmapFinal);
} 
Example #4
0
void CBC_OneDimWriter::RenderBitmapResult(CFX_DIBitmap*& pOutBitmap,
                                          const CFX_WideStringC& contents,
                                          int32_t& e) {
  if (!m_output)
    BC_EXCEPTION_CHECK_ReturnVoid(e);

  pOutBitmap = CreateDIBitmap(m_output->GetWidth(), m_output->GetHeight());
  pOutBitmap->Clear(m_backgroundColor);
  if (!pOutBitmap) {
    e = BCExceptionFailToCreateBitmap;
    return;
  }
  for (int32_t x = 0; x < m_output->GetWidth(); x++) {
    for (int32_t y = 0; y < m_output->GetHeight(); y++) {
      if (m_output->Get(x, y)) {
        pOutBitmap->SetPixel(x, y, m_barColor);
      }
    }
  }
  int32_t i = 0;
  for (; i < contents.GetLength(); i++)
    if (contents.GetAt(i) != ' ') {
      break;
    }
  if (m_locTextLoc != BC_TEXT_LOC_NONE && i < contents.GetLength()) {
    ShowChars(contents, pOutBitmap, nullptr, nullptr, m_barWidth, m_multiple,
              e);
    BC_EXCEPTION_CHECK_ReturnVoid(e);
  }
  CFX_DIBitmap* pStretchBitmap = pOutBitmap->StretchTo(m_Width, m_Height);
  delete pOutBitmap;
  pOutBitmap = pStretchBitmap;
}
Example #5
0
extern "C" AFX_EXT_API   HBITMAP  GetToolbarBitmap(LPWORD wC)
{
	HBITMAP hBitmap = NULL;
	/*if ( NULL == hInst )
		hInst = ::AfxFindResourceHandle( IDB_TOOLBAR32_BMP, RT_BITMAP);*/
	HRSRC hRsrc = ::FindResource(Standard2DDLL.hResource, 
		MAKEINTRESOURCE(IDB_TOOLBAR32_BMP), RT_BITMAP);
	if ( hRsrc ){
		HGLOBAL hglb = LoadResource(Standard2DDLL.hResource, hRsrc);
		if ( hglb ){
			// „итаем заголовок
			LPBITMAPINFO pbi = (LPBITMAPINFO)LockResource(hglb);
			if (pbi ) {
				/*if ( lpnWidth )
					*lpnWidth = pbi->bmiHeader.biWidth;
				if ( lpnHeight )
					*lpnHeight = pbi->bmiHeader.biHeight;*/
				if ( wC )
					*wC = pbi->bmiHeader.biBitCount;
				// „итаем данные
				HDC hdc = GetDC( NULL );
				//hBitmap = CreateDIBitmap( hdc, &pbi->bmiHeader, CBM_INIT, pbi->bmiColors, pbi, DIB_RGB_COLORS);
				//				BYTE* pData = (BYTE*)pbi + sizeof(BITMAPINFO) + pbi->bmiHeader.biClrUsed * sizeof(COLORREF);
				BYTE* pData = (BYTE*)pbi + sizeof(BITMAPINFOHEADER) + pbi->bmiHeader.biClrUsed * sizeof(COLORREF);
				hBitmap = CreateDIBitmap( hdc, &pbi->bmiHeader, CBM_INIT, (void*)pData, pbi, DIB_RGB_COLORS);
				// hBitmap = CreateDIBSection( hdc, pbi, DIB_RGB_COLORS, (LPVOID*)&pbi->bmiColors, NULL, NULL );
				::ReleaseDC	(NULL, hdc);
			}
			FreeResource( hglb );
		}	
	}
	return hBitmap;
}
Example #6
0
HBITMAP MyCreateBitmap(
    HDC hdc,
    INT cx,
    INT cy,
    INT nColors)
{
    BITMAPINFOHEADER bmih;

    if (nColors == 2) {
        return CreateBitmap(cx, cy, 1, 1, NULL);
    }
    else {
        bmih.biSize = sizeof(BITMAPINFOHEADER);
        bmih.biWidth = cx;
        bmih.biHeight = cy;
        bmih.biPlanes = 1;              // 1 plane, 4 bpp is
        bmih.biBitCount = 4;            // 16 colors.

        bmih.biCompression =
        bmih.biSizeImage =
        bmih.biXPelsPerMeter =
        bmih.biYPelsPerMeter =
        bmih.biClrUsed =
        bmih.biClrImportant = 0;

        return CreateDIBitmap(hdc, &bmih, 0L, NULL, NULL, 0);
    }
}
Example #7
0
FARINTERNAL_(HBITMAP) UtConvertDibToBitmap(HANDLE hDib)
{
	VDATEHEAP();

	LPBITMAPINFOHEADER lpbmih;
	HDC hdc; // the device context to create the bitmap for
	size_t uBitsOffset; // the offset to where the image begins in the DIB
	HBITMAP hBitmap; // the bitmap we'll return
	
	if (!(lpbmih = (LPBITMAPINFOHEADER)GlobalLock(hDib)))
		return(NULL);

	if (!(hdc = GetDC(NULL))) // Get screen DC.
	{
		// REVIEW: we may have to use the target device of this
		// cache node.
		return(NULL);
	}

	uBitsOffset =  sizeof(BITMAPINFOHEADER) +
			(lpbmih->biClrUsed ? lpbmih->biClrUsed :
			UtPaletteSize(lpbmih));
					
	hBitmap = CreateDIBitmap(hdc, lpbmih, CBM_INIT,
			((BYTE *)lpbmih)+uBitsOffset,
			(LPBITMAPINFO) lpbmih, DIB_RGB_COLORS);

	// release the DC
	ReleaseDC(NULL, hdc);

	return hBitmap;
}
Example #8
0
HBITMAP CScreenSnap::ChangeDataToBitmap(BYTE* pData)
{
	BITMAPFILEHEADER* pbmfh ;     // DIB位图文件头
	HBITMAP           hBitmap ;
	
	pbmfh = (BITMAPFILEHEADER *)pData;
	if (pbmfh->bfType != * (WORD *) "BM") 
		return NULL ;
	
	HDC hdc = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
	if(hdc == NULL)
		return NULL;

	// 创建DDB位图
	hBitmap = CreateDIBitmap(hdc,              
							(BITMAPINFOHEADER *) (pbmfh + 1),
							CBM_INIT,
							(BYTE *) pbmfh + pbmfh->bfOffBits,
							(BITMAPINFO *) (pbmfh + 1),
							DIB_RGB_COLORS) ;

	DeleteDC(hdc);

	return hBitmap ;
}
Example #9
0
// Umformen einer DIB in eine DDB 
HBITMAP CBildObjekt :: DIBToBitmap (void) 
{
BITMAPINFOHEADER *lpBI;
HPALETTE hPalT;
HDC hDC;
HBITMAP hBM;

	if (!m_hDIB) return NULL;

// Bitmapheader 
	lpBI = (BITMAPINFOHEADER *)GlobalLock (m_hDIB);
	if (!lpBI) return NULL;

// Palette realisieren 
	hDC = :: GetDC (NULL);
	if (m_hPal) {
		hPalT = SelectPalette (hDC, m_hPal, false);
		RealizePalette (hDC);
	}

// device dependent bitmap (DDB) erzeugen 
	hBM = CreateDIBitmap (hDC, lpBI, (long)CBM_INIT,
			(char *)lpBI + lpBI->biSize + 
			DIBNumColors(lpBI)*sizeof(RGBQUAD), //  PaletteSize (lpBI),
			(BITMAPINFO *)lpBI, DIB_RGB_COLORS);

// alte Palette wiedereinstellen
	if (m_hPal)
		SelectPalette (hDC, hPalT, false);

	ReleaseDC (NULL, hDC);
	GlobalUnlock (m_hDIB);

return hBM;
}
Example #10
0
KHMEXP khui_ilist * KHMAPI
khui_create_ilist(int cx, int cy, int n, int ng, int opt) {
    BITMAPV5HEADER head;
    HDC hdc;

    khui_ilist * il = PMALLOC(sizeof(khui_ilist));
    il->cx = cx;
    il->cy = cy;
    il->n = n;
    il->ng = ng;
    il->nused = 0;
    hdc = GetDC(NULL);
    head.bV5Size = sizeof(head);
    head.bV5Width = cx * n;
    head.bV5Height = cy;
    head.bV5Planes = 1;
    head.bV5BitCount = 24;
    head.bV5Compression = BI_RGB;
    head.bV5SizeImage = 0;
    head.bV5XPelsPerMeter = 2835;
    head.bV5YPelsPerMeter = 2835;
    head.bV5ClrUsed = 0;
    head.bV5ClrImportant = 0;
    head.bV5AlphaMask = 0;
    head.bV5CSType = LCS_WINDOWS_COLOR_SPACE;
    head.bV5Intent = LCS_GM_GRAPHICS;
    head.bV5ProfileData = 0;
    head.bV5ProfileSize = 0;
    head.bV5Reserved = 0;
    il->img = CreateDIBitmap(hdc, (BITMAPINFOHEADER *) &head, 0, NULL, NULL, DIB_RGB_COLORS);
    il->mask = CreateBitmap(cx * n, cy, 1, 1, NULL);
    il->idlist = PMALLOC(sizeof(int) * n);

    return il;
}
Example #11
0
HBITMAP CImageFile::LoadFromMemory(LPCVOID pBuffer, DWORD nLength, HDC hUseDC)
{
	LPSTR				hDIB;
	LPVOID				lpDIBBits;
	BITMAPFILEHEADER	bmfHeader;
	DWORD				bmfHeaderLen;

	bmfHeaderLen = sizeof(bmfHeader);
	strncpy( (LPSTR)&bmfHeader, (LPSTR)pBuffer, bmfHeaderLen );
	if ( bmfHeader.bfType != ((WORD) ('M' << 8) | 'B') ) return NULL;

	hDIB = (LPSTR)pBuffer + bmfHeaderLen;
	BITMAPINFOHEADER &bmiHeader = *(LPBITMAPINFOHEADER)hDIB ;
	BITMAPINFO &bmInfo = *(LPBITMAPINFO)hDIB ;
	int nColors = bmiHeader.biClrUsed ? bmiHeader.biClrUsed : 1 << bmiHeader.biBitCount; 
	if ( bmInfo.bmiHeader.biBitCount > 8 )
		lpDIBBits = (LPVOID)((LPDWORD)(bmInfo.bmiColors + bmInfo.bmiHeader.biClrUsed) + 
		((bmInfo.bmiHeader.biCompression == BI_BITFIELDS) ? 3 : 0));
	else
		lpDIBBits = (LPVOID)(bmInfo.bmiColors + nColors);

	HDC hDC = hUseDC ? hUseDC : GetDC( 0 );

	return CreateDIBitmap( hDC, &bmiHeader, CBM_INIT, lpDIBBits, &bmInfo, DIB_RGB_COLORS );
}
Example #12
0
// ---------------------------------------------------------------------------
//
HBITMAP __fastcall TForm1::SPI_LoadImage(String fileName) {
	/* 対応プラグインの検索 */
	for (int i = 0; i < hSPI->Count; i++) { // プラグイン関数の取得
		SPI_ISSUPPORTED spi_issupported = (SPI_ISSUPPORTED) GetProcAddress((HMODULE) hSPI->Items[i], SPIPROC_ISSUPPORTED);
		SPI_GETPICTURE spi_getpicture = (SPI_GETPICTURE) GetProcAddress((HMODULE) hSPI->Items[i], SPIPROC_GETPICTURE);

		if (spi_issupported == NULL || spi_getpicture == NULL) {
			continue;
		}

		// File内容をロードする
		HANDLE handle; // = NULL;

		if ((handle = CreateFile_Read(fileName.w_str())) == INVALID_HANDLE_VALUE) {
			return NULL;
		}

		DWORD filesize = GetFileSize(handle, NULL), readsize;
		LPSTR data = (LPSTR) Heap_Malloc(filesize);
		SetFilePointer(handle, 0, NULL, FILE_BEGIN);

		if (!ReadFile(handle, data, filesize, &readsize, NULL)) {
			CloseHandle(handle);
		}

		CloseHandle(handle);

		// ロードできる形式かどうかをチェックする
		if (spi_issupported(AnsiString(fileName).c_str(), (DWORD) data) == 0) {
			Heap_Free(data);
			continue;
		}

		// 画像を展開する
		HLOCAL info, bm;
		if (spi_getpicture(data, filesize, 1, &info, &bm, NULL, 0) != 0) {
			Heap_Free(data);
		}

		LPBITMAPINFO bmpinfo = (LPBITMAPINFO) LocalLock(info); // BITMAPINFO構造体
		LPBYTE bmbits = (LPBYTE) LocalLock(bm); // 画像データ

		// 取得した情報からBITMAPハンドルを生成する
		HDC dc = GetDC(0);
		HBITMAP bitmap = CreateDIBitmap(dc, &bmpinfo->bmiHeader, CBM_INIT, bmbits, bmpinfo, DIB_RGB_COLORS);
		ReleaseDC(0, dc);

		// Free etc...
		LocalUnlock(info);
		LocalFree(info);
		LocalUnlock(bm);
		LocalFree(bm);
		Heap_Free(data);

		return bitmap;
	}

	return NULL;
}
Example #13
0
STATICFN HBITMAP LoadAlterBitmap(
    INT idbm,
    DWORD rgbNew,
    DWORD rgbNew2)
{
    register INT i;
    LPBITMAPINFOHEADER lpbihInfo;
    HDC hdcScreen;
    HANDLE hresLoad;
    DWORD FAR *qlng;
    LPBYTE lpbBits;
    HANDLE hbmp;
    DWORD rgbReplace1;
    DWORD rgbReplace2;

    hresLoad = FindResource(ghInst, MAKEINTRESOURCE(idbm), RT_BITMAP);
    if (!hresLoad)
        return NULL;

    lpbihInfo = (LPBITMAPINFOHEADER)CloneResource(ghInst, hresLoad);
    if (lpbihInfo == NULL)
        return NULL;

    rgbNew = RGBInvertRGB(rgbNew);
    rgbNew2 = RGBInvertRGB(rgbNew2);
    rgbReplace1 = RGBInvertRGB(REPLACECOLOR1);
    rgbReplace2 = RGBInvertRGB(REPLACECOLOR2);
    qlng = (LPDWORD)((PBYTE)(lpbihInfo) + lpbihInfo->biSize);

    for (i = 0; i < (1 << lpbihInfo->biBitCount); i++, qlng++) {
        if (*qlng == rgbReplace1)
            *qlng = rgbNew;
        else if (*qlng == rgbReplace2)
            *qlng = rgbNew2;
    }

    /*
     * First skip over the header structure.
     */
    lpbBits = (LPBYTE)(lpbihInfo + 1);

    /*
     * Skip the color table entries, if any.
     */
    lpbBits += (1 << (lpbihInfo->biBitCount)) * sizeof(RGBQUAD);

    /*
     * Create a color bitmap compatible with the display device.
     */
    if (hdcScreen = GetDC(NULL)) {
        hbmp = CreateDIBitmap(hdcScreen, lpbihInfo, (LONG)CBM_INIT,
                lpbBits, (LPBITMAPINFO)lpbihInfo, DIB_RGB_COLORS);
        ReleaseDC(NULL, hdcScreen);
    }

    LocalFree(lpbihInfo);

    return hbmp;
}
Example #14
0
HICON Win32Window::CreateIconFromTexture(ptr<Graphics::RawTextureData> texture, BOOL isIcon, int hotX, int hotY)
{
	int width = texture->GetImageWidth();
	int height = texture->GetImageHeight();
	int pitch = (width * 3 + 3) & ~3;
	BITMAPV5HEADER h;
	ZeroMemory(&h, sizeof(h));
	h.bV5Size = sizeof(h);
	h.bV5Width = width;
	h.bV5Height = height;
	h.bV5Planes = 1;
	h.bV5BitCount = 32;
	h.bV5Compression = BI_BITFIELDS;
	h.bV5RedMask = 0x00FF0000;
	h.bV5GreenMask = 0x0000FF00;
	h.bV5BlueMask = 0x000000FF;
	h.bV5AlphaMask = 0xFF000000;
	const uint8_t* pixels = (const uint8_t*)texture->GetMipData();
	uint8_t* buf = new uint8_t[width * 4 * height];
	for(int i = 0; i < height; ++i)
	{
		const uint8_t* linePixels = pixels + i * width * 4;
		uint8_t* lineBuf = buf + (height - 1 - i) * width * 4;
		for(int j = 0; j < width; ++j)
		{
			lineBuf[j * 4 + 0] = linePixels[j * 4 + 2];
			lineBuf[j * 4 + 1] = linePixels[j * 4 + 1];
			lineBuf[j * 4 + 2] = linePixels[j * 4 + 0];
			lineBuf[j * 4 + 3] = linePixels[j * 4 + 3];
		}
	}

	HDC hdc = GetDC(NULL);
	HBITMAP hbmpColor = CreateDIBitmap(hdc, (BITMAPINFOHEADER*)&h, CBM_INIT, buf, (BITMAPINFO*)&h, DIB_RGB_COLORS);
	HBITMAP hbmpMask = CreateBitmap(width, height, 1, 1, NULL);
	ReleaseDC(NULL, hdc);

	delete [] buf;

	if(!hbmpColor || !hbmpMask)
	{
		if(hbmpColor) DeleteBitmap(hbmpColor);
		if(hbmpMask) DeleteBitmap(hbmpMask);
		THROW("Can't create bitmaps");
	}

	ICONINFO ii;
	ii.fIcon = isIcon;
	ii.xHotspot = hotX;
	ii.yHotspot = hotY;
	ii.hbmMask = hbmpMask;
	ii.hbmColor = hbmpColor;
	HICON icon = CreateIconIndirect(&ii);

	DeleteBitmap(hbmpColor);
	DeleteBitmap(hbmpMask);

	return icon;
}
Example #15
0
HBITMAP CreateBitmapObjectFromDibFile (HDC hdc, PTSTR szFileName)
{
     BITMAPFILEHEADER * pbmfh ;
     BOOL               bSuccess ;
     DWORD              dwFileSize, dwHighSize, dwBytesRead ;
     HANDLE             hFile ;
     HBITMAP            hBitmap ;

          // Open the file: read access, prohibit write access

     hFile = CreateFile (szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, 
                         OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL) ;

     if (hFile == INVALID_HANDLE_VALUE)
          return NULL ;

          // Read in the whole file

     dwFileSize = GetFileSize (hFile, &dwHighSize) ;

     if (dwHighSize)
     {
          CloseHandle (hFile) ;
          return NULL ;
     }

     pbmfh = malloc (dwFileSize) ;

     if (!pbmfh)
     {
          CloseHandle (hFile) ;
          return NULL ;
     }

     bSuccess = ReadFile (hFile, pbmfh, dwFileSize, &dwBytesRead, NULL) ;
     CloseHandle (hFile) ;

          // Verify the file

     if (!bSuccess || (dwBytesRead != dwFileSize)         
                   || (pbmfh->bfType != * (WORD *) "BM") 
                   || (pbmfh->bfSize != dwFileSize))
     {
          free (pbmfh) ;
          return NULL ;
     }

          // Create the DDB 

     hBitmap = CreateDIBitmap (hdc,              
                               (BITMAPINFOHEADER *) (pbmfh + 1),
                               CBM_INIT,
                               (BYTE *) pbmfh + pbmfh->bfOffBits,
                               (BITMAPINFO *) (pbmfh + 1),
                               DIB_RGB_COLORS) ;
     free (pbmfh) ;

     return hBitmap ;
}
HBITMAP	CFX_WindowsDIB::GetDDBitmap(const CFX_DIBitmap* pBitmap, HDC hDC)
{
    CFX_ByteString info = GetBitmapInfo(pBitmap);
    HBITMAP hBitmap = NULL;
    hBitmap = CreateDIBitmap(hDC, (BITMAPINFOHEADER*)info.c_str(), CBM_INIT,
        pBitmap->GetBuffer(), (BITMAPINFO*)info.c_str(), DIB_RGB_COLORS);
    return hBitmap;
}
Example #17
0
File: cdib.cpp Project: 0anion0/IBN
HBITMAP CDib::GetHBITMAP(HDC hdc)
{
    if(m_valid)
        return  CreateDIBitmap(hdc,m_pBitmapInfoHeader,
                               CBM_INIT,(VOID *)m_pData,m_pBitmapInfo, DIB_RGB_COLORS);
    else
        return NULL;
}
Example #18
0
DWORD
lsd_display_stretchdibits(WORD msg, HDC32 hDC32, DWORD dwParam,
			LPLSDS_PARAMS lpStruct)
{
    LSDE_STRETCHDATA *lpsd = &lpStruct->lsde.stretchdata;
    HBITMAP hDIB,hBMPOld;
    HDC hCompatDC;
    HDC32 hCompatDC32;
    BOOL bRet;
    LPLOGPALETTE lp;
    HPALETTE     hpal,hpalold = 0;

    if (!lpsd || !lpsd->lpbmi)
	return 0;

    if (!(hCompatDC = CreateCompatibleDC(GETHDC16(hDC32))))
	return 0;

    hpal = hDC32->hPalette;
    lp   = WinMalloc(sizeof(LOGPALETTE) + sizeof(PALETTEENTRY)*356);

    GetPaletteEntries(hpal,0,256,lp->palPalEntry);
    lp->palVersion = 0x300;
    lp->palNumEntries = 256;

    hpal = CreatePalette(lp);
    WinFree(lp);

    if (hpal)
       hpalold = SelectPalette(hCompatDC,hpal,0);

    if (!(hDIB = CreateDIBitmap(hCompatDC,&lpsd->lpbmi->bmiHeader,
	    CBM_INIT,lpsd->lpvBits,lpsd->lpbmi,lpsd->fuColorUse))) {
	DeleteDC(hCompatDC);
	return 0;
    }
    hBMPOld = SelectObject(hCompatDC,hDIB);

    if (hDC32->dwInvalid & IM_BRUSHMASK)
	DisplayValidate(hDC32,lpStruct,IM_BRUSHMASK);

    hCompatDC32 = GETDCINFO(hCompatDC);
    lpsd->hSrcDC32 = (HDC32)(hCompatDC32->lpDrvData);
    RELEASEDCINFO(hCompatDC32);

    bRet = (BOOL)DRVCALL_GRAPHICS(PGH_STRETCHBLT,
		hDC32->lpDrvData,0L,lpStruct);

    if (hpal) {
       SelectPalette(hCompatDC, hpalold, 0);
       DeleteObject(hpal);
    }

    SelectObject(hCompatDC, hBMPOld);
    DeleteObject(hDIB);
    DeleteDC(hCompatDC);
    return (bRet)?lpsd->yDest:0;
}
Example #19
0
HBITMAP
image_make_bitmap_handle( Handle img, HPALETTE pal)
{
   HBITMAP bm;
   XBITMAPINFO xbi;
   BITMAPINFO * bi = image_get_binfo( img, &xbi);
   HPALETTE old = nil, xpal = pal;
   HWND foc = GetFocus();
   HDC dc = GetDC( foc);

   if ( !dc)
      apiErr;

   if ( bi-> bmiHeader. biClrUsed > 0)
      bi-> bmiHeader. biClrUsed = bi-> bmiHeader. biClrImportant = PImage(img)-> palSize;

   if ( xpal == nil)
      xpal = image_make_bitmap_palette( img);

   if ( xpal) {
      old = SelectPalette( dc, xpal, 1);
      RealizePalette( dc);        
   }

   if ((( PImage) img)-> type != imBW)
      bm = CreateDIBitmap( dc, &bi-> bmiHeader, CBM_INIT,
        (( PImage) img)-> data, bi, DIB_RGB_COLORS);
   else {
      bm = CreateBitmap( bi-> bmiHeader. biWidth, bi-> bmiHeader. biHeight, 1, 1, NULL);
      SetDIBits( dc, bm, 0, bi-> bmiHeader. biHeight, (( PImage) img)-> data, bi, DIB_RGB_COLORS);
   }

   if ( !bm) {
      apiErr;
      if ( old) {
         SelectPalette( dc, old, 1);
         RealizePalette( dc);
      }
      if ( xpal != pal)
         DeleteObject( xpal);
      ReleaseDC( foc, dc);
      return nil;
   }

   if ( old) {
      SelectPalette( dc, old, 1);
      RealizePalette( dc);
   }

   if ( xpal != pal)
      DeleteObject( xpal);

   ReleaseDC( foc, dc);

   return bm;
}
Example #20
0
static void loadImage(HWND hWnd, LPWSTR fileName)
{
	char *data;
	int size;
	data = readFile(fileName, &size);
	if (data == nullptr)
	{
		MessageBoxW(hWnd, L"Cannot read file content!", L"Critical", MB_ICONERROR | MB_OK);
		return;
	}

	int width, height;
	char *decoded = fluid_decode(data, size, &width, &height);
	free(data);
	if (decoded == nullptr)
	{
		MessageBoxW(hWnd, L"Decode image file failed.", L"Critical", MB_ICONERROR | MB_OK);
		return;
	}

	/* ARGB -> BGRA, Premultiply alpha */
	unsigned char *r = (unsigned char *) decoded;
	for (int i = 0; i < height; i++)
		for (int j = 0; j < width; j++)
		{
			unsigned char t = r[0];
			r[0] = r[2];
			r[2] = t;

			/* Premultiply (for display) */
			r[0] = r[0] * r[3] / 255 + (255 - r[3]);
			r[1] = r[1] * r[3] / 255 + (255 - r[3]);
			r[2] = r[2] * r[3] / 255 + (255 - r[3]);

			r += 4;
		}

	if (bitmap)
		DeleteObject(bitmap);
	bitmapWidth = width;
	bitmapHeight = height;

	BITMAPINFO bmi;
	bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	bmi.bmiHeader.biWidth = width;
	bmi.bmiHeader.biHeight = -height;
	bmi.bmiHeader.biPlanes = 1;
	bmi.bmiHeader.biBitCount = 32;
	bmi.bmiHeader.biCompression = BI_RGB;
	bmi.bmiHeader.biSizeImage = width * height * 4;
	HDC hdc = GetDC(hWnd);
	bitmap = CreateDIBitmap(hdc, &bmi.bmiHeader, CBM_INIT, decoded, &bmi, DIB_RGB_COLORS);
	ReleaseDC(hWnd, hdc);
	SendMessageW(hWnd, WM_PAINT, 0, 0);
	free(decoded);
}
Example #21
0
HBITMAP ReadBitmapFile( HWND hwnd, char *file_name )
{
    FILE                *fp;
    BITMAPFILEHEADER    file_header;
    BITMAPINFOHEADER    *h;             /* to avoid typeing bitmap_info->... */
    BITMAPINFO          *bitmap_info;
    DWORD               size;           /* generic size - used repeatedly */
    BYTE _HUGE          *mask_ptr;      /* pointer to bit array in memory */
    HBITMAP             bitmap_handle;
    HDC                 hdc;
    HPALETTE            new_palette, old_palette;

    bitmap_handle = (HBITMAP)0;
    fp = fopen( file_name, "rb" );
    if( fp == NULL ) return( bitmap_handle );
    fread( &file_header, sizeof( BITMAPFILEHEADER ), 1, fp );
    if( file_header.bfType != BITMAP_TYPE ) {
        fclose( fp );
        return( bitmap_handle );
    }

    bitmap_info = ReadBitmapInfo( fp );
    if( bitmap_info != NULL ) {
        h = &bitmap_info->bmiHeader;
        fseek( fp, file_header.bfOffBits, SEEK_SET );
        size = BITS_TO_BYTES( h->biWidth * h->biBitCount, h->biHeight );
#ifdef __NT__
        mask_ptr = malloc( size );
        memset( mask_ptr, 0, size );
#else
        mask_ptr = _halloc( size, 1 );
#endif
        if( mask_ptr != NULL ) {
            ReadInPieces( mask_ptr, fp, size );
            new_palette = CreateDIBPalette( bitmap_info );
            if( new_palette ) {
                hdc = GetDC( hwnd );
                old_palette = SelectPalette( hdc, new_palette, FALSE );
                RealizePalette( hdc );
                bitmap_handle = CreateDIBitmap( hdc, h, CBM_INIT,
                                    mask_ptr, bitmap_info, DIB_RGB_COLORS );
                SelectPalette( hdc, old_palette, FALSE );
                DeleteObject( new_palette );
                ReleaseDC( hwnd, hdc );
            }
#ifdef __NT__
            free( mask_ptr );
#else
            _hfree( mask_ptr );
#endif
        }
        free( bitmap_info );
    }
    fclose( fp );
    return( bitmap_handle );
} /* ReadBitmapFile */
HBITMAP			VPictureData_GDIBitmap::GetHBitmap()const
{
	if(fBitmap==NULL && fDIBInfo)
	{
		HDC refdc=GetDC(NULL);
		fBitmap=CreateDIBitmap(refdc,&fDIBInfo->bmiHeader,CBM_INIT,fDIBData,fDIBInfo,DIB_RGB_COLORS);
		ReleaseDC(NULL,refdc);
	}
	return fBitmap;
}
Example #23
0
// Loads a bitmap and returns the handle. Retrieves the color of the
// first pixel in the image and replaces that entry in the color table
// with COLOR_3DFACE
HBITMAP WINAPI
LoadTransparentBitmap(HINSTANCE hInstance, UINT nResID)
{
	// Find the resource
	HRSRC	hrsrc = FindResource(hInstance, MAKEINTRESOURCE(nResID), RT_BITMAP);

	assert(hrsrc);
	if (!hrsrc)
		return NULL;

	// Get a handle for the resource
	HGLOBAL	hglb = LoadResource(hInstance, hrsrc);
	if (!hglb)
		return NULL;

	// Get a pointer to the BITMAPINFOHEADER
	LPBITMAPINFOHEADER	lpbi = (LPBITMAPINFOHEADER)LockResource(hglb);

	// We expect a 4-bpp image only
	assert(lpbi->biBitCount == 4);
	if (lpbi->biBitCount != 4) {
		UnlockResource(hglb);
		FreeResource(hglb);
		return NULL;
	}

	// Get a pointer to the color table
	LPRGBQUAD	pColors = (LPRGBQUAD)((LPSTR)lpbi + (WORD)lpbi->biSize);

	// Look at the first pixel and get the palette index
	UINT	nClrUsed = lpbi->biClrUsed == 0 ? 16 : (UINT)lpbi->biClrUsed;
	LPBYTE	lpBits = (LPBYTE)(pColors + nClrUsed);

	// Munge the color table entry
	COLORREF	clrBtnFace = GetSysColor(COLOR_BTNFACE);
	int			nIndex = *lpBits & 0xF;

	pColors[nIndex].rgbRed = GetRValue(clrBtnFace);
	pColors[nIndex].rgbGreen = GetGValue(clrBtnFace);
	pColors[nIndex].rgbBlue = GetBValue(clrBtnFace);

	// Create the DDB
	HBITMAP		hBitmap;
	HDC			hDC = GetDC(NULL);

	hBitmap = CreateDIBitmap(hDC, lpbi, CBM_INIT, lpBits,
		(LPBITMAPINFO)lpbi, DIB_RGB_COLORS);
	ReleaseDC(NULL, hDC);

	// Release the resource
	UnlockResource(hglb);
	FreeResource(hglb);

	return hBitmap;
}
Example #24
0
extern "C" AFX_EXT_API   HBITMAP  GetObjectBitmap(const char* obID, LPWORD wC)
{
	HBITMAP hBitmap = NULL;
	HRSRC hRsrc = NULL;
	if (strcmp("{0000000000000-0000-0000-000000000001}",obID)==0)
	{
		hRsrc = ::FindResource(Standard2DDLL.hResource, 
			MAKEINTRESOURCE(IDB_PNT32), RT_BITMAP);
		goto lbl;
	}
	if (strcmp("{0000000000000-0000-0000-000000000002}",obID)==0)
	{
		hRsrc = ::FindResource(Standard2DDLL.hResource, 
			MAKEINTRESOURCE(IDB_LINE32), RT_BITMAP);
		goto lbl;	
	}
	if (strcmp("{0000000000000-0000-0000-000000000003}",obID)==0)
	{
		hRsrc = ::FindResource(Standard2DDLL.hResource, 
			MAKEINTRESOURCE(IDB_CIRC32), RT_BITMAP);
		goto lbl;	
	}
	if (strcmp("{0000000000000-0000-0000-000000000004}",obID)==0)
	{
		hRsrc = ::FindResource(Standard2DDLL.hResource, 
			MAKEINTRESOURCE(IDB_ARC32), RT_BITMAP);
		goto lbl;
	}
	if (strcmp("{0000000000000-0000-0000-000000000005}",obID)==0)
	{
		hRsrc = ::FindResource(Standard2DDLL.hResource, 
			MAKEINTRESOURCE(IDB_SPL32), RT_BITMAP);
		goto lbl;
	}
lbl:
	if ( hRsrc ){
		HGLOBAL hglb = LoadResource(Standard2DDLL.hResource, hRsrc);
		if ( hglb ){
			// „итаем заголовок
			LPBITMAPINFO pbi = (LPBITMAPINFO)LockResource(hglb);
			if (pbi ) {
				if ( wC )
					*wC = pbi->bmiHeader.biBitCount;
				// „итаем данные
				HDC hdc = GetDC( NULL );
				BYTE* pData = (BYTE*)pbi + sizeof(BITMAPINFOHEADER) + pbi->bmiHeader.biClrUsed * sizeof(COLORREF);
				hBitmap = CreateDIBitmap( hdc, &pbi->bmiHeader, CBM_INIT, (void*)pData, pbi, DIB_RGB_COLORS);
				::ReleaseDC	(NULL, hdc);
			}
			FreeResource( hglb );
		}	
	}
	return hBitmap;
}
Example #25
0
HBITMAP DIBToBitmap(HDIB hDIB, HPALETTE hPal)
{
    LPSTR       lpDIBHdr, lpDIBBits;  // pointer to DIB header, pointer to DIB bits
    HBITMAP     hBitmap;            // handle to device-dependent bitmap
    HDC         hDC;                    // handle to DC
    HPALETTE    hOldPal = NULL;    // handle to a palette

    // if invalid handle, return NULL 

    if (!hDIB)
        return NULL;

    // lock memory block and get a pointer to it

    lpDIBHdr = (LPSTR)GlobalLock(hDIB);

    // get a pointer to the DIB bits

    lpDIBBits = FindDIBBits(lpDIBHdr);

    // get a DC 

    hDC = GetDC(NULL);
    if (!hDC)
    {
        // clean up and return NULL

        GlobalUnlock(hDIB);
        return NULL;
    }

    // select and realize palette

    if (hPal)
        hOldPal = SelectPalette(hDC, hPal, FALSE);

    RealizePalette(hDC);

    // create bitmap from DIB info. and bits
    hBitmap = CreateDIBitmap(hDC, (LPBITMAPINFOHEADER)lpDIBHdr, CBM_INIT,
            lpDIBBits, (LPBITMAPINFO)lpDIBHdr, DIB_RGB_COLORS);

    // restore previous palette
    if (hOldPal)
        SelectPalette(hDC, hOldPal, FALSE);

    // clean up
    ReleaseDC(NULL, hDC);
    GlobalUnlock(hDIB);

    // return handle to the bitmap
    return hBitmap;
}
Example #26
0
static HBITMAP read_bitmap(const char* path, bool delete_after)
{
    HWND hwnd_desk = GetDesktopWindow();
    HDC hdc_desk = GetDC(hwnd_desk);
    BITMAP bm;
#if 0
    HBITMAP bmp = (HBITMAP)LoadImage(NULL, path, IMAGE_BITMAP, 0,0, LR_LOADFROMFILE);
#else
    HBITMAP bmp = NULL;
    FILE *fp=fopen(path, "rb");
    if (fp)
    {
        BITMAPFILEHEADER hdr;
        fread(&hdr, 1, sizeof(hdr), fp);
        if (0x4D42 == hdr.bfType)
        {
            BITMAPINFOHEADER bih, *pbih; int CU, s; void *lpBits;
            fread(&bih, 1, sizeof(bih), fp);
            CU = bih.biClrUsed * sizeof(RGBQUAD);
            pbih = (PBITMAPINFOHEADER)m_alloc(bih.biSize + CU);
            memmove(pbih, &bih, bih.biSize);
            fread(&((BITMAPINFO*)pbih)->bmiColors, 1, CU, fp);
            s = hdr.bfSize - hdr.bfOffBits;
            lpBits = m_alloc(s);
            fseek(fp, hdr.bfOffBits, SEEK_SET);
            fread(lpBits, 1, s, fp);
            bmp = CreateDIBitmap(hdc_desk, pbih, CBM_INIT, lpBits, (LPBITMAPINFO)pbih, DIB_RGB_COLORS);
            m_free(lpBits);
            m_free(pbih);
        }
        fclose(fp);
    }
#endif
    if (bmp && GetObject(bmp, sizeof bm, &bm))
    {
        // convert in any case (20ms), bc if it's compatible, it's faster to paint.
        HDC hdc_old = CreateCompatibleDC(hdc_desk);
        HGDIOBJ old_bmp = SelectObject(hdc_old, bmp);
        HDC hdc_new = CreateCompatibleDC(hdc_desk);
        HBITMAP bmp_new = CreateCompatibleBitmap(hdc_desk, VScreenWidth, VScreenHeight);
        SelectObject(hdc_new, bmp_new);
        StretchBlt(hdc_new, 0, 0, VScreenWidth, VScreenHeight, hdc_old, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
        DeleteDC(hdc_new);
        DeleteObject(SelectObject(hdc_old, old_bmp));
        DeleteDC(hdc_old);
        bmp = bmp_new;
    }

    ReleaseDC(hwnd_desk, hdc_desk);
    if (delete_after)
        DeleteFile(path);
    return bmp;
}
HBITMAP CXCCRA2RadarCustomizerDlg::create_bitmap(Cvirtual_image image)
{
	image.swap_rb();
	BITMAPINFOHEADER header;
	ZeroMemory(&header, sizeof(BITMAPINFOHEADER));
	header.biSize = sizeof(BITMAPINFOHEADER);
	header.biWidth = image.cx();
	header.biHeight = -image.cy();
	header.biPlanes = 1;
	header.biBitCount = image.cb_pixel() << 3;
	header.biCompression = BI_RGB;
	return CreateDIBitmap(CClientDC(NULL), &header, CBM_INIT, image.image(), reinterpret_cast<BITMAPINFO*>(&header), DIB_RGB_COLORS);
}
Example #28
0
HBITMAP FinishBmp(VBuf *vbuf)
{
    HBITMAP	hBmp  = NULL;
    HWND	hWnd  = GetDesktopWindow();
    HDC		hDc   = NULL;

    if ((hDc = GetDC(hWnd))) {
        hBmp = CreateDIBitmap(hDc, (BITMAPINFOHEADER *)vbuf->Buf(), CBM_INIT,
                              vbuf->Buf() + vbuf->UsedSize(), (BITMAPINFO *)vbuf->Buf(), DIB_RGB_COLORS);
        ReleaseDC(hWnd, hDc);
    }
    return	hBmp;
}
Example #29
0
HBITMAP IconToXorBitmap( HDC hdc, an_icon *icon )
{
    HBITMAP             bitmap_handle = (HBITMAP)0;
    HPALETTE            new_palette, old_palette;

    new_palette = CreateIconPalette( icon->bm );
    old_palette = SelectPalette( hdc, new_palette, FALSE );
    RealizePalette( hdc );
    bitmap_handle = CreateDIBitmap( hdc, &icon->bm->bmiHeader, CBM_INIT,
        icon->xor_mask, icon->bm, DIB_RGB_COLORS );
    SelectPalette( hdc, old_palette, FALSE );
    DeleteObject( new_palette );
    return( bitmap_handle );
} /* IconToXorBitmap */
Example #30
0
/***********************************************************************
 *           DESKTOP_LoadBitmap
 *
 * Load a bitmap from a file. Used by SetDeskWallPaper().
 */
static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
{
    BITMAPFILEHEADER *fileHeader;
    BITMAPINFO *bitmapInfo;
    HBITMAP hbitmap;
    HFILE file;
    LPSTR buffer;
    LONG size;

    /* Read all the file into memory */

    if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
    {
        UINT len = GetWindowsDirectoryA( NULL, 0 );
        if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
                                  len + strlen(filename) + 2 )))
            return 0;
        GetWindowsDirectoryA( buffer, len + 1 );
        strcat( buffer, "\\" );
        strcat( buffer, filename );
        file = _lopen( buffer, OF_READ );
        HeapFree( GetProcessHeap(), 0, buffer );
    }
    if (file == HFILE_ERROR) return 0;
    size = _llseek( file, 0, 2 );
    if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
    {
	_lclose( file );
	return 0;
    }
    _llseek( file, 0, 0 );
    size = _lread( file, buffer, size );
    _lclose( file );
    fileHeader = (BITMAPFILEHEADER *)buffer;
    bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));

      /* Check header content */
    if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
    {
	HeapFree( GetProcessHeap(), 0, buffer );
	return 0;
    }
    hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
                                buffer + fileHeader->bfOffBits,
                                bitmapInfo, DIB_RGB_COLORS );
    HeapFree( GetProcessHeap(), 0, buffer );
    return hbitmap;
}