📄 dctwaterview.cpp
字号:
// DCTWaterView.cpp : implementation of the CDCTWaterView class
//
#include "stdafx.h"
#include "DCTwater.h"
#include "DCTwaterDoc.h"
#include "DCTWaterView.h"
///////////////My code begins//////////////
// These six header files are for "_open", "_read" and "_write" functions
//and string functions
#include <io.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
//The header file for "log", "pow" functions
#include <math.h>
///////////////My code ends//////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDCTWaterView
IMPLEMENT_DYNCREATE(CDCTWaterView, CScrollView)
BEGIN_MESSAGE_MAP(CDCTWaterView, CScrollView)
//{{AFX_MSG_MAP(CDCTWaterView)
ON_WM_DESTROY()
ON_COMMAND(ID_TRANSFORM_BMPRAW, OnTransformBmpraw)
ON_COMMAND(ID_TRANSFORM_RAWBMP, OnTransformRawbmp)
ON_COMMAND(ID_WATERMARK_ORIGINAL, OnWatermarkOriginal)
ON_COMMAND(ID_WATERMARK_ORIGINAL1, OnWatermarkOriginal1)
ON_COMMAND(ID_WATERMARK_PERMUTED, OnWatermarkPermuted)
ON_COMMAND(ID_WATERMARK_SAVE, OnWatermarkSave)
ON_COMMAND(ID_WATERMARK_SAVEAS, OnWatermarkSaveas)
ON_COMMAND(ID_ATTACK_IMAGE, OnAttackImage)
ON_COMMAND(ID_ATTACK_EXTRACT, OnAttackExtract)
ON_COMMAND(ID_ATTACK_SAVE, OnAttackSave)
ON_COMMAND(ID_EMBED_EMBED, OnEmbedEmbed)
ON_COMMAND(ID_EMBED_SAVEIMAGE, OnEmbedSaveimage)
ON_COMMAND(ID_EXTRACT_EXTRACT, OnExtractExtract)
ON_COMMAND(ID_EXTRACT_SAVE, OnExtractSave)
ON_UPDATE_COMMAND_UI(ID_WATERMARK_ORIGINAL1, OnUpdateWatermarkOriginal1)
ON_UPDATE_COMMAND_UI(ID_WATERMARK_PERMUTED, OnUpdateWatermarkPermuted)
ON_UPDATE_COMMAND_UI(ID_WATERMARK_SAVE, OnUpdateWatermarkSave)
ON_UPDATE_COMMAND_UI(ID_WATERMARK_SAVEAS, OnUpdateWatermarkSaveas)
ON_UPDATE_COMMAND_UI(ID_EMBED_SAVEIMAGE, OnUpdateEmbedSaveimage)
ON_UPDATE_COMMAND_UI(ID_EXTRACT_SAVE, OnUpdateExtractSave)
ON_UPDATE_COMMAND_UI(ID_ATTACK_EXTRACT, OnUpdateAttackExtract)
ON_UPDATE_COMMAND_UI(ID_ATTACK_IMAGE, OnUpdateAttackImage)
ON_UPDATE_COMMAND_UI(ID_ATTACK_SAVE, OnUpdateAttackSave)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDCTWaterView construction/destruction
CDCTWaterView::CDCTWaterView()
{
// TODO: add construction code here
///////My code begins/////////////
hEmbedMem=NULL;//clear the memory handle for encode/decode
///////My code ends/////////////
}
CDCTWaterView::~CDCTWaterView()
{
}
BOOL CDCTWaterView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
void CDCTWaterView::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
///////My code begins/////
GlobalFree(hEmbedMem);//release memory
///////My code ends/////
}
/////////////////////////////////////////////////////////////////////////////
// CDCTWaterView drawing
void CDCTWaterView::OnDraw(CDC* pDC)
{
CDCTWaterDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//////////My code Begins to draw the pictures////////////////////
CBrush cb,*cbold;//The Current brush and the old brush
unsigned long int size;//The size of image
char temp[256];//The temporary string
int left,top;//The left and top position for TextOut function
size=pDoc->m_OriginalImageSize;//Get the image size
////If the image size is not right and no watermark is opened, set the screen dark
if((size!=512*512)&&(size!=256*256)&&(size!=640*480)&&(size!=320*240)&&pDoc->m_OriginalWatermarkOpened==FALSE)
{
cb.CreateSolidBrush(RGB(128,128,128));
cbold=pDC->SelectObject(&cb);
pDC->Rectangle(0,0,2500,1200);
pDC->SelectObject(cbold);
return;
}
////Else clear the user screen in white
cb.CreateSolidBrush(RGB(255,255,255));
cbold=pDC->SelectObject(&cb);
pDC->Rectangle(0,0,2500,1200);
pDC->SelectObject(cbold);//Restore the old Brush
////If the watermark is opened,display it
if(pDoc->m_OriginalWatermarkOpened)
{
::StretchDIBits(pDC->m_hDC,20,20+572,128,128,0,0,128,128,pDoc->m_OriginalWatermarkBytes+62,(BITMAPINFO *)(pDoc->m_OriginalWatermarkBytes+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
////Display the original image size information
pDC->SetTextColor(RGB(0,0,255));//set the text color as BLUE color
left=10;//The left position
top=572+128+40;//The top position
//Get the display information
pDC->TextOut(left,top,"Original(128x128)");//Display the information
}
////If the watermark is permuted,display it
if(pDoc->m_Permuted)
{
::StretchDIBits(pDC->m_hDC,20+200,20+572,128,128,0,0,128,128,pDoc->m_PermutedWatermarkBytes+62,(BITMAPINFO *)(pDoc->m_PermutedWatermarkBytes+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
////Display the permuted image information
pDC->SetTextColor(RGB(0,0,225));//Set text color as RED color
left=10+200;//The left position
top=572+128+40;//The top position
//Get the display information
pDC->TextOut(left,top,"Permuted");//Display the information
}
////If the watermark is opened,display it
if(pDoc->m_OriginalWatermarkOpened1)
{
::StretchDIBits(pDC->m_hDC,20,20+572+200,128,128,0,0,128,128,pDoc->m_OriginalWatermarkBytes1+62,(BITMAPINFO *)(pDoc->m_OriginalWatermarkBytes1+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
////Display the original image size information
pDC->SetTextColor(RGB(0,0,255));//set the text color as BLUE color
left=10;//The left position
top=572+128+40+128+40+20;//The top position
//Get the display information
pDC->TextOut(left,top,"Original(128x128)");//Display the information
}
////If the watermark is permuted,display it
if(pDoc->m_Permuted1)
{
::StretchDIBits(pDC->m_hDC,20+200,20+572+200,128,128,0,0,128,128,pDoc->m_PermutedWatermarkBytes1+62,(BITMAPINFO *)(pDoc->m_PermutedWatermarkBytes1+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
////Display the permuted image information
pDC->SetTextColor(RGB(0,0,225));//Set text color as RED color
left=10+200;//The left position
top=572+128+40+128+40+20;//The top position
//Get the display information
pDC->TextOut(left,top,"Permuted");//Display the information
}
////If the original image is wrong return
if((size!=512*512)&&(size!=256*256)&&(size!=640*480)&&(size!=320*240))return;
////Else Show the original image according to the adjustment value
::StretchDIBits(pDC->m_hDC,20,20,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,0,0,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,pDoc->m_DisplayImageBytes+1078,(BITMAPINFO *)(pDoc->m_DisplayImageBytes+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
////Display the original image size information
pDC->SetTextColor(RGB(0,0,255));//set the text color as BLUE color
left=pDoc->m_OriginalImageWidth/2-80;//The left position
top=pDoc->m_OriginalImageHeight+40;//The top position
//Get the display information
sprintf(temp,"Original Image(%dx%d)",pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight);
pDC->TextOut(left,top,temp);//Display the information
////If Subsampled image exists, display it
if(pDoc->m_Subsampled1==TRUE)
{
//Show the subsampled image
::StretchDIBits(pDC->m_hDC,40+pDoc->m_OriginalImageWidth,20,256,256,0,0,256,256,pDoc->m_DisplayImageBytes11+1078,(BITMAPINFO *)(pDoc->m_DisplayImageBytes11+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
}
////If Subsampled image exists, display it
if(pDoc->m_Subsampled2==TRUE)
{
//Show the decoded image
::StretchDIBits(pDC->m_hDC,40+pDoc->m_OriginalImageWidth+256,20,256,256,0,0,256,256,pDoc->m_DisplayImageBytes12+1078,(BITMAPINFO *)(pDoc->m_DisplayImageBytes12+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
}
////If Subsampled image exists, display it
if(pDoc->m_Subsampled3==TRUE)
{
//Show the decoded image
::StretchDIBits(pDC->m_hDC,40+pDoc->m_OriginalImageWidth,20+256,256,256,0,0,256,256,pDoc->m_DisplayImageBytes13+1078,(BITMAPINFO *)(pDoc->m_DisplayImageBytes13+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
}
////If Subsampled image exists, display it
if(pDoc->m_Subsampled4==TRUE)
{
pDC->SetTextColor(RGB(0,0,255));//set the text color as BLUE color
left=pDoc->m_OriginalImageWidth/2*3;//The left position
top=pDoc->m_OriginalImageHeight+40;//The top position
pDC->TextOut(left,top,"Subsampled pictures(4*256*256)");//Display
//Show the decoded image
::StretchDIBits(pDC->m_hDC,40+pDoc->m_OriginalImageWidth+256,20+256,256,256,0,0,256,256,pDoc->m_DisplayImageBytes14+1078,(BITMAPINFO *)(pDoc->m_DisplayImageBytes14+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
}
////If watermarked image exists, display it
if(pDoc->m_Embeded1==TRUE)
{
pDC->SetTextColor(RGB(0,0,255));//set the text color as BLUE color
left=pDoc->m_OriginalImageWidth/2*3+550;//The left position
top=pDoc->m_OriginalImageHeight+40;//The top position
pDC->TextOut(left,top,"Embeded Image(512*512)");//Display
//Get the method information and bitrate
sprintf(temp,"Subsampling Method");
//The left position
left=pDoc->m_OriginalImageWidth*3/2+550;
top=pDoc->m_OriginalImageHeight+60;//The top position
pDC->TextOut(left,top,temp);//Display the information
//Get the PSNR and MSE
sprintf(temp,"(PSNR[%6.4f] MSE[%6.4f])",pDoc->m_EmbededPSNR,pDoc->m_EmbededMSE);
left=pDoc->m_OriginalImageWidth*3/2+550;
top=pDoc->m_OriginalImageHeight+120;//The top position
pDC->TextOut(left,top,temp);//Display the information
//Show the decoded image
::StretchDIBits(pDC->m_hDC,2*(40+pDoc->m_OriginalImageWidth),20,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,0,0,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,pDoc->m_DisplayImageBytes1+1078,(BITMAPINFO *)(pDoc->m_DisplayImageBytes1+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
}
////If watermarked image exists, display it
if(pDoc->m_Embeded0==TRUE)
{
pDC->SetTextColor(RGB(0,0,255));//set the text color as BLUE color
left=pDoc->m_OriginalImageWidth/2*3;//The left position
top=pDoc->m_OriginalImageHeight+40;//The top position
pDC->TextOut(left,top,"Embeded Image");//Display
//Get the method information and bitrate
sprintf(temp,"Variance Based Method");
//The left position
left=pDoc->m_OriginalImageWidth*3/2;
top=pDoc->m_OriginalImageHeight+60;//The top position
pDC->TextOut(left,top,temp);//Display the information
//Get the PSNR and MSE
sprintf(temp,"(PSNR[%6.4f] MSE[%6.4f])",pDoc->m_EmbededPSNR,pDoc->m_EmbededMSE);
top=pDoc->m_OriginalImageHeight+120;//The top position
pDC->TextOut(left,top,temp);//Display the information
//Show the decoded image
::StretchDIBits(pDC->m_hDC,40+pDoc->m_OriginalImageWidth,20,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,0,0,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,pDoc->m_DisplayImageBytes1+1078,(BITMAPINFO *)(pDoc->m_DisplayImageBytes1+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
}
////If watermark is extracted, display it
if(pDoc->m_Extracted==TRUE)
{
::StretchDIBits(pDC->m_hDC,20+400,20+572,128,128,0,0,128,128,pDoc->m_ExtractedWatermarkBytes+62,(BITMAPINFO *)(pDoc->m_ExtractedWatermarkBytes+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
////Display the extracted watermark size information
pDC->SetTextColor(RGB(0,0,225));//Set text color as RED color
left=10+400;//The left position
top=572+128+40;//The top position
sprintf(temp,"Extracted Watermark Before Attack NC=%6.4f",NC1);
//Get the display information
pDC->TextOut(left,top,temp);//Display the information
}
if(pDoc->m_Extracted1==TRUE)
{
::StretchDIBits(pDC->m_hDC,20+400,20+572+200,128,128,0,0,128,128,pDoc->m_ExtractedWatermarkBytes1+62,(BITMAPINFO *)(pDoc->m_ExtractedWatermarkBytes1+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
////Display the extracted watermark size information
pDC->SetTextColor(RGB(0,0,225));//Set text color as RED color
left=10+400;//The left position
top=572+128+40+200;//The top position
sprintf(temp,"Extracted Watermark Before Attack NC=%6.4f",NC2);
//Get the display information
pDC->TextOut(left,top,temp);//Display the information
}
//If the attacked watermark is extracted, display it
if(pDoc->m_AttackExtracked==TRUE)
{
::StretchDIBits(pDC->m_hDC,20+1064,20+572,128,128,0,0,128,128,pDoc->m_AttackedWatermarkBytes+62,(BITMAPINFO *)(pDoc->m_AttackedWatermarkBytes+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
////Display the attacked watermark information
pDC->SetTextColor(RGB(0,0,255));//Set text color as RED color
left=20+1064;//The left position
top=572+128+40;//The top position
sprintf(temp,"Extracted Watermark After Attack NC=%6.4f",NC3);
//Get the display information
pDC->TextOut(left,top,temp);//Display the information
}
if(pDoc->m_AttackExtracked1==TRUE)
{
::StretchDIBits(pDC->m_hDC,20+1064,20+572+200,128,128,0,0,128,128,pDoc->m_AttackedWatermarkBytes1+62,(BITMAPINFO *)(pDoc->m_AttackedWatermarkBytes+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
////Display the attacked watermark information
pDC->SetTextColor(RGB(0,0,255));//Set text color as RED color
left=20+1064;//The left position
top=572+128+40+200;//The top position
sprintf(temp,"Extracted Watermark After Attack NC=%6.4f",NC4);
//Get the display information
pDC->TextOut(left,top,temp);//Display the information
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -