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

📄 multdocview.cpp

📁 合成4个代表K,C,M,Y通道的BMP位图为打印数据
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MultDocView.cpp : implementation of the CMultDocView class
//

#include "stdafx.h"
#include "MultDoc.h"

#include "MultDocDoc.h"
#include "MultDocView.h"
#include "rip.h"
#include "dib.h"
#include "math.h"
#include "Inkdlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMultDocView

IMPLEMENT_DYNCREATE(CMultDocView, CView)

BEGIN_MESSAGE_MAP(CMultDocView, CView)
	//{{AFX_MSG_MAP(CMultDocView)
	ON_COMMAND(ID_RIPTEST3PASSS, OnRiptest3passs)
	ON_COMMAND(ID_TESTPASS, OnTestpass)
	ON_COMMAND(ID_TESTTIME, OnTesttime)
	ON_COMMAND(ID_4BMP2RIP, On4bmp2rip)
	ON_COMMAND(ID_SEEINK, OnSeeink)
	ON_COMMAND(ID_RIPTOCOLOR, OnRiptocolor)
	ON_COMMAND(ID_GENERBMP, OnGenerbmp)
	ON_COMMAND(ID_6BMP2RIP, On6bmp2rip)
	ON_COMMAND(ID_BMPTODAT, OnBmptodat)
	ON_COMMAND(ID_8BMP2RIP, On8bmp2rip)
	ON_COMMAND(ID_10BMP2RIP, On10bmp2rip)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMultDocView construction/destruction

CMultDocView::CMultDocView()
{
	// TODO: add construction code here

}

CMultDocView::~CMultDocView()
{
}

BOOL CMultDocView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMultDocView drawing

void CMultDocView::OnDraw(CDC* pDC)
{
	CMultDocDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
/*	CBitmap bitmap;
//	bitmap.CreateBitmap(50,50,1,24,NULL);
	bitmap.LoadMappedBitmap(IDB_BITMAP1);
	CDC memdc;
	memdc.CreateCompatibleDC(pDC);
	memdc.SelectObject(&bitmap);
	pDC->BitBlt(0,0,50,50,&memdc,0,0,SRCCOPY);
	*/

}

/////////////////////////////////////////////////////////////////////////////
// CMultDocView printing

BOOL CMultDocView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMultDocView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMultDocView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMultDocView diagnostics

#ifdef _DEBUG
void CMultDocView::AssertValid() const
{
	CView::AssertValid();
}

void CMultDocView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMultDocDoc* CMultDocView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMultDocDoc)));
	return (CMultDocDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMultDocView message handlers
//------------------ only use for 3 pass -----------------------------------------
void CMultDocView::OnRiptest3passs() 
{
	// TODO: Add your command handler code here	
	CFileDialog opendia(true,NULL,NULL,OFN_HIDEREADONLY,"rip file(*.prn)|*.prn||",NULL);
	opendia.m_ofn.lpstrInitialDir="d:\\imageresource\\rip";
	if(opendia.DoModal()==IDOK)
	{
		CString str;
		CRip rip;	
		str=opendia.GetPathName();
		if(!rip.LoadRipFile(LPCSTR(str)))
			return ;
		rip.SetPass(3);// pass is 3 ;
		rip.Initmemory();
		if(!rip.Gener4bmp())
			return ;
			for(DWORD i=0;i<rip.count;i++)
			{
			   rip.SendToMemory(i);
			   rip.Mem1to2(i);
			   rip.Pumpdot(i);
			   rip.Reversemem();
			   	rip.Mem2bmp(i,rip.lpmemc2,rip.rh.Width,500);
			}
	}	
}

/////////////////////////// 3,4 pass ////////////////////////////////////////
void CMultDocView::OnTestpass() 
{	// example for CString::GetBuffer

	// TODO: Add your command handler code here
	CFileDialog opendia(true,NULL,NULL,OFN_HIDEREADONLY,"rip file(*.prn)|*.prn||",NULL);
	opendia.m_ofn.lpstrInitialDir="d:\\imageresource\\rip\\";
	if(opendia.DoModal()==IDOK)
	{
		CString str;
		CRip rip;	
		str=opendia.GetPathName();
//-----------------------------------------------------------------------------------
		::SetCursor(LoadCursor(NULL,IDC_WAIT));
		if(!rip.LoadRipFile(LPCSTR(str)))
			return ;	                                    
		if(!rip.Gener4bmp())
			return ;
		rip.SetPass(4);// pass is 4 ;
		rip.Initmemory();
			for(DWORD i=0;i<rip.count;i++)
			{
			rip.SendToMemory(i);
			rip.Mem2bmp(i,rip.lpmemc2,rip.rh.Width,500);
			}
			::SetCursor(LoadCursor(NULL,IDC_ARROW));
	}
}
 ///////////////// debug dump dot time  //////////////////////////////////////
void CMultDocView::OnTesttime() 
{
	// TODO: Add your command handler code here
	CFileDialog opendia(true,NULL,NULL,OFN_HIDEREADONLY,"rip file(*.prn)|*.prn||",NULL);
	opendia.m_ofn.lpstrInitialDir="d:\\imageresource\\rip\\";
	if(opendia.DoModal()==IDOK)
	{
		CString str;
		CRip rip;	
		str=opendia.GetPathName();
		if(!rip.LoadRipFile(LPCSTR(str)))
			return ;                             	
		rip.SetPass(4);// pass is 4 ;
		rip.Initmemory();
			for(DWORD i=0;i<rip.count;i++)
			{
				DWORD start,finish;
				start=GetTickCount();
			rip.SendToMemory(i);  
//			rip.Mem2bmp(i,rip.lpmemc2,rip.rh.Width,500);
			finish=GetTickCount();
			TRACE("%d\n",(finish-start));
			}
	}
}

//-----------------------------------------------------------------------------------
//------------------------------four bmp file generate rip file ---------------------
void CMultDocView::On4bmp2rip() 
{
	
	// TODO: Add your command handler code here
	CFileDialog opendia(true,NULL,NULL,OFN_ALLOWMULTISELECT|OFN_EXPLORER,"bmp file(*.bmp)|*.bmp||",NULL);//default IS OFN_EXPLORER 
	                                                   //except have select OFN_ALLOWMULTISELECT;
	opendia.m_ofn.lpstrInitialDir="d:\\rip\\testtime\\";
	if(opendia.DoModal()==IDOK)
	{
		::SetCursor(LoadCursor(NULL,IDC_WAIT));
		CString string,ripname;
		CStringArray m_aFileNames;

		CString str=opendia.GetPathName();
		m_aFileNames.Add(str.Left(str.GetLength()-6)+"-1.bmp");
		m_aFileNames.Add(str.Left(str.GetLength()-6)+"-2.bmp");
		m_aFileNames.Add(str.Left(str.GetLength()-6)+"-3.bmp");
		m_aFileNames.Add(str.Left(str.GetLength()-6)+"-4.bmp");
		if(	m_aFileNames.GetSize()!=4)
			return ;
		
		BITMAPINFOHEADER bih;
		BITMAPFILEHEADER bfh;
		RipHeader rh;
		string=m_aFileNames.GetAt(0);
	//	string.Delete(string.GetLength()-4,1);
		ripname=string.Left(string.GetLength()-6);
		ripname.Insert(ripname.GetLength(),".prn");
	
		CFile filek(m_aFileNames.GetAt(0),CFile::modeRead);
		CFile filec(m_aFileNames.GetAt(1),CFile::modeRead);
		CFile filem(m_aFileNames.GetAt(2),CFile::modeRead);
		CFile filey(m_aFileNames.GetAt(3),CFile::modeRead);
		CFile filer(ripname,CFile::modeCreate|CFile::modeWrite);

		filec.Read(&bfh,sizeof(BITMAPFILEHEADER));
		filec.Read(&bih,sizeof(BITMAPINFOHEADER));

		rh.Height=bih.biHeight;
		rh.Width=bih.biWidth;
		rh.Colors=4;
		//rh.PaperWidth=1069546429;
		rh.Signature=0;
		rh.XDPI=180;
		rh.YDPI=180;
		rh.BytesPerLine=WIDTHBYTES(bih.biWidth);

		filer.Write(&rh,sizeof(RipHeader));

		long offset=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*2;
		filek.Seek(offset,CFile::begin);
		filec.Seek(offset,CFile::begin);
		filem.Seek(offset,CFile::begin);
		filey.Seek(offset,CFile::begin);


		char* lpchar=new char[rh.BytesPerLine];
		for(long y=0;y<bih.biHeight;y++)
		{
			filek.Read(lpchar,rh.BytesPerLine);
			filer.Write(lpchar,rh.BytesPerLine);

			filec.Read(lpchar,rh.BytesPerLine);
			filer.Write(lpchar,rh.BytesPerLine);

			filem.Read(lpchar,rh.BytesPerLine);
			filer.Write(lpchar,rh.BytesPerLine);

			filey.Read(lpchar,rh.BytesPerLine);
			filer.Write(lpchar,rh.BytesPerLine);
		}
			delete [] lpchar;
			filer.Close();
			filec.Close();
			filem.Close();
			filey.Close();
			filek.Close();
		::SetCursor(LoadCursor(NULL,IDC_ARROW));
		AfxMessageBox("Finished!");
	}
	
}

void CMultDocView::OnSeeink() 
{	CFileDialog dlg(true,NULL,NULL,OFN_HIDEREADONLY,"Bmp file(*.bmp)|*.bmp||",NULL);
	if(dlg.DoModal()==IDOK)
	{	UINT uiDots[256]={0},uiPoints=0,i,j;
			for(i=0;i<256;i++)
		for(j=0;j<8;j++)
			if((i>>j)&1) uiDots[i]++;
		BITMAPINFOHEADER bih;
		BITMAPFILEHEADER bfh;
		
		CFile bmpfile(dlg.GetPathName(),CFile::modeRead);
		bmpfile.Read(&bfh,sizeof(BITMAPFILEHEADER));
		bmpfile.Read(&bih,sizeof(BITMAPINFOHEADER));
		bmpfile.Seek(sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*2,CFile::begin);
		UINT uiBytesPerLine = WIDTHBYTES(bih.biWidth);
		LPBYTE lpBmp = new BYTE[bih.biHeight * uiBytesPerLine];
		for(j=0;j<(UINT)bih.biHeight;j++)
		{	bmpfile.Read(lpBmp,bih.biHeight * uiBytesPerLine);
		}
		for(i=0;i<uiBytesPerLine*bih.biHeight;i++)
		{	uiPoints += uiDots[*(lpBmp+i)];
		}
		CString csStr;
		csStr.Format("%d,%d,%.3f",uiPoints,bih.biHeight*bih.biWidth,(float)uiPoints/(float)(bih.biHeight*bih.biWidth));
		AfxMessageBox(csStr);
		bmpfile.Close();
	}
	return;
	// TODO: Add your command handler code here
	CFileDialog opendia(true,NULL,NULL,OFN_HIDEREADONLY,"rip file(*.prn)|*.prn||",NULL);
	opendia.m_ofn.lpstrInitialDir="d:\\imageresource\\rip\\";
	if(opendia.DoModal()==IDOK)
	{
		CString str;
		CRip rip;	
		str=opendia.GetPathName();
		if(!rip.LoadRipFile(LPCSTR(str)))
			return ;
		Inkstruct count={0};// the same as {0,0,0,0};
//----------------------calc ink dot----------------------------------------------
		::SetCursor(LoadCursor(NULL,IDC_WAIT));
		DWORD start,finish;
		start=GetTickCount();
		rip.CalcInks();
		count=rip.GetInkNums();
		finish=GetTickCount();
		::SetCursor(LoadCursor(NULL,IDC_ARROW));
//---------------------------------------------------------------------
#ifdef _DEBUG	
		afxDump<<finish-start<<"\n";
#endif	
		CInkdlg m_inkdlg;
		m_inkdlg.m_inkc=count.Inkc;
		m_inkdlg.m_inkm=count.Inkm;
		m_inkdlg.m_inky=count.Inky;
		m_inkdlg.m_inkk=count.Inkk;
		UpdateData(true);
		m_inkdlg.DoModal();
			
	}
}

void CMultDocView::OnRiptocolor() 
{
	// TODO: Add your command handler code here

	CFileDialog opendia(true,NULL,NULL,OFN_HIDEREADONLY,"rip file(*.prn)|*.prn||",NULL);
	opendia.m_ofn.lpstrInitialDir="d:\\imageresource\\rip\\";
	if(opendia.DoModal()==IDOK)
	{
		CString str;

⌨️ 快捷键说明

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