本文整理汇总了C++中CreateDIBSection函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateDIBSection函数的具体用法?C++ CreateDIBSection怎么用?C++ CreateDIBSection使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CreateDIBSection函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GPHOTO2_ImageNativeXferGet
/* DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET */
TW_UINT16 GPHOTO2_ImageNativeXferGet (pTW_IDENTITY pOrigin,
TW_MEMREF pData)
{
#ifdef HAVE_GPHOTO2
pTW_UINT32 pHandle = (pTW_UINT32) pData;
HBITMAP hDIB;
BITMAPINFO bmpInfo;
LPBYTE bits, oldbits;
JSAMPROW samprow, oldsamprow;
HDC dc;
FIXME("DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET: implemented, but expect program crash due to DIB.\n");
/* NOTE NOTE NOTE NOTE NOTE NOTE NOTE
*
* While this is a mandatory transfer mode and this function
* is correctly implemented and fully works, the calling program
* will likely crash after calling.
*
* Reason is that there is a lot of example code that does:
* bmpinfo = (LPBITMAPINFOHEADER)GlobalLock(hBITMAP); ... pointer access to bmpinfo
*
* Our current HBITMAP handles do not support getting GlobalLocked -> App Crash
*
* This needs a GDI Handle rewrite, at least for DIB sections.
* - Marcus
*/
if (activeDS.currentState != 6) {
activeDS.twCC = TWCC_SEQERROR;
return TWRC_FAILURE;
}
if (TWRC_SUCCESS != _get_image_and_startup_jpeg()) {
FIXME("Failed to get an image\n");
activeDS.twCC = TWCC_OPERATIONERROR;
return TWRC_FAILURE;
}
TRACE("Acquiring image %dx%dx%d bits from gphoto.\n",
activeDS.jd.output_width, activeDS.jd.output_height,
activeDS.jd.output_components*8);
ZeroMemory (&bmpInfo, sizeof (BITMAPINFO));
bmpInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = activeDS.jd.output_width;
bmpInfo.bmiHeader.biHeight = -activeDS.jd.output_height;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = activeDS.jd.output_components*8;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biSizeImage = 0;
bmpInfo.bmiHeader.biXPelsPerMeter = 0;
bmpInfo.bmiHeader.biYPelsPerMeter = 0;
bmpInfo.bmiHeader.biClrUsed = 0;
bmpInfo.bmiHeader.biClrImportant = 0;
hDIB = CreateDIBSection ((dc = GetDC(activeDS.hwndOwner)), &bmpInfo,
DIB_RGB_COLORS, (LPVOID)&bits, 0, 0);
if (!hDIB) {
FIXME("Failed creating DIB.\n");
gp_file_unref (activeDS.file);
activeDS.file = NULL;
activeDS.twCC = TWCC_LOWMEMORY;
return TWRC_FAILURE;
}
samprow = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,activeDS.jd.output_width*activeDS.jd.output_components);
oldbits = bits;
oldsamprow = samprow;
while ( activeDS.jd.output_scanline<activeDS.jd.output_height ) {
int i, x = pjpeg_read_scanlines(&activeDS.jd,&samprow,1);
if (x != 1) {
FIXME("failed to read current scanline?\n");
break;
}
/* We have to convert from RGB to BGR, see MSDN/ BITMAPINFOHEADER */
for(i=0;i<activeDS.jd.output_width;i++,samprow+=activeDS.jd.output_components) {
*(bits++) = *(samprow+2);
*(bits++) = *(samprow+1);
*(bits++) = *(samprow);
}
bits = (LPBYTE)(((UINT_PTR)bits + 3) & ~3);
samprow = oldsamprow;
}
bits = oldbits;
HeapFree (GetProcessHeap(), 0, samprow);
gp_file_unref (activeDS.file);
activeDS.file = NULL;
ReleaseDC (activeDS.hwndOwner, dc);
*pHandle = (TW_UINT32)hDIB;
activeDS.twCC = TWCC_SUCCESS;
activeDS.currentState = 7;
return TWRC_XFERDONE;
#else
return TWRC_FAILURE;
#endif
}
示例2: if
//.........这里部分代码省略.........
ddsd.ddpfPixelFormat.dwGBitMask = 0x00F0;
ddsd.ddpfPixelFormat.dwBBitMask = 0x000F;
fmt = eX4R4G4B4;
}
if( pRT )
{
pRT->Release();
pRT = NULL;
}
// Create a new texture for the font
hr = pDD->CreateSurface(&ddsd, &m_pTexture, NULL);
if( FAILED(hr) )
return hr;
// Prepare to create a bitmap
DWORD * pBitmapBits;
BITMAPINFO bmi;
ZeroMemory( &bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = (int)m_dwTexWidth;
bmi.bmiHeader.biHeight = -(int)m_dwTexHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biBitCount = 32;
// Create a DC and a bitmap for the font
HDC hDC = CreateCompatibleDC( NULL );
if( NULL == hDC )
return E_FAIL;
HBITMAP hbmBitmap = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS,
(VOID**)&pBitmapBits, NULL, 0 );
SetMapMode( hDC, MM_TEXT );
// Create a font. By specifying ANTIALIASED_QUALITY, we might get an
// antialiased font, but this is not guaranteed.
INT nHeight = -MulDiv( m_dwFontHeight,
(INT)(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale), 72 );
DWORD dwBold = (m_dwFontFlags&D3DFONT_BOLD) ? FW_BOLD : FW_NORMAL;
DWORD dwItalic = (m_dwFontFlags&D3DFONT_ITALIC) ? TRUE : FALSE;
HFONT hFont = CreateFont( nHeight, 0, 0, 0, dwBold, dwItalic,
FALSE, FALSE, DEFAULT_CHARSET, OUT_STRING_PRECIS,
CLIP_STROKE_PRECIS, ANTIALIASED_QUALITY,
VARIABLE_PITCH, m_strFontName );
if( NULL==hFont )
return E_FAIL;
SelectObject( hDC, hbmBitmap );
SelectObject( hDC, hFont );
// Set text properties
SetTextColor( hDC, RGB(255,255,255) );
SetBkColor( hDC, 0x00000000 );
SetTextAlign( hDC, TA_TOP );
// Loop through all printable character and output them to the bitmap..
// Meanwhile, keep track of the corresponding tex coords for each character.
DWORD x = 0;
DWORD y = 0;
TCHAR str[2] = _T("x");
SIZE size;
for( TCHAR c=32; c<127; c++ )
示例3: _ASSERT
void CPPDrawManager::AlphaBitBlt(HDC hDestDC, int nDestX, int nDestY, DWORD dwWidth, DWORD dwHeight, HDC hSrcDC, int nSrcX, int nSrcY, int percent /* = 100 */)
{
_ASSERT ((NULL != hDestDC) || (NULL != hSrcDC));
if (percent >= 100)
{
::BitBlt(hDestDC, nDestX, nDestY, dwWidth, dwHeight, hSrcDC, nSrcX, nSrcY, SRCCOPY);
return;
} //if
HDC hTempDC = ::CreateCompatibleDC(hDestDC);
if (NULL == hTempDC)
return;
//Creates Source DIB
LPBITMAPINFO lpbiSrc;
// Fill in the BITMAPINFOHEADER
lpbiSrc = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
lpbiSrc->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
lpbiSrc->bmiHeader.biWidth = dwWidth;
lpbiSrc->bmiHeader.biHeight = dwHeight;
lpbiSrc->bmiHeader.biPlanes = 1;
lpbiSrc->bmiHeader.biBitCount = 32;
lpbiSrc->bmiHeader.biCompression = BI_RGB;
lpbiSrc->bmiHeader.biSizeImage = dwWidth * dwHeight;
lpbiSrc->bmiHeader.biXPelsPerMeter = 0;
lpbiSrc->bmiHeader.biYPelsPerMeter = 0;
lpbiSrc->bmiHeader.biClrUsed = 0;
lpbiSrc->bmiHeader.biClrImportant = 0;
COLORREF* pSrcBits = NULL;
HBITMAP hSrcDib = CreateDIBSection (
hSrcDC, lpbiSrc, DIB_RGB_COLORS, (void **)&pSrcBits,
NULL, NULL);
if ((NULL != hSrcDib) && (NULL != pSrcBits))
{
HBITMAP hOldTempBmp = (HBITMAP)::SelectObject (hTempDC, hSrcDib);
::BitBlt (hTempDC, 0, 0, dwWidth, dwHeight, hSrcDC, nSrcX, nSrcY, SRCCOPY);
::SelectObject (hTempDC, hOldTempBmp);
//Creates Destination DIB
LPBITMAPINFO lpbiDest;
// Fill in the BITMAPINFOHEADER
lpbiDest = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
lpbiDest->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
lpbiDest->bmiHeader.biWidth = dwWidth;
lpbiDest->bmiHeader.biHeight = dwHeight;
lpbiDest->bmiHeader.biPlanes = 1;
lpbiDest->bmiHeader.biBitCount = 32;
lpbiDest->bmiHeader.biCompression = BI_RGB;
lpbiDest->bmiHeader.biSizeImage = dwWidth * dwHeight;
lpbiDest->bmiHeader.biXPelsPerMeter = 0;
lpbiDest->bmiHeader.biYPelsPerMeter = 0;
lpbiDest->bmiHeader.biClrUsed = 0;
lpbiDest->bmiHeader.biClrImportant = 0;
COLORREF* pDestBits = NULL;
HBITMAP hDestDib = CreateDIBSection (
hDestDC, lpbiDest, DIB_RGB_COLORS, (void **)&pDestBits,
NULL, NULL);
if ((NULL != hDestDib) && (NULL != pDestBits))
{
::SelectObject (hTempDC, hDestDib);
::BitBlt (hTempDC, 0, 0, dwWidth, dwHeight, hDestDC, nDestX, nDestY, SRCCOPY);
::SelectObject (hTempDC, hOldTempBmp);
double src_darken = (double)percent / 100.0;
double dest_darken = 1.0 - src_darken;
for (DWORD pixel = 0; pixel < dwWidth * dwHeight; pixel++, pSrcBits++, pDestBits++)
{
*pDestBits = PixelAlpha(*pSrcBits, src_darken, *pDestBits, dest_darken);
} //for
::SelectObject (hTempDC, hDestDib);
::BitBlt (hDestDC, nDestX, nDestY, dwWidth, dwHeight, hTempDC, 0, 0, SRCCOPY);
::SelectObject (hTempDC, hOldTempBmp);
delete lpbiDest;
::DeleteObject(hDestDib);
} //if
delete lpbiSrc;
::DeleteObject(hSrcDib);
} //if
::DeleteDC(hTempDC);
} //End AlphaBitBlt
示例4: height
RawBitmap::RawBitmap(unsigned nWidth, unsigned nHeight)
:width(nWidth), height(nHeight),
corrected_width(CorrectedWidth(nWidth))
#ifdef ENABLE_OPENGL
, texture(CorrectedWidth(nWidth), nHeight)
#endif
{
assert(nWidth > 0);
assert(nHeight > 0);
#ifdef ENABLE_OPENGL
buffer = new BGRColor[corrected_width * height];
#elif defined(ENABLE_SDL)
Uint32 rmask, gmask, bmask, amask;
int depth;
#ifdef ANDROID
rmask = 0x0000f800;
gmask = 0x000007e0;
bmask = 0x0000001f;
depth = 16;
#else
rmask = 0x00ff0000;
gmask = 0x0000ff00;
bmask = 0x000000ff;
depth = 32;
#endif
amask = 0x00000000;
assert(sizeof(BGRColor) * 8 == depth);
surface = ::SDL_CreateRGBSurface(SDL_SWSURFACE, corrected_width, height,
depth, rmask, gmask, bmask, amask);
assert(!SDL_MUSTLOCK(surface));
buffer = (BGRColor *)surface->pixels;
#else /* !ENABLE_SDL */
bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
bi.bmiHeader.biWidth = corrected_width;
bi.bmiHeader.biHeight = height;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 24;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biSizeImage = 0;
bi.bmiHeader.biXPelsPerMeter = 3780;
bi.bmiHeader.biYPelsPerMeter = 3780;
bi.bmiHeader.biClrUsed = 0;
bi.bmiHeader.biClrImportant = 0;
#ifdef _WIN32_WCE
/* configure 16 bit 5-5-5 on Windows CE */
bi.bmiHeader.biBitCount = 16;
bi.bmiHeader.biCompression = BI_BITFIELDS;
bi.bmiHeader.biClrUsed = 3;
LPVOID p = &bi.bmiColors[0];
DWORD *q = (DWORD *)p;
*q++ = 0x7c00; /* 5 bits red */
*q++ = 0x03e0; /* 5 bits green */
*q++ = 0x001f; /* 5 bits blue */
#endif
#if defined(_WIN32_WCE) && _WIN32_WCE < 0x0400
/* StretchDIBits() is bugged on PPC2002, workaround follows */
VOID *pvBits;
HDC hDC = ::GetDC(NULL);
bitmap = CreateDIBSection(hDC, &bi, DIB_RGB_COLORS, &pvBits, NULL, 0);
::ReleaseDC(NULL, hDC);
buffer = (BGRColor *)pvBits;
#else
buffer = new BGRColor[corrected_width * height];
#endif
#endif /* !ENABLE_SDL */
}
示例5: String
String
MSWindowsClipboardBitmapConverter::toIClipboard(HANDLE data) const
{
// get datator
const char* src = (const char*)GlobalLock(data);
if (src == NULL) {
return String();
}
UInt32 srcSize = (UInt32)GlobalSize(data);
// check image type
const BITMAPINFO* bitmap = reinterpret_cast<const BITMAPINFO*>(src);
LOG((CLOG_INFO "bitmap: %dx%d %d", bitmap->bmiHeader.biWidth, bitmap->bmiHeader.biHeight, (int)bitmap->bmiHeader.biBitCount));
if (bitmap->bmiHeader.biPlanes == 1 &&
(bitmap->bmiHeader.biBitCount == 24 ||
bitmap->bmiHeader.biBitCount == 32) &&
bitmap->bmiHeader.biCompression == BI_RGB) {
// already in canonical form
String image(src, srcSize);
GlobalUnlock(data);
return image;
}
// create a destination DIB section
LOG((CLOG_INFO "convert image from: depth=%d comp=%d", bitmap->bmiHeader.biBitCount, bitmap->bmiHeader.biCompression));
void* raw;
BITMAPINFOHEADER info;
LONG w = bitmap->bmiHeader.biWidth;
LONG h = bitmap->bmiHeader.biHeight;
info.biSize = sizeof(BITMAPINFOHEADER);
info.biWidth = w;
info.biHeight = h;
info.biPlanes = 1;
info.biBitCount = 32;
info.biCompression = BI_RGB;
info.biSizeImage = 0;
info.biXPelsPerMeter = 1000;
info.biYPelsPerMeter = 1000;
info.biClrUsed = 0;
info.biClrImportant = 0;
HDC dc = GetDC(NULL);
HBITMAP dst = CreateDIBSection(dc, (BITMAPINFO*)&info,
DIB_RGB_COLORS, &raw, NULL, 0);
// find the start of the pixel data
const char* srcBits = (const char*)bitmap + bitmap->bmiHeader.biSize;
if (bitmap->bmiHeader.biBitCount >= 16) {
if (bitmap->bmiHeader.biCompression == BI_BITFIELDS &&
(bitmap->bmiHeader.biBitCount == 16 ||
bitmap->bmiHeader.biBitCount == 32)) {
srcBits += 3 * sizeof(DWORD);
}
}
else if (bitmap->bmiHeader.biClrUsed != 0) {
srcBits += bitmap->bmiHeader.biClrUsed * sizeof(RGBQUAD);
}
else {
//http://msdn.microsoft.com/en-us/library/ke55d167(VS.80).aspx
srcBits += (1i64 << bitmap->bmiHeader.biBitCount) * sizeof(RGBQUAD);
}
// copy source image to destination image
HDC dstDC = CreateCompatibleDC(dc);
HGDIOBJ oldBitmap = SelectObject(dstDC, dst);
SetDIBitsToDevice(dstDC, 0, 0, w, h, 0, 0, 0, h,
srcBits, bitmap, DIB_RGB_COLORS);
SelectObject(dstDC, oldBitmap);
DeleteDC(dstDC);
GdiFlush();
// extract data
String image((const char*)&info, info.biSize);
image.append((const char*)raw, 4 * w * h);
// clean up GDI
DeleteObject(dst);
ReleaseDC(NULL, dc);
// release handle
GlobalUnlock(data);
return image;
}
示例6: RGB
//////////////////////////////////////////////////////////////////////////
//函数名:BitmapToRegion
//功能:输入图像句柄,得到抠除了蒙板色的区域
//原作者:Jean-Edouard Lachand Robert, August 5, 1998
//修改人:C瓜哥(www.cguage.com)
HRGN CAnimateButton::BitmapToRegion(HBITMAP hBmp, int nSplit, int n,
COLORREF cTransparentColor = RGB(255, 0, 255), COLORREF cTolerance = RGB(255, 0, 255))
{
HRGN hRgn = NULL;
if (hBmp)
{
// Create a memory DC inside which we will scan the bitmap content
HDC hMemDC = CreateCompatibleDC(NULL);
if (hMemDC)
{
// Get bitmap size
BITMAP bm;
GetObject(hBmp, sizeof(bm), &bm);
// Create a 32 bits depth bitmap and select it into the memory DC
BITMAPINFOHEADER RGB32BITSBITMAPINFO =
{
sizeof(BITMAPINFOHEADER), // biSize
bm.bmWidth, // biWidth;
bm.bmHeight, // biHeight;
1, // biPlanes;
32, // biBitCount
BI_RGB, // biCompression;
0, // biSizeImage;
0, // biXPelsPerMeter;
0, // biYPelsPerMeter;
0, // biClrUsed;
0 // biClrImportant;
};
//每种状态图的宽度
int nBlockWidth = bm.bmWidth / nSplit;
VOID * pbits32;
HBITMAP hbm32 = CreateDIBSection(hMemDC, (BITMAPINFO *)&RGB32BITSBITMAPINFO, DIB_RGB_COLORS, &pbits32, NULL, 0);
if (hbm32)
{
HBITMAP holdBmp = (HBITMAP)SelectObject(hMemDC, hbm32);
// Create a DC just to copy the bitmap into the memory DC
HDC hDC = CreateCompatibleDC(hMemDC);
if (hDC)
{
// Get how many bytes per row we have for the bitmap bits (rounded up to 32 bits)
BITMAP bm32;
GetObject(hbm32, sizeof(bm32), &bm32);
while (bm32.bmWidthBytes % 4)
bm32.bmWidthBytes++;
// Copy the bitmap into the memory DC
HBITMAP holdBmp = (HBITMAP)SelectObject(hDC, hBmp);
BitBlt(hMemDC, 0, 0, nBlockWidth, bm.bmHeight, hDC, nBlockWidth * n, 0, SRCCOPY);
// For better performances, we will use the ExtCreateRegion() function to create the
// region. This function take a RGNDATA structure on entry. We will add rectangles by
// amount of ALLOC_UNIT number in this structure.
#define ALLOC_UNIT 100
DWORD maxRects = ALLOC_UNIT;
HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects));
RGNDATA *pData = (RGNDATA *)GlobalLock(hData);
pData->rdh.dwSize = sizeof(RGNDATAHEADER);
pData->rdh.iType = RDH_RECTANGLES;
pData->rdh.nCount = pData->rdh.nRgnSize = 0;
SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
// Keep on hand highest and lowest values for the "transparent" pixels
BYTE lr = GetRValue(cTransparentColor);
BYTE lg = GetGValue(cTransparentColor);
BYTE lb = GetBValue(cTransparentColor);
BYTE hr = min(0xff, lr + GetRValue(cTolerance));
BYTE hg = min(0xff, lg + GetGValue(cTolerance));
BYTE hb = min(0xff, lb + GetBValue(cTolerance));
// Scan each bitmap row from bottom to top (the bitmap is inverted vertically)
BYTE *p32 = (BYTE *)bm32.bmBits + (bm32.bmHeight - 1) * bm32.bmWidthBytes;
for (int y = 0; y < bm.bmHeight; y++)
{
// Scan each bitmap pixel from left to right
for (int x = 0; x < nBlockWidth; x++)
{
// Search for a continuous range of "non transparent pixels"
int x0 = x;
LONG *p = (LONG *)p32 + x;
while (x < nBlockWidth)
{
BYTE b = GetRValue(*p);
if (b >= lr && b <= hr)
{
b = GetGValue(*p);
if (b >= lg && b <= hg)
{
b = GetBValue(*p);
if (b >= lb && b <= hb)
//.........这里部分代码省略.........
示例7: sizeof
// Create a bitmap for off-screen drawing...
bool CTinyCadView::CreateBitmap(CDC &dc, int width, int height)
{
// Is there already a suitable bitmap?
if (m_bitmap_width >= width && m_bitmap_height >= height)
{
return true;
}
// Is this beyond the maximum size we are willing to allocate?
if (width * height > m_max_bitmap_size)
{
return false;
}
int bpp = dc.GetDeviceCaps(BITSPIXEL);
if (bpp <= 16)
{
bpp = 16;
}
else
{
bpp = 24;
}
// Now try and create the bitmap...
struct
{
BITMAPINFO bi;
RGBQUAD bipal[3];
} q;
q.bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
q.bi.bmiHeader.biWidth = width;
q.bi.bmiHeader.biHeight = height;
q.bi.bmiHeader.biPlanes = 1;
q.bi.bmiHeader.biBitCount = (WORD) bpp;
q.bi.bmiHeader.biCompression = bpp == 16 ? BI_BITFIELDS : BI_RGB;
q.bi.bmiHeader.biSizeImage = 0;
q.bi.bmiHeader.biXPelsPerMeter = 0;
q.bi.bmiHeader.biYPelsPerMeter = 0;
q.bi.bmiHeader.biClrUsed = bpp == 16 ? 3 : 0;
q.bi.bmiHeader.biClrImportant = 0;
q.bi.bmiColors[0].rgbRed = 0;
q.bi.bmiColors[0].rgbGreen = 0;
q.bi.bmiColors[0].rgbBlue = 0;
q.bi.bmiColors[0].rgbReserved = 0;
// Set up the 5-6-5 bit masks
if (bpp == 16)
{
((DWORD*) (q.bi.bmiColors))[0] = (WORD) (0x1F << 11); //make sure that RGQQUAD array is after the q.bi struct
((DWORD*) (q.bi.bmiColors))[1] = (WORD) (0x3F << 5); //otherwise you will get an access violation
((DWORD*) (q.bi.bmiColors))[2] = (WORD) (0x1F << 0);
}
void *bits;
HBITMAP hb = CreateDIBSection(dc.m_hDC, &q.bi, DIB_RGB_COLORS, &bits, NULL, 0);
if (!hb)
{
// Probably not enough memory...
return false;
}
// Do we need to destroy the old bitmap?
if (m_bitmap.m_hObject)
{
m_bitmap.DeleteObject();
}
m_bitmap.Attach(hb);
m_bitmap_width = width;
m_bitmap_height = height;
return true;
}
示例8: MessageBox
//Basic Init, create the font, backbuffer, etc
WINDOW *initscr(void)
{
// _windows = new WINDOW[20]; //initialize all of our variables
BITMAPINFO bmi;
lastchar=-1;
inputdelay=-1;
std::string typeface;
char * typeface_c;
std::ifstream fin;
fin.open("data\\FONTDATA");
if (!fin.is_open()){
MessageBox(WindowHandle, "Failed to open FONTDATA, loading defaults.",
NULL, NULL);
fontheight=16;
fontwidth=8;
} else {
getline(fin, typeface);
typeface_c= new char [typeface.size()+1];
strcpy (typeface_c, typeface.c_str());
fin >> fontwidth;
fin >> fontheight;
if ((fontwidth <= 4) || (fontheight <=4)){
MessageBox(WindowHandle, "Invalid font size specified!",
NULL, NULL);
fontheight=16;
fontwidth=8;
}
}
halfwidth=fontwidth / 2;
halfheight=fontheight / 2;
WindowWidth=80*fontwidth;
WindowHeight=25*fontheight;
WindowX=(GetSystemMetrics(SM_CXSCREEN) / 2)-WindowWidth/2; //center this
WindowY=(GetSystemMetrics(SM_CYSCREEN) / 2)-WindowHeight/2; //sucker
WinCreate(); //Create the actual window, register it, etc
CheckMessages(); //Let the message queue handle setting up the window
WindowDC = GetDC(WindowHandle);
backbuffer = CreateCompatibleDC(WindowDC);
ZeroMemory(&bmi, sizeof(BITMAPINFO));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = WindowWidth;
bmi.bmiHeader.biHeight = -WindowHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount=8;
bmi.bmiHeader.biCompression = BI_RGB; //store it in uncompressed bytes
bmi.bmiHeader.biSizeImage = WindowWidth * WindowHeight * 1;
bmi.bmiHeader.biClrUsed=16; //the number of colors in our palette
bmi.bmiHeader.biClrImportant=16; //the number of colors in our palette
backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC
int nResults = AddFontResourceExA("data\\termfont",FR_PRIVATE,NULL);
if (nResults>0){
font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
PROOF_QUALITY, FF_MODERN, typeface_c); //Create our font
} else {
MessageBox(WindowHandle, "Failed to load default font, using FixedSys.",
NULL, NULL);
font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
PROOF_QUALITY, FF_MODERN, "FixedSys"); //Create our font
}
//FixedSys will be user-changable at some point in time??
SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
SelectObject(backbuffer, font);//Load our font into the DC
// WindowCount=0;
delete typeface_c;
mainwin = newwin(25,80,0,0);
return mainwin; //create the 'stdscr' window and return its ref
};
示例9: ReadSCREENSHOTImage
//.........这里部分代码省略.........
assert(image_info != (const ImageInfo *) NULL);
i=0;
device.cb = sizeof(device);
image=(Image *) NULL;
while(EnumDisplayDevices(NULL,i,&device,0) && ++i)
{
if ((device.StateFlags & DISPLAY_DEVICE_ACTIVE) != DISPLAY_DEVICE_ACTIVE)
continue;
hDC=CreateDC(device.DeviceName,device.DeviceName,NULL,NULL);
if (hDC == (HDC) NULL)
ThrowReaderException(CoderError,"UnableToCreateDC");
screen=AcquireImage(image_info,exception);
screen->columns=(size_t) GetDeviceCaps(hDC,HORZRES);
screen->rows=(size_t) GetDeviceCaps(hDC,VERTRES);
screen->storage_class=DirectClass;
if (image == (Image *) NULL)
image=screen;
else
AppendImageToList(&image,screen);
status=SetImageExtent(screen,screen->columns,screen->rows,exception);
if (status == MagickFalse)
return(DestroyImageList(image));
bitmapDC=CreateCompatibleDC(hDC);
if (bitmapDC == (HDC) NULL)
{
DeleteDC(hDC);
ThrowReaderException(CoderError,"UnableToCreateDC");
}
(void) memset(&bmi,0,sizeof(BITMAPINFO));
bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth=(LONG) screen->columns;
bmi.bmiHeader.biHeight=(-1)*(LONG) screen->rows;
bmi.bmiHeader.biPlanes=1;
bmi.bmiHeader.biBitCount=32;
bmi.bmiHeader.biCompression=BI_RGB;
bitmap=CreateDIBSection(hDC,&bmi,DIB_RGB_COLORS,(void **) &p,NULL,0);
if (bitmap == (HBITMAP) NULL)
{
DeleteDC(hDC);
DeleteDC(bitmapDC);
ThrowReaderException(CoderError,"UnableToCreateBitmap");
}
bitmapOld=(HBITMAP) SelectObject(bitmapDC,bitmap);
if (bitmapOld == (HBITMAP) NULL)
{
DeleteDC(hDC);
DeleteDC(bitmapDC);
DeleteObject(bitmap);
ThrowReaderException(CoderError,"UnableToCreateBitmap");
}
BitBlt(bitmapDC,0,0,(int) screen->columns,(int) screen->rows,hDC,0,0,
SRCCOPY);
(void) SelectObject(bitmapDC,bitmapOld);
for (y=0; y < (ssize_t) screen->rows; y++)
{
q=QueueAuthenticPixels(screen,0,y,screen->columns,1,exception);
if (q == (Quantum *) NULL)
break;
for (x=0; x < (ssize_t) screen->columns; x++)
{
SetPixelRed(image,ScaleCharToQuantum(p->rgbRed),q);
SetPixelGreen(image,ScaleCharToQuantum(p->rgbGreen),q);
SetPixelBlue(image,ScaleCharToQuantum(p->rgbBlue),q);
SetPixelAlpha(image,OpaqueAlpha,q);
p++;
q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(screen,exception) == MagickFalse)
break;
}
DeleteDC(hDC);
DeleteDC(bitmapDC);
DeleteObject(bitmap);
}
}
#elif defined(MAGICKCORE_X11_DELEGATE)
{
const char
*option;
XImportInfo
ximage_info;
XGetImportInfo(&ximage_info);
option=GetImageOption(image_info,"x:screen");
if (option != (const char *) NULL)
ximage_info.screen=IsStringTrue(option);
option=GetImageOption(image_info,"x:silent");
if (option != (const char *) NULL)
ximage_info.silent=IsStringTrue(option);
image=XImportImage(image_info,&ximage_info,exception);
}
#endif
return(image);
}
示例10: paintArea
static void paintArea(HWND hwnd, void *data)
{
RECT xrect;
PAINTSTRUCT ps;
HDC hdc;
HDC rdc;
HBITMAP rbitmap, prevrbitmap;
RECT rrect;
BITMAPINFO bi;
VOID *ppvBits;
HBITMAP ibitmap;
HDC idc;
HBITMAP previbitmap;
BLENDFUNCTION blendfunc;
void *i;
intptr_t dx, dy;
int hscroll, vscroll;
// FALSE here indicates don't send WM_ERASEBKGND
if (GetUpdateRect(hwnd, &xrect, FALSE) == 0)
return; // no update rect; do nothing
getScrollPos(hwnd, &hscroll, &vscroll);
hdc = BeginPaint(hwnd, &ps);
if (hdc == NULL)
xpanic("error beginning Area repaint", GetLastError());
// very big thanks to Ninjifox for suggesting this technique and helping me go through it
// first let's create the destination image, which we fill with the windows background color
// this is how we fake drawing the background; see also http://msdn.microsoft.com/en-us/library/ms969905.aspx
rdc = CreateCompatibleDC(hdc);
if (rdc == NULL)
xpanic("error creating off-screen rendering DC", GetLastError());
// the bitmap has to be compatible with the window
// if we create a bitmap compatible with the DC we just created, it'll be monochrome
// thanks to David Heffernan in http://stackoverflow.com/questions/23033636/winapi-gdi-fillrectcolor-btnface-fills-with-strange-grid-like-brush-on-window
rbitmap = CreateCompatibleBitmap(hdc, xrect.right - xrect.left, xrect.bottom - xrect.top);
if (rbitmap == NULL)
xpanic("error creating off-screen rendering bitmap", GetLastError());
prevrbitmap = (HBITMAP) SelectObject(rdc, rbitmap);
if (prevrbitmap == NULL)
xpanic("error connecting off-screen rendering bitmap to off-screen rendering DC", GetLastError());
rrect.left = 0;
rrect.right = xrect.right - xrect.left;
rrect.top = 0;
rrect.bottom = xrect.bottom - xrect.top;
if (FillRect(rdc, &rrect, areaBackgroundBrush) == 0)
xpanic("error filling off-screen rendering bitmap with the system background color", GetLastError());
i = doPaint(&xrect, hscroll, vscroll, data, &dx, &dy);
if (i == NULL) // cliprect empty
goto nobitmap; // we need to blit the background no matter what
// now we need to shove realbits into a bitmap
// technically bitmaps don't know about alpha; they just ignore the alpha byte
// AlphaBlend(), however, sees it - see http://msdn.microsoft.com/en-us/library/windows/desktop/dd183352%28v=vs.85%29.aspx
ZeroMemory(&bi, sizeof (BITMAPINFO));
bi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
bi.bmiHeader.biWidth = (LONG) dx;
bi.bmiHeader.biHeight = -((LONG) dy); // negative height to force top-down drawing
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 32;
bi.bmiHeader.biCompression = BI_RGB;
bi.bmiHeader.biSizeImage = (DWORD) (dx * dy * 4);
// this is all we need, but because this confused me at first, I will say the two pixels-per-meter fields are unused (see http://blogs.msdn.com/b/oldnewthing/archive/2013/05/15/10418646.aspx and page 581 of Charles Petzold's Programming Windows, Fifth Edition)
// now for the trouble: CreateDIBSection() allocates the memory for us...
ibitmap = CreateDIBSection(NULL, // Ninjifox does this, so do some wine tests (http://source.winehq.org/source/dlls/gdi32/tests/bitmap.c#L725, thanks vpovirk in irc.freenode.net/#winehackers) and even Raymond Chen (http://blogs.msdn.com/b/oldnewthing/archive/2006/11/16/1086835.aspx), so.
&bi, DIB_RGB_COLORS, &ppvBits, 0, 0);
if (ibitmap == NULL)
xpanic("error creating HBITMAP for image returned by AreaHandler.Paint()", GetLastError());
// now we have to do TWO MORE things before we can finally do alpha blending
// first, we need to load the bitmap memory, because Windows makes it for us
// the pixels are arranged in RGBA order, but GDI requires BGRA
// this turns out to be just ARGB in little endian; let's convert into this memory
dotoARGB(i, (void *) ppvBits, FALSE); // FALSE = not NRGBA
// the second thing is... make a device context for the bitmap :|
// Ninjifox just makes another compatible DC; we'll do the same
idc = CreateCompatibleDC(hdc);
if (idc == NULL)
xpanic("error creating HDC for image returned by AreaHandler.Paint()", GetLastError());
previbitmap = (HBITMAP) SelectObject(idc, ibitmap);
if (previbitmap == NULL)
xpanic("error connecting HBITMAP for image returned by AreaHandler.Paint() to its HDC", GetLastError());
// AND FINALLY WE CAN DO THE ALPHA BLENDING!!!!!!111
blendfunc.BlendOp = AC_SRC_OVER;
blendfunc.BlendFlags = 0;
blendfunc.SourceConstantAlpha = 255; // only use per-pixel alphas
blendfunc.AlphaFormat = AC_SRC_ALPHA; // premultiplied
if (AlphaBlend(rdc, 0, 0, (int) dx, (int) dy, // destination
idc, 0, 0, (int) dx, (int)dy, // source
blendfunc) == FALSE)
xpanic("error alpha-blending image returned by AreaHandler.Paint() onto background", GetLastError());
// clean up after idc/ibitmap here because of the goto nobitmap
if (SelectObject(idc, previbitmap) != ibitmap)
//.........这里部分代码省略.........
示例11: CreateCompatibleDC
Filename_notice *prepare_filename_notice(LPDIRECT3DDEVICE8 pd3dDevice,
char const *filename)
{
HRESULT result;
Filename_notice *notice = NULL;
HDC hDC = NULL;
HFONT hFont = NULL;
SIZE size;
int width, height;
LPDIRECT3DTEXTURE8 pTexture = NULL;
LPDIRECT3DVERTEXBUFFER8 pVB = NULL;
DWORD *pBitmapBits = NULL;
BITMAPINFO bmi;
HBITMAP hbmBitmap = NULL;
D3DLOCKED_RECT d3dlr;
BYTE *pDstRow;
int x, y;
hDC = CreateCompatibleDC(NULL);
SetMapMode(hDC, MM_TEXT);
hFont = CreateFont(
FONT_HEIGHT, // height
0, // width (0 = closest)
0, // escapement (0 = none)
0, // orientation (0 = none)
FW_NORMAL, // bold
FALSE, // italic
FALSE, // underline
FALSE, // strikeout
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, // TrueType (OUT_TT_PRECIS) doesn't help
CLIP_DEFAULT_PRECIS,
ANTIALIASED_QUALITY,
VARIABLE_PITCH,
FONT_NAME);
if (hFont == NULL) {
goto done;
}
// Set text properties
SelectObject(hDC, hFont);
SetTextColor(hDC, RGB(255,255,255));
SetBkColor(hDC, 0x00000000);
SetTextAlign(hDC, TA_TOP);
GetTextExtentPoint32(hDC, filename, strlen(filename), &size);
width = size.cx;
height = size.cy;
// Create a new texture for the font
result = pd3dDevice->CreateTexture(width, height, 1, 0, D3DFMT_A4R4G4B4,
D3DPOOL_MANAGED, &pTexture);
if (FAILED(result)) {
goto done;
}
// Prepare to create a bitmap
ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height; // negative means top-down
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biBitCount = 32;
hbmBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS,
(VOID**)&pBitmapBits, NULL, 0);
SelectObject(hDC, hbmBitmap);
ExtTextOut(hDC, 0, 0, ETO_OPAQUE, NULL, filename, strlen(filename), NULL);
// Lock the surface and write the alpha values for the set pixels
pTexture->LockRect(0, &d3dlr, 0, 0);
pDstRow = (BYTE*)d3dlr.pBits;
for (y = 0; y < height; y++) {
WORD *pDst16 = (WORD *)pDstRow;
for (x = 0; x < width; x++) {
BYTE bAlpha = (BYTE)((pBitmapBits[width*y + x] & 0xff) >> 4);
if (bAlpha > 0) {
*pDst16++ = (WORD)((bAlpha << 12) | 0x0fff);
} else {
*pDst16++ = (WORD)(0x0000);
}
}
pDstRow += d3dlr.Pitch;
}
// Done updating texture
pTexture->UnlockRect(0);
// Create vertices
result = pd3dDevice->CreateVertexBuffer(4*sizeof(FONT2DVERTEX),
D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &pVB);
if (FAILED(result)) {
//.........这里部分代码省略.........
示例12: GetDC
void CNtMagickView::DoDisplayImage()
{
CDC *pDC = GetDC();
if (pDC != NULL && m_Image.isValid() )
{
CRect rectClient;
GetClientRect(rectClient);
// Clear the background
pDC->FillSolidRect(rectClient,pDC->GetBkColor());
// Set up the Windows bitmap header
BITMAPINFOHEADER bmi;
bmi.biSize = sizeof(BITMAPINFOHEADER); // Size of structure
bmi.biWidth = m_Image.columns(); // Bitmaps width in pixels
bmi.biHeight = (-1)*m_Image.rows(); // Bitmaps height n pixels
bmi.biPlanes = 1; // Number of planes in the image
bmi.biBitCount = 32; // The number of bits per pixel
bmi.biCompression = BI_RGB; // The type of compression used
bmi.biSizeImage = 0; // The size of the image in bytes
bmi.biXPelsPerMeter = 0; // Horizontal resolution
bmi.biYPelsPerMeter = 0; // Veritical resolution
bmi.biClrUsed = 0; // Number of colors actually used
bmi.biClrImportant = 0; // Colors most important
// Extract the pixels from Magick++ image object and convert to a DIB section
Quantum *pPixels = m_Image.getPixels(0,0,m_Image.columns(),m_Image.rows());
RGBQUAD *prgbaDIB = 0;
HBITMAP hBitmap = CreateDIBSection
(
pDC->m_hDC, // handle to device context
(BITMAPINFO *)&bmi, // pointer to structure containing bitmap size, format, and color data
DIB_RGB_COLORS, // color data type indicator: RGB values or palette indices
(void**)&prgbaDIB, // pointer to variable to receive a pointer to the bitmap's bit values
NULL, // optional handle to a file mapping object
0 // offset to the bitmap bit values within the file mapping object
);
if ( !hBitmap )
return;
unsigned long nPixels = m_Image.columns() * m_Image.rows();
RGBQUAD *pDestPixel = prgbaDIB;
// Transfer pixels, scaling to Quantum
for( unsigned long nPixelCount = nPixels; nPixelCount ; nPixelCount-- )
{
pDestPixel->rgbRed = MagickCore::GetPixelRed(m_Image.constImage(),pPixels)/257;
pDestPixel->rgbGreen = MagickCore::GetPixelGreen(m_Image.constImage(),pPixels)/257;
pDestPixel->rgbBlue = MagickCore::GetPixelBlue(m_Image.constImage(),pPixels)/257;
//.........这里部分代码省略.........
示例13: BitmapToRegion
//
// Since the transparent color for all LiteStep modules should be 0xFF00FF and
// we are going to assume a tolerance of 0x000000, we can ignore the clrTransp
// and clrTolerence parameter and hard code the values for the High and Low RGB
// bytes The orginial code is commented out, if a module needs the removed
// functionality, it should implement this function with the commented out code.
HRGN BitmapToRegion(
HBITMAP hbm,
COLORREF clrTransp, COLORREF clrTolerance,
int xoffset, int yoffset)
{
// start with a completely transparent rgn
// this is more correct as no bmp, should render a transparent background
HRGN hRgn = CreateRectRgn(0, 0, 0, 0);
if (hbm)
{
// create a dc for the 32 bit dib
HDC hdcMem = CreateCompatibleDC(NULL);
if (hdcMem)
{
VOID *pbits32;
HBITMAP hbm32;
BITMAP bm;
// get the size
GetObject(hbm, sizeof(BITMAP), &bm);
BITMAPINFOHEADER bmpInfo32;
bmpInfo32.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo32.biWidth = bm.bmWidth;
bmpInfo32.biHeight = bm.bmHeight;
bmpInfo32.biPlanes = 1;
bmpInfo32.biBitCount = 32;
bmpInfo32.biCompression = BI_RGB;
bmpInfo32.biSizeImage = 0;
bmpInfo32.biXPelsPerMeter = 0;
bmpInfo32.biYPelsPerMeter = 0;
bmpInfo32.biClrUsed = 0;
bmpInfo32.biClrImportant = 0;
hbm32 = CreateDIBSection(hdcMem, (BITMAPINFO*)&bmpInfo32,
DIB_RGB_COLORS, &pbits32, NULL, 0);
if (hbm32)
{
HBITMAP hbmOld32 = (HBITMAP)SelectObject(hdcMem, hbm32);
// Create a DC just to copy the bitmap into the memory D
HDC hdcTmp = CreateCompatibleDC(hdcMem);
if (hdcTmp)
{
// Get how many bytes per row we have for the bitmap bits
// (rounded up to 32 bits)
BITMAP bm32;
GetObject(hbm32, sizeof(bm32), &bm32);
while (bm32.bmWidthBytes % 4)
{
++bm32.bmWidthBytes;
}
#if defined(LS_COMPAT_TRANSPTOL)
// get the limits for the colors
BYTE clrHiR = (0xff - GetRValue(clrTolerance)) > GetRValue(clrTransp) ?
GetRValue(clrTransp) + GetRValue(clrTolerance) : 0xff;
BYTE clrHiG = (0xff - GetGValue(clrTolerance)) > GetGValue(clrTransp) ?
GetGValue(clrTransp) + GetGValue(clrTolerance) : 0xff;
BYTE clrHiB = (0xff - GetBValue(clrTolerance)) > GetBValue(clrTransp) ?
GetBValue(clrTransp) + GetBValue(clrTolerance) : 0xff;
BYTE clrLoR = GetRValue(clrTolerance) < GetRValue(clrTransp) ?
GetRValue(clrTransp) - GetRValue(clrTolerance) : 0x00;
BYTE clrLoG = GetGValue(clrTolerance) < GetGValue(clrTransp) ?
GetGValue(clrTransp) - GetGValue(clrTolerance) : 0x00;
BYTE clrLoB = GetBValue(clrTolerance) < GetBValue(clrTransp) ?
GetBValue(clrTransp) - GetBValue(clrTolerance) : 0x00;
#endif // LS_COMPAT_TRANSPTOL
// Copy the bitmap into the memory D
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcTmp, hbm);
BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight,
hdcTmp, 0, 0, SRCCOPY);
// Scan each bitmap row from bottom to top
// (the bitmap is inverted vertically)
#if defined(LS_COMPAT_TRANSPTOL)
BYTE *p;
#else
DWORD *p;
#endif // LS_COMPAT_TRANSPTOL
BYTE *p32 = (BYTE *)bm32.bmBits + \
(bm32.bmHeight - 1) * bm32.bmWidthBytes;
int y = 0;
while (y < bm.bmHeight)
{
int x = 0, x0;
//.........这里部分代码省略.........
示例14: _get_gphoto2_file_as_DIB
TW_UINT16
_get_gphoto2_file_as_DIB(
const char *folder, const char *filename, CameraFileType type,
HWND hwnd, HBITMAP *hDIB
) {
const unsigned char *filedata;
unsigned long filesize;
int ret;
CameraFile *file;
struct jpeg_source_mgr xjsm;
struct jpeg_decompress_struct jd;
struct jpeg_error_mgr jerr;
HDC dc;
BITMAPINFO bmpInfo;
LPBYTE bits, oldbits;
JSAMPROW samprow, oldsamprow;
if(!libjpeg_handle) {
if(!load_libjpeg()) {
FIXME("Failed reading JPEG because unable to find %s\n", SONAME_LIBJPEG);
filedata = NULL;
return TWRC_FAILURE;
}
}
gp_file_new (&file);
ret = gp_camera_file_get(activeDS.camera, folder, filename, type, file, activeDS.context);
if (ret < GP_OK) {
FIXME("Failed to get file?\n");
gp_file_unref (file);
return TWRC_FAILURE;
}
ret = gp_file_get_data_and_size (file, (const char**)&filedata, &filesize);
if (ret < GP_OK) {
FIXME("Failed to get file data?\n");
return TWRC_FAILURE;
}
/* FIXME: Actually we might get other types than JPEG ... But only handle JPEG for now */
if (filedata[0] != 0xff) {
ERR("File %s/%s might not be JPEG, cannot decode!\n", folder, filename);
}
/* This is basically so we can use in-memory data for jpeg decompression.
* We need to have all the functions.
*/
xjsm.next_input_byte = filedata;
xjsm.bytes_in_buffer = filesize;
xjsm.init_source = _jpeg_init_source;
xjsm.fill_input_buffer = _jpeg_fill_input_buffer;
xjsm.skip_input_data = _jpeg_skip_input_data;
xjsm.resync_to_restart = _jpeg_resync_to_restart;
xjsm.term_source = _jpeg_term_source;
jd.err = pjpeg_std_error(&jerr);
/* jpeg_create_decompress is a macro that expands to jpeg_CreateDecompress - see jpeglib.h
* jpeg_create_decompress(&jd); */
pjpeg_CreateDecompress(&jd, JPEG_LIB_VERSION, (size_t) sizeof(struct jpeg_decompress_struct));
jd.src = &xjsm;
ret=pjpeg_read_header(&jd,TRUE);
jd.out_color_space = JCS_RGB;
pjpeg_start_decompress(&jd);
if (ret != JPEG_HEADER_OK) {
ERR("Jpeg image in stream has bad format, read header returned %d.\n",ret);
gp_file_unref (file);
return TWRC_FAILURE;
}
ZeroMemory (&bmpInfo, sizeof (BITMAPINFO));
bmpInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = jd.output_width;
bmpInfo.bmiHeader.biHeight = -jd.output_height;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = jd.output_components*8;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biSizeImage = 0;
bmpInfo.bmiHeader.biXPelsPerMeter = 0;
bmpInfo.bmiHeader.biYPelsPerMeter = 0;
bmpInfo.bmiHeader.biClrUsed = 0;
bmpInfo.bmiHeader.biClrImportant = 0;
*hDIB = CreateDIBSection ((dc = GetDC(hwnd)), &bmpInfo, DIB_RGB_COLORS, (LPVOID)&bits, 0, 0);
if (!*hDIB) {
FIXME("Failed creating DIB.\n");
gp_file_unref (file);
return TWRC_FAILURE;
}
samprow = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,jd.output_width*jd.output_components);
oldbits = bits;
oldsamprow = samprow;
while ( jd.output_scanline<jd.output_height ) {
int i, x = pjpeg_read_scanlines(&jd,&samprow,1);
if (x != 1) {
FIXME("failed to read current scanline?\n");
break;
}
/* We have to convert from RGB to BGR, see MSDN/ BITMAPINFOHEADER */
for(i=0;i<jd.output_width;i++,samprow+=jd.output_components) {
*(bits++) = *(samprow+2);
*(bits++) = *(samprow+1);
*(bits++) = *(samprow);
//.........这里部分代码省略.........
示例15: create_cgimage_from_icon
/***********************************************************************
* create_cgimage_from_icon
*
* Create a CGImage from a Windows icon.
*/
CGImageRef create_cgimage_from_icon(HANDLE icon, int width, int height)
{
CGImageRef ret = NULL;
HDC hdc;
char buffer[FIELD_OFFSET(BITMAPINFO, bmiColors[256])];
BITMAPINFO *bitmapinfo = (BITMAPINFO*)buffer;
unsigned char *color_bits, *mask_bits;
HBITMAP hbmColor = 0, hbmMask = 0;
int color_size, mask_size;
TRACE("icon %p width %d height %d\n", icon, width, height);
if (!width && !height)
{
ICONINFO info;
BITMAP bm;
if (!GetIconInfo(icon, &info))
return NULL;
GetObjectW(info.hbmMask, sizeof(bm), &bm);
if (!info.hbmColor) bm.bmHeight = max(1, bm.bmHeight / 2);
width = bm.bmWidth;
height = bm.bmHeight;
TRACE("new width %d height %d\n", width, height);
DeleteObject(info.hbmColor);
DeleteObject(info.hbmMask);
}
hdc = CreateCompatibleDC(0);
bitmapinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfo->bmiHeader.biWidth = width;
bitmapinfo->bmiHeader.biHeight = -height;
bitmapinfo->bmiHeader.biPlanes = 1;
bitmapinfo->bmiHeader.biCompression = BI_RGB;
bitmapinfo->bmiHeader.biXPelsPerMeter = 0;
bitmapinfo->bmiHeader.biYPelsPerMeter = 0;
bitmapinfo->bmiHeader.biClrUsed = 0;
bitmapinfo->bmiHeader.biClrImportant = 0;
bitmapinfo->bmiHeader.biBitCount = 32;
color_size = width * height * 4;
bitmapinfo->bmiHeader.biSizeImage = color_size;
hbmColor = CreateDIBSection(hdc, bitmapinfo, DIB_RGB_COLORS, (VOID **) &color_bits, NULL, 0);
if (!hbmColor)
{
WARN("failed to create DIB section for cursor color data\n");
goto cleanup;
}
bitmapinfo->bmiHeader.biBitCount = 1;
bitmapinfo->bmiColors[0].rgbRed = 0;
bitmapinfo->bmiColors[0].rgbGreen = 0;
bitmapinfo->bmiColors[0].rgbBlue = 0;
bitmapinfo->bmiColors[0].rgbReserved = 0;
bitmapinfo->bmiColors[1].rgbRed = 0xff;
bitmapinfo->bmiColors[1].rgbGreen = 0xff;
bitmapinfo->bmiColors[1].rgbBlue = 0xff;
bitmapinfo->bmiColors[1].rgbReserved = 0;
mask_size = ((width + 31) / 32 * 4) * height;
bitmapinfo->bmiHeader.biSizeImage = mask_size;
hbmMask = CreateDIBSection(hdc, bitmapinfo, DIB_RGB_COLORS, (VOID **) &mask_bits, NULL, 0);
if (!hbmMask)
{
WARN("failed to create DIB section for cursor mask data\n");
goto cleanup;
}
ret = create_cgimage_from_icon_bitmaps(hdc, icon, hbmColor, color_bits, color_size, hbmMask,
mask_bits, mask_size, width, height, 0);
cleanup:
if (hbmColor) DeleteObject(hbmColor);
if (hbmMask) DeleteObject(hbmMask);
DeleteDC(hdc);
return ret;
}