compressdlg.cpp
来自「基于块方向的图像无损压缩代码」· C++ 代码 · 共 327 行
CPP
327 行
// compressDlg.cpp : implementation file
//
#include "stdafx.h"
#include "compress.h"
#include "compressDlg.h"
#include "display.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
void _GA_Compress(CString InputFileName,CString OutputFileName);
void _GA_Decompress(CString InputFileName, CString OutputFileName);
double Calculate_CompressRatio(CString SourceFileName,CString ObjectFileName);
double Calculate_SNR(CString SourceFileName,CString ObjectFieName);
short int Width,Height;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCompressDlg dialog
CCompressDlg::CCompressDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCompressDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCompressDlg)
m_StartCompressTime = _T("");
m_EndCompressTime = _T("");
m_StartDecompressTime = _T("");
m_EndDecompressTime = _T("");
m_CompressFile = _T("");
m_CompressRatio = _T("");
m_DecompressFile = _T("");
m_SPRRatio = _T("");
m_CompressedFile = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
bPaint=FALSE;
}
void CCompressDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCompressDlg)
DDX_Control(pDX, IDC_DECOMPRESS_IMAGE, m_DecompressImage);
DDX_Control(pDX, IDC_COMPRESS_IMAGE, m_CompressImage);
DDX_Text(pDX, IDC_COMPRESS_EDIT1, m_StartCompressTime);
DDX_Text(pDX, IDC_COMPRESS_EDIT2, m_EndCompressTime);
DDX_Text(pDX, IDC_DECOMPRESS_EDIT1, m_StartDecompressTime);
DDX_Text(pDX, IDC_DECOMPRESS_EDIT2, m_EndDecompressTime);
DDX_Text(pDX, IDC_COMPRESS_FILE, m_CompressFile);
DDX_Text(pDX, IDC_COMPRESS_RATIO, m_CompressRatio);
DDX_Text(pDX, IDC_DECOMPRESS_FILE, m_DecompressFile);
DDX_Text(pDX, IDC_SPR_EDIT, m_SPRRatio);
DDX_Text(pDX, IDC_COMPRESSEDFILE, m_CompressedFile);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCompressDlg, CDialog)
//{{AFX_MSG_MAP(CCompressDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_COMPRESS_BUTTON, OnCompressButton)
ON_BN_CLICKED(IDC_DECOMPRESS_BUTTON, OnDecompressButton)
ON_BN_CLICKED(IDC_COMPRESS_EXPLOR, OnCompressExplor)
ON_BN_CLICKED(IDC_COMPRESSED_EXPLOR, OnCompressedExplor)
ON_BN_CLICKED(IDC_DECOMPRESS_EXPLOR, OnDecompressExplor)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCompressDlg message handlers
BOOL CCompressDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CCompressDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCompressDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if(bPaint)
{
CRect rcDIB;
rcDIB.top = rcDIB.left = 0;
rcDIB.right = Width;
rcDIB.bottom = Height;
::PaintDIB(dc.m_ps.hdc, &ImageRect, (HDIB)hdibImg,
&rcDIB,&m_CPal);
}
CDialog::OnPaint();
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCompressDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCompressDlg::OnCompressButton()
{
// TODO: Add your control notification handler code here
PALETTEENTRY currentPalette[MAX_COLORS];
CTime MyTime,tTime;
m_CompressImage.GetWindowRect(ImageRect);
ScreenToClient(ImageRect);
ImageRect.top+=12;
ImageRect.left+=3;
ImageRect.right-=3;
ImageRect.bottom-=3;
if(bPaint)
{
m_CPal.DeleteObject();
GlobalFree(hdibImg);
hdibImg=NULL;
}
UpdateData(TRUE);
tTime=MyTime.GetCurrentTime();
m_StartCompressTime=tTime.Format("%H:%M:%S");
hdibImg=appImgToDIB(m_CompressFile );
bPaint=TRUE;
CreateDIBPalette((HDIB)hdibImg, &m_CPal);
m_CPal.GetPaletteEntries(0,MAX_COLORS,(LPPALETTEENTRY)¤tPalette);
_GA_Compress(m_CompressFile,m_CompressedFile);
tTime=MyTime.GetCurrentTime();
m_EndCompressTime=tTime.Format("%H:%M:%S");
char msg[30];
double ratio;
ratio=Calculate_CompressRatio(m_CompressFile,m_CompressedFile);
sprintf(msg,"%f",ratio);
m_CompressRatio=(CString)msg;
UpdateData(FALSE);
::GlobalUnlock(hdibImg);
InvalidateRect((LPRECT)&ImageRect,FALSE);
UpdateWindow();
}
void CCompressDlg::OnDecompressButton()
{
// TODO: Add your control notification handler code here
PALETTEENTRY currentPalette[MAX_COLORS];
CTime MyTime,tTime;
m_DecompressImage.GetWindowRect(ImageRect);
ScreenToClient(ImageRect);
ImageRect.top+=12;
ImageRect.left-=3;
ImageRect.right-=3;
ImageRect.bottom-=3;
if(bPaint)
{
m_CPal.DeleteObject();
GlobalFree(hdibImg);
hdibImg=NULL;
}
UpdateData(TRUE);
tTime=MyTime.GetCurrentTime();
m_StartDecompressTime=tTime.Format("%H:%M:%S");
_GA_Decompress(m_CompressedFile,m_DecompressFile);
tTime=MyTime.GetCurrentTime();
m_EndDecompressTime=tTime.Format("%H:%M:%S");
double SNR;
char msg[30];
SNR=Calculate_SNR(m_CompressFile,m_DecompressFile);
sprintf(msg,"%f",SNR);
m_SPRRatio=(CString)msg;
hdibImg=appImgToDIB(m_DecompressFile );
UpdateData(FALSE);
bPaint=TRUE;
CreateDIBPalette((HDIB)hdibImg, &m_CPal);
m_CPal.GetPaletteEntries(0,MAX_COLORS,(LPPALETTEENTRY)¤tPalette);
::GlobalUnlock(hdibImg);
InvalidateRect((LPRECT)&ImageRect,FALSE);
UpdateWindow();
}
void CCompressDlg::OnCompressExplor()
{
// TODO: Add your control notification handler code here
char FilterString[]="Bitmap File(*.bmp)\0*.bmp\0 All File(*.*)\0*.*\0\0";
CFileDialog dlg(TRUE);
dlg.m_ofn.lpstrFilter=FilterString;
if(dlg.DoModal()==IDOK) m_CompressFile=dlg.GetPathName();
UpdateData(FALSE);
}
void CCompressDlg::OnCompressedExplor()
{
// TODO: Add your control notification handler code here
char FilterString[]="Ari File(*.wsq)\0*.wsq\0 All File(*.*)\0*.*\0\0";
CFileDialog dlg(FALSE);
dlg.m_ofn.lpstrFilter=FilterString;
if(dlg.DoModal()==IDOK) m_CompressedFile=dlg.GetPathName();
UpdateData(FALSE);
}
void CCompressDlg::OnDecompressExplor()
{
// TODO: Add your control notification handler code here
char FilterString[]="Bitmap File(*.bmp)\0*.bmp\0 All File(*.*)\0*.*\0\0";
CFileDialog dlg(FALSE);
dlg.m_ofn.lpstrFilter=FilterString;
if(dlg.DoModal()==IDOK) m_DecompressFile=dlg.GetPathName();
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?