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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/*
* Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library 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 Library General Public License for more details.
*
* You should have received a copy of the GNU Library 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 "krs_paint_layer.h"
#include <tdelocale.h>
#include <kis_colorspace_factory_registry.h>
#include <kis_doc.h>
#include <kis_layer.h>
#include <kis_meta_registry.h>
#include <kis_iterators_pixel.h>
#include <kis_transaction.h>
#include <kis_math_toolbox.h>
#include "krs_iterator.h"
#include "krs_histogram.h"
#include "krs_painter.h"
#include "krs_wavelet.h"
namespace Kross {
namespace ChalkCore {
PaintLayer::PaintLayer(KisPaintLayerSP layer, KisDoc* doc)
: Kross::Api::Class<PaintLayer>("ChalkLayer"), m_layer(layer), m_doc(doc), m_cmd(0)
{
addFunction("createRectIterator", &PaintLayer::createRectIterator);
addFunction("createHLineIterator", &PaintLayer::createHLineIterator);
addFunction("createVLineIterator", &PaintLayer::createVLineIterator);
addFunction("getWidth", &PaintLayer::getWidth);
addFunction("getHeight", &PaintLayer::getHeight);
addFunction("createHistogram", &PaintLayer::createHistogram);
addFunction("createPainter", &PaintLayer::createPainter);
addFunction("beginPainting", &PaintLayer::beginPainting);
addFunction("endPainting", &PaintLayer::endPainting);
addFunction("convertToColorspace", &PaintLayer::convertToColorspace);
addFunction("fastWaveletTransformation", &PaintLayer::fastWaveletTransformation);
addFunction("fastWaveletUntransformation", &PaintLayer::fastWaveletUntransformation);
addFunction("colorSpaceId", &PaintLayer::colorSpaceId);
}
PaintLayer::~PaintLayer()
{
}
const TQString PaintLayer::getClassName() const {
return "Kross::ChalkCore::PaintLayer";
}
Kross::Api::Object::Ptr PaintLayer::createRectIterator(Kross::Api::List::Ptr args)
{
return new Iterator<KisRectIteratorPixel>(
paintLayer()->paintDevice()->createRectIterator(Kross::Api::Variant::toUInt(args->item(0)),
Kross::Api::Variant::toUInt(args->item(1)),
Kross::Api::Variant::toUInt(args->item(2)),
Kross::Api::Variant::toUInt(args->item(3)), true),
paintLayer());
}
Kross::Api::Object::Ptr PaintLayer::createHLineIterator(Kross::Api::List::Ptr args)
{
return new Iterator<KisHLineIteratorPixel>(
paintLayer()->paintDevice()->createHLineIterator(Kross::Api::Variant::toUInt(args->item(0)),
Kross::Api::Variant::toUInt(args->item(1)),
Kross::Api::Variant::toUInt(args->item(2)), true),
paintLayer());
}
Kross::Api::Object::Ptr PaintLayer::createVLineIterator(Kross::Api::List::Ptr args)
{
return new Iterator<KisVLineIteratorPixel>(
paintLayer()->paintDevice()->createVLineIterator(Kross::Api::Variant::toUInt(args->item(0)),
Kross::Api::Variant::toUInt(args->item(1)),
Kross::Api::Variant::toUInt(args->item(2)), true),
paintLayer());
}
Kross::Api::Object::Ptr PaintLayer::getWidth(Kross::Api::List::Ptr)
{
TQRect r1 = paintLayer()->extent();
TQRect r2 = paintLayer()->image()->bounds();
TQRect rect = r1.intersect(r2);
return new Kross::Api::Variant(rect.width());
}
Kross::Api::Object::Ptr PaintLayer::getHeight(Kross::Api::List::Ptr)
{
TQRect r1 = paintLayer()->extent();
TQRect r2 = paintLayer()->image()->bounds();
TQRect rect = r1.intersect(r2);
return new Kross::Api::Variant(rect.height());
}
Kross::Api::Object::Ptr PaintLayer::createHistogram(Kross::Api::List::Ptr args)
{
TQString histoname = Kross::Api::Variant::toString(args->item(0));
KisHistogramProducerFactory* factory = KisHistogramProducerFactoryRegistry::instance()->get(histoname);
/* KisIDList listID = KisHistogramProducerFactoryRegistry::instance()->listKeys();
for(KisIDList::iterator it = listID.begin(); it != listID.end(); it++)
{
kdDebug(41011) << (*it).name() << " " << (*it).id() << endl;
}*/
enumHistogramType type ;
switch( Kross::Api::Variant::toUInt(args->item(1)) )
{
case 1:
type = LOGARITHMIC;
break;
case 0:
default:
type = LINEAR;
break;
}
if(factory && factory->isCompatibleWith( paintLayer()->paintDevice()->colorSpace() ))
{
return new Histogram( paintLayer().data(), factory->generate() , type);
} else {
throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("An error has occured in %1").arg("createHistogram") + "\n" + i18n("The histogram %1 is not available").arg(histoname) ) );
}
return 0;
}
Kross::Api::Object::Ptr PaintLayer::createPainter(Kross::Api::List::Ptr )
{
return new Painter(paintLayer());
}
Kross::Api::Object::Ptr PaintLayer::beginPainting(Kross::Api::List::Ptr args)
{
TQString name = Kross::Api::Variant::toString(args->item(0));
if(m_cmd != 0)
{
delete m_cmd;
}
m_cmd = new KisTransaction(name, paintLayer()->paintDevice());
TQ_CHECK_PTR(m_cmd);
return 0;
}
Kross::Api::Object::Ptr PaintLayer::endPainting(Kross::Api::List::Ptr)
{
if(doc() !=0)
{
doc()->setModified(true);
doc()->currentImage()->activeLayer()->setDirty();
}
if(m_cmd != 0)
{
paintLayer()->image()->undoAdapter()->addCommand(m_cmd);
}
return 0;
}
Kross::Api::Object::Ptr PaintLayer::convertToColorspace(Kross::Api::List::Ptr args)
{
KisColorSpace * dstCS = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID(Kross::Api::Variant::toString(args->item(0)), ""), "");
if(!dstCS)
{
// FIXME: inform user
throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("An error has occured in %1").arg("convertToColorspace") + "\n" + i18n("Colorspace %1 is not available, please check your installation.").arg(Kross::Api::Variant::toString(args->item(0))) ) );
return 0;
}
paintLayer()->paintDevice()->convertTo(dstCS);
return 0;
}
Kross::Api::Object::Ptr PaintLayer::colorSpaceId(Kross::Api::List::Ptr )
{
return new Kross::Api::Variant( paintLayer()->paintDevice()->colorSpace()->id().id() );
}
Kross::Api::Object::Ptr PaintLayer::fastWaveletTransformation(Kross::Api::List::Ptr )
{
KisMathToolbox* mathToolbox = KisMetaRegistry::instance()->mtRegistry()->get( paintLayer()->paintDevice()->colorSpace()->mathToolboxID() );
TQRect rect = paintLayer()->exactBounds();
KisMathToolbox::KisWavelet* wav = mathToolbox->fastWaveletTransformation(paintLayer()->paintDevice(), rect);
return new Wavelet(wav);
}
Kross::Api::Object::Ptr PaintLayer::fastWaveletUntransformation(Kross::Api::List::Ptr args)
{
Wavelet* wav = (Wavelet*)args->item(0).data();
KisMathToolbox* mathToolbox = KisMetaRegistry::instance()->mtRegistry()->get( paintLayer()->paintDevice()->colorSpace()->mathToolboxID() );
TQRect rect = paintLayer()->exactBounds();
mathToolbox->fastWaveletUntransformation( paintLayer()->paintDevice(), rect, wav->wavelet() );
return 0;
}
}
}
|