📄 imagewarp.cpp
字号:
/////////////////////////////////////////////////////////////////////////////////
//
// ImageWarp.cpp: implementation of the CImageWarp class.
//
////////////////////////////////////////////////////////////////////////////////
// 版权所有(2000)
// Copyright(2000)
// 编写者: 向世明
// Author: Xiang Shiming
#include "stdafx.h"
#include "ImageWarp.h"
#include "math.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC(CImageWarp, CImageGeneralTransform)
CImageWarp::CImageWarp()
{
m_dwOperation = IMAGE_GEOMETRY_WARP_X;
m_fAmplitude = 1.0f;
m_fPeriod = 0.0f;
m_fPhase = 0.0f;
m_fOffset = 0.0f;
}
CImageWarp::~CImageWarp()
{
}
#ifdef _DEBUG
void CImageWarp::Dump(CDumpContext& dc) const
{
CImageGeneralTransform::Dump(dc);
}
void CImageWarp::AssertValid() const
{
CImageGeneralTransform::AssertValid();
}
#endif
FLOATPOINT CImageWarp::GetInversePoint(int x, int y, int nWidth, int nHeight)
{
float fx, fy;
//将角度转化成弧度
float fRad = (float)(m_fPhase * PIE / 180.0);
if(m_dwOperation == IMAGE_GEOMETRY_WARP_X)
{
//变换公式:
//y = y0;
//x = x0 + m_fAmplitude * sin(y0 * m_fPeriod / 360 + m_fPhase) + m_fOffset
fRad += (((float)y * (float)m_fPeriod) / 360.0f);
fy = (float)y;
fx = (float)x - (m_fAmplitude * (float)sin(fRad) + m_fOffset);
}
else if(m_dwOperation == IMAGE_GEOMETRY_WARP_Y)
{
//变换公式:
//x = x0;
//y = y0 + m_fAmplitude * sin(x0 * m_fPeriod /360 + m_fPhase) + m_fOffset
fRad += (((float)x * (float)m_fPeriod) / 360.0f);
fx = (float)x;
fy = (float)y - (m_fAmplitude * (float)sin(fRad) + m_fOffset);
}
FLOATPOINT fp;
fp.x = fx;
fp.y = fy;
return fp;
}
void CImageWarp::SetParam4f(float fAmplitude, float fPeriod, float fPhase, float fOffset)
{
m_fAmplitude = fAmplitude;
m_fPeriod = fPeriod;
m_fPhase = fPhase;
m_fOffset = fOffset;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -