예제 #1
0
void CVisionTab::updateDepthStream()
{
	if(WAIT_OBJECT_0 == WaitForSingleObject(kinect.m_dFrameReadyEvent, 0))
	{

	if(pBufDepth == NULL && pDepth != NULL) {
		pBufDepth = pDepth->CopyCDib();
		SetEvent(m_GetDimgEvent);
	}

	if(pDepth != NULL) {delete pDepth; pDepth=NULL;}

	CDib *pDibDepth = kinect.getCDibDepthImage()->CopyCDib();
	pDepth = pDibDepth->CopyCDib();
	
	
	if(pDibDepth) {
		// Display update
		if(clip) {
			CDib *pDepth = pDibDepth->ClipCDib(m_ClipRect);	// memory leak when using median filter... 
			m_DispDepth.SetDib(pDepth);

		} else {
			m_DispDepth.SetDib(pDibDepth->CopyCDib());
		}

		delete pDibDepth;
	}

	}
}
void CDib::Copy(const CDib& dib, UINT nBitCount)
{
	if( &dib != this)
	{
		Empty();
		if( !dib.IsNull() )
		{
		
			int height = dib.GetHeight();
			int width = dib.GetWidth();
			Create(width, height, nBitCount);

			if( nBitCount <= 8)
			{
				CPalette palette;
				dib.CreatePaletteFromImage(palette);
				SetPalette( palette );
				//MakePalette();
			}

			for(int i=0; i<width; i++)
			{
				for(int j=0; j<height; j++)
				{
					SetPixel(i,j, dib.GetPixel(i, j) );
				}
			}
		}
	}
}
예제 #3
0
/*
*--------------------------------------------------------------------------------
*  函数名	: MergeDib
*  功能		: 将窗口内的图像与指定图像融合
*  参数		: CDib* pDib	-	画布图像,融合于此DIB之上
*  算法		: 先隐藏按钮,然后将窗口内的图像抓取下来,再将此DIB与参数DIB融合
*--------------------------------------------------------------------------------
*/
BOOL CFloatDibWnd::MergeDib(CDib * pDib)
{	
	CDib* newDib = new CDib();
	
	// 隐藏全部形变按钮
	if(g_createBtn)
    	HideAllButton();

	CRect rcSelf, rcParent;
	GetWindowRect(&rcSelf);
	::GetWindowRect(m_hParentWnd, &rcParent);

	// 抓取浮动窗口客户区图像
	newDib->Create(GetSafeHwnd(), CRect(0, 0, rcSelf.Width(), rcSelf.Height()) );

	// 计算起点座标
	int xStart, yStart;

	// 减 2 是因为边框占两个像素
	xStart = rcSelf.left - rcParent.left - 2;
	yStart = rcSelf.top - rcParent.top - 2;

	pDib->MergeDib(newDib->GetHandle(), CPoint(xStart, yStart));

	delete newDib;
	return TRUE;
}
예제 #4
0
파일: SpermView.cpp 프로젝트: niepp/sperm-x
BOOL CSpermView::WriteImageToDisk(int i, CFile *pFile)
{
	CDib *pDib = new CDib(m_lpBMIH[i], m_lpImage[i]);
	BOOL ret = pDib->SaveDibFile(pFile);
	delete pDib, pDib = NULL;
	return ret;
}
ERMsg CDib::SaveImage(const CString& filePath, REFGUID guidFileType, int bpp)const
{
	ASSERT( guidFileType != GUID_NULL || !UtilWin::GetFileExtension(filePath).IsEmpty() );
	ERMsg message;

	if( bpp == -1)
	{
		bpp = GetBPP();
	}
	else if( bpp != GetBPP())
	{
		CDib dib;
		dib.Copy( *this, bpp);
		return dib.SaveImage(filePath, guidFileType);
	}

	

	if( FAILED(Save(filePath, guidFileType)))
	{
		CString error;
		error.FormatMessage(IDS_BSC_UNABLE_OPEN_WRITE, filePath );
		message.ajoute( UtilWin::ToUTF8(error) );
	}

	return message;
}
VOID CDibUtil::CopyRect(CDib& src, CDib& dest, const CRect rect)
{
	// TODO: The validation of rect in source and destination
	// images should be checked
	for (LONG y = rect.top; y <= rect.bottom; ++y)
		for (LONG x = rect.left; x <= rect.right; ++x)
			dest.WritePixel(x, y, src.GetPixel(x, y));
}
예제 #7
0
파일: SpermView.cpp 프로젝트: niepp/sperm-x
BOOL CSpermView::ReadImageFromDisk(int i, CFile *pFile)
{
     CDib *pDib = new CDib();
	 BOOL ret = pDib->ReadDibFile(pFile);
	 ::NewDIBImage(m_lpBMIH[i], m_lpImage[i], pDib->m_pInfoHeader->biWidth, pDib->m_pInfoHeader->biHeight, 4);
	 memcpy(m_lpBMIH[i], pDib->m_pInfoHeader, sizeof(BITMAPINFOHEADER));
	 delete pDib, pDib = NULL;
	 return ret;
}
VOID CDibUtil::Subtract(CDib& imgA, CDib& imgB, CDib& dest)
{
	dest.CopyDib(&imgA);
	CSize imageSize = imgA.GetDimensions();

	for (LONG y = 0; y != imageSize.cy; ++y)
		for (LONG x = 0; x != imageSize.cx; ++x)
		{
			dest.WritePixel(x, y, RGBSUB(imgA.GetPixel(x, y), imgB.GetPixel(x, y)));
		}
}
예제 #9
0
CDib* CVisionTab::GetDepthClipImage(RECT *pRect)
{
	CDib* pTmp;
	CDib* pDib;
	
	if(WAIT_OBJECT_0 == WaitForSingleObject(m_GetDimgEvent, INFINITE))
		pTmp = GetDepthImage();
	if(pTmp) pDib = pTmp->ClipCDib(pRect);
	delete pTmp; pTmp=NULL;

	return pDib;
}
예제 #10
0
BOOL CGelDoc::LoadSample(LPCTSTR pszFilename)
{
	CFile file;
	CDib* pDib = NULL;

	TRY
	{
		if (!file.Open(pszFilename, CFile::modeRead | CFile::shareDenyNone))
			AfxThrowResourceException();

		pDib = new CDib();
		pDib->LoadDib(&file); // throws
		pDib->DeleteDib();
		delete pDib;
		pDib = NULL;

		// If we got this far, go for the gusto and replace our sample.

		delete m_pUntransformed;
		file.Seek(0L, CFile::begin);
		m_pUntransformed = new CDib(&file);

		delete m_pTransformed;
		file.Seek(0L, CFile::begin);
		m_pTransformed = new CDib(&file);

		delete m_pSelection;
		file.Seek(0L, CFile::begin);
		m_pSelection = new CDib(&file);

		file.Close();
	}
	CATCH_ALL(e)
	{
		if (pDib)
			delete pDib;

		if (file.m_hFile)
			file.Close();

		return FALSE;
	}
	END_CATCH_ALL

	ApplyGel();
	ApplySelection();
	CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
	if (pFrame)
		pFrame->UpdateSample();

	return TRUE;
}
예제 #11
0
void CVisionTab::updateColorStream()
{
	if(WAIT_OBJECT_0 == WaitForSingleObject(kinect.m_cFrameReadyEvent, 0))
	{
	//ResetEvent(m_GetCimgEvent);
	if(pBufColor == NULL && pColor != NULL ) {
		pBufColor = pColor->CopyCDib();
		SetEvent(m_GetCimgEvent);
	}
	
	if(pColor != NULL) {delete pColor; pColor=NULL;}
	

	CDib* temp = kinect.getCDibColorImage();
	if(!temp) return;

	CDib *pDibRGB = temp->CopyCDib();
	//pColor = pDibRGB->CopyCDib();
	pColor = pDibRGB->GetDistortionCorrectedImage(532.45, 531.82, 0, 331.7, 264.18, 0.16657, -0.29178);	// 카메라 렌즈 왜곡 보정 이미지
	
	

	static bool flag = FALSE;
	
	// 처음 한 번만 Global image의 중심 좌표 계산
	if(!flag && pDibRGB) {
		// Image의 중심 좌표
		m_GlobalCenter.x = pDibRGB->Width()/2;
		m_GlobalCenter.y = pDibRGB->Height()/2;

		// Calibration을 통해 구한 Principal point 저장
		//m_GlobalCenter.x = 331;
		//m_GlobalCenter.y = 264;
		flag = TRUE;
	}

	if(pDibRGB) {
		// Display update
		if(clip) {
			// 원본 이미지도 같이 clip 하려면 주석 반대로..
			/*CDib *pRGB = pDibRGB->ClipCDib(m_ClipRect);
			m_DispRGB.SetDib(pRGB);*/

			m_DispRGB.SetDib(pDibRGB->CopyCDib());
			CalcTime();	// Calc FPS
			
		} else {
			m_DispRGB.SetDib(pDibRGB->CopyCDib());
			CalcTime();	// Calc FPS	
		}


		delete pDibRGB;
	}
	
	//SetEvent(m_GetCimgEvent);

	}
}
예제 #12
0
/*
*--------------------------------------------------------------------------------
*  成员函数名   : OnPaint() 
*  功能描述     : 绘制窗体或窗体尺寸发生改变时重画窗体
*  算法			: 透明显示位图,透明色为 g_stuPaintSet.tranCol
*  附加说明		: 窗口缩放时图像并不改变,而是在显示时改变复制位图,然后缩放显示
*--------------------------------------------------------------------------------
*/
void CFloatDibWnd::OnPaint() 
{
	ASSERT(m_pDib);

	CRect rect;
	GetClientRect(&rect);

	// 用当前图像创建一个临时位图,对它进行缩放显示,以防失真
	CDib *pTmpDib = m_pDib->Clone();
	pTmpDib->ChangeImageSize(rect.Width(), rect.Height()); 
	pTmpDib->DisplayTransparent(GetDC(), 0, 0, g_stuPaintSet.tranCol);
	delete pTmpDib;

	CWnd::OnPaint();
}
예제 #13
0
BOOL CDib::GetBitmapDC(LPCSTR filename,HDC screenDC,HDC& hdc)
{
	CDib dib;
	LPCDibinfo bit;

	bit = dib.GetBitmap(filename);
	hdc = CreateCompatibleDC(screenDC);
	HBITMAP bitmap = CreateCompatibleBitmap(screenDC,bit->DI_Width,bit->DI_Height);
	SelectObject(hdc,bitmap);
	SetDIBitsToDevice(hdc,0,0,bit->DI_Width,bit->DI_Height,0,0,0,bit->DI_Height,bit->DI_Bitmap,bit->DI_BitmapInfo,DIB_RGB_COLORS);
	DeleteObject(bitmap);
	bit->DI_Release();

	return TRUE;
}
VOID CDibUtil::Graying(CDib& src, CDib& dest)
{
	dest.CopyDib(&src);
	CSize imageSize = src.GetDimensions();

	RGBQUAD color;
	for (LONG y = 0; y != imageSize.cy; ++y)
		for (LONG x = 0; x != imageSize.cx; ++x)
		{
			color = src.GetPixel(x, y);
			color.rgbRed = color.rgbGreen = color.rgbBlue
				= GRAYING(color.rgbRed, color.rgbGreen, color.rgbBlue);
			dest.WritePixel(x, y, color);
		}
}
VOID CDibUtil::Binaryzation(CDib& src, CDib& dest, BYTE threshold)
{
	dest.CopyDib(&src);
	CSize imageSize = src.GetDimensions();
	
	RGBQUAD color;
	for (LONG y = 0; y != imageSize.cy; ++y)
		for (LONG x = 0; x != imageSize.cx; ++x)
		{
			color = src.GetPixel(x, y);
			color.rgbRed = color.rgbGreen = color.rgbBlue
				= (GRAYING(color.rgbRed, color.rgbGreen, color.rgbBlue) < threshold) ? 0x00 : 0xFF;
			dest.WritePixel(x, y, color);
		}
}
예제 #16
0
void CDibMgr::RemoveAllDibs()
{
	// Delete all dibs from our collection...

	POSITION pos = m_collDibs.GetHeadPosition();

	while (pos)
	{
		CDib* pDib = (CDib*)m_collDibs.GetNext(pos);
		ASSERT(pDib && pDib->IsValid());

		delete pDib;
	}

	m_collDibs.RemoveAll();
}
예제 #17
0
CDib* CDibMgr::AddDib(const char* sFile, DWORD flags)
{
	// Sanity checks...

	ASSERT(IsValid());
	ASSERT(sFile);


	// Get an hDC to our window...

	HDC hDC = GetDC(FALSE);


	// Set the global hInst in case we are trying to load a res...

	s_hInst = m_hInst;


	// Create and init a new dib...

	CDib* pDib = new CDib();

	if (!pDib->Init(sFile, hDC, flags))
	{
		ReleaseDC(hDC);
		delete pDib;
		return(NULL);
	}


	// Add the new dib to our collection...

	POSITION pos = m_collDibs.AddTail(pDib);

	pDib->SetPos(pos);


	// Clean up...

	ReleaseDC(hDC);


	// All done...

	return(pDib);
}
VOID CDibUtil::Translation(CDib& src, CDib& dest, CPoint& translation)
{
	CSize imageSize = src.GetDimensions();

	ASSERT(imageSize.cx + translation.x >= 0);
	ASSERT(imageSize.cy + translation.y >= 0);
	dest.CreateCDib(CSize(imageSize.cx + translation.x, imageSize.cy + translation.y),
		src.m_lpBMIH->biBitCount);

	for (LONG y = 0, dy = translation.y; y != imageSize.cy; ++y, dy = y + translation.y)
		for (LONG x = 0, dx = translation.x; x != imageSize.cx; ++x, dx = x + translation.x)
		{
			if (dy >= 0 && dx >= 0)
			{
				dest.WritePixel(dx, dy, src.GetPixel(x, y));
			}
		}
}
BOOL CDibUtil::ReadImage(CFile& file, CDib& cdib)
{
	if(!cdib.Read(&file))
		return FALSE;

	if (cdib.m_lpBMIH->biCompression != BI_RGB)
		return FALSE;

	return TRUE;
}
예제 #20
0
CDib* CDibMgr::AddDib(BYTE* pBytes, int type, DWORD flags)
{
	// Sanity checks...

	ASSERT(IsValid());
	ASSERT(pBytes);


	// Get an hDC to our window...

	HDC hDC = GetDC(FALSE);


	// Create and init a new dib...

	CDib* pDib = new CDib();

	if (!pDib->Init(pBytes, type, hDC, flags))
	{
		ReleaseDC(hDC);
		delete pDib;
		return(NULL);
	}


	// Add the new dib to our collection...

	POSITION pos = m_collDibs.AddTail(pDib);

	pDib->SetPos(pos);


	// Clean up...

	ReleaseDC(hDC);


	// All done...

	return(pDib);
}
예제 #21
0
/////////////////////////////////////////////////////////////////////////////
// 创建窗口
/////////////////////////////////////////////////////////////////////////////
BOOL CSplashWnd::Create(CWnd* pParentWnd /*= NULL*/)
{
	CDib	ShowDib;
	CString	FileInput;
	BOOL	bFlag;
	bFlag=TRUE;
	FileInput = theApp.m_xmlPlat.GetNodeText("application\\Splash");
	if(FileInput!="") {
		FileInput = theApp.GetPlatRootPath() + FileInput;
		CFile	fileRead;
		bFlag=fileRead.Open(FileInput,CFile::modeRead);
		if(bFlag)
		{
			ShowDib.Read(&fileRead);
			fileRead.Close();

			HDC		hDC=::GetDC(NULL);
			CDC *pDC=CDC::FromHandle(hDC);
			CSize bmSize;
			HBITMAP	hBmp;
			hBmp=ShowDib.MakeHBitmap(pDC,bmSize);
			::ReleaseDC(NULL,hDC);
			m_bitmap.Attach(hBmp);
		}
	}
	else
		bFlag=FALSE;

	if(!bFlag){
		//if (!m_bitmap.LoadBitmap(IDB_SPLASH))
			return FALSE;
	}

	BITMAP bm;
	m_bitmap.GetBitmap(&bm);

	return CreateEx(0,
		AfxRegisterWndClass(0, AfxGetApp()->LoadStandardCursor(IDC_ARROW)),
		NULL, WS_POPUP | WS_VISIBLE, 0, 0, bm.bmWidth, bm.bmHeight, pParentWnd->GetSafeHwnd(), NULL);
}
/*
 * See http://www.leunen.com/cbuilder/rotbmp.html
 */
VOID CDibUtil::Rotation(CDib& src, CDib& dest, DOUBLE angle)
{
	CSize imageSize = src.GetDimensions();
	LONG width = imageSize.cx;
	LONG height = imageSize.cy;

	// Convert angle to radians
	FLOAT radians = (FLOAT)(angle * M_PI / 180.0);
	FLOAT cosine = (FLOAT)cos(radians);
	FLOAT sine = (FLOAT)sin(radians);
	
	// Compute dimensions of the resulting bitmap
	// First get the coordinates of the 3 corners other than origin
	FLOAT x1 = (-height * sine);
	FLOAT y1 = ( height * cosine);
	FLOAT x2 = ( width  * cosine - height * sine);
	FLOAT y2 = ( height * cosine + width * sine);
	FLOAT x3 = ( width  * cosine);
	FLOAT y3 = ( width  * sine);
	
	FLOAT minx = min(0, min(x1, min(x2, x3)));
	FLOAT miny = min(0, min(y1, min(y2, y3)));
	FLOAT maxx = max(x1, max(x2, x3));
	FLOAT maxy = max(y1, max(y2, y3));
	
	LONG newWidth = (LONG)ceil(fabs(maxx) - minx);
	LONG newHeight = (LONG)ceil(fabs(maxy) - miny);

	dest.CreateCDib(CSize(newWidth, newHeight), src.m_lpBMIH->biBitCount);

	LONG sx, sy;
	for(LONG y = 0; y < newHeight; ++y )
		for(LONG x = 0; x < newWidth; ++x )
		{
			sx = (LONG)((x + minx) * cosine + (y + miny) * sine);
			sy = (LONG)((y + miny) * cosine - (x + minx) * sine);
			if( sx >= 0 && sx < width && sy >= 0 && sy < height )
				dest.WritePixel(x, y, src.GetPixel(sx, sy));
		}
}
예제 #23
0
CDib* CDibMgr::AddDib( CDib *pOriginalDib, CDibPal *pPal )
{
	ASSERT( IsValid() );
	ASSERT( pOriginalDib->GetDepth() == 8 );

	
	HDC		hDC = GetDC( FALSE );
	
	CDib	*pDib = new CDib();
	if( !pDib->Init(hDC, pOriginalDib, pPal) )
	{
		ReleaseDC( hDC );
		delete pDib;
		return NULL;
	}

	POSITION pos = m_collDibs.AddTail(pDib);
	pDib->SetPos(pos);

	ReleaseDC( hDC );

	return pDib;
}
VOID CDibUtil::RandomPixels(CDib& src, CDib& dest, LONG count)
{
	dest.CopyDib(&src);
	CSize imageSize = src.GetDimensions();
	
	srand( (UINT)time( NULL ) );
	
	RGBQUAD color;
	LONG x, y;
	for (LONG i = 0; i != count; ++i)
	{
		// Random color
		color.rgbRed = (BYTE)((DOUBLE)rand() / (RAND_MAX + 1) * 255);
		color.rgbGreen = (BYTE)((DOUBLE)rand() / (RAND_MAX + 1) * 255);
		color.rgbBlue = (BYTE)((DOUBLE)rand() / (RAND_MAX + 1) * 255);
		
		// Random position
		x = (LONG)((DOUBLE)rand() / (RAND_MAX + 1) * imageSize.cx);
		y = (LONG)((DOUBLE)rand() / (RAND_MAX + 1) * imageSize.cy);
		
		// Write
		dest.WritePixel(x, y, color);
	}
}
예제 #25
0
파일: Jpeg.cpp 프로젝트: chinalufei/Red
// save Jpeg file
BOOL CJpeg::Save(LPCSTR lpstrFileName, CDib* pDib, BOOL bColor, int nQuality)
{
	if (pDib == NULL)
		pDib = m_pDib;
	if (pDib == NULL)
		return FALSE;

	HDIB hDib = CopyHandle(pDib->GetHandle());
	if (hDib == NULL)
		return FALSE;

	CDib* pDibTmp = new CDib;
	pDibTmp->Attach(hDib);

	if (pDibTmp->GetBitCount() != 24)
		pDibTmp->ConvertFormat(24);

	UINT uWidth  = pDibTmp->GetWidth();
	UINT uHeight = pDibTmp->GetHeight();

	// convert from DIB format (DWORD aligned, vertically flipped, red and blue swapped)
	BYTE* tmp = ClearDwordAlign(pDibTmp->GetBitsPtr(),
									uWidth,
									WIDTHBYTES(uWidth * 24),
									uHeight);
	if (tmp == NULL)
		return FALSE;

	// convert from DIB
	VertFlipBuf(tmp, uWidth*3, uHeight);

	BGRFromRGB(tmp, uWidth, uHeight);

	BOOL bSuccess = WriteJPEGFile(lpstrFileName,
							tmp,
							uWidth, 
							uHeight,
							bColor,
							nQuality);

	delete pDibTmp;
	FreeBuffer(tmp);

	return bSuccess;
}
예제 #26
0
CDib::CDib(const CDib& dib,CRect rect)
//copy area of interest from dib
{
    int headerSize = sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*dib.m_nColorTableEntries;
    //copy header
    m_lpBMIH = (LPBITMAPINFOHEADER) new char[headerSize];
    memcpy(m_lpBMIH,dib.m_lpBMIH,headerSize);
	//correct size
	m_lpBMIH->biWidth=rect.Width();
	m_lpBMIH->biHeight=rect.Height();
	m_lpBMIH->biSizeImage = 0;
    //compute member variables
    ComputeMetrics();
    ComputePaletteSize(dib.m_lpBMIH->biBitCount);
    MakePalette();
	m_pntOrigo = CPoint(0,0);	//default origo
    //copy bits
    m_lpImage = (LPBYTE)new char[m_dwSizeImage];
	for(int y=rect.top; y<=rect.bottom; y++){
		for(int x=rect.left; x<=rect.right; x++){
			SetPixel(CPoint(x-rect.left,y-rect.top),dib.GetPixel(CPoint(x,y)));
		}
	}
}
예제 #27
0
파일: ImagePcx.cpp 프로젝트: chinalufei/Red
//******************* 保存为PCX (由CDib对象) ***********************
BOOL LanImage::SavePcx(LPCTSTR lpstrFileName, CDib* pDib)
{
    int i = 0;
	if (pDib == NULL)
		return FALSE;

	HDIB hDib = CopyHandle(pDib->GetHandle());
	if (hDib == NULL)
		return FALSE;

	CDib* pDibTmp = new CDib();
	pDibTmp->Attach(hDib);

	UINT uWidth  = pDibTmp->GetWidth();
	UINT uHeight = pDibTmp->GetHeight();

	// 当打开的图像BitCount不为8时,转为8位格式
	if (pDibTmp->GetBitCount() != 8)
		pDibTmp->ConvertFormat(8);

	// make PCX header
	PCXHEAD header;
	memset((LPBYTE)&header, 0, sizeof(PCXHEAD));
	header.manufacturer = 0x0A;
	header.version = 5;
	header.encoding = 1;
	header.bit_per_pixel = 8;
	//header.bit_per_pixel = 24;
	header.xmin = 0;
	header.ymin = 0;
	header.xmax = uWidth-1;
	header.ymax = uHeight-1;
	//header.Xresolution;
	//header.Yresolution;
	header.palette[0] = (BYTE)0x00;  // for correct process for mono
	header.palette[1] = (BYTE)0x00;
	header.palette[2] = (BYTE)0x00;
	header.palette[3] = (BYTE)0xff;
	header.palette[4] = (BYTE)0xff;
	header.palette[5] = (BYTE)0xff;
	//header.palette[48];
	header.reserved = 0;
	header.color_planes = 1;
	header.byte_per_line = uWidth;
	header.palette_type = 1;
	//filler[58];

	// construct PCX palette from DIB color table
	PCXPALETTE palette[256];
	PALETTEENTRY PaletteColors[256];
	pDibTmp->GetPalette()->GetPaletteEntries(0, 256, PaletteColors);
	for (i=0;i<256;i++) 
	{
		palette[i].rgbRed   = PaletteColors[i].peRed;
		palette[i].rgbGreen = PaletteColors[i].peGreen;
		palette[i].rgbBlue  = PaletteColors[i].peBlue;
	}

	// get bits ptr
	HDIB hDIB = CopyHandle(pDibTmp->GetHandle());
	delete pDibTmp;
	LPBYTE lpDIB = (LPBYTE)GlobalLock(hDIB);
	BYTE* lpBuffer = (BYTE *)FindDIBBits(lpDIB);
	WORD wWidthBytes = (WORD)BytesPerLine(lpDIB);

	/*** Open the PCX file ***/
	FILE *outFile;
	if ((outFile=fopen(lpstrFileName,"wb")) == NULL)
	{
		GlobalUnlock(hDIB);
		GlobalFree(hDIB);
		return FALSE;
	}

	/*** Write the header ***/
	fwrite((char *)&header, sizeof(PCXHEAD), 1, outFile);

	/*** Write image data ***/
	for ( i=(int)uHeight-1; i>=0; --i)
	{
		if (! WritePCXLine(header.byte_per_line, lpBuffer+i*wWidthBytes, outFile))
		{
			fclose(outFile);
			GlobalUnlock(hDIB);
			GlobalFree(hDIB);
			return FALSE;
		}
	}

	/*** Write the palette data ***/
	fputc(0x0c, outFile);
	fwrite((char *)palette, 1, sizeof(palette), outFile);

	// clear & close
	fclose(outFile);
	GlobalUnlock(hDIB);
	GlobalFree(hDIB);

	return TRUE;
}
예제 #28
0
bool DecodeBMP(CDataSourceABC &ds, CFrameArray &arrFrames, SIZE &size )
{
    // Attempt to read and verify the signature by reading the file header
    BITMAPFILEHEADER bmf;
    BITMAPINFOHEADER infoHeader;
    DWORD offBits = 0;
    DWORD headerSize;
    bool isCoreFile;
    CDib* pDib = 0;

    try {
        if ( !ds.ReadBytes((BYTE*)&bmf, sizeof(BITMAPFILEHEADER)) )
            throw 1;

        // Determine if it has a BITMAPFILEHEADER
        if (bmf.bfType != 0x4d42)
        {
            ds.Reset();
        }
        else
        {
            // Save offset from file header, if it makes sense
            if (bmf.bfOffBits)
                offBits = bmf.bfOffBits - sizeof(BITMAPFILEHEADER);
        }

        // Read the header size, and validate
        if ( !ds.ReadBytes((BYTE*)&headerSize, sizeof(DWORD)) ||
                (headerSize != sizeof(BITMAPINFOHEADER) &&
                 headerSize != sizeof(BITMAPCOREHEADER) ) )
            throw 1;

        isCoreFile = (headerSize == sizeof(BITMAPCOREHEADER));

        // Prepare the header structure, correcting possible errors in the file
        infoHeader.biSize = sizeof(BITMAPINFOHEADER);

        // If its a core bitmap, convert the header
        if (isCoreFile)
        {
            BITMAPCOREHEADER coreHeader;
            if ( !ds.ReadBytes((BYTE*)&coreHeader.bcWidth, sizeof(BITMAPCOREHEADER) - sizeof(DWORD)) )
                throw 1;
            ConvertCoreHeader(&coreHeader, &infoHeader);
        }
        else
        {
            if( !ds.ReadBytes((BYTE*)&infoHeader.biWidth,
                              sizeof(BITMAPINFOHEADER) - sizeof(DWORD)) )
                throw 1;
        }

        pDib = new CDib(&infoHeader);

        // Read the masks
        if (pDib->GetMaskTable())
        {
            if ( !ds.ReadBytes((BYTE*)pDib->GetMaskTable(), 3 * sizeof(DWORD)) )
                throw 1;
        }

        // Calculate number of colors in color table
        if (pDib->GetColorTable())
        {
            int colors = pDib->GetColorsUsed();
            // Calculate size of color table to read
            int colorsize = colors *
                            ( isCoreFile ? sizeof(RGBTRIPLE) : sizeof(RGBQUAD));

            if ( !ds.ReadBytes((BYTE*)pDib->GetColorTable(), colorsize) )
                throw 1;
            if (isCoreFile)
                ConvertCoreColors(pDib->GetColorTable(), colors);
        }
        // Skip bits if necessary
        DWORD curPos = ds.GetCurrentPos();
        if (offBits && (DWORD)offBits > curPos)
            ds.SetRelativePos(offBits - curPos);

        if ( !ds.ReadBytes(pDib->GetBits(), pDib->GetAllocatedImageSize()) )
            throw 1;
        size.cx = pDib->GetWidth();
        size.cy = pDib->GetHeight();
        CFrame *pFrame = new CFrame( pDib, 0 );
        arrFrames.Add( pFrame );
    }
    catch (...)
    {
        if( pDib )
        {
            delete pDib;
            pDib = NULL;
        }
    }

    if( pDib )
        return true;
    return false;
}
예제 #29
0
void CPluginTestDlg::OnAcquire() 
{
	int iListIndex = m_listPlugins.GetCurSel();
	if ( iListIndex == LB_ERR )
		return;

	// Find the plugin that matches the command ID from the plugin list
	LPADOBEPLUGIN lpPlugin = m_lpPluginList;
	while (lpPlugin)
	{
		if ( lpPlugin->iListIndex == iListIndex )
			break;
		lpPlugin = lpPlugin->lpNext;
	}

	// Get out if you can't find it
	if ( !lpPlugin )
		return;

//j	if ( lpPlugin->piType != PIT_ACQUIRE )
//j		return;

	// Load the acquisition DLL
	HMODULE hModule;
	if ( !( hModule = LoadLibrary(lpPlugin->szFileName)))
		return;

	CWnd* hFocus = GetFocus();

	bool bDone = false;
	m_bAborted = false;

	// Get the entry point into the DLL
	LPACQUIREENTRYPROC lpEntryPoint;
	if (!(lpEntryPoint = (LPACQUIREENTRYPROC)GetProcAddress( hModule,
		(lpPlugin->bOldStyle ? "ENTRYPOINT1" : "ENTRYPOINT") )))
		goto BadStart;

	// Set the FilterRecord Info
	PlatformData MyPlatformData;
	memset(&MyPlatformData, 0, sizeof(MyPlatformData));
	MyPlatformData.hwnd = (long)GetSafeHwnd();

	BufferProcs MyBufferProcs;
	memset(&MyBufferProcs, 0, sizeof(MyBufferProcs));
	MyBufferProcs.bufferProcsVersion = kCurrentBufferProcsVersion;
	MyBufferProcs.numBufferProcs = kCurrentBufferProcsCount;
	MyBufferProcs.allocateProc = MyAllocateBufferProc;
	MyBufferProcs.lockProc = MyLockBufferProc;
	MyBufferProcs.unlockProc = MyUnlockBufferProc;
	MyBufferProcs.freeProc = MyFreeBufferProc;
	MyBufferProcs.spaceProc = MyBufferSpaceProc;

	AcquireRecord Record;
	memset(&Record, 0, sizeof(Record));
	Record.abortProc       = MyAbortProc;
	Record.progressProc    = MyProgressProc;
	Record.maxData         = MyBufferSpaceProc();
	Record.planeMap[0]     = 0;
	Record.planeMap[1]     = 1;
	Record.planeMap[2]     = 2;
	Record.planeMap[3]     = 3;
	Record.platformData    = &MyPlatformData;
	Record.canTranspose    = false;
	Record.needTranspose   = false;
	Record.canReadBack     = false;
	Record.canFinalize	   = true;
	Record.diskSpace       = -1;
	Record.spaceProc       = NULL;
	Record.bufferProcs     = NULL; //j &MyBufferProcs;
	Record.resourceProcs   = NULL;
	Record.processEvent    = NULL;
	Record.displayPixels   = MyDisplayPixelsProc;
	Record.handleProcs     = NULL;
	Record.hostProc	       = NULL;	// Host specific callback procedure
	Record.hostModes	   = (1<<plugInModeRGBColor);

	Record.hostSig         =
		( long )'M' << 24 | ( long )'C' << 16 | ( long )'O' << 8 | ( long )'S';

//j	Record.monitor.gamma   = 65536L;
//j	Record.monitor.redX    = 40960L;
//j	Record.monitor.redY    = 22282L;
//j	Record.monitor.greenX  = 18350L;
//j	Record.monitor.greenY  = 38993L;
//j	Record.monitor.blueX   = 10158L;
//j	Record.monitor.blueY   = 4587L;
//j	Record.monitor.whiteX  = 20493L;
//j	Record.monitor.whiteY  = 21561L;
//j	Record.monitor.ambient = 32768L;

	LPLONG lpData;
	lpData = &lpPlugin->lData;
	short sErrCode;
	sErrCode = true;

	// The acquireSelectorPrepare function sets up the acquire operation.
	try
	{
		(*lpEntryPoint)( (short)acquireSelectorPrepare, (AcquireRecordPtr FAR)&Record, (long* FAR)lpData, (short* FAR)&sErrCode );
	}
	catch(...)
	{
		sErrCode = true;
	}

	if ( sErrCode )
	{
		m_bAborted = true;
		goto BadStart;
	}

	// The acquireSelectorStart function informs the host of the image type, 
	// mode, and resolution. Plugin dialogs are displayed during this call. 
	try
	{
		(*lpEntryPoint)( (short)acquireSelectorStart, (AcquireRecordPtr FAR)&Record, (long* FAR)lpData, (short* FAR)&sErrCode );
	}
	catch(...)
	{
		sErrCode = true;
	}

	if ( sErrCode )
	{
		m_bAborted = true;
	}

	bool bRGBColor;
	bRGBColor = (Record.depth == 8 && Record.planes == 3);
	if ( !bRGBColor || Record.imageMode != plugInModeRGBColor )
	{
		m_bAborted = true;
	}

	// Only support chunky data
	if ( Record.planeBytes != 1 || Record.colBytes != Record.planes )
	{
		m_bAborted = true;
	}

	// Create a DIB to catch the image data
	CDib* pDib;
	if (pDib = new CDib())
	{
		pDib->Create(8 * Record.planes, Record.imageSize.h, Record.imageSize.v);
	}
	else
	{
		m_bAborted = true;
	}

	// Create a progress dialog
	if (CPluginTestDlg::pProgressDlg = new CProgressDlg)
	{
		CPluginTestDlg::pProgressDlg->Create(this);
		CPluginTestDlg::pProgressDlg->SetStatus((const char*)Record.filename);
		CPluginTestDlg::pProgressDlg->SetStep(1);
	}

	// start the processing of the data
	while ( !bDone && !m_bAborted )
	{
		// The acquireSelectorContinue function returns an area of the image to the host.
		try
		{
			(*lpEntryPoint)( (short)acquireSelectorContinue, (AcquireRecordPtr FAR)&Record, (long* FAR)lpData, (short* FAR)&sErrCode );
		}
		catch(...)
		{
			sErrCode = true;
		}

		if ( sErrCode )
		{
			m_bAborted = true;
			break;
		}

		if ( !Record.data )  // no more data
		{
			bDone = true;
			break;
		}

		if (pDib)
		{
			long lRowBytes;
			if ( Record.rowBytes < 1 )
				lRowBytes = ( Record.theRect.right - Record.theRect.left ) * Record.planes; 
			else
				lRowBytes = Record.rowBytes;

			// Write the data into the DIB
			HPTR pData;
			pData = (HPTR)Record.data;
			for (int y=Record.theRect.top; y<Record.theRect.bottom; y++)
			{ 
					HPTR pRow = pDib->GetXY(Record.theRect.left, y);
					if (pRow)
						memcpy(pRow, pData, lRowBytes);
					pData += lRowBytes;
			} //j watch: Record.theRect, Record.loPlane, Record.hiPlane
		}
	}

	if (CPluginTestDlg::pProgressDlg)
		delete pProgressDlg;

	if (pDib)
	{
		pDib->WriteFile("c:\\windows\\desktop\\test.dib");
		delete pDib;
	}

	// The acquireSelectorFinish function must be called when exiting at any 
	// point after acquireSelectorStart is called without error.
	try
	{
		(*lpEntryPoint)( (short)acquireSelectorFinish, (AcquireRecordPtr FAR)&Record, (long* FAR)lpData, (short* FAR)&sErrCode );
	}
	catch(...)
	{
		sErrCode = true;
	}

	if ( sErrCode )
		m_bAborted = true;

	// The acquireSelectorFinalize function must be called if asked for
	if (Record.wantFinalize)
	{
		try
		{
			(*lpEntryPoint)( (short)acquireSelectorFinalize, (AcquireRecordPtr FAR)&Record, (long* FAR)lpData, (short* FAR)&sErrCode );
		}
		catch(...)
		{
			sErrCode = true;
		}
	
		if ( sErrCode )
			m_bAborted = true;
	}

	BadStart:

	if ( hModule )
		FreeLibrary( hModule );

	if ( hFocus )
		hFocus->SetFocus();
}
예제 #30
0
CDib::CDib(const CDib& in)
{
	Copy(in, in.GetBPP());
}