void MagnifierFilter::init(int _w,int _h,int _factor,qreal curve)
{
if(m_width == _w && m_height == _h && m_factor == _factor && m_curve == curve)
return;
if(m_matrixX)
delete m_matrixX;
if(m_matrixY)
delete m_matrixY;
m_width = _w;m_height = _h;
int *dataX = (int*)malloc(m_width * m_height * sizeof(int));
int *dataY = (int*)malloc(m_width * m_height * sizeof(int));
m_easingCurve = QEasingCurve(QEasingCurve::OutInQuad);
int valuex,valuey;
qreal s1,s2,l1,l2;
l1 = 0.2;
l2 = 0.8;
qreal prog,prog1,prog2;
s1 = m_easingCurve.valueForProgress(l1);
s2 = m_easingCurve.valueForProgress(l2);
qreal s = (s2 - s1)/(l2 - l1);
for(int h = 0;h < m_height;h++){
int pos = h * m_width;
prog = qreal(h+1)/(qreal)m_height;
if(prog < l1 || prog > l2){
prog1 = m_easingCurve.valueForProgress(prog);
valuey = m_height * prog1;
}else{
prog1 = (s) * (prog - l1) + s1 ;
valuey = m_height * prog1;
}
for(int w = 0;w < m_width;w++){
prog = qreal(w+1)/(qreal)m_width;
if(prog < l1 || prog > l2){
prog2 = m_easingCurve.valueForProgress(prog);
valuex = m_width * prog2;
}else{
prog2 = (s) * (prog - l1) + s1;
valuex = m_width * prog2;
}
dataX[pos + w] = valuex;
dataY[pos + w] = valuey;
}
}
m_matrixX = new WsMatrix(_w,_h,dataX);
m_matrixY = new WsMatrix(_w,_h,dataY);
}
代码答题看懂了,可是又细节不是很清楚啊,比如:
s1 = m_easingCurve.valueForProgress(l1);
这个到底是什么作用,既然l1已经是qreal,为什么还要调用这个函数呢?
c++ qt
------解决方案--------------------
QEasingCurve是一个封装函数曲线的简易类。
QEasingCurve::valueForProgress(x)相当于y = f(x)。
函数中放大功能使用的是OutInQuad曲线进行像素插值补间。可以看看Qt的easing了解更多插值函数。