⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dctwaterview.cpp

📁 站长!这是DCT域的图像数字水印嵌入及提取程序!请查收!暂归入加密解密类别!
💻 CPP
📖 第 1 页 / 共 5 页
字号:


	//If the attacked image is opened, display it
	if(pDoc->m_AttackedImageOpened&&pDoc->m_Embeded1)
	{
	  ::StretchDIBits(pDC->m_hDC,512*3+110,20,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,0,0,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,pDoc->m_DisplayImageBytes2+1078,(BITMAPINFO *)(pDoc->m_DisplayImageBytes2+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
	  ////Display the attacked image size information
	  pDC->SetTextColor(RGB(0,0,255));//Set text color as RED color
	  left=pDoc->m_OriginalImageWidth*3+180;//The left position
	  top=pDoc->m_OriginalImageHeight+40;//The top position
	  //Get the display information
	  sprintf(temp,"Attacked (%dx%d)",pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight);
	  pDC->TextOut(left,top,temp);//Display the information
	}
	//Delete the brush object cb
	::DeleteObject(&cb);

		//If the attacked image is opened, display it
	if(pDoc->m_AttackedImageOpened&&pDoc->m_Embeded0)
	{
	  ::StretchDIBits(pDC->m_hDC,20+1064+512+20+40,20,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,0,0,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,pDoc->m_DisplayImageBytes2+1078,(BITMAPINFO *)(pDoc->m_DisplayImageBytes2+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
	  ////Display the attacked image size information
	  pDC->SetTextColor(RGB(0,0,255));//Set text color as RED color
	  left=pDoc->m_OriginalImageWidth*3+120;//The left position
	  top=pDoc->m_OriginalImageHeight+40;//The top position
	  //Get the display information
	  sprintf(temp,"Attacked (%dx%d)",pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight);
	  pDC->TextOut(left,top,temp);//Display the information
	}
	//Delete the brush object cb
	::DeleteObject(&cb);
//////////My code ends to draw the pictures////////////////////

}

/////////////////////////////////////////////////////////////////////////////
// CDCTWaterView printing
void CDCTWaterView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
////////////////////My code begins to print///////////////////////
	CDCTWaterDoc* pDoc = GetDocument();//Get pDoc
	ASSERT_VALID(pDoc);//Make pDoc valid
    double a,b;//The ratio for width and height
	char temp[256];//Temporary memory for string
	int left,top,width,height;//The variables for print position
	POINT point;//The position for display information
	CString Title;
	////Set text mode and color and mapmode
	pDC->SetTextAlign(TA_LEFT);//Left mode
	pDC->SetTextColor(RGB(0,0,0));//Block text
	pDC->SetMapMode(1);//Mode 1
	////Get the ratio in width and height directions
	a=(double)pInfo->m_rectDraw.right/5.0*4.0;
	a=a/(double)pDoc->m_OriginalImageWidth;
	b=(double)pInfo->m_rectDraw.bottom/40.0*17.0;
	b=b/(double)pDoc->m_OriginalImageHeight;
	if(a>b)a=b;//Select the smaller one as the common ratio
	
	//The first page is for the original image and original watermarks
	if(pInfo->m_nCurPage==1)
	{
	  ////Calculate the position and size for printing the original image
	  left=(int)((double)pInfo->m_rectDraw.right/2.0)-(int)(a/2.0*(double)pDoc->m_OriginalImageWidth);
	  top=pInfo->m_rectDraw.bottom/20;
	  width=(int)(a*(double)pDoc->m_OriginalImageWidth);
	  height=(int)(a*(double)pDoc->m_OriginalImageHeight);
	  //Get the information for original image
	  Title=pDoc->GetTitle();//Get the document title
	  sprintf(temp,"(Original Size[%dx%d])",pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight);
	  Title+=temp;
	  ////Compute the position to display the information of the original image
	  point.x=left;
	  point.y=top-200;
	  pDC->TextOut(point.x,point.y,Title);//Print the information for original image
	  ////Print the original image
	  ::StretchDIBits(pDC->m_hDC,left,top,width,height,0,0,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,pDoc->m_DisplayImageBytes+1078,(BITMAPINFO *)(pDoc->m_DisplayImageBytes+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
      if(pDoc->m_OriginalWatermarkOpened)
	  {
	    point.x=left+(int)a*64;
	    point.y=top+height+100;
	    pDC->TextOut(point.x,point.y,"Original Watermark(128x128)");//Print the information for original watermark
		////Print the original watermark
	    ::StretchDIBits(pDC->m_hDC,left+(int)(a*64.0),top+height+300,(int)(a*128.0),(int)(a*128.0),0,0,128,128,pDoc->m_OriginalWatermarkBytes+62,(BITMAPINFO *)(pDoc->m_OriginalWatermarkBytes+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
	  }
	  if(pDoc->m_Permuted)
	  {
	    point.x=left+(int)(a*320.0);
	    point.y=top+height+100;
	    pDC->TextOut(point.x,point.y,"Permuted Watermark");//Print the information for original watermark
        ////Print the Permuted watermark
	    ::StretchDIBits(pDC->m_hDC,left+(int)(a*(320.0)),top+height+300,(int)(a*128.0),(int)(a*128.0),0,0,128,128,pDoc->m_PermutedWatermarkBytes+62,(BITMAPINFO *)(pDoc->m_PermutedWatermarkBytes+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
	  }
	
      if(pDoc->m_OriginalWatermarkOpened1)
	  {
	    point.x=left+(int)a*64;
	    point.y=top+height+100;
	    pDC->TextOut(point.x,point.y,"Original Watermark(128x128)");//Print the information for original watermark
		////Print the original watermark
	    ::StretchDIBits(pDC->m_hDC,left+(int)(a*64.0),top+height+300,(int)(a*128.0),(int)(a*128.0),0,0,128,128,pDoc->m_OriginalWatermarkBytes1+62,(BITMAPINFO *)(pDoc->m_OriginalWatermarkBytes1+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
	  }
	  if(pDoc->m_Permuted1)
	  {
	    point.x=left+(int)(a*320.0);
	    point.y=top+height+100;
	    pDC->TextOut(point.x,point.y,"Permuted Watermark");//Print the information for original watermark
        ////Print the Permuted watermark
	    ::StretchDIBits(pDC->m_hDC,left+(int)(a*(320.0)),top+height+300,(int)(a*128.0),(int)(a*128.0),0,0,128,128,pDoc->m_PermutedWatermarkBytes1+62,(BITMAPINFO *)(pDoc->m_PermutedWatermarkBytes1+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
	  }
	
	}
	////The second page:If embeded decoded image exists, print it
	if(pDoc->m_Embeded0||pDoc->m_Embeded1&&pInfo->m_nCurPage==2)
	{
	  ////Calculate the position and size for printing the original image
	  left=(int)((double)pInfo->m_rectDraw.right/2.0)-(int)(a/2.0*(double)pDoc->m_OriginalImageWidth);
	  top=pInfo->m_rectDraw.bottom/20;
	  width=(int)(a*(double)pDoc->m_OriginalImageWidth);
	  height=(int)(a*(double)pDoc->m_OriginalImageHeight);
	  point.x=left;	  
	  point.y=top-200;//Compute the position for the information
	  //Get the encoding method information
	  strcpy(temp,"Embeded Image");
	  pDC->TextOut(point.x,point.y,temp);//Display the information
	  //Display the embeded decoded image
	  ::StretchDIBits(pDC->m_hDC,left,top,width,height,0,0,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,pDoc->m_DisplayImageBytes1+1078,(BITMAPINFO *)(pDoc->m_DisplayImageBytes1+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
      //Get the performance Information
	  sprintf(temp,"(PSNR[%6.4f],MSE[%6.4f])",pDoc->m_EmbededPSNR,pDoc->m_EmbededMSE);
	  point.y=top+height+200;//Get the position
	  pDC->TextOut(point.x,point.y,temp);//Display it
	  if(pDoc->m_Extracted)
	  {
	    point.x=left+(int)(a*192.0);
	    point.y=top+height+800;
	    pDC->TextOut(point.x,point.y,"Extracted Watermark Before Attack");//Print the information for original watermark
        ////Print the Extracted watermark
	    ::StretchDIBits(pDC->m_hDC,left+(int)(a*192.0),top+height+1000,(int)(a*128.0),(int)(a*128.0),0,0,128,128,pDoc->m_ExtractedWatermarkBytes+62,(BITMAPINFO *)(pDoc->m_ExtractedWatermarkBytes+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
	  }
	}
	
	////The third page:If attacked image exists, print it
	if(pDoc->m_AttackedImageOpened&&pInfo->m_nCurPage==3)
	{
	  ////Calculate the position and size for printing the original image
	  left=(int)((double)pInfo->m_rectDraw.right/2.0)-(int)(a/2.0*(double)pDoc->m_OriginalImageWidth);
	  top=pInfo->m_rectDraw.bottom/20;
	  width=(int)(a*(double)pDoc->m_OriginalImageWidth);
	  height=(int)(a*(double)pDoc->m_OriginalImageHeight);
	  //Compute the position for the information
	  point.x=left;
	  point.y=top-200;
	  //Get the encoding method information
	  strcpy(temp,"Attacked Image");		    
	  pDC->TextOut(point.x,point.y,temp);//Display the information
	  //Display the attacked image
	  ::StretchDIBits(pDC->m_hDC,left,top,width,height,0,0,pDoc->m_OriginalImageWidth,pDoc->m_OriginalImageHeight,pDoc->m_DisplayImageBytes2+1078,(BITMAPINFO *)(pDoc->m_DisplayImageBytes2+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
	  
	  if(pDoc->m_AttackExtracked)
	  {
	    point.x=left+(int)(a*192.0);
	    point.y=top+height;
	    pDC->TextOut(point.x,point.y,"Extracted after Attack");//Print the information for original watermark
        ////Print the Extracted watermark
	    ::StretchDIBits(pDC->m_hDC,left+(int)(a*192.0),top+height+200,(int)(a*128.0),(int)(a*128.0),0,0,128,128,pDoc->m_AttackedWatermarkBytes+62,(BITMAPINFO *)(pDoc->m_AttackedWatermarkBytes+sizeof(BITMAPFILEHEADER)),DIB_RGB_COLORS,SRCCOPY);
	  }
	}
	////Call the ondraw function of base class not this class
	CView::OnDraw(pDC);	
////////////////////My code ends to print///////////////////////
}

BOOL CDCTWaterView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
//////My code to set the maxpage as 3 for printing//////////////
	pInfo->SetMaxPage(3);
//////My code to set the maxpage as 3 for printing//////////////
	return DoPreparePrinting(pInfo);
}

void CDCTWaterView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
	
}

void CDCTWaterView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CDCTWaterView diagnostics

#ifdef _DEBUG
void CDCTWaterView::AssertValid() const
{
	CView::AssertValid();
}

void CDCTWaterView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CDCTWaterDoc* CDCTWaterView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDCTWaterDoc)));
	return (CDCTWaterDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDCTWaterView message handlers

//////////////////////////My Code Begins/////////////////////////////////

///////BEGINS:The functions for menu items of IMAGETRANSFORM//////
//This function to Transform a Bmp(256grays and <=640x480)file into Rawfile
void CDCTWaterView::OnTransformBmpraw() 
{
	// TODO: Add your command handler code here
   CDCTWaterDoc* pDoc = GetDocument();//Get the pDoc
   ASSERT_VALID(pDoc);//Set the pDoc valid
   OPENFILENAME ofn;//The structure to open a FileDialog 
   HGLOBAL hbit;//The handle for memory
   hbit=NULL;//Clear the memory handle
   LPBITMAPFILEHEADER bitfile;//The structures for bmp file header   
   LPBITMAPINFOHEADER bitinfo;//The structures for bmp info header   
   int width;//The width of bmp
   int height;//The height of bmp
   int off,offset;//The offset of the actual image data
   int linebytes;//The bytes of each line of bmp
   long int fh;//The file handle
   long int i;
   unsigned char *lpbit;//The pointer of the file data
   char temp[_MAX_PATH+50];//The temperal string
   long int lenbit;//The length of the opened file
   char FileName[_MAX_PATH],FileTitle[_MAX_PATH];//The Filename and FileTitle 
   FileName[0]='\0';//NULL string
   FileTitle[0]='\0';//NULL string
/////Initialize the FileOpenDialog structure begins////
   ofn.lStructSize=sizeof(OPENFILENAME);//The structure size
   ofn.hwndOwner=m_hWnd;//The Owner window handle
   ofn.hInstance=NULL; //None user dialog style template
   //The filter
   ofn.lpstrFilter=TEXT("BMP Image *.bmp\0*.bmp\0All File *.*\0*.*\0\0"); 
   
   ////None user filter
   ofn.lpstrCustomFilter=NULL; 
   ofn.nMaxCustFilter=0; 
   
   ofn.nFilterIndex=1; //Select the item 'BMP Image *.bmp'
   
   ////The filename with full path
   ofn.lpstrFile=FileName; 
   ofn.nMaxFile=_MAX_PATH; 
   
   ////The filename without path
   ofn.lpstrFileTitle=FileTitle; 
   ofn.nMaxFileTitle=_MAX_PATH; 
   strcpy(temp,pDoc->m_CurrentDirectory);
   strcat(temp,"\\bmp");
   if(!SetCurrentDirectory(temp))
   {
	 strcpy(temp,pDoc->m_CurrentDirectory);
   }
   ofn.lpstrInitialDir=temp; 
   ofn.lpstrTitle="Please Open A 256-gray BMP Image"; //The title
   ofn.Flags=OFN_FILEMUSTEXIST; //The flags
   ofn.nFileOffset;//The offset of the filename in the full path
   ofn.nFileExtension;//The offset of the extension in the full path
   ofn.lpstrDefExt="BMP"; //Default extension
   ofn.lCustData=NULL; //None
   ofn.lpfnHook=NULL; //None
   ofn.lpTemplateName=NULL; //None User defined dialog
/////Initialize the FileOpenDialog structure ends////
   //Open the Dialog, and save the structure including the filename
   if(GetOpenFileName(&ofn)==0)return;//If cancle or error,then return
   fh=_open(FileName,_O_RDONLY|_O_BINARY);//Open the file in ReadOnly Mode
   
   ////If the file cannot be opened,return directly
   if(fh==-1)
   {
	 sprintf(temp,"Sorry! Failed to Open File[%s]!",FileName);
	 MessageBox(temp,"Open the File",MB_ICONSTOP|MB_OK);
	 return;
   }
   
   lenbit=_filelength(fh);//Get the length of the opened file
   
   ////If the file is larger than 640x480 bytes,return directly either
   if(lenbit>308280)
   {
   	 _close(fh);//Close the file   
     sprintf(temp,"Sorry!File[%s]Is Bigger Than 640x480!",FileName);//Get the information
	 MessageBox(temp,"Open the File",MB_ICONSTOP|MB_OK);//Display the infomation
	 return;
   }
   
   hbit=GlobalAlloc(GMEM_FIXED,lenbit);//Apply the required memory
   
   ////If memory is not enough, return directly
   if(hbit==NULL)
   {
     _close(fh); //Close the file
	 MessageBox("Sorry!Not Enough Memory!","Open the File",MB_ICONSTOP|MB_OK);//Display the information
	 return;
   }
   
   lpbit=(unsigned char *)hbit;//Give the memory pointer to the file data pointer
   
   ////Read file into memory
   if(_read(fh,lpbit,lenbit)==-1)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -