示例#1
0
//UINT VPIC_API vpic_WriteTGA(const VPicture & pic,BYTE * pStart,VP_LAYER_INFO * pLayerInfo,UINT uFlags)
BOOL LanImage::SaveTga(LPCTSTR pszFileName) const
{
	CFile file;
	if(FALSE == file.Open(pszFileName,CFile::modeCreate | CFile::modeWrite))
		return FALSE;

	TGAHEAD				th;
	
	TGAFooter			tf;
	tf.ext_area = tf.dev_area = 0;
	strcpy(tf.signature,"TRUEVISION-XFILE");

	memset(&th,0,sizeof(th));
	if(GetBitCount() <= 8)
	{
		th.byPalType = 1;
		th.wPalLength = 1 << GetBitCount();
		th.byPalBits = 32;
		th.byImageType = 1;
	}
	else
		th.byImageType = 2;
	
	th.desc = 0;
	th.wWidth = this->GetWidth();
	th.wHeight = this->GetHeight();
	th.byColorBits = this->GetBitCount();

	// 写文件头
	file.Write(&th,sizeof(th));
	// 写调色板
	if(th.byPalType)
	{
		file.Write(this->GetPalette(),sizeof(RGBQUAD) * (1 << this->GetBitCount()));
	}
	// 写图象数据
	int height = th.wHeight;
	int length = th.wWidth * th.byColorBits / 8;
	
	for(int y=0;y<height;++y)
		file.Write(GetLine(y),length);
	
	// 写信息尾
	file.Write(&tf,sizeof(tf));

	return TRUE;
}
示例#2
0
bool CBitmapShow::InitialBitmap(int width,int height)
{
     if((Width==width)&&(Height==height)) return true;
	 Width=width;
	 Height=height;
	 if(m_lpBitmapInfo!=NULL) GlobalFreePtr(m_lpBitmapInfo);
	 int colors=GetNumberColors();
	 if(colors==0) colors=256;
	 m_lpBitmapInfo = (LPBITMAPINFO) GlobalAllocPtr(GHND,sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * colors);
	 m_lpBitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	 m_lpBitmapInfo->bmiHeader.biWidth = Width;
	 m_lpBitmapInfo->bmiHeader.biHeight = Height;
	 m_lpBitmapInfo->bmiHeader.biCompression=GetCompressionKind();
	 m_lpBitmapInfo->bmiHeader.biSizeImage = 0;
	 m_lpBitmapInfo->bmiHeader.biXPelsPerMeter = 0;
	 m_lpBitmapInfo->bmiHeader.biYPelsPerMeter = 0;
	 m_lpBitmapInfo->bmiHeader.biPlanes = 1;
	 m_lpBitmapInfo->bmiHeader.biBitCount =GetBitCount();
	 m_lpBitmapInfo->bmiHeader.biClrUsed = 0;
	 m_lpBitmapInfo->bmiHeader.biClrImportant = 0;
	 ILineBytes=WIDTHBYTES(Width*GetBitCount());
	 m_lpBitmapInfo->bmiHeader.biSizeImage=ILineBytes*Height;
     for(int k=0;k<colors;k++) m_lpBitmapInfo->bmiColors[k].rgbRed=m_lpBitmapInfo->bmiColors[k].rgbGreen=m_lpBitmapInfo->bmiColors[k].rgbBlue=k;
	 if(!CreateDIBPalette())
	 {
         if(m_lpBitmapInfo!=NULL) GlobalFreePtr(m_lpBitmapInfo);
         m_lpBitmapInfo=NULL;
		 return false;
	 }
	 if(lpDIBBits!=NULL) GlobalFreePtr(lpDIBBits);
     lpDIBBits=NULL;
     lpDIBBits=(unsigned char*)GlobalAllocPtr(GHND,ILineBytes*Height);
	 if(lpDIBBits==NULL)
	 {
         if(m_lpBitmapInfo!=NULL) GlobalFreePtr(m_lpBitmapInfo);
         m_lpBitmapInfo=NULL;
         if(Palette!=NULL) delete Palette;
		 Palette=NULL;
		 return false;
	 }
	 return true;
}
示例#3
0
COLORREF CGetColor::GetPixel(int nXPos, int nYPos)
{
	COLORREF cr = {0};
	RECT rcScreen;
	rcScreen.left = nXPos;
	rcScreen.top = nYPos;
	rcScreen.right = nXPos + 1;
	rcScreen.bottom = nYPos + 1;
	if(CopyScreenToData(&rcScreen))
	{
		BYTE* pData;
		DWORD dwLen;
		GetDataSource(&pData, &dwLen);
		DWORD dwBitCount = GetBitCount();
		DWORD dwPaletteSize = 0;
		if (dwBitCount <= 8) 
			dwPaletteSize = (1 <<  dwBitCount) *  sizeof(RGBQUAD);
		BITMAPFILEHEADER bmpFileHred;
		BITMAPINFOHEADER bi;
		memcpy(&bmpFileHred, pData, sizeof(BITMAPFILEHEADER));
		memcpy(&bi, pData + sizeof(BITMAPFILEHEADER), sizeof(BITMAPINFOHEADER));
		
		if(dwBitCount == 8)
		{
			DWORD DataSizePerLine = ((bi.biWidth * dwBitCount + 31) / 32) * 4;
			BYTE* pColor = pData +  sizeof(BITMAPFILEHEADER) +  sizeof(BITMAPINFOHEADER) + dwPaletteSize + DataSizePerLine * ( bi.biHeight - 1) + 0;
			BYTE bColor; memcpy(&bColor, pColor, sizeof(BYTE));
			int nColor = (int)bColor;
			RGBQUAD rgb;
			memcpy(&rgb, pData +  sizeof(BITMAPFILEHEADER) +  sizeof(BITMAPINFOHEADER) + (sizeof(RGBQUAD)*nColor) , sizeof(RGBQUAD));
			cr = RGB(rgb.rgbRed, rgb.rgbGreen, rgb.rgbBlue);
		}
		if(dwBitCount == 24)
		{
			DWORD DataSizePerLine = ((bi.biWidth * dwBitCount + 31) / 32) * 4;
			BYTE* pColor = pData +  sizeof(BITMAPFILEHEADER) +  sizeof(BITMAPINFOHEADER) + 0 + DataSizePerLine * ( bi.biHeight - 1) + 0;
		//	BYTE bColor; memcpy(&bColor, pColor, sizeof(BYTE));
		//	int nColor = (int)bColor;
			RGBQUAD rgb;
			memcpy(&rgb, pColor , sizeof(RGBQUAD));
			cr = RGB(rgb.rgbRed, rgb.rgbGreen, rgb.rgbBlue);
		}
		LockData(false);
	}
	return cr;
}
示例#4
0
bool CGetScreenInfo::CopyScreenToData(LPRECT lpRect)
{
	if(!m_bIsLock)
	{
		HBITMAP hBitmap;
		hBitmap =  CopyScreenToBitmap(lpRect);
		if(hBitmap)
		{
			WORD dwBitCount = (WORD)GetBitCount();
			_BitmapToData(hBitmap, dwBitCount);
		//	DeleteObject(hBitmap);
			return true;
		}
		else
			return false;
	}
	return false;
}
示例#5
0
/////////////////////////////////////////////////////////////////////////////
// Func. Name : CreateDIBSection
// Parameters :
// Return     :
// Remarks    :
//
void CDibBitmap::CreateDIBSection(CDC* dc,CDibPalette* pal,int xl,int yl,WORD nBitCount)
{ 
	m_nWidth = xl;
	m_nHeight = abs(yl);
	xl = xl + ((xl % 4) ? (4 - xl % 4) : 0);
	if(GetSafeHandle() && GetBitCount() == nBitCount && xl == GetWidth() && abs(yl) == GetHeight())
		return;
	LPBITMAPINFO bitmapInfo = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)+256*sizeof(DWORD)];
	BITMAPINFOHEADER header = { 40,640,-480,1,8,0,0,5904,5904,256,0 };
	header.biBitCount = nBitCount;
	header.biWidth  = xl;
	header.biHeight = -abs(yl);
	memcpy(bitmapInfo,&header,sizeof(header));
	memcpy(&m_infoHeader,&header,sizeof(header));
	LPRGBQUAD pRGB = (RGBQUAD*) ((LPBYTE)bitmapInfo + sizeof(BITMAPINFOHEADER));
	//if(pal)	pal->GetPaletteRGBQuad(0,256,pRGB);
	memset(pRGB,0,256*sizeof(RGBQUAD));
	Attach(::CreateDIBSection(dc->GetSafeHdc(),bitmapInfo,DIB_RGB_COLORS,(void**)&m_pData,NULL,0)); 
	safe_delete( bitmapInfo ); 
}
示例#6
0
// Note we only support 8bpp DIBs here, and..
// there is no regard for color table matching between the DIBs
//************************************************************************
void CDib::DibBlt(PDIB pdibDst, int dstLeft, int dstTop, int dstWidth, int dstHeight,
				  int srcLeft, int srcTop, int srcWidth, int srcHeight,
				  BOOL bTransparent, LPRGBTRIPLE lpRGB, LPTR lpLut, HPALETTE hPal )
//************************************************************************
{
HPTR pSrc, pDst;
int iScanS, iScanD, iOverrun;

if ( !pdibDst )
	return;
if ( GetBitCount() != 8 )
	return;
if ( pdibDst->GetBitCount() != 8 )
	return;

// Check the coordinate bounds, to avoid an out of range pointer
if ( srcLeft < 0 )	{ dstLeft -= srcLeft; srcWidth	+= srcLeft; dstWidth  += srcLeft; srcLeft = 0; }
if ( srcTop	 < 0 )	{ dstTop  -= srcTop;  srcHeight += srcTop;	dstHeight += srcTop;  srcTop  = 0; }
if ( dstLeft < 0 )	{ srcLeft -= dstLeft; srcWidth	+= dstLeft; dstWidth  += dstLeft; dstLeft = 0; }
if ( dstTop	 < 0 )	{ srcTop  -= dstTop;  srcHeight += dstTop;	dstHeight += dstTop;  dstTop  = 0; }

if ( srcWidth <= 0 || srcHeight <= 0 || dstWidth <= 0 || dstHeight <= 0 )
	return;

if ( srcLeft - GetWidth()	   >= 0 )	return;
if ( srcTop	 - abs(GetHeight()) >= 0 )	return;
if ( dstLeft - pdibDst->GetWidth()		   >= 0 )	return;
if ( dstTop	 - abs(pdibDst->GetHeight()) >= 0 ) return;

if ( (iOverrun = srcLeft + srcWidth	 - GetWidth())		> 0 )	{ srcWidth	-= iOverrun; dstWidth  -= iOverrun; }
if ( (iOverrun = srcTop	 + srcHeight - abs(GetHeight())) > 0 )	{ srcHeight -= iOverrun; dstHeight -= iOverrun; }
if ( (iOverrun = dstLeft + dstWidth	 - pdibDst->GetWidth())		> 0 )	{ dstWidth	-= iOverrun; srcWidth  -= iOverrun; }
if ( (iOverrun = dstTop	 + dstHeight - abs(pdibDst->GetHeight())) > 0 ) { dstHeight -= iOverrun; srcHeight -= iOverrun; }

if ( srcWidth <= 0 || srcHeight <= 0 || dstWidth <= 0 || dstHeight <= 0 )
	return;

// Get pointers to the start points in the source and destination
if ( !(pSrc = GetXY( srcLeft, srcTop )) )
	return;
if ( !(pDst = pdibDst->GetXY( dstLeft, dstTop )) )
	return;

// Get the scan line widths of each DIB.
iScanS = GetWidthBytes();
iScanD = pdibDst->GetWidthBytes();

// Upside down DIBs have to move backwards
if ( GetHeight() > 0 )
	 iScanS = -iScanS;
if ( pdibDst->GetHeight() > 0 )
	 iScanD = -iScanD;

if ( !bTransparent )
	{ // Copy the lines.
	while ( --srcHeight >= 0 )
		{
		hmemcpy( pDst, pSrc, srcWidth );
		pSrc += iScanS;
		pDst += iScanD;
		}
	}
else
if (lpRGB)
	{ // Copy lines with transparency mask
	WORD src, dst, wMini;
	BYTE dstPixel, srcColor, red, green, blue;
	int iSinc, iDinc, iCount;
						 
	LPRGBQUAD pTable = GetColors();
	if (lpLut)
		{
		wMini = RGB3toMiniRGB(lpRGB->rgbtRed, lpRGB->rgbtGreen, lpRGB->rgbtBlue);
		srcColor = lpLut[wMini];				
		}
	else
	if (hPal)
		{
		srcColor = (BYTE)GetNearestPaletteIndex( hPal, RGB(lpRGB->rgbtRed, lpRGB->rgbtGreen, lpRGB->rgbtBlue) );
		}
	else
		srcColor = 0;

	iSinc = iScanS - srcWidth; // Source increment value
	iDinc = iScanD - srcWidth; // Destination increment value
	while ( --srcHeight >= 0 )
		{
		iCount = srcWidth;	  // Number of pixels to scan.
		while ( --iCount >= 0 )
			{
			src = (WORD)(*pSrc++);
			// Copy pixel only if it isn't transparent.
			if (src == 0)
				pDst++;
			else
			if (src == 255)
				*pDst++ = srcColor;
			else
				{
				if (src > 127)
					++src;
				dst = 256-src;
				dstPixel = *pDst;
				red = (BYTE)((((WORD)lpRGB->rgbtRed * src) + ((WORD)pTable[dstPixel].rgbRed * dst)) >> 8);
				green = (BYTE)((((WORD)lpRGB->rgbtGreen * src) + ((WORD)pTable[dstPixel].rgbGreen * dst)) >> 8);
				blue = (BYTE)((((WORD)lpRGB->rgbtBlue * src) + ((WORD)pTable[dstPixel].rgbBlue * dst)) >> 8);
				if (lpLut)
					{
					wMini = RGB3toMiniRGB(red, green, blue);
					*pDst++ = lpLut[wMini];					
					}
				else
				if (hPal)
					{
					*pDst++ = (BYTE)GetNearestPaletteIndex( hPal, RGB(red, green, blue) );
					}
				else
					{
					pDst++;
					}
				}
			}

		pSrc += iSinc;
		pDst += iDinc;
		}
	}
else
	{ // Copy lines with transparency.