📄 prot.cpp
字号:
{
TW_UINT16 twRc = TWRC_SUCCESS;
HANDLE bmp;
LPBITMAPINFO pdib;
int index;
switch (DSState)
{
case STATE4:
case STATE5:
case STATE6:
switch (pTWMsg->MSG)
{
case MSG_GET://应用程序获取数据源调色板信息,如无则为缺省调色板
bmp=ReadDIBFile((LPSTR)DisplayFileName);
pdib = (LPBITMAPINFO)GlobalLock(bmp);
((pTW_PALETTE8)pTWMsg->pData)->NumColors = (TW_UINT16)pdib->bmiHeader.biClrUsed;
((pTW_PALETTE8)pTWMsg->pData)->PaletteType = TWPA_RGB;
for (index=0;index<(int)pdib->bmiHeader.biClrUsed;index++)
{
((pTW_PALETTE8)pTWMsg->pData)->Colors[index].Channel1 = pdib->bmiColors[index].rgbRed;
((pTW_PALETTE8)pTWMsg->pData)->Colors[index].Channel2 = pdib->bmiColors[index].rgbGreen;
((pTW_PALETTE8)pTWMsg->pData)->Colors[index].Channel3 = pdib->bmiColors[index].rgbBlue;
((pTW_PALETTE8)pTWMsg->pData)->Colors[index].Index = index;
}
GlobalUnlock(bmp);
GlobalFree(bmp);
break;
case MSG_GETDEFAULT:
case MSG_RESET:
case MSG_SET:
break;
default:
DSStatus.ConditionCode = TWCC_BADPROTOCOL;
twRc = TWRC_FAILURE;
DS_Error (E_PALETTE8, DSStatus.ConditionCode);
break;
}
break;
default:
DSStatus.ConditionCode = TWCC_SEQERROR;
twRc = TWRC_FAILURE;
DS_Error (E_PALETTE8, DSStatus.ConditionCode);
break;
}
return twRc;
} // Palette8Msg()
/////////////////////////////////////////////////////////////////////////////////
//应用传输曲线到灰度图
TW_UINT16 GrayResponseMsg (PTWMSG pTWMsg)
{
TW_UINT16 x;
char RespNum[20];
char Color[20];
for(x=0;x<16;x++)
{
sprintf(RespNum,"Response[%ld]",x);
sprintf(Color,"{%ld,%ld,%ld}",((pTW_GRAYRESPONSE)pTWMsg->pData)->Response[x].Channel1,
((pTW_GRAYRESPONSE)pTWMsg->pData)->Response[x].Channel2,
((pTW_GRAYRESPONSE)pTWMsg->pData)->Response[x].Channel3);
WritePrivateProfileString("GrayResponse",RespNum,Color,SourceControl);
}
return(TWRC_SUCCESS);
}
/////////////////////////////////////////////////////////////////////////////////
// RGBResponse -- Note: Uses the GrayResponse structure which is identical to the
// RGBRESPONSE structure in TWAIN 1.5.4
//
//应用传输曲线到RGB图
TW_UINT16 RGBResponseMsg (PTWMSG pTWMsg)
{
TW_UINT16 x;
char RespNum[20];
char Color[20];
for(x=0;x<16;x++)
{
sprintf(RespNum,"Response[%ld]",x);
sprintf(Color,"{%ld,%ld,%ld}",((pTW_GRAYRESPONSE)pTWMsg->pData)->Response[x].Channel1,
((pTW_GRAYRESPONSE)pTWMsg->pData)->Response[x].Channel2,
((pTW_GRAYRESPONSE)pTWMsg->pData)->Response[x].Channel3);
WritePrivateProfileString("RGBResponse",RespNum,Color,SourceControl);
}
return(TWRC_SUCCESS);
}
/////////////////////////////////////////////////////////////////////////////////
// CIEColorMsg --
//转换颜色空间RGB到XYZ
TW_UINT16 CIEColorMsg (PTWMSG pTWMsg)
{
TW_HANDLE phandle;
((pTW_CIECOLOR)pTWMsg->pData)->ColorSpace = TWPT_RGB;
((pTW_CIECOLOR)pTWMsg->pData)->LowEndian = 0;
((pTW_CIECOLOR)pTWMsg->pData)->DeviceDependent = TRUE;
((pTW_CIECOLOR)pTWMsg->pData)->VersionNumber = 0;
// 转换状态 ABC及转换矩阵3*3矩阵
((pTW_CIECOLOR)pTWMsg->pData)->StageABC.Decode[0].StartIn = FloatToFIX32((float)0.1);
((pTW_CIECOLOR)pTWMsg->pData)->StageABC.Mix[0][0] = FloatToFIX32((float)0.0);
((pTW_CIECOLOR)pTWMsg->pData)->StageABC.Mix[0][1] = FloatToFIX32((float)0.1);
((pTW_CIECOLOR)pTWMsg->pData)->StageABC.Mix[0][2] = FloatToFIX32((float)0.2);
((pTW_CIECOLOR)pTWMsg->pData)->StageABC.Mix[1][0] = FloatToFIX32((float)1.0);
((pTW_CIECOLOR)pTWMsg->pData)->StageABC.Mix[1][1] = FloatToFIX32((float)1.1);
((pTW_CIECOLOR)pTWMsg->pData)->StageABC.Mix[1][2] = FloatToFIX32((float)1.2);
((pTW_CIECOLOR)pTWMsg->pData)->StageABC.Mix[2][0] = FloatToFIX32((float)2.0);
((pTW_CIECOLOR)pTWMsg->pData)->StageABC.Mix[2][1] = FloatToFIX32((float)2.1);
((pTW_CIECOLOR)pTWMsg->pData)->StageABC.Mix[2][2] = FloatToFIX32((float)2.2);
//转换状态 LMN及转换矩阵
((pTW_CIECOLOR)pTWMsg->pData)->StageLMN.Decode[0].StartIn = FloatToFIX32((float)1.1);
((pTW_CIECOLOR)pTWMsg->pData)->StageLMN.Mix[0][0] = FloatToFIX32((float)0.0);
((pTW_CIECOLOR)pTWMsg->pData)->StageLMN.Mix[0][1] = FloatToFIX32((float)0.1);
((pTW_CIECOLOR)pTWMsg->pData)->StageLMN.Mix[0][2] = FloatToFIX32((float)0.2);
((pTW_CIECOLOR)pTWMsg->pData)->StageLMN.Mix[1][0] = FloatToFIX32((float)1.0);
((pTW_CIECOLOR)pTWMsg->pData)->StageLMN.Mix[1][1] = FloatToFIX32((float)1.1);
((pTW_CIECOLOR)pTWMsg->pData)->StageLMN.Mix[1][2] = FloatToFIX32((float)1.2);
((pTW_CIECOLOR)pTWMsg->pData)->StageLMN.Mix[2][0] = FloatToFIX32((float)2.0);
((pTW_CIECOLOR)pTWMsg->pData)->StageLMN.Mix[2][1] = FloatToFIX32((float)2.1);
((pTW_CIECOLOR)pTWMsg->pData)->StageLMN.Mix[2][2] = FloatToFIX32((float)2.2);
// CIE空间中的白点值
((pTW_CIECOLOR)pTWMsg->pData)->WhitePoint.X = FloatToFIX32((float)4.4);
((pTW_CIECOLOR)pTWMsg->pData)->WhitePoint.Y = FloatToFIX32((float)5.5);
((pTW_CIECOLOR)pTWMsg->pData)->WhitePoint.Z = FloatToFIX32((float)6.6);
// CIE颜色空间中的黑点值
((pTW_CIECOLOR)pTWMsg->pData)->BlackPoint.X = FloatToFIX32((float)1.1);
((pTW_CIECOLOR)pTWMsg->pData)->BlackPoint.Y = FloatToFIX32((float)5.5);
((pTW_CIECOLOR)pTWMsg->pData)->BlackPoint.Z = FloatToFIX32((float)6.6);
// CIEPoint
((pTW_CIECOLOR)pTWMsg->pData)->WhitePaper.X = FloatToFIX32((float)1.1);
((pTW_CIECOLOR)pTWMsg->pData)->WhitePaper.Y = FloatToFIX32((float)5.5);
((pTW_CIECOLOR)pTWMsg->pData)->WhitePaper.Z = FloatToFIX32((float)6.6);
// CIEPoint
((pTW_CIECOLOR)pTWMsg->pData)->BlackInk.X = FloatToFIX32((float)1.1);
((pTW_CIECOLOR)pTWMsg->pData)->BlackInk.Y = FloatToFIX32((float)5.5);
((pTW_CIECOLOR)pTWMsg->pData)->BlackInk.Z = FloatToFIX32((float)6.6);
phandle = GlobalAlloc(GHND,sizeof(TW_FIX32)*4);
// ((pTW_CIECOLOR)pTWMsg->pData)->Samples[0] = (pTW_FIX32)GlobalLock(phandle);
((pTW_CIECOLOR)pTWMsg->pData)->Samples[0] = FloatToFIX32((float)99.99);
((pTW_CIECOLOR)pTWMsg->pData)->Samples[1] = FloatToFIX32((float)98.98);
((pTW_CIECOLOR)pTWMsg->pData)->Samples[2] = FloatToFIX32((float)97.97);
((pTW_CIECOLOR)pTWMsg->pData)->Samples[3] = FloatToFIX32((float)96.96);
// GlobalUnlock(phandle);
return(TWRC_SUCCESS);
}
/////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////
TW_UINT16 JPEGCompressionMsg (PTWMSG pTWMsg)
{
return(TWRC_SUCCESS);
}
//////////////////////////////////////////////////////////////////////////
// FUNCTION: ImageInfoMsg//提供下面要传输的图象的信息
//
// ARGS: pTWMsg 数据源入口中的消息参数
//
// RETURNS: TWRC_SUCCESS
// TWRC_FAILURE
// TWCC_SEQERROR
// NOTES: Valid states 6.
/////////////////////////////////////////////////////////////////////////////////
TW_UINT16 ImageInfoMsg (PTWMSG pTWMsg)
{
TW_UINT16 twRC = TWRC_SUCCESS;
pTW_IMAGEINFO pII;
short i;
OFSTRUCT of;
int hFile;
BITMAPFILEHEADER Bfh;
LPBITMAPFILEHEADER lpBfh=&Bfh;
BITMAPINFOHEADER Bifh;
LPBITMAPINFOHEADER lpBifh=&Bifh;
if (DSState==STATE6)
{
switch (pTWMsg->MSG)
{
case MSG_GET:
if ((hFile = OpenFile (DisplayFileName, &of, OF_READ)) != HFILE_ERROR)
{
if (hFile < 0)
{
DSStatus.ConditionCode = TWCC_OPERATIONERROR;
DS_Error (E_IMAGEINFOFOPEN, DSStatus.ConditionCode);
return (TWRC_FAILURE);
}
if (_lread(hFile, (LPSTR)lpBfh, sizeof(BITMAPFILEHEADER)) != sizeof(BITMAPFILEHEADER))
{
DSStatus.ConditionCode = TWCC_BUMMER;//不明原因的错误
DS_Error (E_IMAGEINFORHEAD, DSStatus.ConditionCode);
return (TWRC_FAILURE);
}
if (lpBfh->bfType!=0x4D42)//不是位图文件
{
DSStatus.ConditionCode = TWCC_BADVALUE;
DS_Error (E_IMAGEINFOFTYPE, DSStatus.ConditionCode);
return (TWRC_FAILURE);
}
if (_lread(hFile, (LPSTR)lpBifh, sizeof(BITMAPINFOHEADER)) != sizeof(BITMAPINFOHEADER))
{
DSStatus.ConditionCode = TWCC_BUMMER;
DS_Error (E_IMAGEINFOIHEAD, DSStatus.ConditionCode);
return (TWRC_FAILURE);
}
_lclose (hFile);
}
pScanner->m_nColor = GetPrivateProfileInt("color num","color",16777216,InitDir2);
lpBifh->biSize = 40;
lpBifh->biWidth =(long)(((pScanner->m_rtScanZoom).right-(pScanner->m_rtScanZoom).left)/FuMian*(pScanner->m_nDPI));
lpBifh->biHeight =(long)(((pScanner->m_rtScanZoom).bottom-(pScanner->m_rtScanZoom).top)/FuMian*(pScanner->m_nDPI));
lpBifh->biPlanes = 1;
lpBifh->biCompression = 0;
lpBifh->biClrUsed = 0;
lpBifh->biClrImportant = 0;
switch(pScanner->m_nColor)
{
case 16777216:
lpBifh->biBitCount = 24;
lpBifh->biSizeImage = lpBifh->biWidth*lpBifh->biHeight*3;
break;
case 256:
lpBifh->biBitCount = 8;
lpBifh->biSizeImage = lpBifh->biWidth*lpBifh->biHeight;
break;
case 2:
lpBifh->biWidth=(lpBifh->biWidth/8)*8;
lpBifh->biBitCount =1;
lpBifh->biSizeImage = lpBifh->biWidth*lpBifh->biHeight/8;
break;
}
lpBifh->biXPelsPerMeter = pScanner->m_nDPI;
lpBifh->biYPelsPerMeter = pScanner->m_nDPI;
if(lpBifh->biSize!=sizeof(BITMAPINFOHEADER))
{
DSStatus.ConditionCode = TWCC_BADVALUE;
DS_Error (E_IMAGEINFOBTYPE, DSStatus.ConditionCode);
return (TWRC_FAILURE);
}
pII = (pTW_IMAGEINFO)pTWMsg->pData;
pII->XResolution.Whole = (TW_INT16)(lpBifh->biXPelsPerMeter);
pII->YResolution.Whole = (TW_INT16)(lpBifh->biYPelsPerMeter);
pII->XResolution.Frac = pII->YResolution.Frac = 0;
pII->ImageWidth = lpBifh->biWidth;
pII->ImageLength = lpBifh->biHeight;
pII->BitsPerPixel = lpBifh->biBitCount;
pII->Planar = FALSE;
if (lpBifh->biCompression==0L)
pII->Compression = TWCP_NONE;
for (i = 0; i <= 7; i++)
{
pII->BitsPerSample[i] = 0;
}
if(lpBifh->biBitCount==24)
{
pII->SamplesPerPixel = 3;
for (i = 0; i <= 3; i++)
pII->BitsPerSample[i] = lpBifh->biBitCount;
pII->PixelType = TWPT_RGB;
}
if(lpBifh->biBitCount==8)
{
pII->SamplesPerPixel = 1;
pII->BitsPerSample[0] = lpBifh->biBitCount;
pII->PixelType = TWPT_GRAY;
}
if(lpBifh->biBitCount==1)
{
pII->SamplesPerPixel = 1;
pII->BitsPerSample[0] = lpBifh->biBitCount;
pII->PixelType = TWPT_BW;
}
twRC = TWRC_SUCCESS;
break;
default:
DSStatus.ConditionCode = TWCC_BADPROTOCOL;
twRC = TWRC_FAILURE;
DS_Error (E_IMAGEINFOMSG, DSStatus.ConditionCode);
break;
}
}
else
{
DSStatus.ConditionCode = TWCC_SEQERROR;
twRC = TWRC_FAILURE;
DS_Error (E_IMAGEINFOMSG, DSStatus.ConditionCode);
}
return twRC;
}
///////////////////////////////////////////////////////////////////////////
// FUNCTION: ImageLayoutMsg图象版面格式消息
//
// ARGS: pTWMsg 数据源入口中的消息参数
//
// RETURNS: 状态代码
//
// NOTES: This function is is supported to the extent that it will
// return success for each call.
//
TW_UINT16 ImageLayoutMsg (PTWMSG pTWMsg)
{
TW_UINT16 twRc = TWRC_SUCCESS;
TW_FIX32 fix32;
switch (pTWMsg->MSG)
{
case MSG_GET:
case MSG_GETDEFAULT:
case MSG_GETCURRENT:
fix32.Whole =22;
fix32.Frac = 33;
((pTW_IMAGELAYOUT)pTWMsg->pData)->Frame.Top = fix32;
((pTW_IMAGELAYOUT)pTWMsg->pData)->Frame.Left = fix32;
((pTW_IMAGELAYOUT)pTWMsg->pData)->Frame.Right = fix32;
((pTW_IMAGELAYOUT)pTWMsg->pData)->Frame.Bottom = fix32;
((pTW_IMAGELAYOUT)pTWMsg->pData)->DocumentNumber = 4;
((pTW_IMAGELAYOUT)pTWMsg->pData)->PageNumber = 88;
((pTW_IMAGELAYOUT)pTWMsg->pData)->FrameNumber = 1;//每次只有一个选择框
break;
case MSG_SET:
break;
case MSG_RESET:
break;
default:
DSStatus.ConditionCode = TWCC_BADPROTOCOL;
twRc = TWRC_FAILURE;
DS_Error (E_IMAGELAYOUTMSG, DSStatus.ConditionCode);
break;
}
return twRc;
}
/////////////////////////////////////////////////////////////////////////////////
// FUNCTION: ImageMemXferMsg内存缓冲传输
//
// ARGS: pTWMsg message struct, same as list of parms in DS_ENTRY call
//
// RETURNS: TWRC_SUCCESS
// TWRC_FAILURE
// TWCC_BADVALUE
// TWCC_SEQERROR
// TWRC_XFERDONE //数据源传输图象
// TWRC_CANCEL
/////////////////////////////////////////////////////////////////////////////////
DWORD ASPI32Status1=0xff;
SRB_ExecSCSICmd mySRBEIO1;
DWORD ASPIEventStatus1;
TW_UINT16 ImageMemXferMsg (PTWMSG pTWMsg)
{
char details [180];
static int nPrePos;
static int fh;
static DWORD dwFileLen;
static DWORD dwBits;
static HANDLE bmp;
HGLOBAL hbuffer1; //nReadInBytes
static HGLOBAL hbuffer2; //pMem+y0
static HGLOBAL hbuffer3; //pMem+y0
static HGLOBAL hmem; //y0
static HGLOBAL hmem1;
LPSTR lp1,lp2,lp3,lp4,lp5,lp6;
LPSTR lpBits1,lpBits,lpStart1;
static LPSTR lpBits2,lpStart2;
static LPSTR lpBits4,lpStart4;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -