2
* Copyright (c) 2009,2010 Lukáš Tvrdý <lukast.dev@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "kis_alpha_mask.h"
20
#include "kis_debug.h"
26
KisCircleAlphaMask::KisCircleAlphaMask(int radius){
34
KisCircleAlphaMask::~KisCircleAlphaMask()
40
inline void KisCircleAlphaMask::initSigma(qreal sigma)
43
m_sigmaSquared = - 2.0 * m_sigma * m_sigma;
46
void KisCircleAlphaMask::setSigma(qreal sigma, qreal sigmaConst)
49
m_sigmaConst = sigmaConst;
53
void KisCircleAlphaMask::setSigma(qreal sigma)
56
m_sigmaConst = 1.0 / (2.0 * M_PI * m_sigma * m_sigma);
61
// TODO QPoint pos , we will see
62
void KisCircleAlphaMask::generateCircleDistanceMap(bool invert)
65
int yy = 0; // power of y
67
for (int y = 0; y <= m_radius; y++){
69
for (int x = 0; x <= m_radius; x++, pos++){
70
value = sqrt(x*x + yy)/(m_radius);
71
(value > 1.0) ? m_data[pos] = 0.0 : m_data[pos] = (invert ? 1.0 - value : value);
76
void KisCircleAlphaMask::generateGaussMap ( bool invert )
81
// determine the "clever" radius
86
quint8 alpha = qRound(255 * gaussAt(ix, 0) );
94
// TODO: clean up after sucessful debugging
96
qreal step = radius / (qreal)m_radius;
97
kDebug() << "Radius: " << m_radius << " | Computed radius: " << radius << "| Sigma: " << m_sigma << " |Step: " << step;;
98
if (radius == 0) return;
104
for (int y = 0; y <= m_radius; y++) {
105
for (int x = 0; x <= m_radius; x++,pos++) {
106
m_data[pos] = gaussAt(px, py);
114
//qreal dist = maxLen - minLen;
118
// while (pos < m_size){
119
// // m_data[pos] = (m_data[pos] - minLen) / dist;
120
// m_data[pos] = m_data[pos] * 1.0/maxLen;
126
for (int y = 0; y <= m_radius; y++) {
127
for (int x = 0; x <= m_radius; x++,pos++) {
128
printf("%.3f ",m_data[pos]);
138
QImage KisCircleAlphaMask::toQImage()
140
QImage img = QImage(m_width, m_width, QImage::Format_ARGB32);
144
for (int y=0; y < m_width; y++){
145
QRgb *pixel = reinterpret_cast<QRgb *>(img.scanLine(y));
146
for (int x=0; x < m_width; x++, pos++){
147
alpha = qRound(255 * m_data[pos]);
148
pixel[y] = qRgba(alpha, alpha, alpha, 255);
158
void KisCircleAlphaMask::resize(int radius)
162
m_width = m_radius + 1;
164
m_size = m_width * m_width;
165
m_data = new qreal[m_size];
166
memset(m_data, 0 , m_size * sizeof(qreal));
171
void KisCircleAlphaMask::smooth(qreal edge0, qreal edge1)
174
while (pos < m_size){
175
m_data[pos] = smoothstep(edge0, edge1, m_data[pos]);
181
inline qreal KisCircleAlphaMask::smoothstep(qreal edge0, qreal edge1, qreal x)
183
if (x < edge0) return 0.0;
184
if (x >= edge1) return 1.0;
185
x = (x - edge0) / (edge1 - edge0);
186
return x*x*(3 - 2 * x);