📄 dlgrlebmp.cpp
字号:
// DlgRLEBmp.cpp : implementation file
//
#include "stdafx.h"
#include "Compress.h"
#include "DlgRLEBmp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
struct CompressNode{
int val;
CompressNode *next;
};
const int PANES_Row=12;
const int PANES_Col=14;
const int PANE_Height=12;
const int PANE_Width=12;
const COLORREF PANES_BkColor=RGB(255,255,255);//RGB(0xd4,0xd0,0xc8);
const COLORREF PANES_BorderColor=RGB(0x0,0x4d,0x99);
const COLORREF PANE_FillColor=RGB(0,125,0);//RGB(0,0,0);
const COLORREF PANE_NullColor=PANES_BkColor;//RGB(255,255,0);
const int PANES_x10=60;
const int PANES_y10=40;
const int PANES_x11=PANES_x10+PANE_Width*PANES_Col;
const int PANES_y11=PANES_y10+PANE_Height*PANES_Row;
const int PANES_x20=PANES_x11+PANE_Width*9;
const int PANES_y20=PANES_y10;
const int PANES_x21=PANES_x20+PANE_Width*PANES_Col;
const int PANES_y21=PANES_y20+PANE_Height*PANES_Row;
int Original[PANES_Row*PANES_Col];
struct CompressNode *pCompress=new CompressNode;
int Uncompress[PANES_Row*PANES_Col];
/////////////////////////////////////////////////////////////////////////////
// CDlgRLEBmp dialog
CDlgRLEBmp::CDlgRLEBmp(CWnd* pParent /*=NULL*/)
: CDialog(CDlgRLEBmp::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgRLEBmp)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDlgRLEBmp::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgRLEBmp)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgRLEBmp, CDialog)
//{{AFX_MSG_MAP(CDlgRLEBmp)
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BUTTON_Clear, OnBUTTONClear)
ON_BN_CLICKED(IDC_BUTTON_Compress, OnBUTTONCompress)
ON_BN_CLICKED(IDC_BUTTON_Uncompress, OnBUTTONUncompress)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgRLEBmp message handlers
BOOL CDlgRLEBmp::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
pTable1=new CPanes(this,PANES_x10,PANES_y10,PANES_Row,PANES_Col,PANE_Height,PANE_Width,RGB(0,0,0),RGB(0,150,0),RGB(0,230,0),RGB(0,0,0),1,"绘制图像");
pTable2=new CPanes(this,PANES_x20,PANES_y20,PANES_Row,PANES_Col,PANE_Height,PANE_Width,RGB(0,0,0),RGB(0,150,0),RGB(0,230,0),RGB(0,0,0),1,"还原图像");
pTable1->Clear();
pTable2->Clear();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgRLEBmp::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
pTable1->DoLButtonDown(point);
pTable2->DoLButtonDown(point);
CDialog::OnLButtonDown(nFlags, point);
}
void CDlgRLEBmp::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
pTable1->DoMouseMove(point);
pTable2->DoMouseMove(point);
CDialog::OnMouseMove(nFlags, point);
}
void CDlgRLEBmp::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
pTable1->DoLButtonUp(point);
pTable2->DoLButtonUp(point);
CDialog::OnLButtonUp(nFlags, point);
}
void CDlgRLEBmp::OnPaint()
{
CPaintDC dc(this); // device context for painting
pTable1->Draw();
pTable2->Draw();
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
}
void CDlgRLEBmp::OnBUTTONClear()
{
// TODO: Add your control notification handler code here
pTable1->Clear();
pTable2->Clear();
}
void CDlgRLEBmp::OnBUTTONCompress()
{
// TODO: Add your control notification handler code here
/*
int Original[PANES_Row][PANES_Col];
struct CompressNode *pCompress;
int Uncompress[PANES_Row][PANES_Col];
*/
pTable1->Get(Original);
int iNum;
CString s;
struct CompressNode *pPre,*pNext;
pPre=pCompress; pPre->next=NULL;
/**********************************************************
对于二值矩阵Original的每一行{
重复计数iNum赋值为1;
对于该行的第一列~倒数第二列中的每一列{
如果当前列的值=下一列的值{
重复计数iNum加一;
如果当前列是倒数第二列{
如果当前列的值=1,将iNum写入压缩数据链pCompress,否则将-iNum写入压缩数据链pCompress;
}
}
否则{ //如果当前列的值不等于下一列的值
如果当前列的值=1,将iNum写入压缩数据链pCompress,否则将-iNum写入压缩数据链pCompress;
置重复计数iNum为1;
如果当前列是倒数第二列{
如果下一列的值=1,将+1写入压缩数据链pCompress,否则将-1写入压缩数据链pCompress;
}
}
}
}
**********************************************************/
//对于二值矩阵Original的每一行{
for(int i=0; i<PANES_Row; i++){
//重复计数iNum赋值为1;
iNum=1;
//对于该行的第一列~倒数第二列中的每一列{
for(int j=0; j< (PANES_Col-1); j++){
//如果当前列的值=下一列的值{
if( Original[PANES_Col*i+j]==Original[PANES_Col*i+j+1] ){
//重复计数iNum加一;
iNum++;
//如果当前列是倒数第二列{
if( j==(PANES_Col-2) ){
pNext=new CompressNode;
//如果当前列的值=1,将iNum写入压缩数据链pCompress,否则将-iNum写入压缩数据链pCompress;
pNext->val=(Original[PANES_Col*i+j]==1)? iNum:(-iNum);
pNext->next=NULL;
pPre->next=pNext;
pPre=pNext;
iNum=1;
}
}
//否则{ //如果当前列的值不等于下一列的值
else{
pNext=new CompressNode;
//如果当前列的值=1,将iNum写入压缩数据链pCompress,否则将-iNum写入压缩数据链pCompress;
pNext->val=(Original[PANES_Col*i+j]==1)? iNum:(-iNum);
pNext->next=NULL;
pPre->next=pNext;
pPre=pNext;
//置重复计数iNum为1;
iNum=1;
//如果当前列是倒数第二列{
if( j==(PANES_Col-2) ){
pNext=new CompressNode;
//如果下一列的值=1,将+1写入压缩数据链pCompress,否则将-1写入压缩数据链pCompress;
pNext->val=(Original[PANES_Col*i+j+1]==1)? 1:(-1);
pNext->next=NULL;
pPre->next=pNext;
pPre=pNext;
iNum=1;
//}
}
//}
}
//}
}
//}
}
//显示压缩结果,激活解压按钮
pPre=pCompress->next;
CString csCompress="",cs;
int iSum=0;
while(pPre!=NULL){
cs.Format("%6d",pPre->val);
csCompress+=cs;
if(pPre->val>0)
iSum+=pPre->val;
else
iSum-=pPre->val;
if(iSum%PANES_Col==0)
csCompress+="\r\n";
pPre=pPre->next;
}
this->SetDlgItemText(IDC_EDIT_Compress,csCompress);
CButton *pBtn;
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Uncompress);
pBtn->EnableWindow(TRUE);
}
void CDlgRLEBmp::OnBUTTONUncompress()
{
// TODO: Add your control notification handler code here
struct CompressNode *p;
p=pCompress->next;
int k=0;
/***************************************************
如果解压的结果数组Uncompress没有填满{
如果压缩数据链pCompress上的数据已处理完,结束解压;
从压缩数据链上取一个数据;
如果数据值val>0,则向解压结果数组Uncompress中写入val个1,否则写入val个0;
准备取下一个数据;
}
***************************************************/
//如果解压的结果数组Uncompress没有填满{
while( k<(PANES_Row*PANES_Col) ){
//如果压缩数据链pCompress上的数据已处理完,结束解压;
if(p==NULL)
break;
//从压缩数据链上取一个数据;如果数据值val>0,则向解压结果数组Uncompress中写入val个1,
if(p->val>0){
for(int i=0; i<p->val; i++)
Uncompress[k++]=1;
}
//否则写入val个-1;
else{
for(int i=0; i<(-p->val); i++)
Uncompress[k++]=-1;
}
//准备取下一个数据;
p=p->next;
}
//显示图像
pTable2->Fill(Uncompress);
/*
struct CompressNode *pPre,*p;
pPre=pCompress->next;
while(pPre!=NULL){
p=pPre;
pPre=pPre->next;
delete p;
}
*/
CButton *pBtn;
pBtn=(CButton*)GetDlgItem(IDC_BUTTON_Uncompress);
pBtn->EnableWindow(FALSE); //bAble为TRUE或FALSE
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -