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

« back to all changes in this revision

Viewing changes to krita/plugins/paintops/experiment/kis_experiment_paintop.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) 2009 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_experiment_paintop.h"
 
20
#include "kis_experiment_paintop_settings.h"
 
21
 
 
22
#include <cmath>
 
23
 
 
24
#include <QRect>
 
25
#include <QColor>
 
26
#include <QList>
 
27
 
 
28
#include <KoColor.h>
 
29
#include <KoColorSpace.h>
 
30
 
 
31
#include <kis_image.h>
 
32
#include <kis_debug.h>
 
33
 
 
34
#include <kis_brush.h>
 
35
#include <kis_global.h>
 
36
#include <kis_paint_device.h>
 
37
#include <kis_painter.h>
 
38
#include <kis_types.h>
 
39
#include <kis_paintop.h>
 
40
#include <kis_selection.h>
 
41
#include <kis_random_accessor.h>
 
42
#include <KoCompositeOp.h>
 
43
 
 
44
#include <kis_experimentop_option.h>
 
45
 
 
46
KisExperimentPaintOp::KisExperimentPaintOp(const KisExperimentPaintOpSettings *settings, KisPainter * painter, KisImageSP image)
 
47
    : KisPaintOp( painter )
 
48
    , m_settings( settings )
 
49
    , m_image ( image )
 
50
{
 
51
    m_isFirst = true;
 
52
    m_positions.clear();
 
53
 
 
54
    m_startSize = settings->getDouble(EXPERIMENT_START_SIZE);
 
55
    m_endSize = settings->getDouble(EXPERIMENT_END_SIZE);
 
56
 
 
57
    // spacing 
 
58
    qreal average = qMax(m_startSize, m_endSize ) - qMin(m_startSize, m_endSize) * 0.5;
 
59
    if ( average * 0.5 > 1)
 
60
    {
 
61
        m_ySpacing = m_xSpacing = average * 0.5 * settings->getDouble(EXPERIMENT_SPACING);
 
62
    } else
 
63
    {
 
64
        m_ySpacing = m_xSpacing = 1.0;
 
65
    }
 
66
    m_spacing = m_xSpacing;
 
67
 
 
68
    
 
69
    
 
70
    if ( !settings->node() ){
 
71
        m_dev = 0;
 
72
    }else{
 
73
        m_dev = settings->node()->paintDevice();
 
74
    }
 
75
    
 
76
    m_size = 1;
 
77
    m_rotationOption.readOptionSetting(settings);
 
78
    m_sizeOption.readOptionSetting(settings);
 
79
    m_opacityOption.readOptionSetting(settings);
 
80
}
 
81
 
 
82
KisExperimentPaintOp::~KisExperimentPaintOp()
 
83
{
 
84
}
 
85
 
 
86
#define MEMORY
 
87
qreal KisExperimentPaintOp::paintAt(const KisPaintInformation& info)
 
88
{
 
89
    if (!painter()) return m_spacing;
 
90
 
 
91
    if (!m_dab) {
 
92
        m_dab = new KisPaintDevice(painter()->device()->colorSpace());
 
93
    }
 
94
    else {
 
95
        m_dab->clear();
 
96
    }
 
97
 
 
98
#ifdef MEMORY
 
99
    if (!m_oldData) {
 
100
        m_oldData = new KisPaintDevice(painter()->device()->colorSpace());
 
101
    }
 
102
    else {
 
103
        m_oldData->clear();
 
104
    }
 
105
#endif
 
106
 
 
107
 
 
108
    QRect rc; 
 
109
    QRect erasedRc;
 
110
   
 
111
    // delete the previous dab in final datasource which will be bitblt
 
112
    if (!m_isFirst){
 
113
        erasedRc = rc = m_previousDab;
 
114
        KisRectConstIteratorPixel srcIt = m_dev->createRectConstIterator(rc.left(), rc.top(), rc.width(), rc.height());
 
115
#ifdef MEMORY
 
116
        KisRectIteratorPixel dstIt = m_oldData->createRectIterator(rc.left(), rc.top(), rc.width(), rc.height());
 
117
#else
 
118
        KisRectIteratorPixel dstIt = m_dev->createRectIterator(rc.left(), rc.top(), rc.width(), rc.height());
 
119
#endif
 
120
 
 
121
 
 
122
        qint32 pixelSize = m_dev->pixelSize();
 
123
        for (;!srcIt.isDone(); ++srcIt, ++dstIt) {
 
124
            memcpy(dstIt.rawData(),srcIt.oldRawData(), pixelSize );
 
125
        }
 
126
#ifdef MEMORY
 
127
        QString compositeOpId = painter()->compositeOp()->id();
 
128
        painter()->setCompositeOp(COMPOSITE_CLEAR);
 
129
        painter()->bitBlt(rc.topLeft(), m_oldData, rc);
 
130
        painter()->setCompositeOp(compositeOpId);
 
131
#endif
 
132
    }
 
133
 
 
134
    m_painter = new KisPainter(m_dab);
 
135
    m_painter->setFillStyle(KisPainter::FillStyleForegroundColor);
 
136
    m_painter->setPaintColor(painter()->paintColor());
 
137
 
 
138
    
 
139
    m_positions.append(info);
 
140
    int size = m_positions.size();
 
141
    qreal part = 0.0;
 
142
 
 
143
    int diameter;
 
144
    qreal pad;
 
145
    QPointF pos;
 
146
    if (size == 1)
 
147
    {
 
148
        diameter = m_startSize;
 
149
        pad = 0.5 * diameter;
 
150
        pos = m_positions[0].pos();
 
151
        pos -= QPointF(pad,pad);
 
152
        m_painter->paintEllipse(pos.x(), pos.y(), diameter, diameter);
 
153
    }else
 
154
    {
 
155
        for (int i = 0; i < size; i++)
 
156
        {
 
157
            part = (i / (qreal)(size-1));
 
158
 
 
159
            diameter = (1.0 - part) * m_startSize + part * m_endSize; if (diameter < 1.0) continue;
 
160
 
 
161
            pad = 0.5 * diameter;
 
162
 
 
163
            pos = m_positions[i].pos();
 
164
            pos -= QPointF(pad,pad);
 
165
 
 
166
            m_painter->paintEllipse(pos.x(), pos.y(), diameter, diameter);
 
167
        }
 
168
    }
 
169
    
 
170
    
 
171
    
 
172
    // save the size of it so that we can delete it next time
 
173
    rc = m_previousDab = m_dab->extent();
 
174
    painter()->bitBlt(rc.topLeft(), m_dab, rc);
 
175
#ifndef MEMORY
 
176
    m_settings->node()->setDirty(erasedRc);
 
177
#endif
 
178
    m_isFirst = false;
 
179
    
 
180
    delete m_painter;
 
181
    m_painter = 0;
 
182
    
 
183
    return m_spacing;
 
184
}
 
185