~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to .pc/kubuntu_01_arm_needs_qreal.diff/krita/plugins/paintops/softbrush/kis_soft_paintop.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (c) 2009,2010 Lukáš Tvrdý <lukast.dev@gmail.com>
3
 
 *
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.
8
 
 *
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.
13
 
 *
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.
17
 
 */
18
 
 
19
 
#include "kis_soft_paintop.h"
20
 
#include "kis_soft_paintop_settings.h"
21
 
 
22
 
#include <cmath>
23
 
 
24
 
#include <QRect>
25
 
 
26
 
#include <kis_image.h>
27
 
#include <kis_debug.h>
28
 
#include <kis_brush.h>
29
 
#include <kis_global.h>
30
 
#include <kis_paint_device.h>
31
 
#include <kis_painter.h>
32
 
#include <kis_types.h>
33
 
#include <kis_paintop.h>
34
 
#include <kis_selection.h>
35
 
#include <kis_random_accessor.h>
36
 
 
37
 
#include <KoColor.h>
38
 
 
39
 
#include <kis_softop_option.h>
40
 
#include <kis_brush_size_option.h>
41
 
#include "kis_hsv_option.h"
42
 
 
43
 
KisSoftPaintOp::KisSoftPaintOp(const KisSoftPaintOpSettings *settings, KisPainter * painter, KisImageWSP image)
44
 
    : KisPaintOp( painter )
45
 
    , m_settings( settings )
46
 
    , m_image ( image )
47
 
{
48
 
    // custom options
49
 
    m_hsvProperties.readOptionSetting(settings);
50
 
    m_sizeProperties.readOptionSetting(settings);
51
 
    // sensors
52
 
    m_sizeOption.readOptionSetting(settings);
53
 
    m_opacityOption.readOptionSetting(settings);
54
 
    m_rotationOption.readOptionSetting(settings);
55
 
    m_sizeOption.sensor()->reset();
56
 
    m_opacityOption.sensor()->reset();
57
 
    m_rotationOption.sensor()->reset();
58
 
    
59
 
    m_radius = qRound(0.5 * m_sizeProperties.diameter);
60
 
    m_amount = 0.0;
61
 
    m_brushType = SoftBrushType(settings->getInt(SOFT_BRUSH_TIP));
62
 
 
63
 
    if (m_brushType == CURVE){
64
 
        srand48(time(0));
65
 
        
66
 
        m_curveMaskProperties.curve = settings->getCubicCurve(SOFTCURVE_CURVE);
67
 
        m_curveMaskProperties.curveData = m_curveMaskProperties.curve.floatTransfer(m_radius+2);
68
 
 
69
 
        m_curveMask.setProperties(&m_curveMaskProperties);
70
 
        m_curveMask.setSizeProperties(&m_sizeProperties);
71
 
 
72
 
        m_gaussBrush.distMask = 0;
73
 
    }else if (m_brushType == GAUSS){
74
 
        m_gaussBrush.distMask = new KisCircleAlphaMask(m_radius);
75
 
        m_gaussBrush.distMask->setSigma( settings->getDouble(SOFT_SIGMA), settings->getDouble(SOFT_SOFTNESS) / 100.0  );
76
 
        m_gaussBrush.distMask->generateGaussMap( true );
77
 
        qreal start = m_settings->getDouble(SOFT_START);
78
 
        qreal end = m_settings->getDouble(SOFT_END);
79
 
        m_gaussBrush.distMask->smooth( start,end );
80
 
    }
81
 
    m_color = painter->paintColor();
82
 
 
83
 
    // compute spacing for brush
84
 
    m_xSpacing = qMax(0.5,m_sizeProperties.spacing * m_sizeProperties.diameter * m_sizeProperties.scale);
85
 
    m_ySpacing = qMax(0.5,m_sizeProperties.spacing * m_sizeProperties.diameter * m_sizeProperties.aspect * m_sizeProperties.scale);
86
 
    m_spacing = qMax(m_xSpacing, m_ySpacing);
87
 
    
88
 
#ifdef BENCHMARK
89
 
    m_count = m_total = 0;
90
 
#endif
91
 
}
92
 
 
93
 
KisSoftPaintOp::~KisSoftPaintOp()
94
 
{
95
 
    delete m_gaussBrush.distMask;
96
 
}
97
 
 
98
 
double KisSoftPaintOp::paintAt(const KisPaintInformation& info)
99
 
{
100
 
    if (!painter()) return m_spacing;
101
 
 
102
 
    m_color = painter()->paintColor();
103
 
 
104
 
    if (m_hsvProperties.enabled){
105
 
        QHash<QString, QVariant> params;
106
 
        params["h"] = 0.0;
107
 
        params["s"] = 0.0;
108
 
        params["v"] = 0.0;
109
 
        
110
 
        switch (m_hsvProperties.hmode){
111
 
            case 0:
112
 
                params["h"] = m_hsvProperties.hcurve.value( m_amount / (qreal)m_hsvProperties.hAmount ) ;
113
 
                break;
114
 
            case 1:
115
 
                params["h"] = -m_hsvProperties.hcurve.value( m_amount / (qreal)m_hsvProperties.hAmount ) ;
116
 
                break;
117
 
            case 2:
118
 
                params["h"] = drand48() * 2.0 - 1.0;
119
 
            default: break;
120
 
            case 3:
121
 
                params["h"] = scaleForPressure(info.pressure())*0.5;
122
 
            break;
123
 
        }
124
 
    
125
 
        switch (m_hsvProperties.smode){
126
 
            case 0:
127
 
                params["s"] = m_hsvProperties.scurve.value( m_amount / (qreal)m_hsvProperties.sAmount ) ;
128
 
                break;
129
 
            case 1:
130
 
                params["s"] = -m_hsvProperties.scurve.value( m_amount / (qreal)m_hsvProperties.sAmount ) ;
131
 
                break;
132
 
            case 2:
133
 
                params["s"] = drand48() * 2.0 - 1.0;
134
 
                break;
135
 
            case 3:
136
 
                params["s"] = scaleForPressure(info.pressure())*0.5;
137
 
                break;
138
 
        }
139
 
        
140
 
        switch (m_hsvProperties.vmode){
141
 
            case 0:
142
 
                params["v"] = m_hsvProperties.vcurve.value( m_amount / (qreal)m_hsvProperties.vAmount ) ;
143
 
                break;
144
 
            case 1:
145
 
                params["v"] = -m_hsvProperties.vcurve.value( m_amount / (qreal)m_hsvProperties.vAmount ) ;
146
 
                break;
147
 
            case 2:
148
 
                params["v"] = drand48() * 2.0 - 1.0;
149
 
            default: break;
150
 
            case 3:
151
 
                params["v"] = scaleForPressure(info.pressure())*0.5;
152
 
            break;
153
 
 
154
 
        }
155
 
 
156
 
        KoColorTransformation* transfo;
157
 
        transfo = painter()->device()->colorSpace()->createColorTransformation("hsv_adjustment", params);
158
 
        transfo->transform(m_color.data(), m_color.data() , 1);
159
 
        m_amount += 1.0;
160
 
    }
161
 
    
162
 
    if (m_brushType == CURVE){
163
 
        KisFixedPaintDeviceSP dab = cachedDab(painter()->device()->colorSpace());
164
 
 
165
 
        qint32 x;
166
 
        double subPixelX;
167
 
        qint32 y;
168
 
        double subPixelY;
169
 
 
170
 
        QPointF pt = info.pos();
171
 
        if (m_sizeProperties.jitterEnabled){
172
 
            pt.setX(pt.x() + (  ( m_sizeProperties.diameter * drand48() ) - m_radius) * m_sizeProperties.jitterMovementAmount);
173
 
            pt.setY(pt.y() + (  ( m_sizeProperties.diameter * drand48() ) - m_radius) * m_sizeProperties.jitterMovementAmount);
174
 
        }
175
 
 
176
 
        qreal scale = m_sizeProperties.scale * KisPaintOp::scaleForPressure(m_sizeOption.apply(info));
177
 
        qreal rotation = m_sizeProperties.rotation + m_rotationOption.apply(info);
178
 
        
179
 
        QPointF pos = pt - m_curveMask.hotSpot(scale, rotation);
180
 
        
181
 
        splitCoordinate(pos.x(), &x, &subPixelX);
182
 
        splitCoordinate(pos.y(), &y, &subPixelY);
183
 
        
184
 
        m_curveMask.mask(dab,m_color,scale,rotation,subPixelX,subPixelY);
185
 
        quint8 origOpacity = m_opacityOption.apply(painter(), info);
186
 
        QRect rc = dab->bounds();
187
 
        painter()->bltFixed(x,y,dab,rc.x(), rc.y(), rc.width(),rc.height());
188
 
        painter()->setOpacity(origOpacity);
189
 
        return m_spacing;
190
 
    }
191
 
 
192
 
    if (!m_dab) {
193
 
        m_dab = new KisPaintDevice(painter()->device()->colorSpace());
194
 
    }
195
 
    else {
196
 
        m_dab->clear();
197
 
    }
198
 
 
199
 
    quint8 alpha = 0;
200
 
    int pixelSize = m_dab->colorSpace()->pixelSize();
201
 
 
202
 
    int curX = qRound(info.pos().x());
203
 
    int curY = qRound(info.pos().y());
204
 
 
205
 
    int left = curX - m_radius;
206
 
    int top = curY - m_radius;
207
 
 
208
 
    int w = m_radius * 2 + 1;
209
 
    int h = w;
210
 
 
211
 
    int maskX;
212
 
    int maskY;
213
 
 
214
 
    KisRectIterator m_srcIt = m_dab->createRectIterator(left, top, w ,h );
215
 
    int x;
216
 
    int y;
217
 
    
218
 
    int border = ( m_radius ) * ( m_radius );    
219
 
    for (;!m_srcIt.isDone(); ++m_srcIt) {
220
 
 
221
 
        x = m_srcIt.x();
222
 
        y = m_srcIt.y();
223
 
 
224
 
        maskX = x - curX;
225
 
        maskY = y - curY;
226
 
        qreal dist = maskX*maskX + maskY*maskY;
227
 
        if (dist > border)
228
 
        {
229
 
            //continue;
230
 
        }else
231
 
        {
232
 
            if (m_brushType == GAUSS)
233
 
            {
234
 
                alpha = qRound(m_gaussBrush.distMask->valueAt(maskX,maskY) * OPACITY_OPAQUE_U8);
235
 
            }
236
 
            if (alpha == 0) continue;
237
 
            m_color.setOpacity(alpha);
238
 
            memcpy(m_srcIt.rawData(), m_color.data(), pixelSize);
239
 
        }
240
 
    }
241
 
 
242
 
    QRect rc(left,top,w,h); 
243
 
    painter()->bitBlt(rc.x(), rc.y(), m_dab, rc.x(), rc.y(), rc.width(), rc.height());
244
 
    return m_spacing;
245
 
}