// HistoPrevDlg.cpp : implementation file
//
#include "stdafx.h"
#include "effect.h"
#include "HistoPrevDlg.h"
#include "JpegDecoder.h" //by hlb
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHistoPrevDlg dialog
CHistoPrevDlg::CHistoPrevDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHistoPrevDlg::IDD, pParent)
,m_nLimitLow(0)
,m_nLimitUp(255)
{
//{{AFX_DATA_INIT(CHistoPrevDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CHistoPrevDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHistoPrevDlg)
DDX_Control(pDX, IDC_HISTO_PREV, m_stiHistogram);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHistoPrevDlg, CDialog)
//{{AFX_MSG_MAP(CHistoPrevDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHistoPrevDlg message handlers
int CHistoPrevDlg::DoModal()
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::DoModal();
}
void Delayms(DWORD ms)
{
LARGE_INTEGER litmp;
LONGLONG lTimeBegin;
LONGLONG lTimeEnd;
double dMinus;
double dFreq;
double dTim;
QueryPerformanceFrequency(&litmp);
dFreq = litmp.QuadPart;
QueryPerformanceCounter(&litmp);
lTimeBegin = litmp.QuadPart;
do{
QueryPerformanceCounter(&litmp);
lTimeEnd = litmp.QuadPart;
dMinus = (double)(lTimeEnd - lTimeBegin);
dTim = dMinus / dFreq;
}while(dTim<ms*0.001);
}
void CHistoPrevDlg::OnOK()
{
// TODO: Add extra validation here
// 灰度直方图
#if 0
CHistoPrevDlg::Refresh();
#endif
//线性变换
#if 0
{
double slop = 1.5;
double inter = 1.0;
CHistoPrevDlg::LineTrans(M_bImageBuff, m_ImageTempBuff, m_PicWidth, m_PicHeight,slop,inter);
CHistoPrevDlg::showImage();
}
#endif
//幂次变换
#if 0
double a = 0.0;
double b = 1.5;
double c = 0.065;
CHistoPrevDlg::ExpTrans(M_bImageBuff, m_ImageTempBuff, m_PicWidth, m_PicHeight, a, b, c);
CHistoPrevDlg::showImage();
#endif
//图象缩放(最临近插值法)
#if 0
double fx = 1.2;
double fy = 1.2;
UINT outwidth;
UINT outheight;
if(m_ImageTempBuff)
{
delete[] m_ImageTempBuff;
m_ImageTempBuff = NULL;
}
CHistoPrevDlg::ZoomInNomal(M_bImageBuff, m_ImageTempBuff, m_PicWidth, m_PicHeight, outwidth, outheight, fx, fy);
#endif
//图象缩放(双线性插值法)
#if 0
UINT outwidth;
UINT outheight;
double fx = 0.8;
double fy = 0.8;
CHistoPrevDlg::ZoomInterpolation(M_bImageBuff, m_ImageTempBuff, m_PicWidth,m_PicHeight,outwidth,outheight,fx,fy);
m_PicWidth = outwidth;
m_PicHeight = outheight;
CHistoPrevDlg::showImage();
delete[] m_ImageTempBuff;
m_ImageTempBuff = NULL;
#endif
#if 0 //使用最临近插值法旋转图象
double angle = 0.5;
UINT outwidth;
UINT outheight;
CHistoPrevDlg::RotateNormal(M_bImageBuff, m_ImageTempBuff, m_PicWidth, m_PicHeight, outwidth, outheight, angle);
m_PicWidth = outwidth;
m_PicHeight = outheight;
CHistoPrevDlg::showImage();
delete[] m_ImageTempBuff;
m_ImageTempBuff = NULL;
#endif
#if 0 //使用双线性插值法旋转图象
double angle = 1.5;
UINT outwidth;
UINT outheight;
CHistoPrevDlg::RotateInterpolation(M_bImageBuff, m_ImageTempBuff, m_PicWidth, m_PicHeight, outwidth, outheight, angle);
m_PicWidth = outwidth;
m_PicHeight = outheight;
CHistoPrevDlg::showImage();
delete[] m_ImageTempBuff;
m_ImageTempBuff = NULL;
#endif
//使用GDI+来对图象进行几何变换
#if 0
CDC* pDC = m_stiHistogram.GetDC();
Graphics graph(pDC->GetSafeHdc());
Image* image = Image::FromFile(L"WALL03.jpg");
//一、平移
//1)直接平移坐标系
/*
graph.TranslateTransform(70, 50);
graph.DrawImage(image, 0, 0, image->GetWidth(),image->GetHeight());
Invalidate(FALSE);
*/
//2)利用矩阵对象平移坐标系
/*
Matrix matrix1;
matrix1.Translate(70, 50);
graph.SetTransform(&matrix1);
graph.DrawImage(image, 0, 0, image->GetWidth(),image->GetHeight());
Invalidate(FALSE);
*/
//3)自己构建平移矩阵
/*
Matrix matrix2(1,0,0,1, 70, 50);
graph.SetTransform(&matrix2);
graph.DrawImage(image, 0, 0, image->GetWidth(),image->GetHeight());
Invalidate(FALSE);
*/
//二、缩放
/* 1) 直接缩放坐标系
Rect rect(16, 16, image->GetWidth()*0.5,image->GetHeight()*0.5);
//REAL fx = 1.5f;
//REAL fy = 1.5f;
//graph.ScaleTransform(fx, fy);
graph.DrawImage(image,rect);
Invalidate(FALSE);
*/
//利用矩阵对象缩放坐标系
/*
Matrix matrix4;
matrix4.Scale(1.5,1.5);
graph.SetTransform(&matrix4);
graph.DrawImage(image,0, 0);
Invalidate(FALSE);
*/
//自己构建缩放矩阵
/*
Matrix matrix5(1.5, 0, 0,1.5, 0, 0);
graph.SetTransform(&matrix5);
graph.DrawImage(image,0, 0);
Invalidate(FALSE);
*/
//三、旋转
//1)直接旋转坐标系
/*
graph.RotateTransform(30);
graph.DrawImage(image,0, 0);
Invalidate(FALSE);
*/
//2)利用矩阵旋转坐标系
/*
Matrix matrix6;
matrix6.Rotate(30);
graph.SetTransform(&matrix6);
graph.DrawImage(image,0, 0);
Invalidate(FALSE);
*/
//3)利用矩阵转换输出控制点
/*
Point points[]={Point(0,0),Point(image->GetWidth(),0),Point(0, image->GetHeight())};
Matrix matrix7;
matrix7.Rotate(30);
matrix7.TransformPoints(points, 3);
graph.DrawImage(image,points, 3);
Invalidate(FALSE);
*/
//中心旋转
/*
graph.TranslateTransform(100,100);
graph.RotateTransform(25);
graph.TranslateTransform(-(REAL)(image->GetWidth())/2.0f,-(REAL)(image->GetHeight())/2.0f);
graph.DrawImage(image,0, 0);
Invalidate(FALSE);
*/
//变换的组合
/*
CRect winRect;
GetClientRect(winRect);
graph.TranslateTransform(winRect.Width()/2, winRect.Height() / 2);
Point points[] = {
Point(0,0),Point(image->GetWidth(), 0),Point(0, image->GetHeight())
};
graph.ScaleTransform(0.1, 0.1);
for(int i = 0; i < 23; i++)
{
graph.DrawImage(image, points, 3);
Invalidate(FALSE);
graph.ScaleTransform(1.1, 1.1);
graph.TranslateTransform(50, 0);
graph.RotateTransform(30);
}
*/
// 错位
/*
Matrix matrix5(1, 1, 2, 1, 0, 0);
graph.SetTransform(&matrix5);
graph.DrawImage(image,0, 0);
Invalidate(FALSE);
*/
// graph.DrawImage(image,0, 0);
// Invalidate(FALSE);
#endif
RippleEffect(M_bImageBuff,m_ImageTempBuff,m_PicWidth,m_PicHeight,2,1,120,160);
// CDialog::OnOK();
}
void CHistoPrevDlg::Refresh()
{
CDC* pDC = m_stiHistogram.GetDC();
CRect rect;
CDC memDC;
CBitmap MemBitmap;
m_stiHistogram.GetClientRect(rect);
memDC.CreateCompatibleDC(NULL);
MemBitmap.CreateCompatibleBitmap(pDC, rect.Width(),rect.Height());
//选取空白位图
memDC.SelectObject(MemBitmap);
memDC.FillSolidRect(0, 0, rect.Width(),rect.Height(),RGB(255,255,255));
//选取缓存作为画布(画图表面)
Graphics graph(memDC.GetSafeHdc());
//使用白色背景
graph.FillRectangles(&SolidBrush(Color::White), &Rect(0, 0, rect.Width(),rect.Height()),1);
//绘制y轴
graph.DrawLine(&Pen(Color::Black), 10,10,10,280);
graph.DrawLine(&Pen(Color::Black), 10,10,5,15);
graph.DrawLine(&Pen(Color::Black), 10,10,15,15);
//绘制x轴
graph.DrawLine(&Pen(Color::Black), 10,280,290,280);
graph.DrawLine(&Pen(Color::Black), 290,280,285,285);
graph.DrawLine(&Pen(Color::Black), 290,280,285,275);
CString buf;
Font font(L"宋体", 10);
buf = L"0";
/*---------- 注意!!!!----------*/
int nLen = MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);//确定转换为Unicode需要多少缓冲区(返回值也包含了最后一个NULL字符)。
WCHAR *wBuf = new WCHAR[nLen];
MultiByteToWideChar(CP_ACP, 0, buf, -1, wBuf, nLen);
graph.DrawString(wBuf, -1, &font, PointF(8,290), &SolidBrush(Color::Black));
for(int i = 0; i < 256; i+= 5)
{
if(i % 50 == 0)
graph.DrawLine(&Pen(Color::Black),10+i,280, 10+i, 286);
else if(i % 10 ==0)
graph.DrawLine(&Pen(Color::Black),10+i,280, 10+i, 283);
}
评论0