1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/*
* Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_autobrush_resource.h"
#include <kdebug.h>
void KisAutobrushShape::createBrush( TQImage* img)
{
img->create(m_w, m_h, 32);
for(int j = 0; j < m_h; j++)
{
for(int i = 0; i < m_w; i++)
{
TQ_INT8 v = valueAt(i,j);
img->setPixel( i, j, tqRgb(v,v,v));
}
}
}
KisAutobrushCircleShape::KisAutobrushCircleShape(TQ_INT32 w, TQ_INT32 h, double fh, double fv)
: KisAutobrushShape( w, h, w / 2.0 - fh, h / 2.0 - fv),
m_xcentre ( w / 2.0 ),
m_ycentre ( h / 2.0 ),
m_xcoef ( 2.0 / w ),
m_ycoef ( 2.0 / h ),
m_xfadecoef ( (m_fh == 0) ? 1 : ( 1.0 / m_fh)),
m_yfadecoef ( (m_fv == 0) ? 1 : ( 1.0 / m_fv))
{
}
TQ_INT8 KisAutobrushCircleShape::valueAt(TQ_INT32 x, TQ_INT32 y)
{
double xr = (x - m_xcentre) + 0.5;
double yr = (y - m_ycentre) + 0.5;
double n = norme( xr * m_xcoef, yr * m_ycoef);
if( n > 1 )
{
return 255;
}
else
{
double normeFade = norme( xr * m_xfadecoef, yr * m_yfadecoef );
if( normeFade > 1)
{
double xle, yle;
// xle stands for x-coordinate limit exterior
// yle stands for y-coordinate limit exterior
// we are computing the coordinate on the external ellipse in order to compute
// the fade value
if( xr == 0 )
{
xle = 0;
yle = yr > 0 ? 1/m_ycoef : -1/m_ycoef;
} else {
double c = yr / (double)xr;
xle = sqrt(1 / norme( m_xcoef, c * m_ycoef ));
xle = xr > 0 ? xle : -xle;
yle = xle * c;
}
// On the internal limit of the fade area, normeFade is equal to 1
double normeFadeLimitE = norme( xle * m_xfadecoef, yle * m_yfadecoef );
return (uchar)(255 * ( normeFade - 1 ) / ( normeFadeLimitE - 1 ));
} else {
return 0;
}
}
}
KisAutobrushRectShape::KisAutobrushRectShape(TQ_INT32 w, TQ_INT32 h, double fh, double fv)
: KisAutobrushShape( w, h, w / 2.0 - fh, h / 2.0 - fv),
m_xcentre ( w / 2.0 ),
m_ycentre ( h / 2.0 ),
m_c( fv/fh)
{
}
TQ_INT8 KisAutobrushRectShape::valueAt(TQ_INT32 x, TQ_INT32 y)
{
double xr = TQABS(x - m_xcentre);
double yr = TQABS(y - m_ycentre);
if( xr > m_fh || yr > m_fv )
{
if( yr <= ((xr - m_fh) * m_c + m_fv ) )
{
return (uchar)(255 * (xr - m_fh) / (m_w - m_fh));
} else {
return (uchar)(255 * (yr - m_fv) / (m_w - m_fv));
}
}
else {
return 0;
}
}
|