summaryrefslogtreecommitdiffstats
path: root/chalk/plugins/viewplugins/scripting/chalkcore
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2011-06-26 00:41:16 +0000
commit698569f8428ca088f764d704034a1330517b98c0 (patch)
treebf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /chalk/plugins/viewplugins/scripting/chalkcore
parent2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff)
downloadkoffice-698569f8428ca088f764d704034a1330517b98c0.tar.gz
koffice-698569f8428ca088f764d704034a1330517b98c0.zip
Finish rebranding of Krita as Chalk
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238363 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'chalk/plugins/viewplugins/scripting/chalkcore')
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/Makefile.am30
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/chalkcoremodule.cpp288
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/chalkcoremodule.h205
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_brush.cpp41
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_brush.h48
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_color.cpp42
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_color.h49
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_doc.cpp46
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_doc.h53
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_filter.cpp76
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_filter.h76
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_filter_configuration.cpp72
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_filter_configuration.h65
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_histogram.cpp104
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_histogram.h115
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_image.cpp148
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_image.h94
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_iterator.h307
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_paint_layer.cpp207
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_paint_layer.h140
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_painter.cpp358
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_painter.h242
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_pattern.cpp39
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_pattern.h48
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_script_progress.cpp67
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_script_progress.h77
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_wavelet.cpp114
-rw-r--r--chalk/plugins/viewplugins/scripting/chalkcore/krs_wavelet.h92
28 files changed, 3243 insertions, 0 deletions
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/Makefile.am b/chalk/plugins/viewplugins/scripting/chalkcore/Makefile.am
new file mode 100644
index 00000000..448c7c59
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/Makefile.am
@@ -0,0 +1,30 @@
+
+INCLUDES = -I$(top_srcdir)/core -I$(top_srcdir)/chalk/plugins/viewplugins/scripting/chalkscripting \
+ -I$(top_srcdir)/chalk $(KOFFICECORE_INCLUDES) $(KROSS_INCLUDES) \
+ -I$(top_srcdir)/chalk/ui -I$(top_srcdir)/chalk/core -I$(top_srcdir)/chalk/sdk \
+ -I$(top_srcdir)/chalk/chalkcolor $(all_includes)
+
+kde_module_LTLIBRARIES = krosschalkcore.la
+
+krosschalkcore_la_SOURCES = chalkcoremodule.cpp krs_doc.cpp krs_paint_layer.cpp \
+ krs_image.cpp krs_histogram.cpp krs_script_progress.cpp krs_painter.cpp krs_color.cpp \
+ krs_brush.cpp krs_pattern.cpp krs_filter.cpp krs_filter_configuration.cpp \
+ krs_wavelet.cpp
+
+krosschalkcore_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) -module $(LIB_QT) -lkdecore -lkdeui -lkjs -lkdefx -lkio -lkparts -L../../../../../chalk/chalkcolor/.libs -lchalkcolor -L../../../../../chalk/core/.libs -lchalkimage \
+ -L../../../../../chalk/ui/.libs -lchalkui -L../../../../../lib/kofficeui/.libs -lkofficeui -L../../../../../lib/kofficecore/.libs -lkofficecore
+krosschalkcore_la_LIBADD = \
+ $(LIB_QT) \
+ $(LIB_KDECORE) \
+ $(top_builddir)/lib/kross/api/libkrossapi.la \
+ $(top_builddir)/lib/kross/main/libkrossmain.la \
+ $(top_builddir)/chalk/libchalkcommon.la \
+ $(top_builddir)/chalk/plugins/viewplugins/scripting/chalkscripting/libchalkscripting.la
+
+METASOURCES = AUTO
+SUBDIRS = .
+
+KDE_CXXFLAGS = $(USE_EXCEPTIONS)
+
+noinst_HEADERS = krs_doc.h krs_iterator.h krs_painter.h krs_color.h krs_brush.h \
+ krs_filter.h krs_filter_configuration.h krs_wavelet.h
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/chalkcoremodule.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/chalkcoremodule.cpp
new file mode 100644
index 00000000..04f7b653
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/chalkcoremodule.cpp
@@ -0,0 +1,288 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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 "chalkcoremodule.h"
+
+#include <kdebug.h>
+
+//#include <api/variant.h>
+#include <api/qtobject.h>
+#include <main/manager.h>
+
+#include <kis_autobrush_resource.h>
+#include <kis_brush.h>
+#include <kis_colorspace_factory_registry.h>
+#include <kis_doc.h>
+#include <kis_filter.h>
+#include <kis_filter_registry.h>
+#include <kis_image.h>
+#include <kis_meta_registry.h>
+#include <kis_pattern.h>
+#include <kis_resourceserver.h>
+
+#include "kis_script_progress.h"
+
+#include "krs_brush.h"
+#include "krs_color.h"
+#include "krs_doc.h"
+#include "krs_filter.h"
+#include "krs_image.h"
+#include "krs_pattern.h"
+#include "krs_script_progress.h"
+
+extern "C"
+{
+ /**
+ * Exported an loadable function as entry point to use
+ * the \a KexiAppModule.
+ */
+ Kross::Api::Object* KDE_EXPORT init_module(Kross::Api::Manager* manager)
+ {
+ return new Kross::ChalkCore::ChalkCoreModule(manager);
+ }
+}
+
+
+using namespace Kross::ChalkCore;
+
+ChalkCoreFactory::ChalkCoreFactory(TQString packagePath) : Kross::Api::Event<ChalkCoreFactory>("ChalkCoreFactory"), m_packagePath(packagePath)
+{
+ addFunction("newRGBColor", &ChalkCoreFactory::newRGBColor);
+ addFunction("newHSVColor", &ChalkCoreFactory::newHSVColor);
+ addFunction("getPattern", &ChalkCoreFactory::getPattern);
+ addFunction("loadPattern", &ChalkCoreFactory::loadPattern);
+ addFunction("getBrush", &ChalkCoreFactory::getBrush);
+ addFunction("loadBrush", &ChalkCoreFactory::loadBrush);
+ addFunction("getFilter", &ChalkCoreFactory::getFilter);
+ addFunction("newCircleBrush", &ChalkCoreFactory::newCircleBrush);
+ addFunction("newRectBrush", &ChalkCoreFactory::newRectBrush);
+ addFunction("newImage", &ChalkCoreFactory::newImage);
+ addFunction("getPackagePath", &ChalkCoreFactory::getPackagePath);
+}
+
+Kross::Api::Object::Ptr ChalkCoreFactory::newRGBColor(Kross::Api::List::Ptr args)
+{
+ Color* c = new Color(Kross::Api::Variant::toUInt(args->item(0)), Kross::Api::Variant::toUInt(args->item(1)), Kross::Api::Variant::toUInt(args->item(2)), TQColor::Rgb);
+ return c;
+}
+Kross::Api::Object::Ptr ChalkCoreFactory::newHSVColor(Kross::Api::List::Ptr args)
+{
+ return new Color(Kross::Api::Variant::toUInt(args->item(0)), Kross::Api::Variant::toUInt(args->item(1)), Kross::Api::Variant::toUInt(args->item(2)), TQColor::Hsv);
+}
+
+Kross::Api::Object::Ptr ChalkCoreFactory::getPattern(Kross::Api::List::Ptr args)
+{
+ KisResourceServerBase* rServer = KisResourceServerRegistry::instance()->get("PatternServer");
+ TQValueList<KisResource*> resources = rServer->resources();
+
+ TQString name = Kross::Api::Variant::toString(args->item(0));
+
+ for (TQValueList<KisResource*>::iterator it = resources.begin(); it != resources.end(); ++it )
+ {
+ if((*it)->name() == name)
+ {
+ return new Pattern(dynamic_cast<KisPattern*>(*it), true);
+ }
+ }
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("Unknown pattern") ) );
+ return 0;
+
+}
+
+Kross::Api::Object::Ptr ChalkCoreFactory::loadPattern(Kross::Api::List::Ptr args)
+{
+ TQString filename = Kross::Api::Variant::toString(args->item(0));
+ KisPattern* pattern = new KisPattern(filename);
+ if(pattern->load())
+ {
+ return new Pattern( pattern, false );
+ } else {
+ delete pattern;
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("Unknown pattern") ) );
+ return 0;
+ }
+}
+
+Kross::Api::Object::Ptr ChalkCoreFactory::getBrush(Kross::Api::List::Ptr args)
+{
+ KisResourceServerBase* rServer = KisResourceServerRegistry::instance()->get("BrushServer");
+ TQValueList<KisResource*> resources = rServer->resources();
+
+ TQString name = Kross::Api::Variant::toString(args->item(0));
+
+ for (TQValueList<KisResource*>::iterator it = resources.begin(); it != resources.end(); ++it )
+ {
+ if((*it)->name() == name)
+ {
+ return new Brush(dynamic_cast<KisBrush*>(*it), true);
+ }
+ }
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("Unknown brush") ) );
+ return 0;
+}
+
+Kross::Api::Object::Ptr ChalkCoreFactory::loadBrush(Kross::Api::List::Ptr args)
+{
+ TQString filename = Kross::Api::Variant::toString(args->item(0));
+ KisBrush* brush = new KisBrush(filename);
+ if(brush->load())
+ {
+ return new Brush( brush, false );
+ } else {
+ delete brush;
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("Unknown brush") ) );
+ return 0;
+ }
+}
+
+Kross::Api::Object::Ptr ChalkCoreFactory::getFilter(Kross::Api::List::Ptr args)
+{
+ TQString name = Kross::Api::Variant::toString(args->item(0));
+ KisFilter* filter = KisFilterRegistry::instance()->get(name);
+ if(filter)
+ {
+ return new Filter(filter);
+ } else {
+ return 0;
+ }
+}
+
+Kross::Api::Object::Ptr ChalkCoreFactory::newCircleBrush(Kross::Api::List::Ptr args)
+{
+ uint w = TQMAX(1, Kross::Api::Variant::toUInt(args->item(0)));
+ uint h = TQMAX(1, Kross::Api::Variant::toUInt(args->item(1)));
+ uint hf = 0;
+ uint vf = 0;
+ if( args.count() > 2)
+ {
+ hf = Kross::Api::Variant::toUInt(args->item(2));
+ vf = Kross::Api::Variant::toUInt(args->item(3));
+ }
+ KisAutobrushShape* kas = new KisAutobrushCircleShape(w, h, hf, vf);
+ TQImage* brsh = new TQImage();
+ kas->createBrush(brsh);
+ return new Brush(new KisAutobrushResource(*brsh), false);
+}
+Kross::Api::Object::Ptr ChalkCoreFactory::newRectBrush(Kross::Api::List::Ptr args)
+{
+ uint w = TQMAX(1, Kross::Api::Variant::toUInt(args->item(0)));
+ uint h = TQMAX(1, Kross::Api::Variant::toUInt(args->item(1)));
+ uint hf = 0;
+ uint vf = 0;
+ if( args.count() > 2)
+ {
+ hf = Kross::Api::Variant::toUInt(args->item(2));
+ vf = Kross::Api::Variant::toUInt(args->item(3));
+ }
+ KisAutobrushShape* kas = new KisAutobrushRectShape(w, h, hf, vf);
+ TQImage* brsh = new TQImage();
+ kas->createBrush(brsh);
+ return new Brush(new KisAutobrushResource(*brsh), false);;
+}
+
+Kross::Api::Object::Ptr ChalkCoreFactory::newImage(Kross::Api::List::Ptr args)
+{
+ int w = Kross::Api::Variant::toInt(args->item(0));
+ int h = Kross::Api::Variant::toInt(args->item(1));
+ TQString csname = Kross::Api::Variant::toString(args->item(2));
+ TQString name = Kross::Api::Variant::toString(args->item(3));
+ if( w < 0 || h < 0)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("Invalid image size") ) );
+ return 0;
+ }
+ KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID(csname, ""), "");
+ if(!cs)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("Colorspace %0 is not available, please check your installation.").tqarg(csname ) ) );
+ return 0;
+ }
+
+ return new Image(new KisImage(0,w,h, cs, name));
+}
+
+Kross::Api::Object::Ptr ChalkCoreFactory::getPackagePath(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant(m_packagePath);
+}
+
+ChalkCoreModule::ChalkCoreModule(Kross::Api::Manager* manager)
+ : Kross::Api::Module("chalkcore") , m_manager(manager), m_factory(0)
+{
+
+ TQMap<TQString, Object::Ptr> tqchildren = manager->getChildren();
+ kdDebug(41011) << " there are " << tqchildren.size() << endl;
+ for(TQMap<TQString, Object::Ptr>::const_iterator it = tqchildren.begin(); it != tqchildren.end(); it++)
+ {
+ kdDebug(41011) << it.key() << " " << it.data() << endl;
+ }
+
+ // Wrap doc
+ Kross::Api::Object::Ptr chalkdocument = manager->getChild("ChalkDocument");
+ if(chalkdocument) {
+ Kross::Api::QtObject* chalkdocumentqt = (Kross::Api::QtObject*)( chalkdocument.data() );
+ if(chalkdocumentqt) {
+ ::KisDoc* document = (::KisDoc*)( chalkdocumentqt->getObject() );
+ if(document) {
+ addChild( new Doc(document) );
+ } else {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("There was no 'ChalkDocument' published.") );
+ }
+ }
+ }
+ // Wrap ChalkScriptProgress
+ TQString packagePath;
+ Kross::Api::Object::Ptr chalkscriptprogress = manager->getChild("ChalkScriptProgress");
+ if(chalkdocument) {
+ Kross::Api::QtObject* chalkscriptprogressqt = (Kross::Api::QtObject*)( chalkscriptprogress.data() );
+ if(chalkscriptprogressqt) {
+ ::KisScriptProgress* scriptprogress = (::KisScriptProgress*)( chalkscriptprogressqt->getObject() );
+ scriptprogress->activateAsSubject();
+ packagePath = scriptprogress->packagePath();
+ if(scriptprogress) {
+ addChild( new ScriptProgress(scriptprogress) );
+ } else {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("There was no 'ChalkScriptProgress' published.") );
+ }
+ }
+ }
+ m_factory = new ChalkCoreFactory(packagePath);
+}
+
+ChalkCoreModule::~ChalkCoreModule()
+{
+ if(m_factory)
+ delete m_factory;
+}
+
+
+const TQString ChalkCoreModule::getClassName() const
+{
+ return "Kross::ChalkCore::ChalkCoreModule";
+}
+
+Kross::Api::Object::Ptr ChalkCoreModule::call(const TQString& name, Kross::Api::List::Ptr arguments)
+{
+ kdDebug(41011) << "ChalkCoreModule::call = " << name << endl;
+ if( m_factory->isAFunction(name))
+ {
+ return m_factory->call(name, arguments);
+ } else {
+ return Kross::Api::Module::call(name, arguments);
+ }
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/chalkcoremodule.h b/chalk/plugins/viewplugins/scripting/chalkcore/chalkcoremodule.h
new file mode 100644
index 00000000..d719edd6
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/chalkcoremodule.h
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KRITA_KROSS_KRITACOREMODULE_H
+#define KRITA_KROSS_KRITACOREMODULE_H
+
+#include <tqstring.h>
+#include <tqvariant.h>
+
+#define KROSS_MAIN_EXPORT KDE_EXPORT
+
+#include <api/module.h>
+#include <api/event.h>
+
+namespace Kross { namespace Api {
+ class Manager;
+}}
+
+namespace Kross { namespace ChalkCore {
+ /**
+ * This class contains functions use to create new Kross object in a script
+ */
+ class ChalkCoreFactory : public Kross::Api::Event<ChalkCoreFactory>
+ {
+ public:
+ ChalkCoreFactory(TQString packagePath);
+ private:
+ /**
+ * This function return a new Image.
+ * It takes four arguments :
+ * - width
+ * - height
+ * - colorspace id
+ * - name of the image
+ *
+ * And in return you get an Image object.
+ *
+ * For example (in ruby) :
+ * @code
+ * Krosschalkcore::newImage(10,20, "RGBA", "kikoo")
+ * @endcode
+ */
+ Kross::Api::Object::Ptr newImage(Kross::Api::List::Ptr);
+ /**
+ * This function return a new Color with the given RGB triplet
+ * It takes three arguments :
+ * - red color (0 to 255)
+ * - blue color (0 to 255)
+ * - green color (0 to 255)
+ *
+ * For example (in ruby) :
+ * @code
+ * Krosschalkcore::newRGBColor(255,0,0) # create a red color
+ * Krosschalkcore::newRGBColor(255,255,255) # create a white color
+ * @endcode
+ */
+ Kross::Api::Object::Ptr newRGBColor(Kross::Api::List::Ptr);
+ /**
+ * This function return a new Color with the given HSV triplet
+ * It takes three arguments :
+ * - hue color (0 to 255)
+ * - saturation color (0 to 255)
+ * - value color (0 to 255)
+ *
+ * For example (in ruby) :
+ * @code
+ * Krosschalkcore::newRGBColor(255,125,0)
+ * @endcode
+ */
+ Kross::Api::Object::Ptr newHSVColor(Kross::Api::List::Ptr);
+ /**
+ * This function return a Pattern taken from the list of ressources
+ * of chalk
+ * It takes one argument :
+ * - the name of the pattern
+ *
+ * For example (in ruby) :
+ * @code
+ * Krosschalkcore::getPattern("Bricks")
+ * @endcode
+ */
+ Kross::Api::Object::Ptr getPattern(Kross::Api::List::Ptr);
+ /**
+ * This function return a Brush taken from the list of ressources
+ * of chalk
+ * It takes one argument :
+ * - the name of the pattern
+ *
+ * For example (in ruby) :
+ * @code
+ * Krosschalkcore::getBrush("Circle (05)")
+ * @endcode
+ */
+ Kross::Api::Object::Ptr getBrush(Kross::Api::List::Ptr);
+ /**
+ * This function return a Brush with a circular tqshape
+ * It takes at least two arguments :
+ * - width
+ * - height
+ *
+ * It can takes two other arguments :
+ * - width of the shading
+ * - height of the shading
+ *
+ * If the shading isn't specified, no shading will be used.
+ *
+ * For example (in ruby) :
+ * @code
+ * Krosschalkcore::newCircleBrush(10,20) # create a plain circle
+ * Krosschalkcore::newCircleBrush(10,20,5,10) # create a gradient
+ * @endcode
+ */
+ Kross::Api::Object::Ptr newCircleBrush(Kross::Api::List::Ptr);
+ /**
+ * This function return a Brush with a rectangular tqshape
+ * It takes at least two arguments :
+ * - width
+ * - height
+ *
+ * It can takes two other arguments :
+ * - width of the shading
+ * - height of the shading
+ *
+ * If the shading isn't specified, no shading will be used.
+ *
+ * For example (in ruby) :
+ * @code
+ * Krosschalkcore::newRectBrush(10,20) # create a plain rectangle
+ * Krosschalkcore::newRectBrush(10,20,5,10) # create a gradient
+ * @endcode
+ */
+ Kross::Api::Object::Ptr newRectBrush(Kross::Api::List::Ptr);
+ /**
+ * This function return a Filter taken from the list of ressources
+ * of chalk
+ * It takes one argument :
+ * - the name of the filter
+ *
+ * For example (in ruby) :
+ * @code
+ * Krosschalkcore::getFilter("invert")
+ * @endcode
+ */
+ Kross::Api::Object::Ptr getFilter(Kross::Api::List::Ptr);
+ /**
+ * This function loads a Brush and then returns it.
+ * It takes one argument: the filename of the brush.
+ */
+ Kross::Api::Object::Ptr loadBrush(Kross::Api::List::Ptr);
+ /**
+ * This function loads a Pattern and then returns it.
+ * It takes one argument: the filename of the pattern.
+ */
+ Kross::Api::Object::Ptr loadPattern(Kross::Api::List::Ptr);
+ /**
+ * This function return the directory where the script is located.
+ */
+ Kross::Api::Object::Ptr getPackagePath(Kross::Api::List::Ptr);
+ private:
+ TQString m_packagePath;
+ };
+ /**
+ *
+ */
+ class ChalkCoreModule : public Kross::Api::Module
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ ChalkCoreModule(Kross::Api::Manager* manager);
+
+ /**
+ * Destructor.
+ */
+ virtual ~ChalkCoreModule();
+
+ /// \see Kross::Api::Object::getClassName
+ virtual const TQString getClassName() const;
+ virtual Kross::Api::Object::Ptr call(const TQString& name, Kross::Api::List::Ptr arguments);
+ private:
+ Kross::Api::Manager* m_manager;
+ ChalkCoreFactory* m_factory;
+ };
+
+
+}}
+
+#endif
+
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_brush.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/krs_brush.cpp
new file mode 100644
index 00000000..d3f1cb8a
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_brush.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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_brush.h"
+
+#include <kis_brush.h>
+
+namespace Kross {
+
+namespace ChalkCore {
+
+Brush::Brush(KisBrush* brush, bool sharedBrush) : Kross::Api::Class<Brush>("ChalkBrush"), m_brush(brush), m_sharedBrush(sharedBrush)
+{
+}
+
+Brush::~Brush()
+{
+ if(!m_sharedBrush)
+ {
+ delete m_brush;
+ }
+}
+
+}
+
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_brush.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_brush.h
new file mode 100644
index 00000000..7a6bdef5
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_brush.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KROSS_KRITACOREKRS_BRUSH_H
+#define KROSS_KRITACOREKRS_BRUSH_H
+
+#include <api/class.h>
+
+class KisBrush;
+
+namespace Kross {
+
+namespace ChalkCore {
+
+class Brush : public Kross::Api::Class<Brush>{
+ public:
+ /**
+ * @param sharedBrush tell if the brush should be deleted or not when this object is deleted
+ */
+ Brush(KisBrush*, bool sharedBrush );
+ ~Brush();
+ public:
+ inline KisBrush* getBrush() { return m_brush; }
+ private:
+ KisBrush* m_brush;
+ bool m_sharedBrush;
+};
+
+}
+
+}
+
+#endif
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_color.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/krs_color.cpp
new file mode 100644
index 00000000..b02a36f0
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_color.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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_color.h"
+
+namespace Kross {
+
+namespace ChalkCore {
+
+Color::Color ( int x, int y, int z, TQColor::Spec colorSpec )
+ : Kross::Api::Class<Color>("ChalkColor"), m_color(x,y,z,colorSpec)
+{
+}
+
+Color::Color()
+ : Kross::Api::Class<Color>("ChalkColor")
+{
+}
+
+Color::~Color()
+{
+}
+
+
+}
+
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_color.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_color.h
new file mode 100644
index 00000000..7955dc92
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_color.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KROSS_APIKRS_COLOR_H
+#define KROSS_APIKRS_COLOR_H
+
+#include <tqcolor.h>
+
+#include <api/class.h>
+
+namespace Kross {
+
+namespace ChalkCore {
+
+class Color : public Kross::Api::Class<Color>
+{
+ public:
+ Color ( int x, int y, int z, TQColor::Spec colorSpec );
+ Color ();
+
+ ~Color();
+ public:
+ inline const TQString getClassName() const
+ { return "Kross::Chalk::Color"; };
+ inline TQColor toTQColor() { return m_color; };
+ private:
+ TQColor m_color;
+};
+
+}
+
+}
+
+#endif
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_doc.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/krs_doc.cpp
new file mode 100644
index 00000000..4fc37fab
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_doc.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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_doc.h"
+
+#include <kis_doc.h>
+#include <kis_image.h>
+
+#include "krs_image.h"
+
+namespace Kross { namespace ChalkCore {
+
+Doc::Doc(::KisDoc* doc) : Kross::Api::Class<Doc>("ChalkDocument"), m_doc(doc) {
+ addFunction("getImage", &Doc::getImage);
+}
+
+Doc::~Doc() {
+
+}
+
+const TQString Doc::getClassName() const {
+ return "Kross::ChalkCore::Doc";
+}
+
+Kross::Api::Object::Ptr Doc::getImage(Kross::Api::List::Ptr)
+{
+ return new Image(m_doc->currentImage(), m_doc);
+}
+
+}
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_doc.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_doc.h
new file mode 100644
index 00000000..c06e530a
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_doc.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef _KROSS_KRS_DOC_H_
+#define _KROSS_KRS_DOC_H_
+
+class KisDoc;
+
+#include <api/class.h>
+
+namespace Kross { namespace ChalkCore {
+
+class Doc : public Kross::Api::Class<Doc>
+{
+ public:
+ explicit Doc(::KisDoc* doc);
+ virtual ~Doc();
+ virtual const TQString getClassName() const;
+ private:
+ /**
+ * This function return the Image associated with this Doc.
+ *
+ * Example (in Ruby) :
+ * @code
+ * doc = krosschalkcore::get("ChalkDocument")
+ * image = doc.getImage()
+ * @endcode
+ */
+ Kross::Api::Object::Ptr getImage(Kross::Api::List::Ptr);
+ private:
+ KisDoc* m_doc;
+
+};
+}
+}
+
+
+#endif
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_filter.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/krs_filter.cpp
new file mode 100644
index 00000000..ecac5501
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_filter.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2006 Cyrille Berger <[email protected]>
+ *
+ * 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_filter.h"
+
+#include <kis_filter.h>
+#include <kis_paint_layer.h>
+
+#include "krs_filter_configuration.h"
+#include "krs_paint_layer.h"
+
+namespace Kross {
+namespace ChalkCore {
+
+Filter::Filter(KisFilter* filter)
+ : Kross::Api::Class<Filter>("ChalkFilter"), m_filter(filter), m_config( new FilterConfiguration(filter->configuration()) )
+{
+ addFunction("process", &Filter::process);
+ addFunction("getFilterConfiguration", &Filter::getFilterConfiguration);
+
+}
+
+Filter::~Filter()
+{
+}
+
+const TQString Filter::getClassName() const {
+ return "Kross::ChalkCore::Filter";
+}
+
+Kross::Api::Object::Ptr Filter::getFilterConfiguration(Kross::Api::List::Ptr )
+{
+ return m_config;
+}
+
+Kross::Api::Object::Ptr Filter::process(Kross::Api::List::Ptr args)
+{
+ PaintLayer* src = (PaintLayer*)args->item(0).data();
+ if(!m_filter->workWith( src->paintLayer()->paintDevice()->colorSpace()))
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("An error has occured in %1").tqarg("process") ) );
+ }
+ TQRect rect;
+ if( args->count() >1)
+ {
+ uint x = Kross::Api::Variant::toVariant(args->item(1)).toUInt();
+ uint y = Kross::Api::Variant::toVariant(args->item(2)).toUInt();
+ uint w = Kross::Api::Variant::toVariant(args->item(3)).toUInt();
+ uint h = Kross::Api::Variant::toVariant(args->item(4)).toUInt();
+ rect = TQRect(x, y, w, h);
+ } else {
+ TQRect r1 = src->paintLayer()->paintDevice()->extent();
+ TQRect r2 = src->paintLayer()->image()->bounds();
+ rect = r1.intersect(r2);
+ }
+ m_filter->process( src->paintLayer()->paintDevice(), src->paintLayer()->paintDevice(), m_config->filterConfiguration(), rect );
+ return 0;
+}
+
+}
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_filter.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_filter.h
new file mode 100644
index 00000000..1576574b
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_filter.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2006 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KROSS_KRITACOREKRS_FILTER_H
+#define KROSS_KRITACOREKRS_FILTER_H
+
+#include <api/class.h>
+
+class KisFilter;
+
+namespace Kross {
+namespace ChalkCore {
+ class FilterConfiguration;
+
+class Filter : public Kross::Api::Class<Filter>
+{
+ public:
+ Filter(KisFilter*);
+ ~Filter();
+ private:
+ /**
+ * This function return the FilterConfiguration associated with this filter.
+ */
+ Kross::Api::Object::Ptr getFilterConfiguration(Kross::Api::List::Ptr args);
+ /**
+ * This function will apply the filter.
+ * It takes one argument :
+ * - the source layer
+ * You can also use this four aguments :
+ * - x
+ * - y
+ * - width
+ * - height
+ *
+ * (x,y, width, height) defines the rectangular area on which the filter will be computed.
+ * If the rectangle is not defined, then the filter will be apply on alll the source layer.
+ *
+ * For example (in ruby)
+ * @code
+ * doc = Krosschalkcore::get("ChalkDocument")
+ * image = doc.getImage()
+ * layer = image.getActivePaintLayer()
+ * width = layer.getWidth()
+ * height = layer.getHeight()
+ * filter = Krosschalkcore::getFilter("invert")
+ * filter.process(layer, layer)
+ * filter.process(layer, layer, 10, 10, 20, 20 )
+ * @endcode
+ */
+ Kross::Api::Object::Ptr process(Kross::Api::List::Ptr args);
+ public:
+ virtual const TQString getClassName() const;
+ private:
+ KisFilter* m_filter;
+ FilterConfiguration* m_config;
+};
+
+}
+}
+
+#endif
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_filter_configuration.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/krs_filter_configuration.cpp
new file mode 100644
index 00000000..976af321
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_filter_configuration.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2006 Cyrille Berger <[email protected]>
+ *
+ * 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_filter_configuration.h"
+
+#include <api/variant.h>
+
+#include <kis_filter_configuration.h>
+
+namespace Kross {
+namespace ChalkCore {
+
+ FilterConfiguration::FilterConfiguration(KisFilterConfiguration* fConfig)
+ : Kross::Api::Class<FilterConfiguration>("ChalkFilterConfiguration"), m_fConfig(fConfig)
+{
+ addFunction("setProperty", &FilterConfiguration::setProperty);
+ addFunction("getProperty", &FilterConfiguration::getProperty);
+ addFunction("fromXML", &FilterConfiguration::fromXML);
+}
+
+FilterConfiguration::~FilterConfiguration()
+{
+}
+
+const TQString FilterConfiguration::getClassName() const {
+ return "Kross::ChalkCore::FilterConfiguration";
+}
+
+
+Kross::Api::Object::Ptr FilterConfiguration::setProperty(Kross::Api::List::Ptr args)
+{
+ TQString name = Kross::Api::Variant::toString(args->item(0));
+ TQVariant value = Kross::Api::Variant::toVariant(args->item(1));
+ m_fConfig->setProperty(name, value);
+ return 0;
+}
+Kross::Api::Object::Ptr FilterConfiguration::getProperty(Kross::Api::List::Ptr args)
+{
+ TQString name = Kross::Api::Variant::toString(args->item(0));
+ TQVariant value;
+ if(m_fConfig->getProperty( name, value))
+ {
+ return new Kross::Api::Variant(value);
+ } else {
+ return 0;
+ }
+}
+
+Kross::Api::Object::Ptr FilterConfiguration::fromXML(Kross::Api::List::Ptr args)
+{
+ TQString xml = Kross::Api::Variant::toString(args->item(0));
+ m_fConfig->fromXML( xml );
+ return 0;
+}
+
+}
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_filter_configuration.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_filter_configuration.h
new file mode 100644
index 00000000..61378cf4
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_filter_configuration.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2006 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KROSS_KRITACOREKRS_FILTER_CONFIGURATION_H
+#define KROSS_KRITACOREKRS_FILTER_CONFIGURATION_H
+
+#include <api/class.h>
+
+class KisFilterConfiguration;
+
+namespace Kross {
+namespace ChalkCore {
+
+/**
+ @author Cyrille Berger <[email protected]>
+*/
+class FilterConfiguration : public Kross::Api::Class<FilterConfiguration>
+{
+ public:
+ FilterConfiguration(KisFilterConfiguration*);
+ ~FilterConfiguration();
+ public:
+ virtual const TQString getClassName() const;
+ inline KisFilterConfiguration* filterConfiguration() { return m_fConfig; };
+ private:
+ /**
+ * This function define a parameter of the associated Filter.
+ * It takes two arguments :
+ * - the name of the parameter
+ * - the value, whose type depends of the Filter
+ */
+ Kross::Api::Object::Ptr setProperty(Kross::Api::List::Ptr args);
+ /**
+ * This function return the value of a parameter of the associated Filter.
+ * It takes one argument :
+ * - the name of the parameter
+ */
+ Kross::Api::Object::Ptr getProperty(Kross::Api::List::Ptr args);
+ /**
+ * Deserialize
+ */
+ Kross::Api::Object::Ptr fromXML(Kross::Api::List::Ptr args);
+ private:
+ KisFilterConfiguration* m_fConfig;
+};
+
+}
+}
+
+#endif
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_histogram.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/krs_histogram.cpp
new file mode 100644
index 00000000..ea121d7c
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_histogram.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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_histogram.h"
+
+#include <kis_paint_layer.h>
+
+namespace Kross {
+
+namespace ChalkCore {
+
+Histogram::Histogram(KisPaintLayerSP layer,
+ KisHistogramProducerSP producer,
+ const enumHistogramType type)
+ : Kross::Api::Class<Histogram>("ChalkHistogram")
+{
+ m_histogram = new KisHistogram(layer, producer, type);
+ addFunction("getMax", &Histogram::getMax);
+ addFunction("getMin", &Histogram::getMin);
+ addFunction("getHighest", &Histogram::getHighest);
+ addFunction("getLowest", &Histogram::getLowest);
+ addFunction("getMean", &Histogram::getMean);
+ addFunction("getCount", &Histogram::getCount);
+ addFunction("getTotal", &Histogram::getTotal);
+ addFunction("setChannel", &Histogram::setChannel);
+ addFunction("getChannel", &Histogram::getChannel);
+ addFunction("getValue", &Histogram::getValue);
+ addFunction("getNumberOfBins", &Histogram::getNumberOfBins);
+}
+
+Histogram::~Histogram()
+{
+}
+
+const TQString Histogram::getClassName() const {
+ return "Kross::ChalkCore::Histogram";
+}
+
+Kross::Api::Object::Ptr Histogram::setChannel(Kross::Api::List::Ptr args)
+{
+ m_histogram->setChannel(Kross::Api::Variant::toUInt(args->item(0)));
+ return 0;
+}
+Kross::Api::Object::Ptr Histogram::getChannel(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant( m_histogram->channel());
+}
+Kross::Api::Object::Ptr Histogram::getMax(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant( m_histogram->calculations().getMax());
+}
+Kross::Api::Object::Ptr Histogram::getMin(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant( m_histogram->calculations().getMin() );
+}
+Kross::Api::Object::Ptr Histogram::getHighest(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant( m_histogram->calculations().getHighest() );
+}
+Kross::Api::Object::Ptr Histogram::getLowest(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant( m_histogram->calculations().getLowest() );
+}
+Kross::Api::Object::Ptr Histogram::getMean(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant( m_histogram->calculations().getMean() );
+}
+Kross::Api::Object::Ptr Histogram::getCount(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant( m_histogram->calculations().getCount() );
+}
+Kross::Api::Object::Ptr Histogram::getTotal(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant( m_histogram->calculations().getTotal() );
+}
+Kross::Api::Object::Ptr Histogram::getValue(Kross::Api::List::Ptr args)
+{
+ return new Kross::Api::Variant( m_histogram->getValue( Kross::Api::Variant::toUInt(args->item(0)) ) );
+}
+
+Kross::Api::Object::Ptr Histogram::getNumberOfBins(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant( m_histogram->producer()->numberOfBins() );
+}
+
+
+}
+
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_histogram.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_histogram.h
new file mode 100644
index 00000000..50b66ca4
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_histogram.h
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KROSS_KRITACOREHISTOGRAM_H
+#define KROSS_KRITACOREHISTOGRAM_H
+
+#include <api/class.h>
+
+#include <kis_types.h>
+#include <kis_histogram.h>
+
+namespace Kross {
+
+namespace ChalkCore {
+
+/**
+ * This class allow to access the histogram of a PaintLayer.
+ *
+ * Example (in Ruby) :
+ * @code
+ * doc = krosschalkcore::get("ChalkDocument")
+ * image = doc.getImage()
+ * layer = image.getActiveLayer()
+ * histo = layer.createHistogram("RGB8HISTO",0)
+ * min = layer.getMin() * 255
+ * max = layer.getMax() * 255
+ * for i in min..max
+ * print layer.getValue(i)
+ * print "\n"
+ * end
+ * @endcode
+ */
+class Histogram : public Kross::Api::Class<Histogram>
+{
+ public:
+ Histogram(KisPaintLayerSP layer, KisHistogramProducerSP producer, const enumHistogramType type);
+ ~Histogram();
+ virtual const TQString getClassName() const;
+ private:
+ /**
+ * This function return the maximum bound of the histogram
+ * (values at greater position than the maximum are null).
+ * The value is in the range 0.0 - 1.0.
+ */
+ Kross::Api::Object::Ptr getMax(Kross::Api::List::Ptr);
+ /**
+ * This function return the minimum bound of the histogram
+ * (values at smaller position than the minimum are null)
+ * The value is in the range 0.0 - 1.0.
+ */
+ Kross::Api::Object::Ptr getMin(Kross::Api::List::Ptr);
+ /**
+ * This function return the highest value of the histogram
+ */
+ Kross::Api::Object::Ptr getHighest(Kross::Api::List::Ptr);
+ /**
+ * This function return the lowest value of the histogram
+ */
+ Kross::Api::Object::Ptr getLowest(Kross::Api::List::Ptr);
+ /**
+ * This function return the mean of the histogram
+ */
+ Kross::Api::Object::Ptr getMean(Kross::Api::List::Ptr);
+ /**
+ * This function return the number of pixels used by the histogram
+ */
+ Kross::Api::Object::Ptr getCount(Kross::Api::List::Ptr);
+ /**
+ * This function return the sum of all values of the histogram
+ */
+ Kross::Api::Object::Ptr getTotal(Kross::Api::List::Ptr);
+ /**
+ * Select the channel of the layer on which to get the result of the histogram.
+ * This function takes one argument :
+ * - channel number
+ */
+ Kross::Api::Object::Ptr setChannel(Kross::Api::List::Ptr);
+ /**
+ * Return the selected channel
+ */
+ Kross::Api::Object::Ptr getChannel(Kross::Api::List::Ptr);
+ /**
+ * Return the value of a bin of the histogram.
+ * This function takes one argument :
+ * - index, in the range [0..255],
+ */
+ Kross::Api::Object::Ptr getValue(Kross::Api::List::Ptr);
+ /**
+ * Return the number of bins of this histogram.
+ */
+ Kross::Api::Object::Ptr getNumberOfBins(Kross::Api::List::Ptr);
+ private:
+ KisHistogram* m_histogram;
+};
+
+}
+
+}
+
+#endif
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_image.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/krs_image.cpp
new file mode 100644
index 00000000..c93d6e88
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_image.cpp
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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_image.h"
+
+#include <klocale.h>
+
+#include <kis_colorspace_factory_registry.h>
+#include <kis_image.h>
+#include <kis_filter_strategy.h>
+#include <kis_group_layer.h>
+#include <kis_paint_layer.h>
+#include <kis_meta_registry.h>
+
+
+#include "krs_paint_layer.h"
+
+namespace Kross {
+
+namespace ChalkCore {
+
+ Image::Image(KisImageSP image, KisDoc* doc)
+ : Kross::Api::Class<Image>("ChalkImage"), m_image(image), m_doc(doc)
+{
+ addFunction("getActivePaintLayer", &Image::getActivePaintLayer);
+ addFunction("getWidth", &Image::getWidth);
+ addFunction("getHeight", &Image::getHeight);
+ addFunction("convertToColorspace", &Image::convertToColorspace);
+ addFunction("createPaintLayer", &Image::createPaintLayer);
+ addFunction("colorSpaceId", &Image::colorSpaceId);
+ addFunction("scale", &Image::scale);
+ addFunction("resize", &Image::resize);
+}
+
+
+Image::~Image()
+{
+}
+
+const TQString Image::getClassName() const {
+ return "Kross::ChalkCore::Image";
+}
+
+Kross::Api::Object::Ptr Image::getActivePaintLayer(Kross::Api::List::Ptr)
+{
+ KisPaintLayer* activePaintLayer = dynamic_cast<KisPaintLayer*>(m_image->activeLayer().data());
+ if(activePaintLayer )
+ {
+ return new PaintLayer(activePaintLayer, m_doc);
+ } else {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("The active layer is not paintable.") );
+ return 0;
+ }
+}
+Kross::Api::Object::Ptr Image::getWidth(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant(m_image->width());
+}
+Kross::Api::Object::Ptr Image::getHeight(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant(m_image->height());
+}
+Kross::Api::Object::Ptr Image::convertToColorspace(Kross::Api::List::Ptr args)
+{
+ KisColorSpace * dstCS = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID(Kross::Api::Variant::toString(args->item(0)), ""), "");
+ if(!dstCS)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("Colorspace %0 is not available, please check your installation.").tqarg(Kross::Api::Variant::toString(args->item(0))) ) );
+ return 0;
+ }
+ m_image->convertTo(dstCS);
+ return 0;
+}
+
+Kross::Api::Object::Ptr Image::colorSpaceId(Kross::Api::List::Ptr )
+{
+ return new Kross::Api::Variant( m_image->colorSpace()->id().id() );
+}
+
+
+Kross::Api::Object::Ptr Image::createPaintLayer(Kross::Api::List::Ptr args)
+{
+ TQString name = Kross::Api::Variant::toString(args->item(0));
+ int opacity = Kross::Api::Variant::toInt(args->item(1));
+ opacity = CLAMP(opacity, 0, 255);
+ TQString csname;
+ if(args->count() > 2)
+ {
+ csname = Kross::Api::Variant::toString(args->item(2));
+ } else {
+ csname = m_image->colorSpace()->id().id();
+ }
+ KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID(csname, ""), "");
+ KisPaintLayer* layer;
+ if(cs)
+ {
+ layer = new KisPaintLayer(m_image, name, opacity, cs);
+ } else {
+ layer = new KisPaintLayer(m_image, name, opacity);
+ }
+ layer->setVisible(true);
+
+ m_image->addLayer(layer, m_image->rootLayer(), 0);
+ return new PaintLayer(layer);
+
+}
+
+Kross::Api::Object::Ptr Image::scale(Kross::Api::List::Ptr args)
+{
+ double cw = Kross::Api::Variant::toDouble(args->item(0));
+ double ch = Kross::Api::Variant::toDouble(args->item(1));
+ m_image->scale( cw, ch, 0, KisFilterStrategyRegistry::instance()->get( "Mitchell") );
+ return 0;
+}
+Kross::Api::Object::Ptr Image::resize(Kross::Api::List::Ptr args)
+{
+ int nw = Kross::Api::Variant::toInt(args->item(0));
+ int nh = Kross::Api::Variant::toInt(args->item(1));
+ int x = 0;
+ int y = 0;
+ if(args->count() > 2)
+ {
+ x = Kross::Api::Variant::toInt(args->item(2));
+ y = Kross::Api::Variant::toInt(args->item(3));
+ }
+ m_image->resize( nw, nh, x, y );
+ return 0;
+}
+
+
+}
+
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_image.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_image.h
new file mode 100644
index 00000000..91314f3f
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_image.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KROSS_KRITACOREKRSIMAGE_H
+#define KROSS_KRITACOREKRSIMAGE_H
+
+#include <api/class.h>
+
+#include <kis_types.h>
+
+class KisDoc;
+
+namespace Kross {
+
+namespace ChalkCore {
+
+class Image : public Kross::Api::Class<Image>
+{
+ public:
+ Image(KisImageSP image, KisDoc* doc = 0);
+ ~Image();
+ virtual const TQString getClassName() const;
+ private:
+ /**
+ * Return the active PaintLayer, if any.
+ */
+ Kross::Api::Object::Ptr getActivePaintLayer(Kross::Api::List::Ptr);
+ /**
+ * Return the width of the image.
+ */
+ Kross::Api::Object::Ptr getWidth(Kross::Api::List::Ptr);
+ /**
+ * Return the height of the image.
+ */
+ Kross::Api::Object::Ptr getHeight(Kross::Api::List::Ptr);
+ /**
+ * Resize an image
+ */
+ Kross::Api::Object::Ptr resize(Kross::Api::List::Ptr);
+ /**
+ * Scale an image
+ */
+ Kross::Api::Object::Ptr scale(Kross::Api::List::Ptr);
+ /**
+ * Convert the image to a colorspace.
+ * This function takes one argument :
+ * - the name of the destination colorspace
+ *
+ * For example (in Ruby) :
+ * @code
+ * image.convertToColorspace("CMYK")
+ * @endcode
+ */
+ Kross::Api::Object::Ptr convertToColorspace(Kross::Api::List::Ptr args);
+ /**
+ * Return the id of the colorspace of this image.
+ */
+ Kross::Api::Object::Ptr colorSpaceId(Kross::Api::List::Ptr );
+ /**
+ * Create a new PaintLayer for this image, and return it.
+ * This function takes at least two arguments :
+ * - the name of the layer
+ * - the opacity of the layer (between 0 and 255)
+ *
+ * This function can take one optional argument :
+ * - the id of the colorSpace (if this is not specified, the new PaintLayer
+ * will have the same colorspace as the image)
+ */
+ Kross::Api::Object::Ptr createPaintLayer(Kross::Api::List::Ptr args);
+ private:
+ KisImageSP m_image;
+ KisDoc* m_doc;
+};
+
+}
+
+}
+
+#endif
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_iterator.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_iterator.h
new file mode 100644
index 00000000..2e17ed98
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_iterator.h
@@ -0,0 +1,307 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KROSS_KRITACOREKRS_ITERATOR_H
+#define KROSS_KRITACOREKRS_ITERATOR_H
+
+#include <tqobject.h>
+#include <api/class.h>
+//#include <api/proxy.h>
+//#include <api/variant.h>
+
+#include <klocale.h>
+
+#include <kis_paint_layer.h>
+#include <kis_paint_device.h>
+#include <kis_types.h>
+
+#include <kis_script_monitor.h>
+
+namespace Kross {
+
+namespace ChalkCore {
+
+//<beurk> stupid TQt which doesn't support templated TQObject
+class IteratorMemoryManaged {
+ public:
+ virtual void tqinvalidateIterator() = 0;
+};
+
+class IteratorMemoryManager : public TQObject {
+ Q_OBJECT
+ TQ_OBJECT
+ public:
+ IteratorMemoryManager(IteratorMemoryManaged* it) : m_it(it)
+ {
+ // Connect the Monitor to know when the invalidating of iterator is needed
+ connect(KisScriptMonitor::instance(), TQT_SIGNAL(executionFinished(const Kross::Api::ScriptAction* )), this, TQT_SLOT(tqinvalidateIterator()));
+
+ }
+ public slots:
+ void tqinvalidateIterator()
+ {
+ m_it->tqinvalidateIterator();
+ }
+ private:
+ IteratorMemoryManaged* m_it;
+};
+//</beurk>
+/**
+ * This object allow to change the value of pixel one by one.
+ * The name of some function depends of the colorspace, for instance, if
+ * the colorspace of the layer is RGB, you will have setR, setG, setB... and for CMYK,
+ * setC, setM, setY, setK. In the doc bellow we will consider the colorspace is called ABC with
+ * three channels : A, B and C.
+ *
+ * Function: setA setB setC
+ * Those functions take one argument:
+ * - the new value of one of the channel of this pixel
+ *
+ * Function: setABC
+ * Set the value of all channels.
+ * This function take one argument:
+ * - an array with the new value for all channels
+ */
+template<class _T_It>
+class Iterator : public Kross::Api::Class<Iterator<_T_It> >, private IteratorMemoryManaged
+{
+ public:
+ Iterator(_T_It it, KisPaintLayerSP layer) : Kross::Api::Class<Iterator<_T_It> >("ChalkIterator"), m_itmm (new IteratorMemoryManager(this)), m_it(new _T_It(it)), nchannels(layer->paintDevice()->nChannels()), m_layer(layer)
+ {
+ // navigate in the iterator
+ this->addFunction("next",
+ new Kross::Api::ProxyFunction<
+ Iterator<_T_It>, // instance
+ bool (Iterator<_T_It>::*)(), // method
+ Kross::Api::Variant // return-value
+ >(this, &Iterator<_T_It>::next));
+ this->addFunction("isDone",
+ new Kross::Api::ProxyFunction<
+ Iterator<_T_It>, // instance
+ bool (Iterator<_T_It>::*)(), // method
+ Kross::Api::Variant // return-value
+ >(this, &Iterator<_T_It>::isDone));
+
+ // get/set value
+ TQValueVector<KisChannelInfo *> channels = layer->paintDevice()->colorSpace()->channels();
+ TQString initiales = "";
+ for(TQValueVector<KisChannelInfo *>::iterator itC = channels.begin(); itC != channels.end(); itC++)
+ {
+ KisChannelInfo * ci = *itC;
+ initiales += ci->name().left(1);
+ switch(ci->channelValueType())
+ {
+ case KisChannelInfo::UINT8:
+ this->addFunction("get"+ci->name(),
+ new Kross::Api::Function1< Iterator<_T_It> , uint >(
+ this, &Iterator<_T_It>::getChannelUINT8, ci->pos() ) );
+ this->addFunction("set"+ci->name(),
+ new Kross::Api::Function1< Iterator<_T_It> , uint >(
+ this, &Iterator<_T_It>::setChannelUINT8, ci->pos() ) );
+ break;
+ case KisChannelInfo::UINT16:
+ this->addFunction("get"+ci->name(),
+ new Kross::Api::Function1< Iterator<_T_It> , uint >(
+ this, &Iterator<_T_It>::getChannelUINT16, ci->pos() ) );
+ this->addFunction("set"+ci->name(),
+ new Kross::Api::Function1< Iterator<_T_It> , uint >(
+ this, &Iterator<_T_It>::setChannelUINT16, ci->pos() ) );
+ break;
+ case KisChannelInfo::FLOAT32:
+ this->addFunction("get"+ci->name(),
+ new Kross::Api::Function1< Iterator<_T_It> , uint >(
+ this, &Iterator<_T_It>::getChannelFLOAT, ci->pos() ) );
+ this->addFunction("set"+ci->name(),
+ new Kross::Api::Function1< Iterator<_T_It> , uint >(
+ this, &Iterator<_T_It>::setChannelFLOAT, ci->pos() ) );
+ break;
+ default:
+ kdDebug(41011) << "unsupported data format in scripts" << endl;
+ break;
+ }
+ }
+ initiales = initiales.upper();
+ // set/get general
+ addFunction("set" + initiales, &Iterator::setPixel);
+ addFunction("get" + initiales, &Iterator::getPixel);
+ kdDebug(41011) << ( "get" + initiales ) << endl;
+ // Various colorSpace
+ addFunction("invertColor", &Iterator::invertColor);
+ addFunction("darken", &Iterator::darken);
+ }
+
+ ~Iterator()
+ {
+ tqinvalidateIterator();
+ delete m_itmm;
+ }
+ virtual const TQString getClassName() const {
+ return "Kross::ChalkCore::KrsDoc";
+ };
+ private:
+ /**
+ * Darken a pixel.
+ * This functions at least one argument:
+ * - shade amount use to darken all color channels
+ *
+ * This function can take the following optional argument:
+ * - compensation to limit the darkening
+ */
+ Kross::Api::Object::Ptr darken(Kross::Api::List::Ptr args)
+ {
+ TQ_INT32 shade = Kross::Api::Variant::toUInt( args->item(0) );
+ bool compensate = (args->count() == 2);
+ double compensation = compensate ? Kross::Api::Variant::toDouble( args->item(2) ) : 0.;
+ m_layer->paintDevice()->colorSpace()->darken(m_it->rawData(), m_it->rawData(), shade, compensate, compensation, 1);
+ return 0;
+ }
+ /**
+ * Invert the color of a pixel.
+ */
+ Kross::Api::Object::Ptr invertColor(Kross::Api::List::Ptr )
+ {
+ m_layer->paintDevice()->colorSpace()->invertColor(m_it->rawData(), 1);
+ return 0;
+ }
+ /**
+ * Increment the positon, and go to the next pixel.
+ */
+ bool next()
+ {
+ ++(*m_it);
+ return m_it->isDone();
+ }
+ /**
+ * Return true if the iterator is at the end, and that no more pixels are available.
+ */
+ bool isDone()
+ {
+ return m_it->isDone();
+ }
+ Kross::Api::Object::Ptr getChannelUINT8(Kross::Api::List::Ptr, uint channelpos)
+ {
+ TQ_UINT8* data = (TQ_UINT8*)(m_it->rawData() + channelpos);
+ return new Kross::Api::Variant( * data);
+ }
+ Kross::Api::Object::Ptr setChannelUINT8(Kross::Api::List::Ptr args, uint channelpos)
+ {
+ TQ_UINT8* data = (TQ_UINT8*)(m_it->rawData() + channelpos); //*(uint*)channelpos);
+ *data = Kross::Api::Variant::toUInt( args->item(0) );
+ return 0;
+ }
+ Kross::Api::Object::Ptr getChannelUINT16(Kross::Api::List::Ptr, uint channelpos)
+ {
+ TQ_UINT16* data = (TQ_UINT16*)(m_it->rawData() + channelpos);
+ return new Kross::Api::Variant( * data);
+ }
+ Kross::Api::Object::Ptr setChannelUINT16(Kross::Api::List::Ptr args, uint channelpos)
+ {
+ TQ_UINT16* data = (TQ_UINT16*)(m_it->rawData() + channelpos);
+ *data = Kross::Api::Variant::toUInt( args->item(0) );
+ return 0;
+ }
+ Kross::Api::Object::Ptr getChannelFLOAT(Kross::Api::List::Ptr, uint channelpos)
+ {
+ float* data = (float*)(m_it->rawData() + channelpos);
+ return new Kross::Api::Variant( * data);
+ }
+ Kross::Api::Object::Ptr setChannelFLOAT(Kross::Api::List::Ptr args, uint channelpos)
+ {
+ float* data = (float*)(m_it->rawData() + channelpos);
+ *data = Kross::Api::Variant::toUInt( args->item(0) );
+ return 0;
+ }
+ Kross::Api::Object::Ptr getPixel(Kross::Api::List::Ptr)
+ {
+ TQValueVector<KisChannelInfo *> channels = m_layer->paintDevice()->colorSpace()->channels();
+ TQValueList<TQVariant> pixel;
+ for(TQValueVector<KisChannelInfo *>::iterator itC = channels.begin(); itC != channels.end(); itC++)
+ {
+ KisChannelInfo * ci = *itC;
+ TQ_UINT8* data = (TQ_UINT8*)(m_it->rawData() + ci->pos());
+ switch(ci->channelValueType())
+ {
+ case KisChannelInfo::UINT8:
+ pixel.push_back( *data);
+ break;
+ case KisChannelInfo::UINT16:
+ pixel.push_back( *((TQ_UINT16*) data) );
+ break;
+ case KisChannelInfo::FLOAT32:
+ pixel.push_back( *((float*) data) );
+ break;
+ default:
+ kdDebug(41011) << i18n("An error has occurred in %1").tqarg("getPixel") << endl;
+ kdDebug(41011) << i18n("unsupported data format in scripts") << endl;
+ break;
+ }
+ }
+ return new Kross::Api::Variant( pixel);
+ }
+ Kross::Api::Object::Ptr setPixel(Kross::Api::List::Ptr args)
+ {
+ TQValueList<TQVariant> pixel = Kross::Api::Variant::toList( args->item(0) );
+ TQValueVector<KisChannelInfo *> channels = m_layer->paintDevice()->colorSpace()->channels();
+ uint i = 0;
+ for(TQValueVector<KisChannelInfo *>::iterator itC = channels.begin(); itC != channels.end(); itC++, i++)
+ {
+ KisChannelInfo * ci = *itC;
+ TQ_UINT8* data = (TQ_UINT8*)(m_it->rawData() + ci->pos());
+ switch(ci->channelValueType())
+ {
+ case KisChannelInfo::UINT8:
+ *data = pixel[i].toUInt();
+ break;
+ case KisChannelInfo::UINT16:
+ *((TQ_UINT16*) data) = pixel[i].toUInt();
+ break;
+ case KisChannelInfo::FLOAT32:
+ *((float*) data) = pixel[i].toDouble();
+ break;
+ default:
+ kdDebug(41011) << i18n("An error has occurred in %1").tqarg("setPixel") << endl;
+ kdDebug(41011) << i18n("unsupported data format in scripts") << endl;
+ break;
+ }
+ }
+ return 0;
+ }
+ private:
+ virtual void tqinvalidateIterator()
+ {
+ kdDebug(41011) << "invalidating iterator" << endl;
+ if(m_it)
+ {
+ kdDebug(41011) << "deleting iterator" << endl;
+ delete m_it;
+ }
+ m_it = 0;
+ kdDebug() << " Iterator = " << m_it << endl;
+ }
+ private:
+ IteratorMemoryManager* m_itmm;
+ _T_It* m_it;
+ int nchannels;
+ KisPaintLayerSP m_layer;
+};
+
+}
+
+}
+
+#endif
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_paint_layer.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/krs_paint_layer.cpp
new file mode 100644
index 00000000..5f800f6a
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_paint_layer.cpp
@@ -0,0 +1,207 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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 <klocale.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").tqarg("createHistogram") + "\n" + i18n("The histogram %1 is not available").tqarg(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());
+ Q_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").tqarg("convertToColorspace") + "\n" + i18n("Colorspace %1 is not available, please check your installation.").tqarg(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;
+}
+
+
+}
+
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_paint_layer.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_paint_layer.h
new file mode 100644
index 00000000..18ac5088
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_paint_layer.h
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KROSS_KRITACOREKRSLAYER_H
+#define KROSS_KRITACOREKRSLAYER_H
+
+#include <api/class.h>
+
+#include <kis_types.h>
+#include <kis_paint_layer.h>
+
+class KisDoc;
+class KisTransaction;
+
+namespace Kross {
+
+namespace ChalkCore {
+
+/**
+@author Cyrille Berger
+*/
+class PaintLayer : public Kross::Api::Class<PaintLayer>
+{
+ public:
+ explicit PaintLayer(KisPaintLayerSP layer, KisDoc* doc = 0);
+ virtual ~PaintLayer();
+ virtual const TQString getClassName() const;
+ private:
+ /**
+ * Create an iterator over a layer, it will iterate on a rectangle area.
+ * This function takes four arguments :
+ * - x
+ * - y
+ * - width of the rectangle
+ * - height of the rectangle
+ */
+ Kross::Api::Object::Ptr createRectIterator(Kross::Api::List::Ptr);
+ /**
+ * Create an iterator over a layer, it will iterate on a row.
+ * This function takes three arguments :
+ * - x start in the row
+ * - y vertical position of the row
+ * - width of the row
+ */
+ Kross::Api::Object::Ptr createHLineIterator(Kross::Api::List::Ptr);
+ /**
+ * Create an iterator over a layer, it will iterate on a column.
+ * This function takes three arguments :
+ * - x horizontal position of the column
+ * - y start in the column
+ * - height of the column
+ */
+ Kross::Api::Object::Ptr createVLineIterator(Kross::Api::List::Ptr);
+ /**
+ * Return the width of the layer
+ */
+ Kross::Api::Object::Ptr getWidth(Kross::Api::List::Ptr);
+ /**
+ * Return the height of the layer
+ */
+ Kross::Api::Object::Ptr getHeight(Kross::Api::List::Ptr);
+ /**
+ * This function creates an Histogram for this layer.
+ * It takes two arguments :
+ * - the type of the histogram ("RGB8HISTO")
+ * - 0 if the histogram is linear, or 1 if it is logarithmic
+ */
+ Kross::Api::Object::Ptr createHistogram(Kross::Api::List::Ptr);
+ /**
+ * This function create a Painter which will allow you to some painting on the layer.
+ */
+ Kross::Api::Object::Ptr createPainter(Kross::Api::List::Ptr);
+ /**
+ * Uses this function to create a new undo entry.
+ */
+ Kross::Api::Object::Ptr beginPainting(Kross::Api::List::Ptr args);
+ /**
+ * Uses this function to close the current undo entry and add it to the history.
+ */
+ Kross::Api::Object::Ptr endPainting(Kross::Api::List::Ptr args);
+ /**
+ * Convert the image to a colorspace.
+ * This function takes one argument :
+ * - the name of the destination colorspace
+ *
+ * For example (in Ruby) :
+ * @code
+ * image.convertToColorspace("CMYK")
+ * @endcode
+ */
+ Kross::Api::Object::Ptr convertToColorspace(Kross::Api::List::Ptr args);
+ /**
+ * Return the id of the colorspace of this paint layer.
+ */
+ Kross::Api::Object::Ptr colorSpaceId(Kross::Api::List::Ptr );
+ /**
+ * Return the fast wavelet transformed of the layer
+ */
+ Kross::Api::Object::Ptr fastWaveletTransformation(Kross::Api::List::Ptr args);
+ /**
+ * Untransform a fast wavelet into this layer
+ * It takes one argument :
+ * - a wavelet object
+ *
+ * For example (in Ruby) :
+ * @code
+ * wavelet = layer.fastWaveletTransformation()
+ * layer.fastWaveletUntransformation(wavelet)
+ * @endcode
+ */
+ Kross::Api::Object::Ptr fastWaveletUntransformation(Kross::Api::List::Ptr args);
+ public:
+ inline KisPaintLayerSP paintLayer() { return m_layer; }
+ inline KisDoc* doc() { return m_doc; }
+ private:
+ KisPaintLayerSP m_layer;
+ KisDoc* m_doc;
+ KisTransaction* m_cmd;
+};
+
+}
+
+}
+
+#endif
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_painter.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/krs_painter.cpp
new file mode 100644
index 00000000..44991303
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_painter.cpp
@@ -0,0 +1,358 @@
+/*
+ * Copyright (c) 2005-2006 Cyrille Berger <[email protected]>
+ *
+ * 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_painter.h"
+
+#include <kis_convolution_painter.h>
+#include <kis_fill_painter.h>
+#include <kis_paint_layer.h>
+#include <kis_paintop_registry.h>
+#include <kis_painter.h>
+
+#include "krs_brush.h"
+#include "krs_color.h"
+#include "krs_pattern.h"
+
+namespace Kross {
+
+namespace ChalkCore {
+
+Painter::Painter(KisPaintLayerSP layer)
+ : Kross::Api::Class<Painter>("ChalkPainter"), m_layer(layer),m_painter(new KisPainter(layer->paintDevice())),m_threshold(1)
+{
+ // convolution
+ addFunction("convolve", &Painter::convolve);
+ // Fill specific
+ addFunction("setFillThreshold", &Painter::setFillThreshold);
+ addFunction("fillColor", &Painter::fillColor);
+ addFunction("fillPattern", &Painter::fillPattern);
+
+ // Painting operations
+ addFunction("paintPolyline", &Painter::paintPolyline);
+ addFunction("paintLine", &Painter::paintLine);
+ addFunction("paintBezierCurve", &Painter::paintBezierCurve);
+ addFunction("paintEllipse", &Painter::paintEllipse);
+ addFunction("paintPolygon", &Painter::paintPolygon);
+ addFunction("paintRect", &Painter::paintRect);
+ addFunction("paintAt", &Painter::paintAt);
+ addFunction("setBackgroundColor", &Painter::setBackgroundColor);
+ addFunction("setPaintColor", &Painter::setPaintColor);
+
+ // Color operations
+ addFunction("setPattern", &Painter::setPattern);
+ addFunction("setBrush", &Painter::setBrush);
+
+ // How is painting done operations
+ addFunction("setPaintOp", &Painter::setPaintOp);
+ // Special settings
+ addFunction("setDuplicateOffset", &Painter::setDuplicateOffset);
+
+ // Style operation
+ addFunction("setOpacity", &Painter::setOpacity);
+ addFunction("setStrokeStyle", &Painter::setStrokeStyle);
+ addFunction("setFillStyle", &Painter::setFillStyle);
+}
+
+
+Painter::~Painter()
+{
+ delete m_painter;
+}
+
+Kross::Api::Object::Ptr Painter::convolve(Kross::Api::List::Ptr args)
+{
+ KisConvolutionPainter* cp = new KisConvolutionPainter(m_painter->device());
+ TQRect rect;
+ KisKernel kernel;
+ kernel.factor = Kross::Api::Variant::toInt(args->item(1));
+ kernel.offset = Kross::Api::Variant::toInt(args->item(2));
+
+ uint borderop = 3;
+ if( args.count() > 3 )
+ {
+ borderop = Kross::Api::Variant::toUInt(args->item(3));
+ }
+ uint channelsFlag = KisChannelInfo::FLAG_COLOR;
+ if( args.count() > 4 )
+ {
+ channelsFlag = Kross::Api::Variant::toUInt(args->item(4));
+ }
+ if( args.count() > 5)
+ {
+ uint x = Kross::Api::Variant::toUInt(args->item(5));
+ uint y = Kross::Api::Variant::toUInt(args->item(6));
+ uint w = Kross::Api::Variant::toUInt(args->item(7));
+ uint h = Kross::Api::Variant::toUInt(args->item(8));
+ rect = TQRect(x,y,w,h);
+ } else {
+ TQRect r1 = paintLayer()->paintDevice()->extent();
+ TQRect r2 = paintLayer()->image()->bounds();
+ rect = r1.intersect(r2);
+ }
+
+ TQValueList<TQVariant> kernelH = Kross::Api::Variant::toList( args->item(0) );
+
+ TQVariant firstlineVariant = *kernelH.begin();
+ if(firstlineVariant.type() != TQVariant::List)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(i18n("An error has occured in %1").tqarg("applyConvolution")) );
+ }
+
+ TQValueList<TQVariant> firstline = firstlineVariant.toList();
+
+ kernel.height = kernelH.size();
+ kernel.width = firstline.size();
+
+ kernel.data = new TQ_INT32[kernel.height * kernel.width];
+
+ uint i = 0;
+ for(TQValueList<TQVariant>::iterator itK = kernelH.begin(); itK != kernelH.end(); itK++, i ++ )
+ {
+ TQVariant lineVariant = *kernelH.begin();
+ if(lineVariant.type() != TQVariant::List)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(i18n("An error has occured in %1").tqarg("applyConvolution")) );
+ }
+ TQValueList<TQVariant> line = firstlineVariant.toList();
+ if(line.size() != kernel.width)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(i18n("An error has occured in %1").tqarg("applyConvolution")) );
+ }
+ uint j = 0;
+ for(TQValueList<TQVariant>::iterator itLine = line.begin(); itLine != line.end(); itLine++, j ++ )
+ {
+ kernel.data[ j + i * kernel.width ] = (*itLine).toInt();
+ }
+ }
+ cp->applyMatrix(&kernel, rect.x(), rect.y(), rect.width(), rect.height(), (KisConvolutionBorderOp)borderop, (KisChannelInfo::enumChannelFlags) channelsFlag);
+
+ delete[] kernel.data;
+ return 0;
+}
+
+
+KisFillPainter* Painter::createFillPainter()
+{
+ KisFillPainter* fp = new KisFillPainter(m_painter->device());
+ fp->setBrush( m_painter->brush() );
+ fp->setFillColor( m_painter->fillColor() );
+ fp->setPaintColor( m_painter->paintColor() );
+ fp->setFillStyle( m_painter->fillStyle() );
+ fp->setOpacity( m_painter->opacity() );
+ fp->setPattern( m_painter->pattern() );
+ return fp;
+}
+
+Kross::Api::Object::Ptr Painter::setFillThreshold(Kross::Api::List::Ptr args)
+{
+ m_threshold = Kross::Api::Variant::toInt(args->item(0));
+ return 0;
+}
+Kross::Api::Object::Ptr Painter::fillColor(Kross::Api::List::Ptr args)
+{
+ KisFillPainter* fp = createFillPainter();
+ uint x = Kross::Api::Variant::toUInt(args->item(0));
+ uint y = Kross::Api::Variant::toUInt(args->item(1));
+
+ fp->fillColor( x, y );
+ return 0;
+}
+Kross::Api::Object::Ptr Painter::fillPattern(Kross::Api::List::Ptr args)
+{
+ KisFillPainter* fp = createFillPainter();
+ uint x = Kross::Api::Variant::toUInt(args->item(0));
+ uint y = Kross::Api::Variant::toUInt(args->item(1));
+ fp->fillPattern(x, y);
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::setStrokeStyle(Kross::Api::List::Ptr args)
+{
+ uint style = Kross::Api::Variant::toVariant(args->item(0)).toUInt();
+ KisPainter::StrokeStyle strokestyle;
+ switch(style)
+ {
+ case 1:
+ strokestyle = KisPainter::StrokeStyleBrush;
+ break;
+ default:
+ strokestyle = KisPainter::StrokeStyleNone;
+ }
+ m_painter->setStrokeStyle(strokestyle);
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::setFillStyle(Kross::Api::List::Ptr args)
+{
+ uint style = Kross::Api::Variant::toVariant(args->item(0)).toUInt();
+ KisPainter::FillStyle fillstyle;
+ switch(style)
+ {
+ case 1:
+ fillstyle = KisPainter::FillStyleForegroundColor;
+ break;
+ case 2:
+ fillstyle = KisPainter::FillStyleBackgroundColor;
+ break;
+ case 3:
+ fillstyle = KisPainter::FillStylePattern;
+ break;
+ default:
+ fillstyle = KisPainter::FillStyleNone;
+ }
+ m_painter->setFillStyle(fillstyle);
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::setOpacity(Kross::Api::List::Ptr args)
+{
+ TQ_UINT8 opacity = Kross::Api::Variant::toVariant(args->item(0)).toUInt();
+ m_painter->setOpacity(opacity);
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::setDuplicateOffset(Kross::Api::List::Ptr args)
+{
+ double x1 = Kross::Api::Variant::toVariant(args->item(0)).toDouble();
+ double y1 = Kross::Api::Variant::toVariant(args->item(1)).toDouble();
+ m_painter->setDuplicateOffset(KisPoint(x1,y1));
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::paintPolyline(Kross::Api::List::Ptr args)
+{
+ TQValueList<TQVariant> pointsX = Kross::Api::Variant::toList( args->item(0) );
+ TQValueList<TQVariant> pointsY = Kross::Api::Variant::toList( args->item(1) );
+ if(pointsX.size() != pointsY.size())
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("the two lists should have the same size.") );
+ }
+ m_painter->paintPolyline( createPointsVector( pointsX, pointsY));
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::paintLine(Kross::Api::List::Ptr args)
+{
+ double x1 = Kross::Api::Variant::toVariant(args->item(0)).toDouble();
+ double y1 = Kross::Api::Variant::toVariant(args->item(1)).toDouble();
+ double p1 = Kross::Api::Variant::toVariant(args->item(2)).toDouble();
+ double x2 = Kross::Api::Variant::toVariant(args->item(3)).toDouble();
+ double y2 = Kross::Api::Variant::toVariant(args->item(4)).toDouble();
+ double p2 = Kross::Api::Variant::toVariant(args->item(5)).toDouble();
+ m_painter->paintLine(KisPoint( x1, y1), p1, 0.0, 0.0, KisPoint( x2, y2 ), p2, 0.0, 0.0 );
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::paintBezierCurve(Kross::Api::List::Ptr args)
+{
+ double x1 = Kross::Api::Variant::toVariant(args->item(0)).toDouble();
+ double y1 = Kross::Api::Variant::toVariant(args->item(1)).toDouble();
+ double p1 = Kross::Api::Variant::toVariant(args->item(2)).toDouble();
+ double cx1 = Kross::Api::Variant::toVariant(args->item(3)).toDouble();
+ double cy1 = Kross::Api::Variant::toVariant(args->item(4)).toDouble();
+ double cx2 = Kross::Api::Variant::toVariant(args->item(5)).toDouble();
+ double cy2 = Kross::Api::Variant::toVariant(args->item(6)).toDouble();
+ double x2 = Kross::Api::Variant::toVariant(args->item(7)).toDouble();
+ double y2 = Kross::Api::Variant::toVariant(args->item(8)).toDouble();
+ double p2 = Kross::Api::Variant::toVariant(args->item(9)).toDouble();
+ m_painter->paintBezierCurve( KisPoint(x1,y1), p1, 0.0, 0.0, KisPoint(cx1,cy1), KisPoint(cx2,cy2), KisPoint(x2,y2), p2, 0.0, 0.0);
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::paintEllipse(Kross::Api::List::Ptr args)
+{
+ double x1 = Kross::Api::Variant::toVariant(args->item(0)).toDouble();
+ double y1 = Kross::Api::Variant::toVariant(args->item(1)).toDouble();
+ double x2 = Kross::Api::Variant::toVariant(args->item(2)).toDouble();
+ double y2 = Kross::Api::Variant::toVariant(args->item(3)).toDouble();
+ double p1 = Kross::Api::Variant::toVariant(args->item(4)).toDouble();
+ m_painter->paintEllipse( KisPoint(x1,y1), KisPoint(x2,y2), p1, 0.0, 0.0 );
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::paintPolygon(Kross::Api::List::Ptr args)
+{
+ TQValueList<TQVariant> pointsX = Kross::Api::Variant::toList( args->item(0) );
+ TQValueList<TQVariant> pointsY = Kross::Api::Variant::toList( args->item(1) );
+ if(pointsX.size() != pointsY.size())
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("the two lists should have the same size.") );
+ }
+ m_painter->paintPolygon( createPointsVector(pointsX, pointsY));
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::paintRect(Kross::Api::List::Ptr args)
+{
+ double x1 = Kross::Api::Variant::toVariant(args->item(0)).toDouble();
+ double y1 = Kross::Api::Variant::toVariant(args->item(1)).toDouble();
+ double x2 = Kross::Api::Variant::toVariant(args->item(2)).toDouble();
+ double y2 = Kross::Api::Variant::toVariant(args->item(3)).toDouble();
+ double p1 = Kross::Api::Variant::toVariant(args->item(4)).toDouble();
+ m_painter->paintRect( KisPoint(x1, y1), KisPoint(x2,y2), p1, 0, 0);
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::paintAt(Kross::Api::List::Ptr args)
+{
+ double x1 = Kross::Api::Variant::toVariant(args->item(0)).toDouble();
+ double y1 = Kross::Api::Variant::toVariant(args->item(1)).toDouble();
+ double p1 = Kross::Api::Variant::toVariant(args->item(2)).toDouble();
+ m_painter->paintAt( KisPoint( x1, y1 ), p1, 0.0, 0.0);
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::setBackgroundColor(Kross::Api::List::Ptr args)
+{
+ Color* c = (Color*)args->item(0).data();
+ m_painter->setBackgroundColor( KisColor(c->toTQColor(), paintLayer()->paintDevice()->colorSpace() ));
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::setPaintColor(Kross::Api::List::Ptr args)
+{
+ Color* c = (Color*)args->item(0).data();
+ m_painter->setPaintColor( KisColor(c->toTQColor(), paintLayer()->paintDevice()->colorSpace() ));
+ return 0;
+}
+
+Kross::Api::Object::Ptr Painter::setPattern(Kross::Api::List::Ptr args)
+{
+ Pattern* p = (Pattern*)args->item(0).data();
+ m_painter->setPattern( p->getPattern());
+ return 0;
+}
+
+
+Kross::Api::Object::Ptr Painter::setBrush(Kross::Api::List::Ptr args)
+{
+ Brush* b = (Brush*)args->item(0).data();
+ m_painter->setBrush( b->getBrush());
+ return 0;
+}
+Kross::Api::Object::Ptr Painter::setPaintOp(Kross::Api::List::Ptr args)
+{
+ TQString id = Kross::Api::Variant::toString(args->item(0));
+ KisPaintOp* op = KisPaintOpRegistry::instance()->paintOp( id, 0, m_painter );
+ m_painter->setPaintOp( op );
+ return 0;
+}
+
+}
+
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_painter.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_painter.h
new file mode 100644
index 00000000..f4e2c06a
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_painter.h
@@ -0,0 +1,242 @@
+/*
+ * Copyright (c) 2005-2006 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KROSS_KRITACOREKRS_PAINTER_H
+#define KROSS_KRITACOREKRS_PAINTER_H
+
+#include <api/class.h>
+
+#include <kis_point.h>
+#include <kis_types.h>
+#include <kis_paint_layer.h>
+
+class KisPainter;
+class KisFillPainter;
+
+namespace Kross {
+
+namespace ChalkCore {
+
+class Painter : public Kross::Api::Class<Painter>
+{
+ public:
+ explicit Painter(KisPaintLayerSP layer);
+ ~Painter();
+ private:
+ // Convolution
+ /**
+ * This function apply a convolution kernel to an image.
+ * It takes at least three arguments :
+ * - a list of a list with the kernel (all lists need to have the same size)
+ * - factor
+ * - offset
+ *
+ * The value of a pixel will be given by the following function K*P/factor + offset,
+ * where K is the kernel and P is the neighbourhood.
+ *
+ * It can takes the following optional arguments :
+ * - borderOp control how to convolve the pixels on the border of an image ( 0 use the default color
+ * 1 use the pixel on the opposite side of the image 2 use the border pixel 3 avoid border pixels)
+ * - channel ( 1 for color 2 for alpha 3 for both)
+ * - x
+ * - y
+ * - width
+ * - height
+ */
+ Kross::Api::Object::Ptr convolve(Kross::Api::List::Ptr args);
+ // Fill specific
+ /**
+ * Set the threshold the fill threshold.
+ * It takes one argument :
+ * - threshold
+ */
+ Kross::Api::Object::Ptr setFillThreshold(Kross::Api::List::Ptr args);
+ /**
+ * Start filling color.
+ * It takes two argument :
+ * - x
+ * - y
+ */
+ Kross::Api::Object::Ptr fillColor(Kross::Api::List::Ptr args);
+ /**
+ * start filling a pattern
+ * It takes two argument :
+ * - x
+ * - y
+ */
+ Kross::Api::Object::Ptr fillPattern(Kross::Api::List::Ptr args);
+ // Painting operations
+ /**
+ * This function will paint a polyline.
+ * It takes two arguments :
+ * - a list of x position
+ * - a list of y position
+ */
+ Kross::Api::Object::Ptr paintPolyline(Kross::Api::List::Ptr args);
+ /**
+ * This function will paint a line.
+ * It takes five arguments :
+ * - x1
+ * - y1
+ * - x2
+ * - y2
+ * - pressure
+ */
+ Kross::Api::Object::Ptr paintLine(Kross::Api::List::Ptr args);
+ /**
+ * This function will paint a Bezier curve.
+ * It takes ten arguments :
+ * - x1
+ * - y1
+ * - p1
+ * - cx1
+ * - cy1
+ * - cx2
+ * - cx2
+ * - x2
+ * - y2
+ * - p2
+ *
+ * Where (x1,y1) is the start position, p1 is the pressure at the start,
+ * (x2,y2) is the ending position, p2 is the pressure at the end. (cx1,cy1) and (cx2,cy2)
+ * are the position of the control points.
+ */
+ Kross::Api::Object::Ptr paintBezierCurve(Kross::Api::List::Ptr args);
+ /**
+ * This function will paint an ellipse.
+ * It takes five arguments :
+ * - x1
+ * - y1
+ * - x2
+ * - y2
+ * - pressure
+ *
+ * Where (x1,y1) and (x2,y2) are the position of the two centers.
+ */
+ Kross::Api::Object::Ptr paintEllipse(Kross::Api::List::Ptr args);
+ /**
+ * This function will paint a polygon.
+ * It takes two arguments :
+ * - a list of x position
+ * - a list of y position
+ */
+ Kross::Api::Object::Ptr paintPolygon(Kross::Api::List::Ptr args);
+ /**
+ * This function will paint a rectangle.
+ * It takes five arguments :
+ * - x
+ * - y
+ * - width
+ * - height
+ * - pressure
+ */
+ Kross::Api::Object::Ptr paintRect(Kross::Api::List::Ptr args);
+ /**
+ * This function will paint at a given position.
+ * It takes three arguments :
+ * - x
+ * - y
+ * - pressure
+ */
+ Kross::Api::Object::Ptr paintAt(Kross::Api::List::Ptr args);
+ // Color operations
+ /**
+ * This functions set the paint color (also called foreground color).
+ * It takes one argument :
+ * - a Color
+ */
+ Kross::Api::Object::Ptr setPaintColor(Kross::Api::List::Ptr args);
+ /**
+ * This functions set the background color.
+ * It takes one argument :
+ * - a Color
+ */
+ Kross::Api::Object::Ptr setBackgroundColor(Kross::Api::List::Ptr args);
+ // How is painting done operations
+ /**
+ * This functions set the pattern used for filling.
+ * It takes one argument :
+ * - a Pattern object
+ */
+ Kross::Api::Object::Ptr setPattern(Kross::Api::List::Ptr args);
+ /**
+ * This functions set the brush used for painting.
+ * It takes one argument :
+ * - a Brush object
+ */
+ Kross::Api::Object::Ptr setBrush(Kross::Api::List::Ptr args);
+ /**
+ * This function define the paint operation.
+ * It takes one argument :
+ * - the name of the paint operation
+ */
+ Kross::Api::Object::Ptr setPaintOp(Kross::Api::List::Ptr args);
+ // Special settings
+ /**
+ * This function define the duplicate offset.
+ * It takes two arguments :
+ * - horizontal offset
+ * - vertical offset
+ */
+ Kross::Api::Object::Ptr setDuplicateOffset(Kross::Api::List::Ptr args);
+ // Style operation
+ /**
+ * This function set the opacity of the painting
+ * It takes one argument :
+ * - opacity in the range 0 to 255
+ */
+ Kross::Api::Object::Ptr setOpacity(Kross::Api::List::Ptr args);
+ /**
+ * This function set the style of the stroke.
+ * It takes one argument :
+ * - 0 for none 1 for brush
+ */
+ Kross::Api::Object::Ptr setStrokeStyle(Kross::Api::List::Ptr args);
+ /**
+ * This function set the fill style of the Painter.
+ * It takes one argument :
+ * - 0 for none 1 for fill with foreground color 2 for fill with background color
+ * 3 for fill with a pattern
+ */
+ Kross::Api::Object::Ptr setFillStyle(Kross::Api::List::Ptr args);
+ protected:
+ inline KisPaintLayerSP paintLayer() { return m_layer; }
+ private:
+ inline vKisPoint createPointsVector( TQValueList<TQVariant> xs, TQValueList<TQVariant> ys)
+ {
+ vKisPoint a;
+ TQValueList<TQVariant>::iterator itx = xs.begin();
+ TQValueList<TQVariant>::iterator ity = ys.begin();
+ for(; itx != xs.end(); ++itx, ++ity)
+ {
+ a.push_back(KisPoint( (*itx).toDouble(), (*ity).toDouble()));
+ }
+ return a;
+ }
+ inline KisFillPainter* createFillPainter();
+ private:
+ KisPaintLayerSP m_layer;
+ KisPainter* m_painter;
+ int m_threshold;
+};
+
+}
+
+}
+
+#endif
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_pattern.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/krs_pattern.cpp
new file mode 100644
index 00000000..8ee4f909
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_pattern.cpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2006 Cyrille Berger <[email protected]>
+ *
+ * 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_pattern.h"
+
+#include <kis_pattern.h>
+
+namespace Kross {
+
+namespace ChalkCore {
+
+Pattern::Pattern(KisPattern* pattern, bool sharedPattern) : Kross::Api::Class<Pattern>("ChalkPattern"), m_pattern(pattern), m_sharedPattern(sharedPattern)
+{
+}
+
+Pattern::~Pattern()
+{
+ if(!m_sharedPattern)
+ delete m_pattern;
+}
+
+}
+
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_pattern.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_pattern.h
new file mode 100644
index 00000000..be39cf31
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_pattern.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2006 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KROSS_KRITACOREKRS_PATTERN_H
+#define KROSS_KRITACOREKRS_PATTERN_H
+
+#include <api/class.h>
+
+class KisPattern;
+
+namespace Kross {
+
+namespace ChalkCore {
+
+class Pattern : public Kross::Api::Class<Pattern>{
+ public:
+ /**
+ * @param sharedPattern tell if the pattern should be deleted or not when this object is deleted
+ */
+ Pattern(KisPattern*, bool sharedPattern);
+ ~Pattern();
+ public:
+ inline KisPattern* getPattern() { return m_pattern; }
+ private:
+ KisPattern* m_pattern;
+ bool m_sharedPattern;
+};
+
+}
+
+}
+
+#endif
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_script_progress.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/krs_script_progress.cpp
new file mode 100644
index 00000000..b36076c4
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_script_progress.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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_script_progress.h"
+
+#include "kis_script_progress.h"
+
+namespace Kross {
+
+namespace ChalkCore {
+
+ScriptProgress::ScriptProgress(KisScriptProgress* script): Kross::Api::Class<ScriptProgress>("ChalkScript"), m_script(script)
+{
+ addFunction("setProgressTotalSteps", &ScriptProgress::setProgressTotalSteps);
+ addFunction("setProgressTotalSteps", &ScriptProgress::setProgressTotalSteps);
+ addFunction("setProgress", &ScriptProgress::setProgress);
+ addFunction("incProgress", &ScriptProgress::incProgress);
+ addFunction("setProgressStage", &ScriptProgress::setProgressStage);
+}
+
+
+ScriptProgress::~ScriptProgress()
+{
+}
+
+Kross::Api::Object::Ptr ScriptProgress::setProgressTotalSteps(Kross::Api::List::Ptr args)
+{
+ m_script->setProgressTotalSteps( Kross::Api::Variant::toUInt(args->item(0)) );
+ return 0;
+}
+
+Kross::Api::Object::Ptr ScriptProgress::setProgress(Kross::Api::List::Ptr args)
+{
+ m_script->setProgress( Kross::Api::Variant::toUInt(args->item(0)) );
+ return 0;
+}
+
+Kross::Api::Object::Ptr ScriptProgress::incProgress(Kross::Api::List::Ptr)
+{
+ m_script->incProgress();
+ return 0;
+}
+
+Kross::Api::Object::Ptr ScriptProgress::setProgressStage(Kross::Api::List::Ptr args)
+{
+ m_script->setProgressStage( Kross::Api::Variant::toString(args->item(0)), Kross::Api::Variant::toUInt(args->item(1)) );
+ return 0;
+}
+
+}
+
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_script_progress.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_script_progress.h
new file mode 100644
index 00000000..b2ae7e44
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_script_progress.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2005 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KROSS_KRITACOREKRS_SCRIPTPROGRESS_H
+#define KROSS_KRITACOREKRS_SCRIPTPROGRESS_H
+
+#include <api/class.h>
+
+class KisScriptProgress;
+
+namespace Kross {
+
+namespace ChalkCore {
+
+/**
+ * ScriptProgress is used to manage the progress bar of the status bar in chalk
+ *
+ * For example (in ruby) :
+ * @code
+ * script = Krosschalkcore::get("ChalkScript")
+ * script.setProgressTotalSteps(1000)
+ * script.setProgressStage("progressive", 0)
+ * for i in 1..900
+ * script.incProgress()
+ * end
+ * script.setProgressStage("brutal", 1000)
+ * @endcode
+ */
+class ScriptProgress : public Kross::Api::Class<ScriptProgress> {
+ public:
+ ScriptProgress(KisScriptProgress* Script);
+ ~ScriptProgress();
+ private:
+ /**
+ * This function set the number of steps that the script will require.
+ * It takes one argument :
+ * - maximum value of the progress
+ */
+ Kross::Api::Object::Ptr setProgressTotalSteps(Kross::Api::List::Ptr);
+ /**
+ * This function set the value of progress.
+ * It takes one argument :
+ * - value of the progress
+ */
+ Kross::Api::Object::Ptr setProgress(Kross::Api::List::Ptr);
+ /**
+ * This function increment of one step the position of the progress.
+ */
+ Kross::Api::Object::Ptr incProgress(Kross::Api::List::Ptr);
+ /**
+ * This function set the value of the progress and display the text
+ */
+ Kross::Api::Object::Ptr setProgressStage(Kross::Api::List::Ptr);
+ private:
+ KisScriptProgress* m_script;
+};
+
+}
+
+}
+
+#endif
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_wavelet.cpp b/chalk/plugins/viewplugins/scripting/chalkcore/krs_wavelet.cpp
new file mode 100644
index 00000000..e166de7c
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_wavelet.cpp
@@ -0,0 +1,114 @@
+/*
+ * This file is part of the KDE project
+ *
+ * Copyright (c) 2006 Cyrille Berger <[email protected]>
+ *
+ * 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 "krs_wavelet.h"
+
+#include <klocale.h>
+
+#include <kis_math_toolbox.h>
+
+namespace Kross {
+
+namespace ChalkCore {
+
+Wavelet::Wavelet(KisMathToolbox::KisWavelet* kwl)
+ : Kross::Api::Class<Wavelet>("ChalkWavelet"), m_wavelet(kwl)
+{
+ addFunction("getNCoeff", &Wavelet::getNCoeff);
+ addFunction("setNCoeff", &Wavelet::setNCoeff);
+ addFunction("getXYCoeff", &Wavelet::getXYCoeff);
+ addFunction("setXYCoeff", &Wavelet::setXYCoeff);
+ addFunction("getDepth", &Wavelet::getDepth);
+ addFunction("getSize", &Wavelet::getSize);
+ addFunction("getNumCoeffs", &Wavelet::getNumCoeffs);
+ m_numCoeff = m_wavelet->size*m_wavelet->size*m_wavelet->depth;
+}
+
+
+Wavelet::~Wavelet()
+{
+}
+
+
+Kross::Api::Object::Ptr Wavelet::getNCoeff(Kross::Api::List::Ptr args)
+{
+ TQ_UINT32 n = Kross::Api::Variant::toUInt(args->item(0));
+ if( n > m_numCoeff)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("An error has occured in %1").tqarg("getNCoeff") + "\n" + i18n("Index out of bound") ) );
+ }
+ return new Kross::Api::Variant(*(m_wavelet->coeffs + n ));
+}
+
+Kross::Api::Object::Ptr Wavelet::setNCoeff(Kross::Api::List::Ptr args)
+{
+ TQ_UINT32 n = Kross::Api::Variant::toUInt(args->item(0));
+ double v = Kross::Api::Variant::toDouble(args->item(1));
+ if( n > m_numCoeff)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("An error has occured in %1").tqarg("setNCoeff") + "\n" + i18n("Index out of bound") ) );
+ }
+ *(m_wavelet->coeffs + n ) = v;
+ return 0;
+}
+
+Kross::Api::Object::Ptr Wavelet::getXYCoeff(Kross::Api::List::Ptr args)
+{
+ TQ_UINT32 x = Kross::Api::Variant::toUInt(args->item(0));
+ TQ_UINT32 y = Kross::Api::Variant::toUInt(args->item(1));
+ if( x > m_wavelet->size && y > m_wavelet->size)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("An error has occured in %1").tqarg("getXYCoeff") + "\n" + i18n("Index out of bound") ) );
+ }
+ return new Kross::Api::Variant(*(m_wavelet->coeffs + (x + y * m_wavelet->size ) * m_wavelet->depth ));
+}
+
+Kross::Api::Object::Ptr Wavelet::setXYCoeff(Kross::Api::List::Ptr args)
+{
+ TQ_UINT32 x = Kross::Api::Variant::toUInt(args->item(0));
+ TQ_UINT32 y = Kross::Api::Variant::toUInt(args->item(1));
+ double v = Kross::Api::Variant::toDouble(args->item(2));
+ if( x > m_wavelet->size && y > m_wavelet->size)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("An error has occured in %1").tqarg("setXYCoeff") + "\n" + i18n("Index out of bound") ));
+ }
+ *(m_wavelet->coeffs + (x + y * m_wavelet->size ) * m_wavelet->depth ) = v;
+ return 0;
+}
+
+Kross::Api::Object::Ptr Wavelet::getDepth(Kross::Api::List::Ptr /*args*/)
+{
+ return new Kross::Api::Variant(m_wavelet->depth);
+}
+
+Kross::Api::Object::Ptr Wavelet::getSize(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant(m_wavelet->size);
+}
+
+Kross::Api::Object::Ptr Wavelet::getNumCoeffs(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant(m_numCoeff);
+}
+
+
+}
+
+}
diff --git a/chalk/plugins/viewplugins/scripting/chalkcore/krs_wavelet.h b/chalk/plugins/viewplugins/scripting/chalkcore/krs_wavelet.h
new file mode 100644
index 00000000..8a9a0889
--- /dev/null
+++ b/chalk/plugins/viewplugins/scripting/chalkcore/krs_wavelet.h
@@ -0,0 +1,92 @@
+/*
+ * This file is part of the KDE project
+ *
+ * Copyright (c) 2006 Cyrille Berger <[email protected]>
+ *
+ * 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.
+ */
+
+#ifndef KROSS_KRITACOREKRS_WAVELET_H
+#define KROSS_KRITACOREKRS_WAVELET_H
+
+#include <api/class.h>
+
+#include <kis_math_toolbox.h>
+
+namespace Kross {
+
+namespace ChalkCore {
+
+/**
+ @author Cyrille Berger <[email protected]>
+*/
+class Wavelet : public Kross::Api::Class<Wavelet>
+{
+ public:
+ Wavelet(KisMathToolbox::KisWavelet* wavelet);
+ ~Wavelet();
+ private:
+ /**
+ * Return the value of the Nth coefficient
+ * The function takes one argument :
+ * - the index of the coefficient
+ */
+ Kross::Api::Object::Ptr getNCoeff(Kross::Api::List::Ptr);
+ /**
+ * Set the value of the Nth coefficient
+ * The function takes two arguments :
+ * - the index of the coefficient
+ * - the new value of the coefficient
+ */
+ Kross::Api::Object::Ptr setNCoeff(Kross::Api::List::Ptr);
+ /**
+ * Return the value of a coefficient
+ * The function takes two arguments :
+ * - x
+ * - y
+ */
+ Kross::Api::Object::Ptr getXYCoeff(Kross::Api::List::Ptr);
+ /**
+ * Set the value of a coefficient
+ * The function takes three arguments :
+ * - x
+ * - y
+ * - the new value of the coefficient
+ */
+ Kross::Api::Object::Ptr setXYCoeff(Kross::Api::List::Ptr);
+ /**
+ * Return the depth of the layer
+ */
+ Kross::Api::Object::Ptr getDepth(Kross::Api::List::Ptr);
+ /**
+ * Return the size of the wavelet (size = width = height)
+ */
+ Kross::Api::Object::Ptr getSize(Kross::Api::List::Ptr);
+ /**
+ * Return the number of coefficients in this wavelet (= size * size * depth)
+ */
+ Kross::Api::Object::Ptr getNumCoeffs(Kross::Api::List::Ptr);
+ public:
+ KisMathToolbox::KisWavelet* wavelet() { return m_wavelet; }
+ private:
+ KisMathToolbox::KisWavelet* m_wavelet;
+ uint m_numCoeff;
+};
+
+}
+
+}
+
+#endif