📄 entropycodingview.cpp
字号:
// entropyCodingView.cpp : implementation of the CentropyCodingView class
//
#include "stdafx.h"
#include "entropyCoding.h"
#include "entropyCodingDoc.h"
#include "entropyCodingView.h"
#include "HuffencodeDialog.h"
#include "RunlengthDialog.h"
#include "ACDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CentropyCodingView
IMPLEMENT_DYNCREATE(CentropyCodingView, CView)
BEGIN_MESSAGE_MAP(CentropyCodingView, CView)
//{{AFX_MSG_MAP(CentropyCodingView)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_Huff_Encode, OnHuffEncode)
ON_COMMAND(ID_RunLength_Coding, OnRunLengthCoding)
ON_COMMAND(ID_Arithmetic_Coding, OnArithmeticCoding)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CentropyCodingView construction/destruction
CentropyCodingView::CentropyCodingView()
{
// TODO: add construction code here
}
CentropyCodingView::~CentropyCodingView()
{
}
BOOL CentropyCodingView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CentropyCodingView drawing
void CentropyCodingView::OnDraw(CDC* pDC)
{
CentropyCodingDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if(!IsFirstDraw)
{
int i,j;
CDC * dc;
dc=GetDC();
for(i=0;i<m_orgHeight;i++)
for(j=0;j<m_orgWidth;j++)
{
dc->SetPixel(j,i,RGB(
m_pImageData[m_orgWidth*(m_orgHeight-i)+j],
m_pImageData[m_orgWidth*(m_orgHeight-i)+j],
m_pImageData[m_orgWidth*(m_orgHeight-i)+j]));
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CentropyCodingView printing
BOOL CentropyCodingView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CentropyCodingView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CentropyCodingView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CentropyCodingView diagnostics
#ifdef _DEBUG
void CentropyCodingView::AssertValid() const
{
CView::AssertValid();
}
void CentropyCodingView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CentropyCodingDoc* CentropyCodingView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CentropyCodingDoc)));
return (CentropyCodingDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CentropyCodingView message handlers
void CentropyCodingView::OnFileOpen()
{
CentropyCodingDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CFileDialog dlg(true,NULL,NULL,OFN_OVERWRITEPROMPT,"bmp(*.bmp)|*.bmp||",NULL);
if(dlg.DoModal()==IDOK)
{
m_szFileName = dlg.GetFileName();
m_szFilePathName = dlg.GetPathName();
}
else
return;
m_pImageData = OpenBMP(m_szFilePathName, &m_orgWidth, &m_orgHeight);
IsFirstDraw=FALSE;
Invalidate(TRUE);
}
BYTE * CentropyCodingView::OpenBMP(CString fileName, long *width, long *height)
{
BYTE * pData;
*width = 0;
*height = 0;
if(fileName=="")
return NULL;
BITMAPINFO bmpInfo;
BITMAPFILEHEADER bmpFileHead;
CFile file;
if((file.Open(fileName,CFile::modeRead|CFile::shareDenyNone))==NULL)
{
AfxMessageBox("Can not open the file");
return NULL;
}
file.Read(&bmpFileHead,sizeof(BITMAPFILEHEADER));
file.Read(&bmpInfo,sizeof(BITMAPINFOHEADER));
*width = bmpInfo.bmiHeader.biWidth;
*height = bmpInfo.bmiHeader.biHeight;
long lFileSize = bmpFileHead.bfSize - bmpFileHead.bfOffBits;
pData = (BYTE*)new char[lFileSize];
if(!pData)
return NULL;
file.ReadHuge(pData,lFileSize);
file.Close();
return pData;
}
void CentropyCodingView::OnHuffEncode()
{
CHuffencodeDialog dlg;
dlg.DoModal();
}
void CentropyCodingView::OnRunLengthCoding()
{
CRunlengthDialog dlg;
dlg.DoModal();
}
void CentropyCodingView::OnArithmeticCoding()
{
CACDialog dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -