74
74
int Height = m_orgImage.height();
76
76
// Determine the shift in pixels from the shift in percentage.
77
m_settings.xshift = m_settings.xshift*Height/200.0;
78
m_settings.yshift = m_settings.yshift*Width /200.0;
77
m_settings.yshift = m_settings.yshift*Height/200.0;
78
m_settings.xshift = m_settings.xshift*Width /200.0;
80
80
// Determine the outer radius of the filter. This is the half diagonal
81
81
// measure of the image multiplied by the radius factor.
83
83
xsize = (Height + 1) / 2;
84
84
ysize = (Width + 1) / 2;
85
erad = approx(hypothenuse(xsize,ysize) * m_settings.outerradius);
86
irad = approx(hypothenuse(xsize,ysize) * m_settings.outerradius * m_settings.innerradius);
88
xsize = ((Height + 1) / 2) + abs(m_settings.xshift);
89
ysize = ((Width + 1) / 2) + abs(m_settings.yshift);
90
diagonal = approx(hypothenuse(xsize,ysize)) + 1;
92
xctr = ((Height + 1) / 2) + m_settings.xshift;
93
yctr = ((Width + 1) / 2) + m_settings.yshift;
95
for (row = 0 ; !m_cancel && (row < Width) ; ++row)
85
erad = qRound(hypothenuse(xsize, ysize) * m_settings.outerradius);
86
irad = qRound(hypothenuse(xsize, ysize) * m_settings.outerradius * m_settings.innerradius);
88
xsize = qRound(Width / 2.0 + fabs(m_settings.xshift));
89
ysize = qRound(Height / 2.0 + fabs(m_settings.yshift));
91
diagonal = qRound(hypothenuse(xsize,ysize)) + 1;
93
xctr = qRound(Width / 2.0 + m_settings.xshift);
94
yctr = qRound(Height / 2.0 + m_settings.yshift);
97
for (row = 0 ; runningFlag() && (row < Width) ; ++row)
99
for (col = 0 ; !m_cancel && (col < Height) ; ++col)
101
for (col = 0 ; runningFlag() && (col < Height) ; ++col)
101
103
p = (col * Width + row)*4;
102
xd = abs(xctr - col);
103
td = (sqrt((xd * xd) + (yd * yd)) + 0.5);
104
xd = abs(yctr - col);
105
td = qRound(hypothenuse(xd,yd));
105
107
if (!m_orgImage.sixteenBit()) // 8 bits image
112
114
else // 16 bits image.
114
NewBits16[ p ] = clamp16bits(data16[ p ] * real_attenuation(erad/2,erad,td));
115
NewBits16[p+1] = clamp16bits(data16[p+1] * real_attenuation(erad/2,erad,td));
116
NewBits16[p+2] = clamp16bits(data16[p+2] * real_attenuation(erad/2,erad,td));
116
NewBits16[ p ] = clamp16bits(data16[ p ] * real_attenuation(irad,erad,td));
117
NewBits16[p+1] = clamp16bits(data16[p+1] * real_attenuation(irad,erad,td));
118
NewBits16[p+2] = clamp16bits(data16[p+2] * real_attenuation(irad,erad,td));
117
119
NewBits16[p+3] = data16[p+3];
128
int AntiVignettingFilter::approx(double x)
130
return ((int) x+0.5);
133
double AntiVignettingFilter::hypothenuse(double x, double y)
130
inline double AntiVignettingFilter::hypothenuse(double x, double y)
135
132
return (sqrt (x*x + y*y));