summaryrefslogtreecommitdiffstats
path: root/krita/plugins/viewplugins/scripting
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /krita/plugins/viewplugins/scripting
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'krita/plugins/viewplugins/scripting')
-rw-r--r--krita/plugins/viewplugins/scripting/Makefile.am28
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/Makefile.am29
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/kritacoremodule.cpp288
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/kritacoremodule.h205
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_brush.cpp41
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_brush.h48
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_color.cpp42
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_color.h49
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_doc.cpp46
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_doc.h53
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_filter.cpp76
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_filter.h76
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_filter_configuration.cpp72
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_filter_configuration.h65
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_histogram.cpp104
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_histogram.h115
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_image.cpp148
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_image.h94
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_iterator.h306
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_paint_layer.cpp207
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_paint_layer.h140
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_painter.cpp358
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_painter.h242
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_pattern.cpp39
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_pattern.h48
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_script_progress.cpp67
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_script_progress.h77
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_wavelet.cpp114
-rw-r--r--krita/plugins/viewplugins/scripting/kritacore/krs_wavelet.h92
-rw-r--r--krita/plugins/viewplugins/scripting/kritascripting.desktop81
-rw-r--r--krita/plugins/viewplugins/scripting/kritascripting/Makefile.am19
-rw-r--r--krita/plugins/viewplugins/scripting/kritascripting/kis_script_monitor.cpp51
-rw-r--r--krita/plugins/viewplugins/scripting/kritascripting/kis_script_monitor.h50
-rw-r--r--krita/plugins/viewplugins/scripting/kritascripting/kis_script_progress.cpp64
-rw-r--r--krita/plugins/viewplugins/scripting/kritascripting/kis_script_progress.h54
-rw-r--r--krita/plugins/viewplugins/scripting/samples/Makefile.am3
-rw-r--r--krita/plugins/viewplugins/scripting/samples/python/Makefile.am5
-rw-r--r--krita/plugins/viewplugins/scripting/samples/python/invert.py48
-rw-r--r--krita/plugins/viewplugins/scripting/samples/python/invertpython.rc9
-rw-r--r--krita/plugins/viewplugins/scripting/samples/python/reshapehisto.py300
-rw-r--r--krita/plugins/viewplugins/scripting/samples/python/reshapehisto.rc9
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/Makefile.am18
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/changecs.rb5
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/changecs.rc9
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rb31
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rc9
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/invert.rb45
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/invertruby.rc9
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rb98
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rc9
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rb70
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rc9
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rb133
-rw-r--r--krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rc9
-rw-r--r--krita/plugins/viewplugins/scripting/scripting.cc111
-rw-r--r--krita/plugins/viewplugins/scripting/scripting.h53
-rw-r--r--krita/plugins/viewplugins/scripting/scripting.rc10
57 files changed, 4590 insertions, 0 deletions
diff --git a/krita/plugins/viewplugins/scripting/Makefile.am b/krita/plugins/viewplugins/scripting/Makefile.am
new file mode 100644
index 00000000..f361a6ce
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/Makefile.am
@@ -0,0 +1,28 @@
+SUBDIRS = kritascripting kritacore samples
+
+kritarcdir = $(kde_datadir)/kritaplugins
+kritarc_DATA = scripting.rc
+
+kde_services_DATA = kritascripting.desktop
+
+
+INCLUDES = -I$(top_srcdir)/krita/sdk \
+ -I$(top_srcdir)/krita/core \
+ -I$(top_srcdir)/krita/kritacolor/ \
+ -I$(top_srcdir)/krita/ui \
+ -I$(top_builddir)/lib/kross/main \
+ $(KROSS_INCLUDES) \
+ $(KOFFICE_INCLUDES) \
+ $(all_includes)
+
+kritascripting_la_SOURCES = scripting.cc
+
+kde_module_LTLIBRARIES = kritascripting.la
+noinst_HEADERS = scripting.h
+
+kritascripting_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kritascripting_la_LIBADD = $(top_builddir)/krita/libkritacommon.la $(top_builddir)/lib/kross/main/libkrossmain.la ./kritascripting/libkritascripting.la
+
+KDE_CXXFLAGS = $(USE_EXCEPTIONS)
+
+kritascripting_la_METASOURCES = AUTO
diff --git a/krita/plugins/viewplugins/scripting/kritacore/Makefile.am b/krita/plugins/viewplugins/scripting/kritacore/Makefile.am
new file mode 100644
index 00000000..e948f647
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/Makefile.am
@@ -0,0 +1,29 @@
+
+INCLUDES = -I$(top_srcdir)/core -I$(top_srcdir)/krita/plugins/viewplugins/scripting/kritascripting \
+ -I$(top_srcdir)/krita $(KOFFICECORE_INCLUDES) $(KROSS_INCLUDES) \
+ -I$(top_srcdir)/krita/ui -I$(top_srcdir)/krita/core -I$(top_srcdir)/krita/sdk \
+ -I$(top_srcdir)/krita/kritacolor $(all_includes)
+
+kde_module_LTLIBRARIES = krosskritacore.la
+
+krosskritacore_la_SOURCES = kritacoremodule.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
+
+krosskritacore_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) -module
+krosskritacore_la_LIBADD = \
+ $(LIB_QT) \
+ $(LIB_KDECORE) \
+ $(top_builddir)/lib/kross/api/libkrossapi.la \
+ $(top_builddir)/lib/kross/main/libkrossmain.la \
+ $(top_builddir)/krita/libkritacommon.la \
+ $(top_builddir)/krita/plugins/viewplugins/scripting/kritascripting/libkritascripting.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/krita/plugins/viewplugins/scripting/kritacore/kritacoremodule.cpp b/krita/plugins/viewplugins/scripting/kritacore/kritacoremodule.cpp
new file mode 100644
index 00000000..899291ce
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/kritacoremodule.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 "kritacoremodule.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::KritaCore::KritaCoreModule(manager);
+ }
+}
+
+
+using namespace Kross::KritaCore;
+
+KritaCoreFactory::KritaCoreFactory(QString packagePath) : Kross::Api::Event<KritaCoreFactory>("KritaCoreFactory"), m_packagePath(packagePath)
+{
+ addFunction("newRGBColor", &KritaCoreFactory::newRGBColor);
+ addFunction("newHSVColor", &KritaCoreFactory::newHSVColor);
+ addFunction("getPattern", &KritaCoreFactory::getPattern);
+ addFunction("loadPattern", &KritaCoreFactory::loadPattern);
+ addFunction("getBrush", &KritaCoreFactory::getBrush);
+ addFunction("loadBrush", &KritaCoreFactory::loadBrush);
+ addFunction("getFilter", &KritaCoreFactory::getFilter);
+ addFunction("newCircleBrush", &KritaCoreFactory::newCircleBrush);
+ addFunction("newRectBrush", &KritaCoreFactory::newRectBrush);
+ addFunction("newImage", &KritaCoreFactory::newImage);
+ addFunction("getPackagePath", &KritaCoreFactory::getPackagePath);
+}
+
+Kross::Api::Object::Ptr KritaCoreFactory::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)), QColor::Rgb);
+ return c;
+}
+Kross::Api::Object::Ptr KritaCoreFactory::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)), QColor::Hsv);
+}
+
+Kross::Api::Object::Ptr KritaCoreFactory::getPattern(Kross::Api::List::Ptr args)
+{
+ KisResourceServerBase* rServer = KisResourceServerRegistry::instance()->get("PatternServer");
+ QValueList<KisResource*> resources = rServer->resources();
+
+ QString name = Kross::Api::Variant::toString(args->item(0));
+
+ for (QValueList<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 KritaCoreFactory::loadPattern(Kross::Api::List::Ptr args)
+{
+ QString 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 KritaCoreFactory::getBrush(Kross::Api::List::Ptr args)
+{
+ KisResourceServerBase* rServer = KisResourceServerRegistry::instance()->get("BrushServer");
+ QValueList<KisResource*> resources = rServer->resources();
+
+ QString name = Kross::Api::Variant::toString(args->item(0));
+
+ for (QValueList<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 KritaCoreFactory::loadBrush(Kross::Api::List::Ptr args)
+{
+ QString 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 KritaCoreFactory::getFilter(Kross::Api::List::Ptr args)
+{
+ QString 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 KritaCoreFactory::newCircleBrush(Kross::Api::List::Ptr args)
+{
+ uint w = QMAX(1, Kross::Api::Variant::toUInt(args->item(0)));
+ uint h = QMAX(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);
+ QImage* brsh = new QImage();
+ kas->createBrush(brsh);
+ return new Brush(new KisAutobrushResource(*brsh), false);
+}
+Kross::Api::Object::Ptr KritaCoreFactory::newRectBrush(Kross::Api::List::Ptr args)
+{
+ uint w = QMAX(1, Kross::Api::Variant::toUInt(args->item(0)));
+ uint h = QMAX(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);
+ QImage* brsh = new QImage();
+ kas->createBrush(brsh);
+ return new Brush(new KisAutobrushResource(*brsh), false);;
+}
+
+Kross::Api::Object::Ptr KritaCoreFactory::newImage(Kross::Api::List::Ptr args)
+{
+ int w = Kross::Api::Variant::toInt(args->item(0));
+ int h = Kross::Api::Variant::toInt(args->item(1));
+ QString csname = Kross::Api::Variant::toString(args->item(2));
+ QString 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.").arg(csname ) ) );
+ return 0;
+ }
+
+ return new Image(new KisImage(0,w,h, cs, name));
+}
+
+Kross::Api::Object::Ptr KritaCoreFactory::getPackagePath(Kross::Api::List::Ptr)
+{
+ return new Kross::Api::Variant(m_packagePath);
+}
+
+KritaCoreModule::KritaCoreModule(Kross::Api::Manager* manager)
+ : Kross::Api::Module("kritacore") , m_manager(manager), m_factory(0)
+{
+
+ QMap<QString, Object::Ptr> children = manager->getChildren();
+ kdDebug(41011) << " there are " << children.size() << endl;
+ for(QMap<QString, Object::Ptr>::const_iterator it = children.begin(); it != children.end(); it++)
+ {
+ kdDebug(41011) << it.key() << " " << it.data() << endl;
+ }
+
+ // Wrap doc
+ Kross::Api::Object::Ptr kritadocument = manager->getChild("KritaDocument");
+ if(kritadocument) {
+ Kross::Api::QtObject* kritadocumentqt = (Kross::Api::QtObject*)( kritadocument.data() );
+ if(kritadocumentqt) {
+ ::KisDoc* document = (::KisDoc*)( kritadocumentqt->getObject() );
+ if(document) {
+ addChild( new Doc(document) );
+ } else {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception("There was no 'KritaDocument' published.") );
+ }
+ }
+ }
+ // Wrap KritaScriptProgress
+ QString packagePath;
+ Kross::Api::Object::Ptr kritascriptprogress = manager->getChild("KritaScriptProgress");
+ if(kritadocument) {
+ Kross::Api::QtObject* kritascriptprogressqt = (Kross::Api::QtObject*)( kritascriptprogress.data() );
+ if(kritascriptprogressqt) {
+ ::KisScriptProgress* scriptprogress = (::KisScriptProgress*)( kritascriptprogressqt->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 'KritaScriptProgress' published.") );
+ }
+ }
+ }
+ m_factory = new KritaCoreFactory(packagePath);
+}
+
+KritaCoreModule::~KritaCoreModule()
+{
+ if(m_factory)
+ delete m_factory;
+}
+
+
+const QString KritaCoreModule::getClassName() const
+{
+ return "Kross::KritaCore::KritaCoreModule";
+}
+
+Kross::Api::Object::Ptr KritaCoreModule::call(const QString& name, Kross::Api::List::Ptr arguments)
+{
+ kdDebug(41011) << "KritaCoreModule::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/krita/plugins/viewplugins/scripting/kritacore/kritacoremodule.h b/krita/plugins/viewplugins/scripting/kritacore/kritacoremodule.h
new file mode 100644
index 00000000..97abc8b9
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/kritacoremodule.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 <qstring.h>
+#include <qvariant.h>
+
+#define KROSS_MAIN_EXPORT KDE_EXPORT
+
+#include <api/module.h>
+#include <api/event.h>
+
+namespace Kross { namespace Api {
+ class Manager;
+}}
+
+namespace Kross { namespace KritaCore {
+ /**
+ * This class contains functions use to create new Kross object in a script
+ */
+ class KritaCoreFactory : public Kross::Api::Event<KritaCoreFactory>
+ {
+ public:
+ KritaCoreFactory(QString 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
+ * Krosskritacore::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
+ * Krosskritacore::newRGBColor(255,0,0) # create a red color
+ * Krosskritacore::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
+ * Krosskritacore::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 krita
+ * It takes one argument :
+ * - the name of the pattern
+ *
+ * For example (in ruby) :
+ * @code
+ * Krosskritacore::getPattern("Bricks")
+ * @endcode
+ */
+ Kross::Api::Object::Ptr getPattern(Kross::Api::List::Ptr);
+ /**
+ * This function return a Brush taken from the list of ressources
+ * of krita
+ * It takes one argument :
+ * - the name of the pattern
+ *
+ * For example (in ruby) :
+ * @code
+ * Krosskritacore::getBrush("Circle (05)")
+ * @endcode
+ */
+ Kross::Api::Object::Ptr getBrush(Kross::Api::List::Ptr);
+ /**
+ * This function return a Brush with a circular shape
+ * 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
+ * Krosskritacore::newCircleBrush(10,20) # create a plain circle
+ * Krosskritacore::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 shape
+ * 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
+ * Krosskritacore::newRectBrush(10,20) # create a plain rectangle
+ * Krosskritacore::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 krita
+ * It takes one argument :
+ * - the name of the filter
+ *
+ * For example (in ruby) :
+ * @code
+ * Krosskritacore::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:
+ QString m_packagePath;
+ };
+ /**
+ *
+ */
+ class KritaCoreModule : public Kross::Api::Module
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ KritaCoreModule(Kross::Api::Manager* manager);
+
+ /**
+ * Destructor.
+ */
+ virtual ~KritaCoreModule();
+
+ /// \see Kross::Api::Object::getClassName
+ virtual const QString getClassName() const;
+ virtual Kross::Api::Object::Ptr call(const QString& name, Kross::Api::List::Ptr arguments);
+ private:
+ Kross::Api::Manager* m_manager;
+ KritaCoreFactory* m_factory;
+ };
+
+
+}}
+
+#endif
+
diff --git a/krita/plugins/viewplugins/scripting/kritacore/krs_brush.cpp b/krita/plugins/viewplugins/scripting/kritacore/krs_brush.cpp
new file mode 100644
index 00000000..a6ae513c
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+Brush::Brush(KisBrush* brush, bool sharedBrush) : Kross::Api::Class<Brush>("KritaBrush"), m_brush(brush), m_sharedBrush(sharedBrush)
+{
+}
+
+Brush::~Brush()
+{
+ if(!m_sharedBrush)
+ {
+ delete m_brush;
+ }
+}
+
+}
+
+}
diff --git a/krita/plugins/viewplugins/scripting/kritacore/krs_brush.h b/krita/plugins/viewplugins/scripting/kritacore/krs_brush.h
new file mode 100644
index 00000000..f31e877d
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+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/krita/plugins/viewplugins/scripting/kritacore/krs_color.cpp b/krita/plugins/viewplugins/scripting/kritacore/krs_color.cpp
new file mode 100644
index 00000000..e459b1cd
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+Color::Color ( int x, int y, int z, QColor::Spec colorSpec )
+ : Kross::Api::Class<Color>("KritaColor"), m_color(x,y,z,colorSpec)
+{
+}
+
+Color::Color()
+ : Kross::Api::Class<Color>("KritaColor")
+{
+}
+
+Color::~Color()
+{
+}
+
+
+}
+
+}
diff --git a/krita/plugins/viewplugins/scripting/kritacore/krs_color.h b/krita/plugins/viewplugins/scripting/kritacore/krs_color.h
new file mode 100644
index 00000000..8d46760b
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 <qcolor.h>
+
+#include <api/class.h>
+
+namespace Kross {
+
+namespace KritaCore {
+
+class Color : public Kross::Api::Class<Color>
+{
+ public:
+ Color ( int x, int y, int z, QColor::Spec colorSpec );
+ Color ();
+
+ ~Color();
+ public:
+ inline const QString getClassName() const
+ { return "Kross::Krita::Color"; };
+ inline QColor toQColor() { return m_color; };
+ private:
+ QColor m_color;
+};
+
+}
+
+}
+
+#endif
diff --git a/krita/plugins/viewplugins/scripting/kritacore/krs_doc.cpp b/krita/plugins/viewplugins/scripting/kritacore/krs_doc.cpp
new file mode 100644
index 00000000..23dffabb
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+Doc::Doc(::KisDoc* doc) : Kross::Api::Class<Doc>("KritaDocument"), m_doc(doc) {
+ addFunction("getImage", &Doc::getImage);
+}
+
+Doc::~Doc() {
+
+}
+
+const QString Doc::getClassName() const {
+ return "Kross::KritaCore::Doc";
+}
+
+Kross::Api::Object::Ptr Doc::getImage(Kross::Api::List::Ptr)
+{
+ return new Image(m_doc->currentImage(), m_doc);
+}
+
+}
+}
diff --git a/krita/plugins/viewplugins/scripting/kritacore/krs_doc.h b/krita/plugins/viewplugins/scripting/kritacore/krs_doc.h
new file mode 100644
index 00000000..16336f94
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+class Doc : public Kross::Api::Class<Doc>
+{
+ public:
+ explicit Doc(::KisDoc* doc);
+ virtual ~Doc();
+ virtual const QString getClassName() const;
+ private:
+ /**
+ * This function return the Image associated with this Doc.
+ *
+ * Example (in Ruby) :
+ * @code
+ * doc = krosskritacore::get("KritaDocument")
+ * image = doc.getImage()
+ * @endcode
+ */
+ Kross::Api::Object::Ptr getImage(Kross::Api::List::Ptr);
+ private:
+ KisDoc* m_doc;
+
+};
+}
+}
+
+
+#endif
diff --git a/krita/plugins/viewplugins/scripting/kritacore/krs_filter.cpp b/krita/plugins/viewplugins/scripting/kritacore/krs_filter.cpp
new file mode 100644
index 00000000..ee11d35d
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+Filter::Filter(KisFilter* filter)
+ : Kross::Api::Class<Filter>("KritaFilter"), m_filter(filter), m_config( new FilterConfiguration(filter->configuration()) )
+{
+ addFunction("process", &Filter::process);
+ addFunction("getFilterConfiguration", &Filter::getFilterConfiguration);
+
+}
+
+Filter::~Filter()
+{
+}
+
+const QString Filter::getClassName() const {
+ return "Kross::KritaCore::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").arg("process") ) );
+ }
+ QRect 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 = QRect(x, y, w, h);
+ } else {
+ QRect r1 = src->paintLayer()->paintDevice()->extent();
+ QRect 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/krita/plugins/viewplugins/scripting/kritacore/krs_filter.h b/krita/plugins/viewplugins/scripting/kritacore/krs_filter.h
new file mode 100644
index 00000000..62554ef9
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+ 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 = Krosskritacore::get("KritaDocument")
+ * image = doc.getImage()
+ * layer = image.getActivePaintLayer()
+ * width = layer.getWidth()
+ * height = layer.getHeight()
+ * filter = Krosskritacore::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 QString getClassName() const;
+ private:
+ KisFilter* m_filter;
+ FilterConfiguration* m_config;
+};
+
+}
+}
+
+#endif
diff --git a/krita/plugins/viewplugins/scripting/kritacore/krs_filter_configuration.cpp b/krita/plugins/viewplugins/scripting/kritacore/krs_filter_configuration.cpp
new file mode 100644
index 00000000..3479cf38
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+ FilterConfiguration::FilterConfiguration(KisFilterConfiguration* fConfig)
+ : Kross::Api::Class<FilterConfiguration>("KritaFilterConfiguration"), m_fConfig(fConfig)
+{
+ addFunction("setProperty", &FilterConfiguration::setProperty);
+ addFunction("getProperty", &FilterConfiguration::getProperty);
+ addFunction("fromXML", &FilterConfiguration::fromXML);
+}
+
+FilterConfiguration::~FilterConfiguration()
+{
+}
+
+const QString FilterConfiguration::getClassName() const {
+ return "Kross::KritaCore::FilterConfiguration";
+}
+
+
+Kross::Api::Object::Ptr FilterConfiguration::setProperty(Kross::Api::List::Ptr args)
+{
+ QString name = Kross::Api::Variant::toString(args->item(0));
+ QVariant 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)
+{
+ QString name = Kross::Api::Variant::toString(args->item(0));
+ QVariant 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)
+{
+ QString xml = Kross::Api::Variant::toString(args->item(0));
+ m_fConfig->fromXML( xml );
+ return 0;
+}
+
+}
+}
diff --git a/krita/plugins/viewplugins/scripting/kritacore/krs_filter_configuration.h b/krita/plugins/viewplugins/scripting/kritacore/krs_filter_configuration.h
new file mode 100644
index 00000000..7c8c3020
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+/**
+ @author Cyrille Berger <[email protected]>
+*/
+class FilterConfiguration : public Kross::Api::Class<FilterConfiguration>
+{
+ public:
+ FilterConfiguration(KisFilterConfiguration*);
+ ~FilterConfiguration();
+ public:
+ virtual const QString 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/krita/plugins/viewplugins/scripting/kritacore/krs_histogram.cpp b/krita/plugins/viewplugins/scripting/kritacore/krs_histogram.cpp
new file mode 100644
index 00000000..953eb868
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+Histogram::Histogram(KisPaintLayerSP layer,
+ KisHistogramProducerSP producer,
+ const enumHistogramType type)
+ : Kross::Api::Class<Histogram>("KritaHistogram")
+{
+ 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 QString Histogram::getClassName() const {
+ return "Kross::KritaCore::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/krita/plugins/viewplugins/scripting/kritacore/krs_histogram.h b/krita/plugins/viewplugins/scripting/kritacore/krs_histogram.h
new file mode 100644
index 00000000..b238c5db
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+/**
+ * This class allow to access the histogram of a PaintLayer.
+ *
+ * Example (in Ruby) :
+ * @code
+ * doc = krosskritacore::get("KritaDocument")
+ * 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 QString 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/krita/plugins/viewplugins/scripting/kritacore/krs_image.cpp b/krita/plugins/viewplugins/scripting/kritacore/krs_image.cpp
new file mode 100644
index 00000000..b274ad33
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+ Image::Image(KisImageSP image, KisDoc* doc)
+ : Kross::Api::Class<Image>("KritaImage"), 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 QString Image::getClassName() const {
+ return "Kross::KritaCore::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.").arg(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)
+{
+ QString name = Kross::Api::Variant::toString(args->item(0));
+ int opacity = Kross::Api::Variant::toInt(args->item(1));
+ opacity = CLAMP(opacity, 0, 255);
+ QString 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/krita/plugins/viewplugins/scripting/kritacore/krs_image.h b/krita/plugins/viewplugins/scripting/kritacore/krs_image.h
new file mode 100644
index 00000000..0be2e46f
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+class Image : public Kross::Api::Class<Image>
+{
+ public:
+ Image(KisImageSP image, KisDoc* doc = 0);
+ ~Image();
+ virtual const QString 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/krita/plugins/viewplugins/scripting/kritacore/krs_iterator.h b/krita/plugins/viewplugins/scripting/kritacore/krs_iterator.h
new file mode 100644
index 00000000..9493f49a
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/krs_iterator.h
@@ -0,0 +1,306 @@
+/*
+ * 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 <qobject.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 KritaCore {
+
+//<beurk> stupid Qt which doesn't support templated QObject
+class IteratorMemoryManaged {
+ public:
+ virtual void invalidateIterator() = 0;
+};
+
+class IteratorMemoryManager : public QObject {
+ Q_OBJECT
+ public:
+ IteratorMemoryManager(IteratorMemoryManaged* it) : m_it(it)
+ {
+ // Connect the Monitor to know when the invalidating of iterator is needed
+ connect(KisScriptMonitor::instance(), SIGNAL(executionFinished(const Kross::Api::ScriptAction* )), this, SLOT(invalidateIterator()));
+
+ }
+ public slots:
+ void invalidateIterator()
+ {
+ m_it->invalidateIterator();
+ }
+ 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> >("KritaIterator"), 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
+ QValueVector<KisChannelInfo *> channels = layer->paintDevice()->colorSpace()->channels();
+ QString initiales = "";
+ for(QValueVector<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()
+ {
+ invalidateIterator();
+ delete m_itmm;
+ }
+ virtual const QString getClassName() const {
+ return "Kross::KritaCore::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)
+ {
+ Q_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)
+ {
+ Q_UINT8* data = (Q_UINT8*)(m_it->rawData() + channelpos);
+ return new Kross::Api::Variant( * data);
+ }
+ Kross::Api::Object::Ptr setChannelUINT8(Kross::Api::List::Ptr args, uint channelpos)
+ {
+ Q_UINT8* data = (Q_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)
+ {
+ Q_UINT16* data = (Q_UINT16*)(m_it->rawData() + channelpos);
+ return new Kross::Api::Variant( * data);
+ }
+ Kross::Api::Object::Ptr setChannelUINT16(Kross::Api::List::Ptr args, uint channelpos)
+ {
+ Q_UINT16* data = (Q_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)
+ {
+ QValueVector<KisChannelInfo *> channels = m_layer->paintDevice()->colorSpace()->channels();
+ QValueList<QVariant> pixel;
+ for(QValueVector<KisChannelInfo *>::iterator itC = channels.begin(); itC != channels.end(); itC++)
+ {
+ KisChannelInfo * ci = *itC;
+ Q_UINT8* data = (Q_UINT8*)(m_it->rawData() + ci->pos());
+ switch(ci->channelValueType())
+ {
+ case KisChannelInfo::UINT8:
+ pixel.push_back( *data);
+ break;
+ case KisChannelInfo::UINT16:
+ pixel.push_back( *((Q_UINT16*) data) );
+ break;
+ case KisChannelInfo::FLOAT32:
+ pixel.push_back( *((float*) data) );
+ break;
+ default:
+ kdDebug(41011) << i18n("An error has occurred in %1").arg("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)
+ {
+ QValueList<QVariant> pixel = Kross::Api::Variant::toList( args->item(0) );
+ QValueVector<KisChannelInfo *> channels = m_layer->paintDevice()->colorSpace()->channels();
+ uint i = 0;
+ for(QValueVector<KisChannelInfo *>::iterator itC = channels.begin(); itC != channels.end(); itC++, i++)
+ {
+ KisChannelInfo * ci = *itC;
+ Q_UINT8* data = (Q_UINT8*)(m_it->rawData() + ci->pos());
+ switch(ci->channelValueType())
+ {
+ case KisChannelInfo::UINT8:
+ *data = pixel[i].toUInt();
+ break;
+ case KisChannelInfo::UINT16:
+ *((Q_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").arg("setPixel") << endl;
+ kdDebug(41011) << i18n("unsupported data format in scripts") << endl;
+ break;
+ }
+ }
+ return 0;
+ }
+ private:
+ virtual void invalidateIterator()
+ {
+ 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/krita/plugins/viewplugins/scripting/kritacore/krs_paint_layer.cpp b/krita/plugins/viewplugins/scripting/kritacore/krs_paint_layer.cpp
new file mode 100644
index 00000000..1f79b22c
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+PaintLayer::PaintLayer(KisPaintLayerSP layer, KisDoc* doc)
+ : Kross::Api::Class<PaintLayer>("KritaLayer"), 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 QString PaintLayer::getClassName() const {
+ return "Kross::KritaCore::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)
+{
+ QRect r1 = paintLayer()->extent();
+ QRect r2 = paintLayer()->image()->bounds();
+ QRect rect = r1.intersect(r2);
+ return new Kross::Api::Variant(rect.width());
+}
+Kross::Api::Object::Ptr PaintLayer::getHeight(Kross::Api::List::Ptr)
+{
+ QRect r1 = paintLayer()->extent();
+ QRect r2 = paintLayer()->image()->bounds();
+ QRect rect = r1.intersect(r2);
+ return new Kross::Api::Variant(rect.height());
+}
+
+Kross::Api::Object::Ptr PaintLayer::createHistogram(Kross::Api::List::Ptr args)
+{
+ QString histoname = Kross::Api::Variant::toString(args->item(0));
+ KisHistogramProducerFactory* factory = KisHistogramProducerFactoryRegistry::instance()->get(histoname);
+
+/* KisIDList listID = KisHistogramProducerFactoryRegistry::instance()->listKeys();
+ for(KisIDList::iterator it = listID.begin(); it != listID.end(); it++)
+ {
+ kdDebug(41011) << (*it).name() << " " << (*it).id() << endl;
+ }*/
+
+ enumHistogramType type ;
+ switch( Kross::Api::Variant::toUInt(args->item(1)) )
+ {
+ case 1:
+ type = LOGARITHMIC;
+ break;
+ case 0:
+ default:
+ type = LINEAR;
+ break;
+ }
+ if(factory && factory->isCompatibleWith( paintLayer()->paintDevice()->colorSpace() ))
+ {
+ return new Histogram( paintLayer().data(), factory->generate() , type);
+ } else {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception( i18n("An error has occured in %1").arg("createHistogram") + "\n" + i18n("The histogram %1 is not available").arg(histoname) ) );
+ }
+ return 0;
+}
+
+Kross::Api::Object::Ptr PaintLayer::createPainter(Kross::Api::List::Ptr )
+{
+ return new Painter(paintLayer());
+}
+
+Kross::Api::Object::Ptr PaintLayer::beginPainting(Kross::Api::List::Ptr args)
+{
+ QString 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").arg("convertToColorspace") + "\n" + i18n("Colorspace %1 is not available, please check your installation.").arg(Kross::Api::Variant::toString(args->item(0))) ) );
+ return 0;
+ }
+ paintLayer()->paintDevice()->convertTo(dstCS);
+ return 0;
+}
+
+Kross::Api::Object::Ptr PaintLayer::colorSpaceId(Kross::Api::List::Ptr )
+{
+ return new Kross::Api::Variant( paintLayer()->paintDevice()->colorSpace()->id().id() );
+}
+
+
+Kross::Api::Object::Ptr PaintLayer::fastWaveletTransformation(Kross::Api::List::Ptr )
+{
+ KisMathToolbox* mathToolbox = KisMetaRegistry::instance()->mtRegistry()->get( paintLayer()->paintDevice()->colorSpace()->mathToolboxID() );
+ QRect 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() );
+ QRect rect = paintLayer()->exactBounds();
+ mathToolbox->fastWaveletUntransformation( paintLayer()->paintDevice(), rect, wav->wavelet() );
+ return 0;
+}
+
+
+}
+
+}
diff --git a/krita/plugins/viewplugins/scripting/kritacore/krs_paint_layer.h b/krita/plugins/viewplugins/scripting/kritacore/krs_paint_layer.h
new file mode 100644
index 00000000..4ddfd4bd
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+/**
+@author Cyrille Berger
+*/
+class PaintLayer : public Kross::Api::Class<PaintLayer>
+{
+ public:
+ explicit PaintLayer(KisPaintLayerSP layer, KisDoc* doc = 0);
+ virtual ~PaintLayer();
+ virtual const QString 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/krita/plugins/viewplugins/scripting/kritacore/krs_painter.cpp b/krita/plugins/viewplugins/scripting/kritacore/krs_painter.cpp
new file mode 100644
index 00000000..621a173d
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+Painter::Painter(KisPaintLayerSP layer)
+ : Kross::Api::Class<Painter>("KritaPainter"), 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());
+ QRect 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 = QRect(x,y,w,h);
+ } else {
+ QRect r1 = paintLayer()->paintDevice()->extent();
+ QRect r2 = paintLayer()->image()->bounds();
+ rect = r1.intersect(r2);
+ }
+
+ QValueList<QVariant> kernelH = Kross::Api::Variant::toList( args->item(0) );
+
+ QVariant firstlineVariant = *kernelH.begin();
+ if(firstlineVariant.type() != QVariant::List)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(i18n("An error has occured in %1").arg("applyConvolution")) );
+ }
+
+ QValueList<QVariant> firstline = firstlineVariant.toList();
+
+ kernel.height = kernelH.size();
+ kernel.width = firstline.size();
+
+ kernel.data = new Q_INT32[kernel.height * kernel.width];
+
+ uint i = 0;
+ for(QValueList<QVariant>::iterator itK = kernelH.begin(); itK != kernelH.end(); itK++, i ++ )
+ {
+ QVariant lineVariant = *kernelH.begin();
+ if(lineVariant.type() != QVariant::List)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(i18n("An error has occured in %1").arg("applyConvolution")) );
+ }
+ QValueList<QVariant> line = firstlineVariant.toList();
+ if(line.size() != kernel.width)
+ {
+ throw Kross::Api::Exception::Ptr( new Kross::Api::Exception(i18n("An error has occured in %1").arg("applyConvolution")) );
+ }
+ uint j = 0;
+ for(QValueList<QVariant>::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)
+{
+ Q_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)
+{
+ QValueList<QVariant> pointsX = Kross::Api::Variant::toList( args->item(0) );
+ QValueList<QVariant> 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)
+{
+ QValueList<QVariant> pointsX = Kross::Api::Variant::toList( args->item(0) );
+ QValueList<QVariant> 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->toQColor(), 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->toQColor(), 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)
+{
+ QString 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/krita/plugins/viewplugins/scripting/kritacore/krs_painter.h b/krita/plugins/viewplugins/scripting/kritacore/krs_painter.h
new file mode 100644
index 00000000..37ae7993
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+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( QValueList<QVariant> xs, QValueList<QVariant> ys)
+ {
+ vKisPoint a;
+ QValueList<QVariant>::iterator itx = xs.begin();
+ QValueList<QVariant>::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/krita/plugins/viewplugins/scripting/kritacore/krs_pattern.cpp b/krita/plugins/viewplugins/scripting/kritacore/krs_pattern.cpp
new file mode 100644
index 00000000..8b89c8a7
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+Pattern::Pattern(KisPattern* pattern, bool sharedPattern) : Kross::Api::Class<Pattern>("KritaPattern"), m_pattern(pattern), m_sharedPattern(sharedPattern)
+{
+}
+
+Pattern::~Pattern()
+{
+ if(!m_sharedPattern)
+ delete m_pattern;
+}
+
+}
+
+}
diff --git a/krita/plugins/viewplugins/scripting/kritacore/krs_pattern.h b/krita/plugins/viewplugins/scripting/kritacore/krs_pattern.h
new file mode 100644
index 00000000..f7dd7e35
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+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/krita/plugins/viewplugins/scripting/kritacore/krs_script_progress.cpp b/krita/plugins/viewplugins/scripting/kritacore/krs_script_progress.cpp
new file mode 100644
index 00000000..e653f12a
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+ScriptProgress::ScriptProgress(KisScriptProgress* script): Kross::Api::Class<ScriptProgress>("KritaScript"), 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/krita/plugins/viewplugins/scripting/kritacore/krs_script_progress.h b/krita/plugins/viewplugins/scripting/kritacore/krs_script_progress.h
new file mode 100644
index 00000000..535485cb
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+/**
+ * ScriptProgress is used to manage the progress bar of the status bar in krita
+ *
+ * For example (in ruby) :
+ * @code
+ * script = Krosskritacore::get("KritaScript")
+ * 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/krita/plugins/viewplugins/scripting/kritacore/krs_wavelet.cpp b/krita/plugins/viewplugins/scripting/kritacore/krs_wavelet.cpp
new file mode 100644
index 00000000..d2786780
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+Wavelet::Wavelet(KisMathToolbox::KisWavelet* kwl)
+ : Kross::Api::Class<Wavelet>("KritaWavelet"), 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)
+{
+ Q_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").arg("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)
+{
+ Q_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").arg("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)
+{
+ Q_UINT32 x = Kross::Api::Variant::toUInt(args->item(0));
+ Q_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").arg("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)
+{
+ Q_UINT32 x = Kross::Api::Variant::toUInt(args->item(0));
+ Q_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").arg("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/krita/plugins/viewplugins/scripting/kritacore/krs_wavelet.h b/krita/plugins/viewplugins/scripting/kritacore/krs_wavelet.h
new file mode 100644
index 00000000..bee73e9b
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritacore/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 KritaCore {
+
+/**
+ @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
diff --git a/krita/plugins/viewplugins/scripting/kritascripting.desktop b/krita/plugins/viewplugins/scripting/kritascripting.desktop
new file mode 100644
index 00000000..cfdbbbf4
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritascripting.desktop
@@ -0,0 +1,81 @@
+[Desktop Entry]
+Name=Scripting plugin
+Name[bg]=Приставка за скриптове
+Name[ca]=Connector de seqüenciació
+Name[da]=Scriptplugin
+Name[de]=Skripting-Modul
+Name[el]=Πρόσθετο γραφής σεναρίων
+Name[eo]=Skriptad-kromaĵo
+Name[es]=Complemento para guiones
+Name[et]=Skriptiplugin
+Name[fa]=وصلۀ دست‌نوشته
+Name[fr]=Module de scriptage
+Name[fy]=Skriptplugin
+Name[ga]=Breiseán scriptithe
+Name[gl]=Plugin de programación
+Name[he]=תוסף לתסריטים
+Name[hu]=Szkript modul
+Name[is]=Skriftu íforrit
+Name[it]=Plugin di scripting
+Name[ja]=スクリプトプラグイン
+Name[km]=កម្មវិធី​ជំនួយ​សម្រាប់​ស្គ្រីប
+Name[nb]=Programtillegg for skripting
+Name[nds]=Skriptmoduul
+Name[ne]=प्लगइन स्क्रिप्ट गर्दै
+Name[nl]=Scriptplugin
+Name[pl]=Wtyczka obsługi języków skryptowych
+Name[pt]='Plugin' de programação
+Name[pt_BR]=Plugin de programação
+Name[ru]=Модуль поддержки сценариев
+Name[sk]=Modul pre skripty
+Name[sl]=Vstavek za skripte
+Name[sr]=Прикључак за скриптовање
+Name[sr@Latn]=Priključak za skriptovanje
+Name[sv]=Skriptinsticksprogram
+Name[uk]=Втулок для скриптів
+Name[uz]=Skriptlash plagini
+Name[uz@cyrillic]=Скриптлаш плагини
+Name[zh_CN]=脚本插件
+Name[zh_TW]=命令稿外掛程式
+Comment=Allow execution of scripts
+Comment[bg]=Изпълнение на скриптове
+Comment[ca]=Permet l'execució de seqüències
+Comment[da]=Tillad kørsel af script
+Comment[de]=Ermöglicht das Ausführen von Skripten
+Comment[el]=Επιτρέπει την εκτέλεση σεναρίων
+Comment[eo]=Permesi ruligon de skriptoj
+Comment[es]=Permite la ejecución de guiones
+Comment[et]=Võimaldab skriptide käivitamist
+Comment[fa]=اجازۀ اجرای دست‌نوشته‌ها
+Comment[fr]=Permet d'exécuter des scripts
+Comment[fy]=Hjirmei kinne skripts útfierd wurde
+Comment[gl]=Permite executar guións
+Comment[he]=אפשרות להרצת תסריטים
+Comment[hu]=Lehetővé teszi szkriptek végrehajtását
+Comment[is]=Leyfa að skriftur séu keyrðar
+Comment[it]=Permette di eseguire script
+Comment[ja]=スクリプトの実行を可能にします
+Comment[km]=អនុញ្ញាត​ឲ្យ​ប្រតិបត្តិ​ស្គ្រីប
+Comment[lv]=Atļaut skriptu izpildi
+Comment[nb]=Tillater skriptkjøring
+Comment[nds]=Skripten utföhren
+Comment[ne]=स्क्रिप्टको कार्यान्वयनलाई अनुमति दिनुहोस्
+Comment[nl]=Hiermee kunnen scripts uitgevoerd worden
+Comment[pl]=Zezwala na wykonywanie skryptów
+Comment[pt]=Permitir executar programas ou 'scripts'
+Comment[pt_BR]=Permitir executar programas ou 'scripts'
+Comment[ru]=Возможность выполнения сценариев
+Comment[sk]=Povoliť vykonávanie skriptov
+Comment[sl]=Dovoli izvedbo skriptov
+Comment[sr]=Омогући извршавање скрипти
+Comment[sr@Latn]=Omogući izvršavanje skripti
+Comment[sv]=Tillåt körning av skript
+Comment[uk]=Дає змогу виконувати скрипти
+Comment[uz]=Skriptlarni ishga tushirishga ruxsat berish
+Comment[uz@cyrillic]=Скриптларни ишга туширишга рухсат бериш
+Comment[zh_CN]=允许执行脚本
+Comment[zh_TW]=允許執行命令稿
+ServiceTypes=Krita/ViewPlugin
+Type=Service
+X-KDE-Library=kritascripting
+X-Krita-Version=2
diff --git a/krita/plugins/viewplugins/scripting/kritascripting/Makefile.am b/krita/plugins/viewplugins/scripting/kritascripting/Makefile.am
new file mode 100644
index 00000000..76dc7ea5
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritascripting/Makefile.am
@@ -0,0 +1,19 @@
+INCLUDES = -I$(top_srcdir)/krita/sdk \
+ -I$(top_srcdir)/krita/core \
+ -I$(top_srcdir)/krita/kritacolor/ \
+ -I$(top_srcdir)/krita/ui \
+ $(KROSS_INCLUDES) \
+ $(KOFFICE_INCLUDES) \
+ $(all_includes)
+
+
+lib_LTLIBRARIES = libkritascripting.la
+libkritascripting_la_SOURCES = kis_script_progress.cpp kis_script_monitor.cpp
+noinst_HEADERS = kis_script_progress.h
+
+libkritascripting_la_LDFLAGS = -no-undefined $(all_libraries)
+libkritascripting_la_LIBADD = $(top_builddir)/krita/libkritacommon.la $(top_builddir)/lib/kross/main/libkrossmain.la
+
+KDE_CXXFLAGS = $(USE_EXCEPTIONS)
+
+libkritascripting_la_METASOURCES = AUTO
diff --git a/krita/plugins/viewplugins/scripting/kritascripting/kis_script_monitor.cpp b/krita/plugins/viewplugins/scripting/kritascripting/kis_script_monitor.cpp
new file mode 100644
index 00000000..8bb12596
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritascripting/kis_script_monitor.cpp
@@ -0,0 +1,51 @@
+/*
+ * 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 "kis_script_monitor.h"
+
+#include <main/scriptaction.h>
+#include <main/scriptguiclient.h>
+
+
+KisScriptMonitor::KisScriptMonitor()
+{
+}
+
+
+KisScriptMonitor::~KisScriptMonitor()
+{
+ s_instance = 0;
+}
+
+void KisScriptMonitor::monitor(Kross::Api::ScriptGUIClient* guiClient)
+{
+ connect(guiClient, SIGNAL(executionFinished( const Kross::Api::ScriptAction* )), SIGNAL(executionFinished( const Kross::Api::ScriptAction* )));
+ connect(guiClient, SIGNAL(executionStarted( const Kross::Api::ScriptAction* )), SIGNAL(executionStarted( const Kross::Api::ScriptAction* )));
+}
+
+KisScriptMonitor* KisScriptMonitor::s_instance = 0;
+
+KisScriptMonitor* KisScriptMonitor::instance()
+{
+ if(s_instance == 0)
+ s_instance = new KisScriptMonitor();
+ return s_instance;
+}
+
+#include "kis_script_monitor.moc"
+
diff --git a/krita/plugins/viewplugins/scripting/kritascripting/kis_script_monitor.h b/krita/plugins/viewplugins/scripting/kritascripting/kis_script_monitor.h
new file mode 100644
index 00000000..de1e0380
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritascripting/kis_script_monitor.h
@@ -0,0 +1,50 @@
+/*
+ * 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 KIS_SCRIPT_MONITOR_H
+#define KIS_SCRIPT_MONITOR_H
+
+#include <qobject.h>
+
+namespace Kross {
+ namespace Api {
+ class ScriptGUIClient;
+ class ScriptAction;
+ }
+}
+
+/**
+ @author Cyrille Berger <[email protected]>
+*/
+class KisScriptMonitor : public QObject {
+ Q_OBJECT
+ private:
+ KisScriptMonitor();
+ ~KisScriptMonitor();
+ public:
+ static KisScriptMonitor* instance();
+ void monitor(Kross::Api::ScriptGUIClient* guiClient);
+ signals:
+ void executionFinished(const Kross::Api::ScriptAction* );
+ void executionStarted(const Kross::Api::ScriptAction* );
+ private:
+ static KisScriptMonitor* s_instance;
+
+};
+
+#endif
diff --git a/krita/plugins/viewplugins/scripting/kritascripting/kis_script_progress.cpp b/krita/plugins/viewplugins/scripting/kritascripting/kis_script_progress.cpp
new file mode 100644
index 00000000..c3629304
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritascripting/kis_script_progress.cpp
@@ -0,0 +1,64 @@
+/*
+ * 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 "kis_script_progress.h"
+
+#include <kis_progress_display_interface.h>
+#include <kis_view.h>
+
+void KisScriptProgress::activateAsSubject()
+{
+ m_view->canvasSubject()->progressDisplay()->setSubject( this, true, false /* TODO: how to cancel a script ? */ );
+}
+
+void KisScriptProgress::setProgressTotalSteps(Q_INT32 totalSteps)
+{
+ m_progressTotalSteps = totalSteps;
+ m_progressSteps = 0;
+ m_lastProgressPerCent = 0;
+ emit notifyProgress(0);
+}
+
+void KisScriptProgress::setProgress(Q_INT32 progress)
+{
+ m_progressSteps = progress;
+ Q_INT32 progressPerCent = (m_progressSteps * 100) / (m_progressTotalSteps > 0 ? m_progressTotalSteps : 1);
+
+ if (progressPerCent != m_lastProgressPerCent) {
+
+ m_lastProgressPerCent = progressPerCent;
+ emit notifyProgress(progressPerCent);
+ }
+}
+
+void KisScriptProgress::incProgress()
+{
+ setProgress( ++m_progressSteps );
+}
+
+void KisScriptProgress::setProgressStage(const QString& stage, Q_INT32 progress)
+{
+ Q_INT32 progressPerCent = (progress * 100) / (m_progressTotalSteps > 0 ? m_progressTotalSteps : 1);
+ m_lastProgressPerCent = progress;
+ emit notifyProgressStage( stage, progressPerCent);
+}
+
+void KisScriptProgress::progressDone()
+{
+ emit notifyProgressDone();
+}
diff --git a/krita/plugins/viewplugins/scripting/kritascripting/kis_script_progress.h b/krita/plugins/viewplugins/scripting/kritascripting/kis_script_progress.h
new file mode 100644
index 00000000..864a6760
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/kritascripting/kis_script_progress.h
@@ -0,0 +1,54 @@
+/*
+ * 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 _KIS_SCRIPT_PROGRESS_H_
+#define _KIS_SCRIPT_PROGRESS_H_
+
+#include <kis_progress_subject.h>
+
+class KisView;
+
+/**
+ * TODO: clarify the situation, while, in the future, multiple scripts could be running at a same time,
+ * some of the functions are global to all script and some aren't.
+ */
+class KisScriptProgress : public KisProgressSubject
+{
+ public:
+ KisScriptProgress(KisView* view) : m_view(view) {};
+ public:
+ /**
+ * This function will set this class as the KisProgressSubject in view
+ */
+ void activateAsSubject();
+ virtual void cancel() {};
+ public:
+ void setProgressTotalSteps(Q_INT32 totalSteps);
+ void setProgress(Q_INT32 progress);
+ void incProgress();
+ void setProgressStage(const QString& stage, Q_INT32 progress);
+ void progressDone();
+ inline void setPackagePath(QString path) { m_packagePath = path; };
+ inline QString packagePath() { return m_packagePath; }
+ private:
+ Q_INT32 m_progressSteps, m_progressTotalSteps, m_lastProgressPerCent;
+ KisView * m_view;
+ QString m_packagePath;
+};
+
+#endif
diff --git a/krita/plugins/viewplugins/scripting/samples/Makefile.am b/krita/plugins/viewplugins/scripting/samples/Makefile.am
new file mode 100644
index 00000000..1eebb4c7
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/Makefile.am
@@ -0,0 +1,3 @@
+INCLUDES = -I$(srcdir)/../../../sdk -I$(srcdir)/../../../core -I$(srcdir)/../../../kritacolor/ -I$(srcdir)/../../../ui -I$(top_srcdir)/kexi/scriptingcore/main $(KOFFICE_INCLUDES) $(all_includes)
+METASOURCES = AUTO
+SUBDIRS = python ruby
diff --git a/krita/plugins/viewplugins/scripting/samples/python/Makefile.am b/krita/plugins/viewplugins/scripting/samples/python/Makefile.am
new file mode 100644
index 00000000..5b1f28f3
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/python/Makefile.am
@@ -0,0 +1,5 @@
+scriptinvertdir = $(kde_datadir)/krita/scripts/invertpython
+scriptinvert_SCRIPTS = invert.py invertpython.rc
+
+scriptreshapedir = $(kde_datadir)/krita/scripts/reshapehisto
+scriptreshape_SCRIPTS = reshapehisto.py reshapehisto.rc
diff --git a/krita/plugins/viewplugins/scripting/samples/python/invert.py b/krita/plugins/viewplugins/scripting/samples/python/invert.py
new file mode 100644
index 00000000..2c87593d
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/python/invert.py
@@ -0,0 +1,48 @@
+# This file is part of Krita
+#
+# 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 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.
+
+class Inverter:
+ def __init__(self):
+ try:
+ import krosskritacore
+ except:
+ raise "Import of the KritaCore module failed."
+ doc = krosskritacore.get("KritaDocument")
+ script = krosskritacore.get("KritaScript")
+ image = doc.getImage()
+ layer = image.getActivePaintLayer()
+ if(layer.colorSpaceId() != "RGBA" ):
+ raise("This script works only for 8bit RGBA layers")
+ width = layer.getWidth()
+ height = layer.getHeight()
+ script.setProgressTotalSteps(width * height)
+ layer.beginPainting("invert")
+ it = layer.createRectIterator( 0, 0, width, height )
+ print "kikoo\n"
+ finesh = it.isDone()
+ while (not finesh) :
+ p = it.getRGBA()
+ p[0] = 255 - p[0]
+ p[1] = 255 - p[1]
+ p[2] = 255 - p[2]
+ it.setRGBA(p)
+ script.incProgress()
+ finesh = it.next()
+ layer.endPainting()
+
+Inverter()
diff --git a/krita/plugins/viewplugins/scripting/samples/python/invertpython.rc b/krita/plugins/viewplugins/scripting/samples/python/invertpython.rc
new file mode 100644
index 00000000..d2224311
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/python/invertpython.rc
@@ -0,0 +1,9 @@
+<KrossScripting>
+ <ScriptAction
+ name="InvertPython"
+ text="Invert (python)"
+ description="Invert the pixel of an image (python)"
+ icon=""
+ interpreter="python"
+ file="invert.py" />
+</KrossScripting>
diff --git a/krita/plugins/viewplugins/scripting/samples/python/reshapehisto.py b/krita/plugins/viewplugins/scripting/samples/python/reshapehisto.py
new file mode 100644
index 00000000..4a79e68c
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/python/reshapehisto.py
@@ -0,0 +1,300 @@
+# This file is part of Krita
+#
+# 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 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.
+
+import math
+
+# it's an experimental script to try to reshape histogram, while the results are far to be convincing yet
+# it is still an example on how to use histogram in a script
+
+def sign(a):
+ if a < 0:
+ return -1
+ else:
+ return 1
+#def abs(a):
+ #if a <
+
+def computeDiff(histo, histoTarget):
+ diff = [ ]
+ histoMax = histo.getHighest()
+ count = 0
+ while( count < 256 ) :
+ v = histo.getValue(count)
+ diff.append( v / histoMax - histoTarget[count])
+ count += 1
+ derivdiff = [ ]
+ derivdiff.append(diff[1] - diff[0] )
+ count = 1
+ while( count < 255 ) :
+ derivdiff.append((diff[count+1] - diff[count - 1])/2.0)
+ print count
+ print " "
+ print derivdiff[count]
+ print " "
+ count += 1
+ derivdiff.append(diff[255] - diff[254] )
+ return diff
+
+try:
+ import krosskritacore
+except:
+ raise "Import of the KritaCore module failed."
+
+#histoTarget = [ 0.0, 0.01226531745085, 0.024528789662323, 0.0367885716726463, 0.049042819075215, 0.0612896882960706, 0.0735273368712555, 0.0857539237239997, 0.0979676094416996, 0.110166556552646, 0.122348929802458, 0.13451289643019, 0.146656626444054, 0.158778292896733, 0.170876072160234, 0.18294814420024, 0.194992692849922, 0.207007906083172, 0.218991976287209, 0.230943100534525, 0.242859480854121, 0.254739324502003, 0.266580844230888, 0.278382258559083, 0.290141792038499, 0.301857675521758, 0.313528146428344, 0.325151449009778, 0.336725834613756, 0.348249561947225, 0.359720897338346, 0.371138114997318, 0.38249949727601, 0.393803334926368, 0.405047927357568, 0.416231582891849, 0.427352619019025, 0.4384093626496, 0.449400150366478, 0.460323328675215, 0.471177254252771, 0.481960294194744, 0.492670826261026, 0.50330723911986, 0.513867932590253, 0.524351317882718, 0.534755817838293, 0.545079867165813, 0.555321912677404, 0.565480413522147, 0.575553841417885, 0.585540680881154, 0.595439429455167, 0.605248597935856, 0.614966710595909, 0.624592305406788, 0.634123934258679, 0.643560163178352, 0.652899572544893, 0.662140757303275, 0.671282327175744, 0.680322906870975, 0.689261136290974, 0.698095670735701, 0.706825181105366, 0.715448354100387, 0.723963892418968, 0.732370514952268, 0.740666956977137, 0.748851970346384, 0.756924323676554, 0.764882802533185, 0.772726209613504, 0.780453364926561, 0.788063105970749, 0.795554287908693, 0.802925783739486, 0.810176484468239, 0.817305299272921, 0.824311155668464, 0.83119299966812, 0.837949795942015, 0.84458052797292, 0.851084198209167, 0.857459828214736, 0.863706458816447, 0.869823150248263, 0.875808982292675, 0.881663054419139, 0.887384485919556, 0.892972416040772, 0.898426004114068, 0.903744429681637, 0.908926892620016, 0.913972613260457, 0.918880832506229, 0.923650811946811, 0.928281833968988, 0.93277320186481, 0.937124239936404, 0.941334293597632, 0.945402729472569, 0.949328935490789, 0.953112320979447, 0.956752316752142, 0.960248375194552, 0.963599970346811, 0.966806597982642, 0.969867775685214, 0.972783042919718, 0.97555196110265, 0.978174113667795, 0.980649106128898, 0.982976566139007, 0.985156143546496, 0.987187510447739, 0.989070361236445, 0.990804412649628, 0.99238940381023, 0.993825096266363, 0.995111274027184, 0.99624774359539, 0.997234333996328, 0.998070896803715, 0.998757306161974, 0.99929345880516, 0.999679274072503, 0.999914693920536, 0.999999682931835, 0.99993422832034, 0.999718339933283, 0.999352050249705, 0.998835414375572, 0.998168510035481, 0.997351437560967, 0.996384319875413, 0.995267302475555, 0.994000553409588, 0.992584263251893, 0.991018645074359, 0.989303934414332, 0.987440389239176, 0.985428289907469, 0.983267939126818, 0.980959661908326, 0.978503805517689, 0.975900739422957, 0.973150855238948, 0.970254566668332, 0.967212309439392, 0.964024541240472, 0.960691741651122, 0.957214412069943, 0.953593075639162, 0.949828277165924, 0.945920583040329, 0.941870581150226, 0.937678880792763, 0.933346112582728, 0.928872928357675, 0.924260001079857, 0.919508024734984, 0.914617714227821, 0.909589805274631, 0.90442505429249, 0.899124238285494, 0.89368815472786, 0.888117621443952, 0.882413476485242, 0.876576578004235, 0.870607804125365, 0.86450805281288, 0.858278241735758, 0.851919308129644, 0.845432208655849, 0.83881791925743, 0.832077435012361, 0.825211769983833, 0.818221957067693, 0.811109047837053, 0.803874112384084, 0.796518239159033, 0.789042534806467, 0.781448123998789, 0.773736149267035, 0.76590777082899, 0.757964166414642, 0.749906531088995, 0.741736077072283, 0.733454033557598, 0.725061646525966, 0.716560178558895, 0.707950908648432, 0.699235132004742, 0.690414159861254, 0.681489319277395, 0.672461952938941, 0.663333418956019, 0.654105090658787, 0.644778356390828, 0.635354619300277, 0.625835297128734, 0.616221821997965, 0.606515640194456, 0.596718211951823, 0.586831011231134, 0.576855525499155, 0.566793255504575, 0.556645715052225, 0.546414430775338, 0.536100941905873, 0.525706800042952, 0.515233568919429, 0.504682824166636, 0.49405615307734, 0.483355154366944, 0.472581437932973, 0.461736624612871, 0.450822345940161, 0.439840243898986, 0.428791970677089, 0.417679188417244, 0.406503568967204, 0.39526679362818, 0.383970552901897, 0.372616546236274, 0.361206481769749, 0.349742076074299, 0.338225053897198, 0.326657147901536, 0.315040098405551, 0.303375653120808, 0.291665566889271, 0.279911601419294, 0.268115525020586, 0.256279112338177, 0.244404144085436, 0.232492406776176, 0.220545692455878, 0.208565798432095, 0.196554527004056, 0.184513685191523, 0.172445084462932, 0.160350540462877, 0.148231872738948, 0.136090904468, 0.123929462181863, 0.111749375492553, 0.0995524768170189, 0.0873406011014653, 0.0751155855452987, 0.0628792693247314, 0.0506334933160884, 0.0383800998188613, 0.0261209322785436, 0.0138578350092972 ]
+
+histoTarget = [ 0.0, 0.00392156862745098, 0.00784313725490196, 0.0117647058823529, 0.0156862745098039, 0.0196078431372549, 0.0235294117647059, 0.0274509803921569, 0.0313725490196078, 0.0352941176470588, 0.0392156862745098, 0.0431372549019608, 0.0470588235294118, 0.0509803921568627, 0.0549019607843137, 0.0588235294117647, 0.0627450980392157, 0.0666666666666667, 0.0705882352941176, 0.0745098039215686, 0.0784313725490196, 0.0823529411764706, 0.0862745098039216, 0.0901960784313725, 0.0941176470588235, 0.0980392156862745, 0.101960784313725, 0.105882352941176, 0.109803921568627, 0.113725490196078, 0.117647058823529, 0.12156862745098, 0.125490196078431, 0.129411764705882, 0.133333333333333, 0.137254901960784, 0.141176470588235, 0.145098039215686, 0.149019607843137, 0.152941176470588, 0.156862745098039, 0.16078431372549, 0.164705882352941, 0.168627450980392, 0.172549019607843, 0.176470588235294, 0.180392156862745, 0.184313725490196, 0.188235294117647, 0.192156862745098, 0.196078431372549, 0.2, 0.203921568627451, 0.207843137254902, 0.211764705882353, 0.215686274509804, 0.219607843137255, 0.223529411764706, 0.227450980392157, 0.231372549019608, 0.235294117647059, 0.23921568627451, 0.243137254901961, 0.247058823529412, 0.250980392156863, 0.254901960784314, 0.258823529411765, 0.262745098039216, 0.266666666666667, 0.270588235294118, 0.274509803921569, 0.27843137254902, 0.282352941176471, 0.286274509803922, 0.290196078431373, 0.294117647058824, 0.298039215686275, 0.301960784313725, 0.305882352941176, 0.309803921568627, 0.313725490196078, 0.317647058823529, 0.32156862745098, 0.325490196078431, 0.329411764705882, 0.333333333333333, 0.337254901960784, 0.341176470588235, 0.345098039215686, 0.349019607843137, 0.352941176470588, 0.356862745098039, 0.36078431372549, 0.364705882352941, 0.368627450980392, 0.372549019607843, 0.376470588235294, 0.380392156862745, 0.384313725490196, 0.388235294117647, 0.392156862745098, 0.396078431372549, 0.4, 0.403921568627451, 0.407843137254902, 0.411764705882353, 0.415686274509804, 0.419607843137255, 0.423529411764706, 0.427450980392157, 0.431372549019608, 0.435294117647059, 0.43921568627451, 0.443137254901961, 0.447058823529412, 0.450980392156863, 0.454901960784314, 0.458823529411765, 0.462745098039216, 0.466666666666667, 0.470588235294118, 0.474509803921569, 0.47843137254902, 0.482352941176471, 0.486274509803922, 0.490196078431373, 0.494117647058824, 0.498039215686275, 0.501960784313725, 0.505882352941176, 0.509803921568627, 0.513725490196078, 0.517647058823529, 0.52156862745098, 0.525490196078431, 0.529411764705882, 0.533333333333333, 0.537254901960784, 0.541176470588235, 0.545098039215686, 0.549019607843137, 0.552941176470588, 0.556862745098039, 0.56078431372549, 0.564705882352941, 0.568627450980392, 0.572549019607843, 0.576470588235294, 0.580392156862745, 0.584313725490196, 0.588235294117647, 0.592156862745098, 0.596078431372549, 0.6, 0.603921568627451, 0.607843137254902, 0.611764705882353, 0.615686274509804, 0.619607843137255, 0.623529411764706, 0.627450980392157, 0.631372549019608, 0.635294117647059, 0.63921568627451, 0.643137254901961, 0.647058823529412, 0.650980392156863, 0.654901960784314, 0.658823529411765, 0.662745098039216, 0.666666666666667, 0.670588235294118, 0.674509803921569, 0.67843137254902, 0.682352941176471, 0.686274509803922, 0.690196078431373, 0.694117647058824, 0.698039215686274, 0.701960784313725, 0.705882352941177, 0.709803921568627, 0.713725490196078, 0.717647058823529, 0.72156862745098, 0.725490196078431, 0.729411764705882, 0.733333333333333, 0.737254901960784, 0.741176470588235, 0.745098039215686, 0.749019607843137, 0.752941176470588, 0.756862745098039, 0.76078431372549, 0.764705882352941, 0.768627450980392, 0.772549019607843, 0.776470588235294, 0.780392156862745, 0.784313725490196, 0.788235294117647, 0.792156862745098, 0.796078431372549, 0.8, 0.803921568627451, 0.807843137254902, 0.811764705882353, 0.815686274509804, 0.819607843137255, 0.823529411764706, 0.827450980392157, 0.831372549019608, 0.835294117647059, 0.83921568627451, 0.843137254901961, 0.847058823529412, 0.850980392156863, 0.854901960784314, 0.858823529411765, 0.862745098039216, 0.866666666666667, 0.870588235294118, 0.874509803921569, 0.87843137254902, 0.882352941176471, 0.886274509803922, 0.890196078431372, 0.894117647058824, 0.898039215686275, 0.901960784313726, 0.905882352941176, 0.909803921568627, 0.913725490196078, 0.917647058823529, 0.92156862745098, 0.925490196078431, 0.929411764705882, 0.933333333333333, 0.937254901960784, 0.941176470588235, 0.945098039215686, 0.949019607843137, 0.952941176470588, 0.956862745098039, 0.96078431372549, 0.964705882352941, 0.968627450980392, 0.972549019607843, 0.976470588235294, 0.980392156862745, 0.984313725490196, 0.988235294117647, 0.992156862745098, 0.996078431372549, 1.0 ]
+
+doc = krosskritacore.get("KritaDocument")
+image = doc.getImage()
+layer = image.getActivePaintLayer()
+if (layer.colorSpaceId() != "RGBA" ):
+ raise("This script works only for 8bit RGBA layers")
+
+width = layer.getWidth()
+height = layer.getHeight()
+
+countreshaping = 0
+while countreshaping < 1:
+ histo = layer.createHistogram("RGB8HISTO",0)
+ print "################################### histogram reshaping ##################################################"
+ if histo == 0:
+ raise "Uncompatible histogram\n"
+ print "Max : " + str( histo.getMax() ) + " Min : " + str( histo.getMin() )
+
+ #Compute the area of the target histogram
+ aireHistoTarget = 0.0
+ count = 0
+ while( count < 256 ) :
+ aireHistoTarget += histoTarget[count]
+ count += 1
+
+ #compute the table for the blue channel
+ histo.setChannel(0)
+ tableb = [ ]
+ histoMax = histo.getHighest()
+ aireHisto = width * height
+ coeff = aireHistoTarget / aireHisto
+ count = 0
+ position = 0
+ residu = 0.
+ while( count < 256 ) :
+ residu += histo.getValue(count) * coeff
+ while residu > 0.0:
+ residu -= histoTarget[position]
+ position += 1
+ tableb.append( position )
+ count += 1
+ #compute the table for the green channel
+ histo.setChannel(1)
+ tableg = [ ]
+ histoMax = histo.getHighest()
+ aireHisto = width * height
+ coeff = aireHistoTarget / aireHisto
+ count = 0
+ position = 0
+ residu = 0.
+ while( count < 256 ) :
+ residu += histo.getValue(count) * coeff
+ while residu > 0.0:
+ residu -= histoTarget[position]
+ position += 1
+ tableg.append( position )
+ count += 1
+ #compute the table for the red channel
+ histo.setChannel(2)
+ tabler = [ ]
+ histoMax = histo.getHighest()
+ aireHisto = width * height
+ coeff = aireHistoTarget / aireHisto
+ count = 0
+ position = 0
+ residu = 0.
+ while( count < 256 ) :
+ residu += histo.getValue(count) * coeff
+ while residu > 0.0:
+ residu -= histoTarget[position]
+ position += 1
+ tabler.append( position )
+ count += 1
+
+ it = layer.createRectIterator( 0, 0, width, height )
+ print "kikoo : " + str(countreshaping)
+ while (not it.isDone()) :
+ r = it.getRed()
+ g = it.getGreen()
+ b = it.getBlue()
+ #var = ( tabler[r] - r + tableg[g] - g + tableb[b] - b ) / 3
+ #ng = g + var
+ #nr = r + var
+ #nb = b + var
+ it.setRed(tabler[r])
+ it.setGreen(tableg[g])
+ it.setBlue(tableb[b])
+ it.next()
+
+ #histo.setChannel(0)
+ #diff = [ ]
+ #histoMax = histo.getHighest()
+ #count = 0
+ #while( count < 256 ) :
+ #v = histo.getValue(count)
+ #diff.append( v / histoMax - histoTarget[count])
+ #count += 1
+ #diffb = [ ]
+ #diffb.append(diff[1] - diff[0] )
+ #count = 1
+ #while( count < 255 ) :
+ #diffb.append((diff[count+1] - diff[count - 1])/2.0)
+ #count += 1
+ #diffb.append(diff[255] - diff[254] )
+
+ #histo.setChannel(1)
+ #diff = [ ]
+ #histoMax = histo.getHighest()
+ #count = 0
+ #while( count < 256 ) :
+ #v = histo.getValue(count)
+ #diff.append( v / histoMax - histoTarget[count])
+ #count += 1
+ #diffg = [ ]
+ #diffg.append(diff[1] - diff[0] )
+ #count = 1
+ #while( count < 255 ) :
+ #diffg.append((diff[count+1] - diff[count - 1])/2.0)
+ #count += 1
+ #diffg.append(diff[255] - diff[254] )
+
+ #histo.setChannel(2)
+ #diff = [ ]
+ #histoMax = histo.getHighest()
+ #count = 0
+ #while( count < 256 ) :
+ #v = histo.getValue(count)
+ #diff.append( v / histoMax - histoTarget[count])
+ #count += 1
+ #diffr = [ ]
+ #diffr.append(diff[1] - diff[0] )
+ #count = 1
+ #while( count < 255 ) :
+ #diffr.append((diff[count+1] - diff[count - 1])/2.0)
+ #count += 1
+ #diffr.append(diff[255] - diff[254] )
+
+
+ #histo.setChannel(0)
+ #diff = [ ]
+ #histoMax = histo.getHighest()
+ #count = 0
+ #while( count < 256 ) :
+ #v = histo.getValue(count)
+ #diff.append( v / histoMax - histoTarget[count])
+ #count += 1
+ #diffb = [ ]
+ #diffb.append( sign(diff[1] - diff[0] ) * abs(diff[0]) )
+ #count = 1
+ #while( count < 255 ) :
+ #diffb.append( sign(diff[count+1] - diff[count - 1]) * abs(diff[count]) )
+ #count += 1
+ #diffb.append( sign(diff[255] - diff[254] ) * abs(diff[255]) )
+
+ #histo.setChannel(1)
+ #diff = [ ]
+ #histoMax = histo.getHighest()
+ #count = 0
+ #while( count < 256 ) :
+ #v = histo.getValue(count)
+ #diff.append( v / histoMax - histoTarget[count])
+ #count += 1
+ #diffg = [ ]
+ #diffg.append( sign(diff[1] - diff[0] ) * abs(diff[0]) )
+ #count = 1
+ #while( count < 255 ) :
+ #diffg.append( sign(diff[count+1] - diff[count - 1]) * abs(diff[count]) )
+ #count += 1
+ #diffg.append( sign(diff[255] - diff[254] ) * abs(diff[255]) )
+
+ #histo.setChannel(2)
+ #diff = [ ]
+ #histoMax = histo.getHighest()
+ #count = 0
+ #while( count < 256 ) :
+ #v = histo.getValue(count)
+ #diff.append( v / histoMax - histoTarget[count])
+ #count += 1
+ #diffr = [ ]
+ #diffr.append( sign(diff[1] - diff[0] ) * abs(diff[0]) )
+ #count = 1
+ #while( count < 255 ) :
+ #diffr.append( sign(diff[count+1] - diff[count - 1]) * abs(diff[count]) )
+ #count += 1
+ #diffr.append( sign(diff[255] - diff[254] ) * abs(diff[255]) )
+
+
+ #print str(diffr) + " " + str(diff[count+1]) + " " + str(diff[count-1])
+
+ #histo.setChannel(0)
+ #diffb = computeDiff(histo, histoTarget)
+ #print "##########################"
+ #count = 0
+ #while( count < 256 ) :
+ #print count
+ #print " "
+ #print diffb[count]
+ #print "\n"
+ #count += 1
+
+ #histo.setChannel(1)
+ #diffg = computeDiff(histo, histoTarget)
+ #print "##########################"
+ #count = 0
+ #while( count < 256 ) :
+ #print count
+ #print " "
+ #print diffg[count]
+ #print "\n"
+ #count += 1
+
+ #histo.setChannel(2)
+ #diffr = computeDiff(histo, histoTarget)
+ #print "##########################"
+ #count = 0
+ #while( count < 256 ) :
+ #print count
+ #print " "
+ #print diffr[count]
+ #print "\n"
+ #count += 1
+
+ #it = layer.createRectIterator( 0, 0, width, height )
+ #print "kikoo : " + str(countreshaping)
+ #while (not it.isDone()) :
+ #r = it.getRed()
+ #g = it.getGreen()
+ #b = it.getBlue()
+ #coeff = 1.0 - ( diffr[r] + diffg[g] + diffb[b] ) / 3.0
+ ##print str(r) + " = " + str(diffr[r]) + " " + str(g) + " = " + str(diffg[g]) + " " + str(b) + " = " + str(diffb[b]) + " coeff = " + str(coeff)
+ #ng = g * coeff
+ #nr = r * coeff
+ #nb = b * coeff
+ #it.setRed(nr)
+ #it.setGreen(ng)
+ #it.setBlue(nb)
+ #it.next()
+ countreshaping += 1
+
+doc.notifyModification()
diff --git a/krita/plugins/viewplugins/scripting/samples/python/reshapehisto.rc b/krita/plugins/viewplugins/scripting/samples/python/reshapehisto.rc
new file mode 100644
index 00000000..481f5764
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/python/reshapehisto.rc
@@ -0,0 +1,9 @@
+<KrossScripting>
+ <ScriptAction
+ name="ReshapeHistogramPython"
+ text="Reshape Histogram (python)"
+ description="It's an experimental approach to improve color of image, it doesn't work as it, but it show how to use an histogram in a script :)"
+ icon=""
+ interpreter="python"
+ file="reshapehisto.py" />
+</KrossScripting>
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/Makefile.am b/krita/plugins/viewplugins/scripting/samples/ruby/Makefile.am
new file mode 100644
index 00000000..2aa79416
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/Makefile.am
@@ -0,0 +1,18 @@
+scriptsinvertdir = $(kde_datadir)/krita/scripts/invertruby
+scriptsinvert_SCRIPTS = invert.rb invertruby.rc
+
+scriptschangecsdir = $(kde_datadir)/krita/scripts/changecs
+scriptschangecs_SCRIPTS = changecs.rb changecs.rc
+
+scriptsrandompaintdir = $(kde_datadir)/krita/scripts/randompaint
+scriptsrandompaint_SCRIPTS = randompaint.rb randompaint.rc
+
+scriptsfilterstestdir = $(kde_datadir)/krita/scripts/filterstest
+scriptsfilterstest_SCRIPTS = filterstest.rb filterstest.rc
+
+scriptstorturefiltersdir = $(kde_datadir)/krita/scripts/torturefilters
+scriptstorturefilters_SCRIPTS = torture-filters.rb torture-filters.rc
+
+scriptstorturepaintingdir = $(kde_datadir)/krita/scripts/torturepainting
+scriptstorturepainting_SCRIPTS = torture-painting.rb torture-painting.rc
+
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/changecs.rb b/krita/plugins/viewplugins/scripting/samples/ruby/changecs.rb
new file mode 100644
index 00000000..f5d99a3f
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/changecs.rb
@@ -0,0 +1,5 @@
+require "krosskritacore"
+
+doc = Krosskritacore::get("KritaDocument")
+image = doc.getImage()
+image.convertToColorspace("LABA")
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/changecs.rc b/krita/plugins/viewplugins/scripting/samples/ruby/changecs.rc
new file mode 100644
index 00000000..4121693d
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/changecs.rc
@@ -0,0 +1,9 @@
+<KrossScripting>
+ <ScriptAction
+ name="ChangeColorspaceRuby"
+ text="Change Colorspace"
+ description="Demonstrate how to change the colorspace in a script"
+ icon=""
+ interpreter="ruby"
+ file="changecs.rb" />
+</KrossScripting>
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rb b/krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rb
new file mode 100644
index 00000000..20d42dbf
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rb
@@ -0,0 +1,31 @@
+# This file is part of Krita
+#
+# 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 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.
+
+require "krosskritacore"
+
+doc = Krosskritacore::get("KritaDocument")
+
+image = doc.getImage()
+layer = image.getActivePaintLayer()
+width = layer.getWidth()
+height = layer.getHeight()
+
+filter = Krosskritacore::getFilter("invert")
+
+filter.process(layer )
+filter.process(layer, 10, 10, 20, 20 )
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rc b/krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rc
new file mode 100644
index 00000000..2f8dfb98
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/filterstest.rc
@@ -0,0 +1,9 @@
+<KrossScripting>
+ <ScriptAction
+ name="FiltersTestRuby"
+ text="Filters Test"
+ description="Test of filters in scripting (ruby)"
+ icon=""
+ interpreter="ruby"
+ file="filterstest.rb" />
+</KrossScripting>
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/invert.rb b/krita/plugins/viewplugins/scripting/samples/ruby/invert.rb
new file mode 100644
index 00000000..0a055028
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/invert.rb
@@ -0,0 +1,45 @@
+# This file is part of Krita
+#
+# 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 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.
+
+require "krosskritacore"
+
+doc = Krosskritacore::get("KritaDocument")
+script = Krosskritacore::get("KritaScript")
+image = doc.getImage()
+layer = image.getActivePaintLayer()
+
+if(layer.colorSpaceId() != "RGBA" )
+ raise("This script works only for 8bit RGBA layers")
+end
+
+width = layer.getWidth()
+height = layer.getHeight()
+script.setProgressTotalSteps(width * height)
+layer.beginPainting("invert")
+it = layer.createRectIterator( 0, 0, width, height )
+while (it.isDone() == 0)
+ p = it.getRGBA()
+ p[0] = 255 - p[0]
+ p[1] = 255 - p[1]
+ p[2] = 255 - p[2]
+ it.setRGBA(p)
+ script.incProgress()
+ it.next()
+end
+
+layer.endPainting()
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/invertruby.rc b/krita/plugins/viewplugins/scripting/samples/ruby/invertruby.rc
new file mode 100644
index 00000000..9cc7bd6a
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/invertruby.rc
@@ -0,0 +1,9 @@
+<KrossScripting>
+ <ScriptAction
+ name="InvertRuby"
+ text="Invert (ruby)"
+ description="Invert the pixel of an image (ruby)"
+ icon=""
+ interpreter="ruby"
+ file="invert.rb" />
+</KrossScripting>
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rb b/krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rb
new file mode 100644
index 00000000..9e2f504f
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rb
@@ -0,0 +1,98 @@
+def randomizeStyle(painter)
+ painter.setFillStyle(4 *rand)
+ painter.setStrokeStyle(2 *rand)
+end
+
+require "krosskritacore"
+
+doc = Krosskritacore::get("KritaDocument")
+script = Krosskritacore::get("KritaScript")
+
+image = doc.getImage()
+layer = image.getActivePaintLayer()
+width = layer.getWidth()
+height = layer.getHeight()
+
+script.setProgressTotalSteps(110)
+layer.beginPainting("random paint")
+
+painter = layer.createPainter()
+
+# create painting color
+blackcolor = Krosskritacore::newRGBColor(0,0,0)
+
+# set painting color
+painter.setPaintColor( blackcolor )
+
+# get the brush
+brush = Krosskritacore::getBrush("Circle (05)")
+
+# define the brush
+painter.setBrush(brush)
+
+# get the pattern
+pattern = Krosskritacore::getPattern("Bricks")
+
+# set the pattern
+painter.setPattern(pattern)
+
+# define the paint operation
+painter.setPaintOp("paintbrush")
+
+# randomly paint
+for i in 1..10
+ # set painting color
+ painter.setPaintColor( Krosskritacore::newRGBColor(rand*255,rand*255,rand*255) )
+ painter.paintAt(rand * width , rand * height,1.1)
+ script.incProgress()
+end
+
+# randomly rect or circle paint
+for i in 1..100
+ # set painting color
+ painter.setPaintColor( Krosskritacore::newRGBColor(rand*255,rand*255,rand*255) )
+ painter.setBackgroundColor( Krosskritacore::newRGBColor(rand*255,rand*255,rand*255) )
+ painter.setOpacity( rand*255 )
+# set the brush
+ if(rand < 0.5)
+ painter.setBrush( Krosskritacore::newRectBrush(rand*20,rand*20,rand*10,rand*10) )
+ else
+ painter.setBrush( Krosskritacore::newCircleBrush(rand*20,rand*20,rand*10,rand*10) )
+ end
+ # paint a point
+ shape = rand * 7
+ painter.setStrokeStyle(1)
+ if( shape < 1 )
+ painter.paintAt(rand * width , rand * height,1.1)
+ elsif(shape < 2 )
+ xs = Array.new
+ ys = Array.new
+ for i in 0..6
+ xs[i] = rand*width
+ ys[i] = rand*height
+ end
+ painter.paintPolyline(xs,ys)
+ elsif(shape < 3)
+ painter.paintLine(rand * width, rand * height, 1.1, rand * width, rand * height,1.1)
+ elsif(shape < 4)
+ painter.paintBezierCurve(rand * width, rand * height, 1.1, rand * width, rand * height, rand * width , rand * height, rand * width, rand * height, 1.1)
+ elsif(shape < 5)
+ randomizeStyle(painter)
+ painter.paintEllipse(rand * width, rand * height, rand * width, rand * height, 1.1)
+ elsif(shape < 6)
+ xs = Array.new
+ ys = Array.new
+ for i in 0..6
+ xs[i] = rand*width
+ ys[i] = rand*height
+ end
+ randomizeStyle(painter)
+ painter.paintPolygon(xs, ys)
+ elsif(shape < 7)
+ randomizeStyle(painter)
+ painter.paintRect(rand * width, rand * height, rand * width, rand * height, 1.1)
+ end
+ script.incProgress()
+end
+
+layer.endPainting()
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rc b/krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rc
new file mode 100644
index 00000000..3697f700
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/randompaint.rc
@@ -0,0 +1,9 @@
+<KrossScripting>
+ <ScriptAction
+ name="RandomPaintRuby"
+ text="Random Paint"
+ description="Demonstrate how to use the Painter script API and paint random shape on screen"
+ icon=""
+ interpreter="ruby"
+ file="randompaint.rb" />
+</KrossScripting>
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rb b/krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rb
new file mode 100644
index 00000000..58cddcd6
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rb
@@ -0,0 +1,70 @@
+# This file is part of Krita
+#
+# 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.
+
+require "krosskritacore"
+
+doc = Krosskritacore::get("KritaDocument")
+
+image = doc.getImage()
+layer = image.getActivePaintLayer()
+
+def testFilter(layer, filterid)
+ print " applying filter ", filterid, "\n"
+ begin
+ filter = Krosskritacore::getFilter(filterid)
+ filter.process(layer)
+ rescue
+ print " WARNING: this filter is incompatible with this colorspace\n"
+ end
+end
+
+
+def testColorspace(layer, colorspaceid)
+ print "Testing for ", colorspaceid, "\n"
+ if (layer.colorSpaceId() != colorspaceid)
+ layer.convertToColorspace(colorspaceid)
+ end
+ testFilter(layer, "invert")
+ testFilter(layer, "bumpmap")
+ testFilter(layer, "cimg")
+ testFilter(layer, "desaturate")
+ testFilter(layer, "autocontrast")
+ testFilter(layer, "brightnesscontrast")
+ testFilter(layer, "gaussian blur")
+ testFilter(layer, "cubism")
+ testFilter(layer, "emboss")
+ testFilter(layer, "simplenoisereducer")
+ testFilter(layer, "waveletnoisereducer")
+ testFilter(layer, "oilpaint")
+ testFilter(layer, "pixelize")
+ testFilter(layer, "raindrops")
+ testFilter(layer, "roundcorners")
+ testFilter(layer, "smalltiles")
+ testFilter(layer, "sobel")
+end
+
+testColorspace(layer, "RGBA")
+testColorspace(layer, "RGBA16")
+testColorspace(layer, "RGBAF16HALF")
+testColorspace(layer, "RGBAF32")
+testColorspace(layer, "CMYK")
+testColorspace(layer, "CMYKA16")
+testColorspace(layer, "CMYK")
+testColorspace(layer, "CMYKA16")
+testColorspace(layer, "LABA")
+testColorspace(layer, "LMSAF32")
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rc b/krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rc
new file mode 100644
index 00000000..c56c2818
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/torture-filters.rc
@@ -0,0 +1,9 @@
+<KrossScripting>
+ <ScriptAction
+ name="TortureFiltersRuby"
+ text="Torture Krita with Filters"
+ description="Test all filters with all colorspaces (ruby)"
+ icon=""
+ interpreter="ruby"
+ file="torture-filters.rb" />
+</KrossScripting>
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rb b/krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rb
new file mode 100644
index 00000000..67042de2
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rb
@@ -0,0 +1,133 @@
+# This file is part of Krita
+#
+# 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.
+
+require "krosskritacore"
+
+class TorturePainting
+
+ def initialize()
+
+ doc = Krosskritacore::get("KritaDocument")
+ @script = Krosskritacore::get("KritaScript")
+
+ @image = doc.getImage()
+ @width = @image.getWidth()
+ @height = @image.getHeight()
+
+ @script.setProgressTotalSteps(30 * 10)
+
+ testColorspace("RGBA")
+ testColorspace("RGBA16")
+ testColorspace("RGBAF16HALF")
+ testColorspace("RGBAF32")
+ testColorspace("CMYK")
+ testColorspace("CMYKA16")
+ testColorspace("CMYK")
+ testColorspace("CMYKA16")
+ testColorspace("LABA")
+ testColorspace("LMSAF32")
+
+
+ end
+
+ def randomizeStyle(painter)
+ painter.setFillStyle(4 *rand)
+ painter.setStrokeStyle(2 *rand)
+ end
+
+
+ def testColorspace(cs)
+ print "Torturing for ", cs, "\n"
+ layer = @image.createPaintLayer("torture", 255 * rand, "RGBA" );
+ torture(layer)
+ end
+
+
+ def torture(layer)
+ layer.beginPainting("torture painting")
+
+ painter = layer.createPainter()
+
+ # create painting color
+ blackcolor = Krosskritacore::newRGBColor(0,0,0)
+
+ # set painting color
+ painter.setPaintColor( blackcolor )
+
+ # get the pattern
+ pattern = Krosskritacore::getPattern("Bricks")
+
+ # set the pattern
+ painter.setPattern(pattern)
+
+ # define the paint operation
+ painter.setPaintOp("paintbrush")
+
+ # randomly rect or circle paint
+ for i in 1..30
+ # set painting color
+ painter.setPaintColor( Krosskritacore::newRGBColor(rand*255,rand*255,rand*255) )
+ painter.setBackgroundColor( Krosskritacore::newRGBColor(rand*255,rand*255,rand*255) )
+ painter.setOpacity( rand*255 )
+ # set the brush
+ if(rand < 0.5)
+ painter.setBrush( Krosskritacore::newRectBrush(rand*20,rand*20,rand*10,rand*10) )
+ else
+ painter.setBrush( Krosskritacore::newCircleBrush(rand*20,rand*20,rand*10,rand*10) )
+ end
+ # paint a point
+ shape = rand * 7
+ painter.setStrokeStyle(1)
+ if( shape < 1 )
+ painter.paintAt(rand * @width , rand * @height,1.1)
+ elsif(shape < 2 )
+ xs = Array.new
+ ys = Array.new
+ for i in 0..6
+ xs[i] = rand*@width
+ ys[i] = rand*@height
+ end
+ painter.paintPolyline(xs,ys)
+ elsif(shape < 3)
+ painter.paintLine(rand * @width, rand * @height, 1.1, rand * @width, rand * @height,1.1)
+ elsif(shape < 4)
+ painter.paintBezierCurve(rand * @width, rand * @height, 1.1, rand * @width, rand * @height, rand * @width , rand * @height, rand * @width, rand * @height, 1.1)
+ elsif(shape < 5)
+ randomizeStyle(painter)
+ painter.paintEllipse(rand * @width, rand * @height, rand * @width, rand * @height, 1.1)
+ elsif(shape < 6)
+ xs = Array.new
+ ys = Array.new
+ for i in 0..6
+ xs[i] = rand*@width
+ ys[i] = rand*@height
+ end
+ randomizeStyle(painter)
+ painter.paintPolygon(xs, ys)
+ elsif(shape < 7)
+ randomizeStyle(painter)
+ painter.paintRect(rand * @width, rand * @height, rand * @width, rand * @height, 1.1)
+ end
+ @script.incProgress()
+ end
+ layer.endPainting()
+ end
+
+end
+
+TorturePainting.new() \ No newline at end of file
diff --git a/krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rc b/krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rc
new file mode 100644
index 00000000..6b54fa9d
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/samples/ruby/torture-painting.rc
@@ -0,0 +1,9 @@
+<KrossScripting>
+ <ScriptAction
+ name="TorturePainting"
+ text="Torture Krita with Painting"
+ description="Paint on an image and create multiple layers"
+ icon=""
+ interpreter="ruby"
+ file="torture-painting.rb" />
+</KrossScripting>
diff --git a/krita/plugins/viewplugins/scripting/scripting.cc b/krita/plugins/viewplugins/scripting/scripting.cc
new file mode 100644
index 00000000..d7f5fde7
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/scripting.cc
@@ -0,0 +1,111 @@
+/*
+ * This file is part of the KDE project
+ *
+ * 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 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 "scripting.h"
+
+#include <stdlib.h>
+#include <vector>
+
+#include <qapplication.h>
+#include <qpoint.h>
+
+#include <kdebug.h>
+#include <kfiledialog.h>
+#include <kgenericfactory.h>
+#include <kiconloader.h>
+#include <kinstance.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kstandarddirs.h>
+#include <ktempfile.h>
+
+#define KROSS_MAIN_EXPORT KDE_EXPORT
+#include <main/manager.h>
+#include <main/scriptguiclient.h>
+#include <main/wdgscriptsmanager.h>
+
+#include <kopalettemanager.h>
+
+#include <kis_doc.h>
+#include <kis_global.h>
+#include <kis_types.h>
+#include <kis_view.h>
+#include <kis_image.h>
+#include <kis_layer.h>
+
+#include "kritascripting/kis_script_progress.h"
+#include "kritascripting/kis_script_monitor.h"
+
+typedef KGenericFactory<Scripting> KritaScriptingFactory;
+K_EXPORT_COMPONENT_FACTORY( kritascripting, KritaScriptingFactory( "krita" ) )
+
+Scripting::Scripting(QObject *parent, const char *name, const QStringList &)
+ : KParts::Plugin(parent, name)
+{
+ setInstance(KritaScriptingFactory::instance());
+
+
+ if ( parent->inherits("KisView") )
+ {
+ setInstance(Scripting::instance());
+ m_view = (KisView*) parent;
+ m_scriptguiclient = new Kross::Api::ScriptGUIClient( m_view, m_view );
+// m_scriptguiclient ->setXMLFile(locate("data","kritaplugins/scripting.rc"), true);
+ //BEGIN TODO: understand why the ScriptGUIClient doesn't "link" its actions to the menu
+ setXMLFile(locate("data","kritaplugins/scripting.rc"), true);
+ new KAction(i18n("Execute Script File..."), 0, 0, m_scriptguiclient, SLOT(executeScriptFile()), actionCollection(), "executescriptfile");
+ new KAction(i18n("Script Manager..."), 0, 0, m_scriptguiclient, SLOT(showScriptManager()), actionCollection(), "configurescripts");
+ //END TODO
+
+ QWidget * w = new Kross::Api::WdgScriptsManager(m_scriptguiclient, m_view);
+
+ m_view->canvasSubject()->paletteManager()->addWidget(w, "Scripts Manager", krita::LAYERBOX, 10, PALETTE_DOCKER, false);
+
+ connect(m_scriptguiclient, SIGNAL(executionFinished( const Kross::Api::ScriptAction* )), this, SLOT(executionFinished(const Kross::Api::ScriptAction*)));
+ connect(m_scriptguiclient, SIGNAL(executionStarted( const Kross::Api::ScriptAction* )), this, SLOT(executionStarted(const Kross::Api::ScriptAction*)));
+ KisScriptMonitor::instance()->monitor( m_scriptguiclient );
+
+ Kross::Api::Manager::scriptManager()->addQObject(m_view->canvasSubject()->document(), "KritaDocument");
+ Kross::Api::Manager::scriptManager()->addQObject(m_view, "KritaView");
+ m_scriptProgress = new KisScriptProgress(m_view);
+ Kross::Api::Manager::scriptManager()->addQObject(m_scriptProgress, "KritaScriptProgress");
+
+ }
+
+}
+
+Scripting::~Scripting()
+{
+}
+
+void Scripting::executionFinished(const Kross::Api::ScriptAction*)
+{
+ m_view->canvasSubject()->document()->setModified(true);
+ m_view->canvasSubject()->document()->currentImage()->activeLayer()->setDirty();
+ m_scriptProgress->progressDone();
+ QApplication::restoreOverrideCursor();
+}
+
+void Scripting::executionStarted(const Kross::Api::ScriptAction* act)
+{
+ kdDebug(41011) << act->getPackagePath() << endl;
+ m_scriptProgress->setPackagePath( act->getPackagePath() );
+}
+
+
+#include "scripting.moc"
diff --git a/krita/plugins/viewplugins/scripting/scripting.h b/krita/plugins/viewplugins/scripting/scripting.h
new file mode 100644
index 00000000..238483c8
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/scripting.h
@@ -0,0 +1,53 @@
+/*
+ * This file is part of Krita
+ *
+ * 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 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 SCRIPTING_H
+#define SCRIPTING_H
+
+#include <kparts/plugin.h>
+
+class KisView;
+class KisScript;
+class KisScriptProgress;
+
+namespace Kross {
+ namespace Api {
+ class ScriptGUIClient;
+ class ScriptAction;
+ }
+}
+
+class Scripting : public KParts::Plugin
+{
+ Q_OBJECT
+ public:
+ Scripting(QObject *parent, const char *name, const QStringList &);
+ virtual ~Scripting();
+ private slots:
+ void executionFinished(const Kross::Api::ScriptAction*);
+ void executionStarted(const Kross::Api::ScriptAction*);
+ private:
+ KisView * m_view;
+ Kross::Api::ScriptGUIClient* m_scriptguiclient;
+ KisScriptProgress* m_scriptProgress;
+};
+
+
+#endif
diff --git a/krita/plugins/viewplugins/scripting/scripting.rc b/krita/plugins/viewplugins/scripting/scripting.rc
new file mode 100644
index 00000000..8d2ba496
--- /dev/null
+++ b/krita/plugins/viewplugins/scripting/scripting.rc
@@ -0,0 +1,10 @@
+<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd">
+<kpartgui library="kritascripting" version="3">
+ <MenuBar>
+ <Menu name="Scripts"><text>S&amp;cripts</text>
+ <Separator/>
+ <Action name="executescriptfile"/>
+ <Action name="configurescripts"/>
+ </Menu>
+ </MenuBar>
+</kpartgui>