?? watermarkxview.cpp
字號:
// WaterMarkView.cpp : implementation of the CWaterMarkxView class
//
#include "stdafx.h"
#include "WaterMarkx.h"
#include "WaterMarkxDoc.h"
#include "WaterMarkxView.h"
#include "FirstWindow.h"
#include "stdlib.h"
#include "libmatlb.hpp"
#include "libmwsglm.hpp"
//#include "C_imwrite.hpp"
//#include "subplot.hpp"
//#include "imshow.hpp"
//#include "imread.hpp"
//#include "title.hpp"
#include "dct2.hpp"
#include "idct2.hpp"
//#include "isrgb.hpp"
//#include "rgb2gray.hpp"
//#include "clf.hpp"
//#include "imagesc.hpp"
#include "dibapi.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//標準文件框的文件名過濾器
static char BASED_CODE szFilter[]="BMP Files (*.bmp)|*.bmp|TIFF Files (*.tif)|*.tif|All Files(*.*)|*.*||";
/////////////////////////////////////////////////////////////////////////////
// CWaterMarkxView
// %定義中頻系數
int midband[8][8]={ {0,0,0,0,1,1,1,0},\
{0,0,0,0,1,1,1,0},\
{0,0,0,1,1,1,0,0},\
{0,0,0,1,1,1,0,0},\
{0,0,1,1,1,0,0,0},\
{0,0,1,1,1,0,0,0},\
{1,1,1,0,0,0,0,0},\
{1,1,1,0,0,0,0,0}};
IMPLEMENT_DYNCREATE(CWaterMarkxView, CFormView)
BEGIN_MESSAGE_MAP(CWaterMarkxView, CFormView)
//{{AFX_MSG_MAP(CWaterMarkxView)
ON_WM_DESTROY()
ON_WM_TIMER()
ON_WM_CTLCOLOR()
ON_WM_PAINT()
ON_WM_CLOSE()
ON_COMMAND(ID_WATER_INSERT, OnWaterInsert)
ON_COMMAND(ID_WATER_DISTILL, OnWaterDistill)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_OPEN_WATER, OnFileOpenWater)
ON_COMMAND(ID_DISTILL_OPEN, OnDistillOpen)
ON_WM_CREATE()
ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFileOpen)
ON_UPDATE_COMMAND_UI(ID_FILE_OPEN_WATER, OnUpdateFileOpenWater)
ON_UPDATE_COMMAND_UI(ID_WATER_INSERT, OnUpdateWaterInsert)
ON_UPDATE_COMMAND_UI(ID_WATER_DISTILL, OnUpdateWaterDistill)
ON_UPDATE_COMMAND_UI(ID_DISTILL_OPEN, OnUpdateDistillOpen)
ON_COMMAND(ID_FILE_SAVEQIANRU, OnFileSaveqianru)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVEQIANRU, OnUpdateFileSaveqianru)
ON_COMMAND(ID_FILE_SAVESHUIYIN, OnFileSaveshuiyin)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVESHUIYIN, OnUpdateFileSaveshuiyin)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
ON_BN_CLICKED(IDC_BUTTON1, OnAssaultTest)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWaterMarkxView construction/destruction
CWaterMarkxView::CWaterMarkxView()
: CFormView(CWaterMarkxView::IDD)
{
//{{AFX_DATA_INIT(CWaterMarkxView)
// NOTE: the ClassWizard will add member initialization here
A=5; // %0的嵌入強度因子
B=3; // %1的嵌入強度因子
G=3; // %嵌入強度因子
blocksize=8; // %原始圖像分塊系數大小
watersize=4; // %水印分塊系數大小
Filename=_T(""); //包含路徑
Filetype=_T("");
bWait=-1;
bfont=0;
bshow=0;
bdishow=0;
binsert=0;
bcheck=0;
bsave_I=0;
bsave_C=0;
i_Mc=0;
i_Nc=0;
i_Mw=0;
i_Nw=0;
water_block=0;
i_max_message=0;
//}}AFX_DATA_INIT
// TODO: add construction code here
m_OriginHDIB=NULL;
m_SuiyinHDIB=NULL;
m_QianruHDIB=NULL;
m_TiquHDIB=NULL;
m_OriginpalDIB=NULL;
m_SuiyinpalDIB=NULL;
m_OriginImageSize=0;
m_SuiyinImageSize=0;
}
CWaterMarkxView::~CWaterMarkxView()
{
}
void CWaterMarkxView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWaterMarkxView)
DDX_Control(pDX, IDC_SIM, m_sim);
DDX_Control(pDX, IDC_PSNR, m_psnr);
DDX_Control(pDX, IDC_TIME, m_time);
DDX_Control(pDX, IDC_CQ, m_cq);
DDX_Control(pDX, IDC_TITLE, m_title);
DDX_Control(pDX, IDC_NC, m_nc);
//}}AFX_DATA_MAP
}
BOOL CWaterMarkxView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CWaterMarkxView::OnInitialUpdate()
{
static int Counter = 0;
const char *p = "lib"; int argc = 1;
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
//libmmfileInitialize();
//libmwsglmInitialize();
//mlfHGInitialize( &argc, &p);//初始化
//InitializeModule_imshow(); //imshow 函數初始化
//InitializeModule_imagesc();
//InitializeModule_C_imwrite(); // C_imwrite函數初始化
//CreatFigDlg();
m_cq.SetCaption("");
m_psnr.SetCaption("");
m_sim.SetCaption("");
if (!Counter)
{
CFirstWindow dlg;
if(dlg.DoModal()==IDOK)
{
Counter++;
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CWaterMarkxView printing
BOOL CWaterMarkxView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CWaterMarkxView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CWaterMarkxView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CWaterMarkxView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CWaterMarkxView diagnostics
#ifdef _DEBUG
void CWaterMarkxView::AssertValid() const
{
CFormView::AssertValid();
}
void CWaterMarkxView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CWaterMarkxDoc* CWaterMarkxView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWaterMarkxDoc)));
return (CWaterMarkxDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWaterMarkxView message handlers
void CWaterMarkxView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
CRect rectClient;
CBrush brushBkColor;
GetClientRect(rectClient);
brushBkColor.CreateSolidBrush(RGB(128,128,128)); // 64 128 128
pDC->DPtoLP(rectClient);
pDC->FillRect(rectClient,&brushBkColor);
}
void CWaterMarkxView::OnDestroy()
{
CFormView::OnDestroy();
// TODO: Add your message handler code here
if(~h_a.IsEmpty())
h_a.Clear();
if(~h_fig.IsEmpty())
h_fig.Clear();
KillTimer(1);
KillTimer(2);
KillTimer(3);
//close(mwArray("all"));
//TerminateModule_imshow(); //結束imshow函數
//TerminateModule_C_imwrite();
}
void CWaterMarkxView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
char strMsg[50];
if(bWait==0)
{
DCTWater();
bWait=-1;
busydlg.OnOK();
KillTimer(1);
}
if(bWait==1)
{
DCTCheck();
bWait=-1;
busydlg.OnOK();
KillTimer(2);
}
if(bfont==1)
{
m_title.SetForeColor(255); //顯示紅色
m_title.SetBorderColor(16711680); //顯示藍色
bfont+=1;
}
else if(bfont==2)
{
m_title.SetForeColor(16711680);
m_title.SetBorderColor(65535); //顯示黃色
bfont-=2;
}
else
{
m_title.SetForeColor(65535);
m_title.SetBorderColor(255);
bfont+=1;
}
//得到指向狀態條窗口的指針
CStatusBar *pStatus=(CStatusBar*)AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
CTime time=CTime::GetCurrentTime();//返回系統當前時間
sprintf(strMsg,"%02d:%02d:%02d",time.GetHour(),time.GetMinute(),time.GetSecond());
pStatus->SetPaneText(3,strMsg);//在第四個指示器中顯示當前時間
CFormView::OnTimer(nIDEvent);
}
HBRUSH CWaterMarkxView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
//MessageBox("1354");
CBrush brush;
brush.CreateStockObject(HOLLOW_BRUSH);
/*if (pWnd->GetDlgCtrlID()==IDC_STATIC1||pWnd->GetDlgCtrlID()==IDC_STATIC2
||pWnd->GetDlgCtrlID()==IDC_STATIC3||pWnd->GetDlgCtrlID()==IDC_STATIC4
||pWnd->GetDlgCtrlID()==IDC_STATIC5||pWnd->GetDlgCtrlID()==IDC_STATIC6
||pWnd->GetDlgCtrlID()==IDC_STATIC7||pWnd->GetDlgCtrlID()==IDC_STATIC8
||pWnd->GetDlgCtrlID()==IDC_STATIC9||pWnd->GetDlgCtrlID()==IDC_COMRATIOTAB)
{
pDC->SetTextColor(RGB(255,255,0));
pDC->SetBkColor(0x00808040);
return HBRUSH(brush);
}*/
if(nCtlColor==CTLCOLOR_STATIC)
{pDC->SetTextColor(RGB(255,255,255));
pDC->SetBkColor(RGB(153,153,153));
return HBRUSH(brush);
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CWaterMarkxView::OnPaint()
{
CPaintDC dc(this); // device context for painting
int nImageWidth,nImageHeight;
// TODO: Add your message handler code here
CRect rectClient;
CBrush brushBkColor;
GetClientRect(rectClient);
brushBkColor.CreateSolidBrush(RGB(128,128,128));
dc.DPtoLP(rectClient);
dc.FillRect(rectClient,&brushBkColor);
if(m_OriginHDIB!=NULL)
{
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) m_OriginHDIB);
// 圖象寬度
nImageWidth=::DIBWidth(lpDIB);
// 圖象高度
nImageHeight=::DIBHeight(lpDIB);
CRect Rcdib;
Rcdib.top = Rcdib.left = 0;
Rcdib.right = nImageWidth;
Rcdib.bottom = nImageHeight;
::GlobalUnlock((HGLOBAL) m_OriginHDIB);
::PaintDIB(dc.m_hDC, &m_rectInitImage, m_OriginHDIB,
&Rcdib,m_OriginpalDIB);
}
if(m_SuiyinHDIB!=NULL)
{
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) m_SuiyinHDIB);
// 圖象寬度
nImageWidth=::DIBWidth(lpDIB);
// 圖象高度
nImageHeight=::DIBHeight(lpDIB);
CRect Rcdib;
Rcdib.top = Rcdib.left = 0;
Rcdib.right = nImageWidth;
Rcdib.bottom = nImageHeight;
::GlobalUnlock((HGLOBAL) m_SuiyinHDIB);
::PaintDIB(dc.m_hDC, &m_rectSuiyin, m_SuiyinHDIB,
&Rcdib,m_SuiyinpalDIB);
}
if(m_QianruHDIB!=NULL)
{
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) m_QianruHDIB);
// 圖象寬度
nImageWidth=::DIBWidth(lpDIB);
// 圖象高度
nImageHeight=::DIBHeight(lpDIB);
CRect Rcdib;
Rcdib.top = Rcdib.left = 0;
Rcdib.right = nImageWidth;
Rcdib.bottom = nImageHeight;
::GlobalUnlock((HGLOBAL) m_QianruHDIB);
::PaintDIB(dc.m_hDC, &m_rectQianruSuiyin, m_QianruHDIB,
&Rcdib,m_OriginpalDIB);
}
if(m_TiquHDIB!=NULL)
{
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) m_TiquHDIB);
// 圖象寬度
nImageWidth=::DIBWidth(lpDIB);
// 圖象高度
nImageHeight=::DIBHeight(lpDIB);
CRect Rcdib;
Rcdib.top = Rcdib.left = 0;
Rcdib.right = nImageWidth;
Rcdib.bottom = nImageHeight;
::GlobalUnlock((HGLOBAL) m_TiquHDIB);
::PaintDIB(dc.m_hDC, &m_rectTiquSuiyin, m_TiquHDIB,
&Rcdib,m_SuiyinpalDIB);
}
// Do not call CFormView::OnPaint() for painting messages
}
BOOL CWaterMarkxView::DestroyWindow()
{
// TODO: Add your specialized code here and/or call the base class
mlfHGTerminate();
libmwsglmTerminate();
libmmfileTerminate();
return CFormView::DestroyWindow();
}
void CWaterMarkxView::CreatFigDlg()
{
// TODO: Add your control notification handler code here
// 若還沒有創建坐標系則創建坐標系
if(tobool(isempty(h_a)))
{
char FigName[] ="fff"; //"_Figure_";
double BKColor[] = {0.306,0.433,0.746}; //0.306,0.433,0.746
char strVisible[] = "Off";
mwArray mwFigName(FigName);
mwArray mwBKColor(1,3,BKColor);
mwArray mwVisible(strVisible);
h_a = Get_h(mwFigName,mwBKColor,mwVisible);
// 查找Figure窗口
HWND hFig = ::FindWindow(NULL,FigName);
if(hFig == NULL)
{
AfxMessageBox("未能產生Figure窗口,圖形繪制失敗!");
return;
}
// 去掉Figure窗口的標題欄和邊框
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -