CReportFile.cpp
资源名称:VC++视频传输.rar [点击查看]
上传用户:hxb_1234
上传日期:2010-03-30
资源大小:8328k
文件大小:3k
源码类别:
VC书籍
开发平台:
Visual C++
- // CReportFile.cpp: implementation of the CReportFile class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "XvidQuantsParser.h"
- #include "CReportFile.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CReportFile::CReportFile()
- {
- //data = NULL;
- }
- CReportFile::~CReportFile()
- {
- //if (data != NULL) delete[] data;
- }
- //-----------------------------------------------------------------------------------------------
- bool CReportFile::Save(CString filepath, CXvid &xvid, int start, int stop)
- {
- CFile rfile;
- //File header
- fileHdr.rtyp = 0x08;
- fileHdr.rmajor = 1;
- fileHdr.rminor = 1;
- //Info header
- infoHdr.fps = xvid.GetRate();
- infoHdr.width = xvid.GetWidth();
- infoHdr.height = xvid.GetHeight();
- infoHdr.nframes = stop-start;
- infoHdr.nmax = xvid.GetMaxQuant();
- infoHdr.nmin = xvid.GetMinQuant();
- infoHdr.navg = xvid.GetAvgQuants();
- infoHdr.icount = xvid.GetIFrameCount();
- infoHdr.iavg = xvid.GetIAvgQuants();
- infoHdr.pcount = xvid.GetPFrameCount();
- infoHdr.pavg = xvid.GetPAvgQuants();
- infoHdr.nfsmax = xvid.GetMaxFrameSize();
- infoHdr.nfsmin = xvid.GetMinFrameSize();
- infoHdr.ifsmax = xvid.GetIMaxFrameSize();
- infoHdr.ifsmin = xvid.GetIMinFrameSize();
- infoHdr.pfsmax = xvid.GetPMaxFrameSize();
- infoHdr.pfsmin = xvid.GetPMinFrameSize();
- //save file...
- if (!rfile.Open(filepath, CFile::modeCreate|CFile::modeWrite))
- {
- return false;
- }
- rfile.Write(&fileHdr, sizeof(REPORTFILEHEADER));
- rfile.Write(&infoHdr, sizeof(REPORTINFOHEADER));
- rfile.Write(xvid.GetQuantsArray(), sizeof(CXvid::QUANTS)*infoHdr.nframes);
- //cleanup
- rfile.Close();
- return true;
- }
- //-----------------------------------------------------------------------------------------------
- bool CReportFile::Load(CString filepath, CXvid &xvid)
- {
- CFile rfile;
- CXvid::QUANTS* databuf=NULL;
- //load file...
- if (!rfile.Open(filepath, CFile::modeRead))
- {
- return false;
- }
- //Check file header
- rfile.Read(&fileHdr, sizeof(REPORTFILEHEADER));
- if (fileHdr.rtyp != 0x08)
- {
- return false;
- }
- if (fileHdr.rminor != 1)
- {
- AfxMessageBox("Wrong report file version!");
- return false;
- }
- //load info header
- rfile.Read(&infoHdr, sizeof(REPORTINFOHEADER));
- xvid.SetRate(infoHdr.fps);
- xvid.SetWidth(infoHdr.width);
- xvid.SetHeight(infoHdr.height);
- xvid.SetFrameCount(infoHdr.nframes);
- xvid.SetMaxQuant(infoHdr.nmax);
- xvid.SetMinQuant(infoHdr.nmin);
- xvid.SetAvgQuants(infoHdr.navg);
- xvid.SetIFrameCount(infoHdr.icount);
- xvid.SetIAvgQuants(infoHdr.iavg);
- xvid.SetPFrameCount(infoHdr.pcount);
- xvid.SetPAvgQuants(infoHdr.pavg);
- xvid.SetMaxFrameSize(infoHdr.nfsmax);
- xvid.SetMinFrameSize(infoHdr.nfsmin);
- xvid.SetIMaxFrameSize(infoHdr.ifsmax);
- xvid.SetIMinFrameSize(infoHdr.ifsmin);
- xvid.SetPMaxFrameSize(infoHdr.pfsmax);
- xvid.SetPMinFrameSize(infoHdr.pfsmin);
- //load quants data
- databuf = new CXvid::QUANTS[infoHdr.nframes];
- rfile.Read(databuf, sizeof(CXvid::QUANTS)*infoHdr.nframes);
- xvid.SetQuantsArray(databuf, infoHdr.nframes);
- //cleanup
- rfile.Close();
- xvid.SetOpened(true);
- xvid.SetAnalysed(true);
- return true;
- }