⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cegdiobject.cpp

📁 This software which draw graph on the windows ce.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	if( !m_pBitmapBuffer ) 
	{
		bReturn = FALSE;
		goto Exit;
	}

    /* Warning : Does not support 8 byte color model in here */
	for( nY = 0; nY < Bitmap.bmHeight ; nY ++ )
	{
		for( nX = 0; nX < Bitmap.bmWidth ; nX ++ )
		{

			nColor = pCEDraw->GetBitmapPointColor( ( pBuffer +  ( nX ) * 3 +
											               ( Bitmap.bmHeight - nY - 1 ) * 
											                 nBitmapYPitch ) );
			if( cByte == 2 )
				*(unsigned short*)( m_pBitmapBuffer + ( nX + nY * Bitmap.bmWidth ) * cByte ) = nColor;
			else *( m_pBitmapBuffer + ( nX + nY * Bitmap.bmWidth ) * cByte ) = (BYTE)nColor;
				
		}
	}

	// Restore device contexts
Exit:
	::SelectObject( memDc, hOldBitmap1 );
	::SelectObject( targetDc, hOldBitmap2 );
	DeleteDC( memDc );
	DeleteDC( targetDc );
	DeleteObject( hBitmap );
	DeleteObject( hTargetBitmap );
	return bReturn;
}

//
// Function : BitBlt()
// Transfers pixels from a specified source rectangle to a specified destination rectangle
//
BOOL CCEBitmap::BitBlt( CCEDraw* pCEDraw, int nXDest, int nYDest, int nWidth, int nHeight, int nXSrc, int nYSrc, DWORD dwRop, float fAlpha )
{
	if( NULL == pCEDraw || NULL == m_pBitmapBuffer ) return FALSE;
	unsigned char* pBuffer = pCEDraw->GetBuffer();
	unsigned char* pBitmap = m_pBitmapBuffer;
	long cbxPitch = pCEDraw->m_cbxPitch;
	long cbyPitch = pCEDraw->m_cbyPitch;
	long cbxBmpPitch = pCEDraw->GetDisplayProperties().cBPP / 8;
	long cbyBmpPitch = cbxBmpPitch * m_sizeBitmap.cx;
	long cBPP = pCEDraw->GetDisplayProperties().cBPP;
	
	// The buffer type is screenbuffer, so...
	if( m_nType == CEB_TYPE_SCREENBUFFER  )
	{
		//cbxBmpPitch = cbxPitch;
		//cbyBmpPitch = cbyPitch;
		if( dwRop == SRCCOPY )
			memcpy( pCEDraw->GetBuffer(), m_pBitmapBuffer, m_sizeBitmap.cx * m_sizeBitmap.cy * pCEDraw->GetDisplayProperties().cBPP / 8 );
		else return FALSE;
	}

	nWidth == 0 ? nWidth = m_sizeBitmap.cx : nWidth;
	nHeight == 0 ? nHeight = m_sizeBitmap.cy : nHeight;

    if( ( nXSrc + nWidth ) > m_sizeBitmap.cx ) nWidth = m_sizeBitmap.cx - nXSrc;
	if( ( nYSrc + nHeight ) > m_sizeBitmap.cy ) nHeight = m_sizeBitmap.cy - nYSrc;
	
	if( ( nXDest + nWidth ) > (LONG)pCEDraw->GetDisplayProperties().cxWidth )
		nWidth = pCEDraw->GetDisplayProperties().cxWidth - nXDest;
	if( ( nYDest + nHeight ) > (LONG)pCEDraw->GetDisplayProperties().cyHeight )
		nHeight = pCEDraw->GetDisplayProperties().cyHeight - nYDest;

	if( pCEDraw->IsPointOutside( nXDest, nYDest ) && 
		pCEDraw->IsPointOutside( nXDest + nWidth, nYDest + nHeight ) &&
		pCEDraw->IsPointOutside( nXDest + nWidth, nYDest ) &&
		pCEDraw->IsPointOutside( nXDest, nYDest + nHeight ) ) return TRUE; // Not need to draw the bitmap;

	// Prepare the buffer pointer...
	pBuffer += nXDest * cbxPitch + nYDest * cbyPitch;
	pBitmap += nXSrc * cbxBmpPitch + nYSrc * cbyBmpPitch;

	// Copy the buffer data ...
	
	unsigned char* pHeadBuffer = pBuffer;
	unsigned char* pHeadBmpBuffer = pBitmap;
	unsigned short ColorR, ColorG, ColorB, Color;
	if( dwRop == SRCCOPY )
	{
		for( int y = 0; y < nHeight; y ++ ) 
		{
			pBuffer = pHeadBuffer;
			pBitmap = pHeadBmpBuffer;
			for( int x = 0; x < nWidth; x ++ ) 
			{
				
				if( cBPP == 8 ) 
				{
					*pBuffer = *pBitmap;
				}
				else 
				{
					*(unsigned short*)pBuffer = *(unsigned short*)pBitmap;
				}
				pBuffer += cbxPitch;
				pBitmap += cbxBmpPitch;
			}
			pHeadBmpBuffer += cbyBmpPitch;
			pHeadBuffer += cbyPitch;
		}
	}
	else if( dwRop == SRCCOLORKEY )
	{	
		// Get the up left color as the colorkey
		unsigned short ColorKey;
		if( cBPP == 8 ) ColorKey = *pHeadBmpBuffer;
		else ColorKey = *(unsigned short*)pHeadBmpBuffer;

		for( int y = 0; y < nHeight; y ++ ) 
		{
			pBuffer = pHeadBuffer;
			pBitmap = pHeadBmpBuffer;
			for( int x = 0; x < nWidth; x ++ ) 
			{
				
				if( cBPP == 8 ) 
				{
					if( *pBitmap != ColorKey ) *pBuffer = *pBitmap;
				}
				else 
				{
					if( *(unsigned short*)pBitmap != ColorKey )
						*(unsigned short*)pBuffer = *(unsigned short*)pBitmap;
				}
				pBuffer += cbxPitch;
				pBitmap += cbxBmpPitch;
			}
			pHeadBmpBuffer += cbyBmpPitch;
			pHeadBuffer += cbyPitch;
		}
	}
	else if ( dwRop == SRCALPHA && fAlpha != 0.5f )
	{
		for( int y = 0; y < nHeight; y ++ ) 
		{
			pBuffer = pHeadBuffer;
			pBitmap = pHeadBmpBuffer;
			for( int x = 0; x < nWidth; x ++ ) 
			{
				
				if( cBPP == 8 ) 
				{
					*pBuffer = *pBitmap;
				}
				else 
				{
					if( pCEDraw->GetDisplayProperties().ffFormat & kfDirect565 )
					{
						/* n% ALPHA */
						Color = *(unsigned short*)pBuffer;
						ColorR = (unsigned short)((Color >> 11) & 0x1f) * ( 1 - fAlpha );
						ColorG = (unsigned short)((Color >> 5) & 0x3f) * ( 1 - fAlpha );
						ColorB = (unsigned short)(Color & 0x1f) * ( 1 - fAlpha );
						Color = *(unsigned short*)pBitmap;
						ColorR = (unsigned short)(((Color >> 11)&0x1f) * fAlpha + ColorR);
						ColorG = (unsigned short)(((Color >> 5)&0x3f) * fAlpha + ColorG);
						ColorB = (unsigned short)((Color & 0x1f)* fAlpha + ColorB);
						Color = (unsigned short)( ( ColorR & 0xff ) << 11 | 
										  ( ColorG & 0xff ) << 5 | 
										  ( ColorB & 0xff ) );
						*(unsigned short*)pBuffer = Color;
					}
					else if( pCEDraw->GetDisplayProperties().ffFormat & kfDirect555 )
					{
							/* n% ALPHA */
						Color = *(unsigned short*)pBuffer;
						ColorR = (unsigned short)((Color >> 10) & 0x1f) * ( 1 - fAlpha );
						ColorG = (unsigned short)((Color >> 5) & 0x1f) * ( 1 - fAlpha );
						ColorB = (unsigned short)(Color & 0x1f) * ( 1 - fAlpha );
						Color = *(unsigned short*)pBitmap;
						ColorR = (unsigned short)(((Color >> 10)&0x1f) * fAlpha + ColorR);
						ColorG = (unsigned short)(((Color >> 5)&0x1f) * fAlpha + ColorG);
						ColorB = (unsigned short)((Color & 0x1f)* fAlpha + ColorB);
						Color = (unsigned short)( ( ColorR & 0xff ) << 10 | 
										  ( ColorG & 0xff ) << 5 | 
										  ( ColorB & 0xff ) );
						*(unsigned short*)pBuffer = Color;
					
					}
					else *(unsigned short*)pBuffer = Color;
				}
				pBuffer += cbxPitch;
				pBitmap += cbxBmpPitch;
			}
			pHeadBmpBuffer += cbyBmpPitch;
			pHeadBuffer += cbyPitch;
		}
	}
	else if ( dwRop == SRCALPHA )
	{
		for( int y = 0; y < nHeight; y ++ ) 
		{
			pBuffer = pHeadBuffer;
			pBitmap = pHeadBmpBuffer;
			for( int x = 0; x < nWidth; x ++ ) 
			{
				
				if( cBPP == 8 ) 
				{
					*pBuffer = *pBitmap;
				}
				else 
				{
					if( pCEDraw->GetDisplayProperties().ffFormat & kfDirect565 )
					{
						Color = *(unsigned short*)pBuffer;
						ColorR = ((Color >> 11)&0x1f)>>1;
						ColorG = ((Color >> 5)&0x3f)>>1;
						ColorB = (Color & 0x1f)>>1;
						Color = *(unsigned short*)pBitmap;
						ColorR = ((Color >> 11)&0x1f)>>1 + ColorR;
						ColorG = ((Color >> 5)&0x3f)>>1 + ColorG;
						ColorB = ((Color & 0x1f))>>1 + ColorB;
						Color = (unsigned short)( ( ColorR & 0xff ) << 11 | 
										  ( ColorG & 0xff ) << 5 | 
										  ( ColorB & 0xff ) );
						*(unsigned short*)pBuffer = Color;
					}
					else *(unsigned short*)pBuffer = Color;
				}
				pBuffer += cbxPitch;
				pBitmap += cbxBmpPitch;
			}
			pHeadBmpBuffer += cbyBmpPitch;
			pHeadBuffer += cbyPitch;
		}
	}

	return TRUE;
}

//
// Function : LoadFile()
// Use the IMGDECMP.DLL to load the image data file...
//
HBITMAP CCEBitmap::LoadFile( LPCTSTR lpszBitmapName )
{
	HBITMAP hBitmap = 0;

	HDC hdc = CreateCompatibleDC(NULL);

	HRESULT hr;
	BYTE    szBuffer[1024] = {0};
	HANDLE hFile = INVALID_HANDLE_VALUE;

	DecompressImageInfo	dii;

	hFile = CreateFile(lpszBitmapName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if (hFile == INVALID_HANDLE_VALUE)
	{
		DeleteDC( hdc );
		return FALSE;
	}

	// Fill in the 'DecompressImageInfo' structure
	dii.dwSize = sizeof( DecompressImageInfo );		// Size of this structure
	dii.pbBuffer = szBuffer;						// Pointer to the buffer to use for data
	dii.dwBufferMax = 1024;							// Size of the buffer
	dii.dwBufferCurrent = 0;						// The amount of data which is current in the buffer
	dii.phBM = &hBitmap;							// Pointer to the bitmap returned (can be NULL)
	dii.ppImageRender = NULL;						// Pointer to an IImageRender object (can be NULL)
	dii.iBitDepth = GetDeviceCaps(hdc,BITSPIXEL);	// Bit depth of the output image
	dii.lParam = ( LPARAM ) hFile;					// User parameter for callback functions
	dii.hdc = hdc;							    	// HDC to use for retrieving palettes
	dii.iScale = 100;   							// Scale factor (1 - 100)
	dii.iMaxWidth = 10000;		        			// Maximum width of the output image
	dii.iMaxHeight = 10000;     					// Maxumum height of the output image
	dii.pfnGetData = GetImageData;					// Callback function to get image data
	dii.pfnImageProgress = ImageProgress;			// Callback function to notify caller of progress decoding the image
	dii.crTransparentOverride = ( UINT ) -1;		// If this color is not (UINT)-1, it will override the
													// transparent color in the image with this color. (GIF ONLY)

	// Process and decompress the image data
	typedef HRESULT (CALLBACK* ULPRET)( DecompressImageInfo*	pParams );

	HINSTANCE       hLib;
    ULPRET          lpfnDLLProc;

    hLib = LoadLibrary ( L"Imgdecmp.dll" );
    if ( hLib )
    {
       lpfnDLLProc = (ULPRET) GetProcAddress ( hLib, L"DecompressImageIndirect" );
       hr = (*lpfnDLLProc) ( &dii );
       FreeLibrary ( hLib );
    }

	// Clean up 
	DeleteDC( hdc );
	CloseHandle( hFile );
	return hBitmap;
}

//
// Function : GetImageData()
// Callback function to load image data...
//
DWORD CALLBACK CCEBitmap::GetImageData(LPSTR szBuffer, DWORD dwBufferMax, LPARAM lParam )
{
	DWORD dwNumberOfBytesRead;

	if ( (HANDLE)lParam == INVALID_HANDLE_VALUE )
		return 0;

	ReadFile( (HANDLE)lParam, szBuffer, dwBufferMax, &dwNumberOfBytesRead, NULL );

	// Return number of bytes read
	return dwNumberOfBytesRead;
}

void CALLBACK CCEBitmap::ImageProgress(IImageRender *pRender, BOOL bComplete, LPARAM lParam )
{
	if( bComplete )
	{
		// (Optional) add code here for completion processing
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -