chalk

kis_paintop.cpp
1/*
2 * Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
3 * Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
4 * Copyright (c) 2004 Clarence Dang <dang@kde.org>
5 * Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
6 * Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22#include "tqwidget.h"
23#include "kis_painter.h"
24#include "kis_layer.h"
25#include "kis_types.h"
26#include "kis_paintop.h"
27#include "kis_alpha_mask.h"
28#include "kis_point.h"
29#include "kis_colorspace.h"
30#include "kis_global.h"
31#include "kis_iterators_pixel.h"
32#include "kis_color.h"
33
34KisPaintOp::KisPaintOp(KisPainter * painter)
35 : m_dab(0)
36{
37 m_painter = painter;
38 setSource(painter->device());
39}
40
41KisPaintOp::~KisPaintOp()
42{
43}
44
45KisPaintDeviceSP KisPaintOp::computeDab(KisAlphaMaskSP mask) {
46 return computeDab(mask, m_painter->device()->colorSpace());
47}
48
49KisPaintDeviceSP KisPaintOp::computeDab(KisAlphaMaskSP mask, KisColorSpace *cs)
50{
51 // XXX: According to the SeaShore source, the Gimp uses a
52 // temporary layer the size of the layer that is being painted
53 // on. This layer is cleared between painting actions. Our
54 // temporary layer, dab, is for every paintAt, composited with
55 // the target layer. We only use a real temporary layer for things
56 // like filter tools.
57
58 if(!m_dab || m_dab->colorSpace() != cs)
59 m_dab = new KisPaintDevice(cs, "dab");
60 TQ_CHECK_PTR(m_dab);
61
62 KisColor kc = m_painter->paintColor();
63
64 KisColorSpace * colorSpace = m_dab->colorSpace();
65
66 TQ_INT32 pixelSize = colorSpace->pixelSize();
67
68 TQ_INT32 maskWidth = mask->width();
69 TQ_INT32 maskHeight = mask->height();
70
71 // Convert the kiscolor to the right colorspace.
72 kc.convertTo(colorSpace);
73
74 KisHLineIteratorPixel hiter = m_dab->createHLineIterator(0, 0, maskWidth, true);
75 for (int y = 0; y < maskHeight; y++)
76 {
77 int x=0;
78 while(! hiter.isDone())
79 {
80 // XXX: Set mask
81 colorSpace->setAlpha(kc.data(), mask->alphaAt(x++, y), 1);
82 memcpy(hiter.rawData(), kc.data(), pixelSize);
83 ++hiter;
84 }
85 hiter.nextRow();
86 }
87
88 return m_dab;
89}
90
91void KisPaintOp::splitCoordinate(double coordinate, TQ_INT32 *whole, double *fraction)
92{
93 TQ_INT32 i = static_cast<TQ_INT32>(coordinate);
94
95 if (coordinate < 0) {
96 // We always want the fractional part to be positive.
97 // E.g. -1.25 becomes -2 and +0.75
98 i--;
99 }
100
101 double f = coordinate - i;
102
103 *whole = i;
104 *fraction = f;
105}
106
107void KisPaintOp::setSource(KisPaintDeviceSP p) {
108 Q_ASSERT(p);
109 m_source = p;
110}
111
112
113KisPaintOpSettings* KisPaintOpFactory::settings(TQWidget* /*parent*/, const KisInputDevice& /*inputDevice*/) { return 0; }
A colorspace is the definition of a certain color model in Chalk.
virtual TQ_UINT32 pixelSize() const =0
The size in bytes of a single pixel in this color model.
virtual void setAlpha(TQ_UINT8 *pixels, TQ_UINT8 alpha, TQ_INT32 nPixels) const =0
Set the alpha channel of the given run of pixels to the given value.
A KisColor describes a color in a certain colorspace.
Definition kis_color.h:33
void convertTo(KisColorSpace *cs)
Convert this KisColor to the specified colorspace.
TQ_UINT8 * data() const
For easy memcpy'ing etc.
Definition kis_color.h:62
The pixel iterators are high level iterarators.
A paint device contains the actual pixel data and offers methods to read and write pixels.
virtual KisPaintOpSettings * settings(TQWidget *parent, const KisInputDevice &inputDevice)
Create and return an (abstracted) widget with options for this paintop when used with the specified i...
KisPainter contains the graphics primitives necessary to draw on a KisPaintDevice.
Definition kis_painter.h:56
KisPaintDeviceSP device() const
Returns the current paint device.
Definition kis_painter.h:95