GetInfoFun.cpp
上传用户:yatsl7111
上传日期:2007-01-08
资源大小:1433k
文件大小:3k
- #include "stdafx.h"
- #include "PcxModule.h"
- #include "PcxDeclare.h"
- #define DIBSCANLINE_WIDTHBYTES(bits) (((bits)+31)/32*4)
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //#include "PcxModule.h"
- void Pcx_GET_FILE_INFO(INFOSTR *pInfo)
- {
- CFile file;
- CFileStatus status;
- PCXFILEHEADER PcxHeader;
- // DWORD dwSize;
- UINT uRet;
- // 检验入口参数是否符合接口定义
- ASSERT(pInfo->result == ER_EMPTY);
- ASSERT(::strlen(pInfo->filename));
- // 此时,该文件必需是一个已存在的、并且是有效的PCX文件
- ASSERT(pInfo->state == PKST_PASSVER);
- // 客户模块必需要先将imginfo清空为0
- ASSERT(pInfo->imginfo.imgtype == IMT_NULL);
- // 打开指定文件
- if (!file.Open(pInfo->filename, CFile::modeRead))
- {
- pInfo->result = ER_FILERWERR;
- return;
- }
- // 读取PCX的文件头结构
- file.SeekToBegin();
- uRet = file.Read((LPSTR)&PcxHeader, sizeof(PcxHeader));
- if (uRet != sizeof(PcxHeader))
- {
- file.Close();
- pInfo->result = ER_FILERWERR;
- return;
- }
- // 读取图像信息数据
- LPIMAGEINFOSTR lpImgInfoStr = &pInfo->imginfo;
- // 获取文件的长度、图像的宽度、高度等信息
- lpImgInfoStr->imgtype = IMT_RESSTATIC;
- lpImgInfoStr->imgformat = IMF_PCX;
- lpImgInfoStr->filesize = file.GetLength();
- /*
- pInfo->wight = PcxHeader.wRight - PcxHeader.wLeft + 1;
- pInfo->height = PcxHeader.wBottom - PcxHeader.wTop + 1;
- pInfo->colorhight = PcxHeader.byBits*PcxHeader.byPlanes;
- */
- lpImgInfoStr->width = (DWORD) PcxHeader.wRight - PcxHeader.wLeft + 1 ;
- lpImgInfoStr->height = (DWORD)PcxHeader.wBottom - PcxHeader.wTop + 1 ;
- lpImgInfoStr->bitcount = (DWORD)PcxHeader.byBits*PcxHeader.byPlanes;
- // if(PcxHeader.biCompression==1)//Must
- lpImgInfoStr->compression = ICS_PCXRLE;
- // 每一图像行所占的字节数(DWORD对齐,表示位图解压后的有效值)
- lpImgInfoStr->linesize = DIBSCANLINE_WIDTHBYTES(lpImgInfoStr->width * lpImgInfoStr->bitcount );
- lpImgInfoStr->imgnumbers = 1; // PCX文件中只有一个图像
- lpImgInfoStr->imgchang = 0; // 表示可以被编辑
- // 获取文件最后的修改日期(月在高字节,日在低字节)
- file.GetStatus(status);
- lpImgInfoStr->year = (WORD)status.m_mtime.GetYear();
- lpImgInfoStr->monday = (WORD)status.m_mtime.GetMonth();
- lpImgInfoStr->monday <<= 8;
- lpImgInfoStr->monday |= (WORD)status.m_mtime.GetDay();
- // 获取文件最后的修改时间(字序:最高—0, 2—时,1—分,0—秒)
- lpImgInfoStr->time = status.m_mtime.GetHour();
- lpImgInfoStr->time <<= 8;
- lpImgInfoStr->time |= status.m_mtime.GetMinute();
- lpImgInfoStr->time <<= 8;
- lpImgInfoStr->time |= status.m_mtime.GetSecond();
- lpImgInfoStr->time &= 0xffffff;
- file.Close();
- // 设置出口数据
- pInfo->state = PKST_PASSINFO;
- pInfo->result = ER_SUCCESS;
- }