📄 readdata.cpp
字号:
// ReadData.cpp : implementation file
//
#include "stdafx.h"
#include "LPTDLL.h"
#include "ReadData.h"
#include "MessageDefine.h"
#include "EasyISP1581ExB.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CReadData
extern CString filename;
IMPLEMENT_DYNCREATE(CReadData, CWinThread)
CReadData::CReadData()
{
m_AlreadyData=false;
}
CReadData::~CReadData()
{
}
BOOL CReadData::InitInstance()
{
// TODO: perform and per-thread initialization here
return TRUE;
}
int CReadData::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(CReadData, CWinThread)
//{{AFX_MSG_MAP(CReadData)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_MESSAGE(MESSAGEWRITE,WriteData)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReadData message handlers
void CReadData::WriteData(WPARAM wParam, LPARAM lParam)
{
char temp [80],cc[80];
int nResult=0;
int nBytes = 0;
ULONG repeat, loopcounter = 0;
UINT totaltoTx=0, toTxNow=0, exitFlag=0;
struct CThreadParam * threadParam;
unsigned char *pcIoBuffer;
unsigned char *picbuffer;
BITMAPFILEHEADER bitmapfileheader;
BITMAPINFOHEADER bitmapinfoheader;
DWORD curtime;
int nflag=0;
////////////////////////////////////////////////////////////////
CFile fDataOut;
CFile fDataOut1;
// CString filename;
// filename.Format("picture%d.bmp",wParam);
nResult=Ex_Vender_ScanOrPrint(0x01,MAX);
if(nResult==0){
picbuffer = new unsigned char[MAX*3];
pcIoBuffer = new unsigned char[MAX];
fDataOut.Open(filename, CFile::modeCreate | CFile::modeWrite,NULL) ;
bitmapfileheader.bfType=0x4d42;
bitmapfileheader.bfSize = 3686454;
bitmapfileheader.bfOffBits = 54;
bitmapinfoheader.biBitCount = 24;
bitmapinfoheader.biWidth = 1280;
bitmapinfoheader.biHeight = 960;
bitmapinfoheader.biPlanes = 1;
bitmapinfoheader.biClrImportant = 0;
bitmapinfoheader.biClrUsed = 0;
bitmapinfoheader.biCompression = 0;
bitmapinfoheader.biSize = 40;
bitmapinfoheader.biSizeImage = 3686400;
bitmapinfoheader.biXPelsPerMeter = 0x0ec4;
bitmapinfoheader.biYPelsPerMeter = 0x0ec4;
fDataOut.Write(&bitmapfileheader,14);
fDataOut.Write(&bitmapinfoheader,40);
totaltoTx = MAX;
if(totaltoTx>MAX)
{
totaltoTx = totaltoTx -MAX;
toTxNow =MAX;
}
else
{
toTxNow = totaltoTx;
exitFlag=1;
}
nBytes=Ex_ReadData(2,pcIoBuffer,toTxNow,1000);
/////////////////////////////////////
fDataOut.Write(pcIoBuffer,MAX);
long i,j,k;
BYTE R,G,B;
k=0;
long kl,kp;
kp=0;
int line=960,row=1281;
//////////////////图像显示部分
for(i=2;i<line-2;i++) //482 Line
// for(i=2;i<500;i++)
{
for(j=2;j<row-2;j++) //642 ROW
//for(j=2;j<500;j++)
{
if(i%2==1 && j%2==1)
{
//if( abs( *(pcIoBuffer+(i-1)*1000+j-1) - *(pcIoBuffer+(i-1)*1000+j+1)>abs(*(pcIoBuffer+(i+1)*1000+j-1)-*(pcIoBuffer+(i+1)*1000+j+1)))
R=(*(pcIoBuffer+(i-1)*row+j-1)+*(pcIoBuffer+(i-1)*row+j+1)+*(pcIoBuffer+(i+1)*row+j-1)+*(pcIoBuffer+(i+1)*row+j+1))/4;
if( abs( *(pcIoBuffer+(i-2)*row+j) - *(pcIoBuffer+(i+2)*row+j))>abs(*(pcIoBuffer+i*row+j-2)-*(pcIoBuffer+i*row+j+2)) )
G=(*(pcIoBuffer+(i-1)*row+j)+*(pcIoBuffer+(i+1)*row+j))/2;
else if( abs( *(pcIoBuffer+(i-2)*row+j) - *(pcIoBuffer+(i+2)*row+j))<abs(*(pcIoBuffer+i*row+j-2)-*(pcIoBuffer+i*row+j+2)))
G=(*(pcIoBuffer+i*row+j+1)+*(pcIoBuffer+i*row+j-1))/2;
else
( abs( *(pcIoBuffer+(i-1)*row+j) - *(pcIoBuffer+(i+1)*row+j))>abs(*(pcIoBuffer+i*row+j-1)-*(pcIoBuffer+i*row+j+1)))/4;
B=*(pcIoBuffer+i*row+j);
}
else if(i%2==1 && j%2==0)
{
R=(*(pcIoBuffer+(i-1)*row+j)+*(pcIoBuffer+(i+1)*row+j))/2;
G=*(pcIoBuffer+i*row+j);
B=(*(pcIoBuffer+i*row+j-1)+*(pcIoBuffer+i*row+j+1))/2;
}
else if(i%2==0 && j%2==1)
{
R=(*(pcIoBuffer+i*row+j-1)+*(pcIoBuffer+i*row+j+1))/2;
G=*(pcIoBuffer+i*row+j);
B=(*(pcIoBuffer+(i-1)*row+j)+*(pcIoBuffer+(i+1)*row+j))/2;
}
else if(i%2==0 && j%2==0)
{
R=*(pcIoBuffer+i*row+j);
B=(*(pcIoBuffer+(i-1)*row+j-1)+*(pcIoBuffer+(i-1)*row+j+1)+*(pcIoBuffer+(i+1)*row+j-1)+*(pcIoBuffer+(i+1)*row+j+1))/4;
if( abs( *(pcIoBuffer+(i-2)*row+j) - *(pcIoBuffer+(i+2)*row+j))>abs(*(pcIoBuffer+i*row+j-2)-*(pcIoBuffer+i*row+j+2)))
G=(*(pcIoBuffer+(i-1)*row+j)+*(pcIoBuffer+(i+1)*row+j))/2;
else if( abs( *(pcIoBuffer+(i-2)*row+j) - *(pcIoBuffer+(i+2)*row+j))<abs(*(pcIoBuffer+i*row+j-2)-*(pcIoBuffer+i*row+j+2)))
G=(*(pcIoBuffer+i*row+j+1)+*(pcIoBuffer+i*row+j-1))/2;
else
( abs( *(pcIoBuffer+(i-1)*row+j) - *(pcIoBuffer+(i+1)*row+j))>abs(*(pcIoBuffer+i*row+j-1)-*(pcIoBuffer+i*row+j+1)))/4;
}
picbuffer[i*1280*3+j+2]=R;
picbuffer[i*1280*3+j+1]=G;
picbuffer[i*1280*3+j]=B;
}
}
fDataOut.Write(picbuffer,3686400);
fDataOut.Close();
delete picbuffer;
SendMessage(m_formhandle,10002,NULL ,NULL);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -