Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 9fec2a11 authored by Cyrille Berger's avatar Cyrille Berger

take advantage of the scripting api breakage to seperate the paint layer from...

take advantage of the scripting api breakage to seperate the paint layer from the device in the scripting API as well.

svn path=/trunk/koffice/; revision=663990
parent 69204e38
......@@ -4,6 +4,7 @@ set(krossmodulekrita_LIB_SRCS
krs_module.cpp
krs_progress.cpp
krs_paint_layer.cpp
krs_paint_device.cpp
krs_image.cpp
krs_histogram.cpp
krs_painter.cpp
......
......@@ -18,7 +18,7 @@
#include "krs_filter.h"
#include "krs_module.h"
#include "krs_paint_layer.h"
#include "krs_paint_device.h"
#include <kis_filter.h>
#include <kis_paint_layer.h>
......@@ -72,36 +72,36 @@ const QString Filter::toXML()
bool Filter::process(QObject* layer)
{
PaintLayer* paintlayer = dynamic_cast< PaintLayer* >(layer);
if(! paintlayer || ! m_filter->workWith( paintlayer->paintLayer()->paintDevice()->colorSpace()))
PaintDevice* paintDevice = dynamic_cast< PaintDevice* >(layer);
if(! paintDevice || ! m_filter->workWith( paintDevice->paintDevice()->colorSpace()))
{
kWarning() << i18n("An error has occurred in %1",QString("process")) << endl;
return false;
}
QRect r1 = paintlayer->paintLayer()->paintDevice()->extent();
QRect r1 = paintDevice->paintDevice()->extent();
QRect rect;
if(paintlayer->paintLayer()->image())
if(paintDevice->paintDevice()->image())
{
QRect r2 = paintlayer->paintLayer()->image()->bounds();
QRect r2 = paintDevice->paintDevice()->image()->bounds();
rect = r1.intersect(r2);
} else {
rect = r1;
}
m_filter->process(paintlayer->paintLayer()->paintDevice(), rect, 0/*m_filter->configuration()*/);
m_filter->process(paintDevice->paintDevice(), rect, 0/*m_filter->configuration()*/);
return true;
}
bool Filter::process(QObject* layer, int x, int y, int width, int height)
{
PaintLayer* paintlayer = dynamic_cast< PaintLayer* >(layer);
if(! paintlayer || ! m_filter->workWith( paintlayer->paintLayer()->paintDevice()->colorSpace()))
PaintDevice* paintDevice = dynamic_cast< PaintDevice* >(layer);
if(! paintDevice || ! m_filter->workWith( paintDevice->paintDevice()->colorSpace()))
{
kWarning() << i18n("An error has occurred in %1",QString("process")) << endl;
return false;
}
QRect rect(x, y, width, height);
m_filter->process(paintlayer->paintLayer()->paintDevice(), rect, 0/*m_filter->configuration()*/);
m_filter->process(paintDevice->paintDevice(), rect, 0/*m_filter->configuration()*/);
return true;
}
......
......@@ -17,17 +17,17 @@
*/
#include "krs_histogram.h"
#include "krs_paint_layer.h"
#include "krs_paint_device.h"
#include <kis_paint_layer.h>
using namespace Scripting;
Histogram::Histogram(PaintLayer* layer, KoHistogramProducerSP producer, const enumHistogramType type)
Histogram::Histogram(PaintDevice* layer, KoHistogramProducerSP producer, const enumHistogramType type)
: QObject(layer)
{
setObjectName("KritaHistogram");
m_histogram = new KisHistogram(layer->paintLayer(), producer, type);
m_histogram = new KisHistogram(layer->paintDevice(), producer, type);
}
Histogram::~Histogram()
......
......@@ -26,16 +26,16 @@
namespace Scripting {
class PaintLayer;
class PaintDevice;
/**
* This class allow to access the histogram of a \a PaintLayer object.
* This class allow to access the histogram of a \a PaintDevice object.
*
* Example (in Ruby) :
* @code
* require "Krita"
* image = Krita.image()
* layer = image.activePaintLayer()
* layer = image.activePaintDevice()
* histo = layer.createHistogram("RGB8HISTO",0)
* min = histo.min() * 255
* max = histo.max() * 255
......@@ -48,7 +48,7 @@ class Histogram : public QObject
{
Q_OBJECT
public:
Histogram(PaintLayer* layer, KoHistogramProducerSP producer, const enumHistogramType type);
Histogram(PaintDevice* layer, KoHistogramProducerSP producer, const enumHistogramType type);
~Histogram();
public slots:
......
......@@ -17,7 +17,7 @@
*/
#include "krs_image.h"
#include "krs_paint_layer.h"
#include "krs_paint_device.h"
#include "krs_module.h"
#include <klocale.h>
......@@ -49,7 +49,7 @@ QObject* Image::activePaintLayer()
{
KisPaintLayer* activePaintLayer = dynamic_cast< KisPaintLayer* >(m_image->activeLayer().data());
if(activePaintLayer)
return new PaintLayer(this, KisPaintLayerSP(activePaintLayer), m_doc);
return new PaintDevice(this, activePaintLayer->paintDevice(), m_doc);
kWarning() << "The active layer is not paintable." << endl;
return 0;
}
......@@ -114,7 +114,7 @@ QObject* Image::createPaintLayer(const QString& name, int opacity, const QString
: new KisPaintLayer(m_image.data(), name, opacity);
layer->setVisible(true);
m_image->addLayer(KisLayerSP(layer), m_image->rootLayer(), KisLayerSP(0));
return new PaintLayer(this, KisPaintLayerSP(layer));
return new PaintDevice(this, layer->paintDevice() );
}
#include "krs_image.moc"
......@@ -27,9 +27,8 @@
#include <KoColorTransformation.h>
#include "krs_paint_layer.h"
#include "krs_paint_device.h"
#include <kis_paint_layer.h>
#include <kis_paint_device.h>
#include <kis_types.h>
......@@ -141,10 +140,10 @@ template<class _T_It>
class Iterator : public IteratorBase
{
public:
Iterator(PaintLayer* layer, _T_It it)
Iterator(PaintDevice* layer, _T_It it)
: IteratorBase(layer)
, m_it(new _T_It(it))
, m_layer(layer->paintLayer())
, m_layer(layer->paintDevice())
{
}
......@@ -178,26 +177,26 @@ class Iterator : public IteratorBase
QVariant channel(uint channelnr)
{
QList<KoChannelInfo*> channels = m_layer->paintDevice()->colorSpace()->channels();
QList<KoChannelInfo*> channels = m_layer->colorSpace()->channels();
return channelnr < uint(channels.count()) ? channelValue(channels[channelnr]) : QVariant();
}
void setChannel(uint channelnr, const QVariant& value)
{
QList<KoChannelInfo*> channels = m_layer->paintDevice()->colorSpace()->channels();
QList<KoChannelInfo*> channels = m_layer->colorSpace()->channels();
if(channelnr < uint(channels.count()))
setChannelValue(channels[channelnr], value);
}
uint channelCount()
{
return m_layer->paintDevice()->colorSpace()->channels().count();
return m_layer->colorSpace()->channels().count();
}
QVariantList pixel()
{
QVariantList pixel;
QList<KoChannelInfo*> channels = m_layer->paintDevice()->colorSpace()->channels();
QList<KoChannelInfo*> channels = m_layer->colorSpace()->channels();
for(QList<KoChannelInfo*>::iterator itC = channels.begin(); itC != channels.end(); ++itC)
pixel.push_back( channelValue(*itC) );
return pixel;
......@@ -205,7 +204,7 @@ class Iterator : public IteratorBase
void setPixel(QVariantList pixel)
{
QList<KoChannelInfo *> channels = m_layer->paintDevice()->colorSpace()->channels();
QList<KoChannelInfo *> channels = m_layer->colorSpace()->channels();
uint i = 0;
const uint size = pixel.size();
for(QList<KoChannelInfo *>::iterator itC = channels.begin(); itC != channels.end() && i < size; ++itC, ++i)
......@@ -214,14 +213,14 @@ class Iterator : public IteratorBase
void invertColor()
{
KoColorTransformation* invertTransfo = m_layer->paintDevice()->colorSpace()->createInvertTransformation();
KoColorTransformation* invertTransfo = m_layer->colorSpace()->createInvertTransformation();
invertTransfo->transform(m_it->oldRawData(), m_it->rawData(), 1);
delete invertTransfo; // FIXME don't create an invert transfo each time
}
void darken(int shade, bool compensate, double compensation)
{
KoColorTransformation* transfo = m_layer->paintDevice()->colorSpace()->createDarkenAdjustement(shade, compensate, compensation);
KoColorTransformation* transfo = m_layer->colorSpace()->createDarkenAdjustement(shade, compensate, compensation);
transfo->transform(m_it->rawData(), m_it->rawData(), 1);
delete transfo;
}
......@@ -270,7 +269,7 @@ class Iterator : public IteratorBase
private:
_T_It* m_it;
KisPaintLayerSP m_layer;
KisPaintDeviceSP m_layer;
};
}
......
/*
* Copyright (c) 2005,2007 Cyrille Berger <cberger@cberger.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "krs_paint_device.h"
#include "krs_image.h"
#include <QBuffer>
#include <klocale.h>
#include <KoColorSpaceRegistry.h>
#include <kis_doc2.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 <kis_undo_adapter.h>
#include "krs_iterator.h"
#include "krs_histogram.h"
#include "krs_painter.h"
#include "krs_wavelet.h"
using namespace Scripting;
PaintDevice::PaintDevice(Image* image, KisPaintDeviceSP device, KisDoc2* doc)
: QObject(image)
, m_device(device)
, m_doc(doc)
, m_cmd(0)
{
setObjectName("KritaLayer");
}
PaintDevice::~PaintDevice()
{
}
int PaintDevice::width()
{
QRect r1 = paintDevice()->extent();
QRect r2 = paintDevice()->image()->bounds();
QRect rect = r1.intersect(r2);
return rect.width();
}
int PaintDevice::height()
{
QRect r1 = paintDevice()->extent();
QRect r2 = paintDevice()->image()->bounds();
QRect rect = r1.intersect(r2);
return rect.height();
}
QString PaintDevice::colorSpaceId()
{
return paintDevice()->colorSpace()->id();
}
bool PaintDevice::convertToColorspace(const QString& colorspacename)
{
KoColorSpace * dstCS = KoColorSpaceRegistry::instance()->colorSpace(colorspacename, 0);
if(!dstCS)
{
kWarning() << QString("Colorspace %1 is not available, please check your installation.").arg(colorspacename) << endl;
return false;
}
paintDevice()->convertTo(dstCS);
return true;
}
QObject* PaintDevice::createRectIterator(uint x, uint y, uint width, uint height)
{
return new Iterator<KisRectIteratorPixel>(this,
paintDevice()->createRectIterator(x, y, width, height));
}
QObject* PaintDevice::createHLineIterator(uint x, uint y, uint width)
{
return new Iterator<KisHLineIteratorPixel>(this,
paintDevice()->createHLineIterator(x, y, width));
}
QObject* PaintDevice::createVLineIterator(uint x, uint y, uint height)
{
return new Iterator<KisVLineIteratorPixel>(this,
paintDevice()->createVLineIterator(x, y, height));
}
QObject* PaintDevice::createHistogram(const QString& histoname, uint typenr)
{
KoHistogramProducerFactory* factory = KoHistogramProducerFactoryRegistry::instance()->value(histoname);
/*
QList<KoID> listID = KisHistogramProducerFactoryRegistry::instance()->listKeys();
for(QList<KoID>::iterator it = listID.begin(); it != listID.end(); it++)
kDebug(41011) << (*it).name() << " " << (*it).id() << endl;
*/
enumHistogramType type ;
switch(typenr)
{
case 1:
type = LOGARITHMIC;
break;
case 0:
default:
type = LINEAR;
break;
}
if(factory && factory->isCompatibleWith( paintDevice()->colorSpace() ))
return new Histogram(this, factory->generate() , type);
kWarning() << QString("An error has occurred in %1\n%2").arg("createHistogram").arg( QString("The histogram %1 is not available").arg(histoname) );
return 0;
}
QObject* PaintDevice::createPainter()
{
return new Painter(this);
}
void PaintDevice::beginPainting(const QString& name)
{
if(m_cmd != 0)
{
delete m_cmd;
}
m_cmd = new KisTransaction(name, paintDevice());
Q_CHECK_PTR(m_cmd);
}
void PaintDevice::endPainting()
{
if(doc() !=0)
{
doc()->setModified(true);
doc()->image()->activeLayer()->setDirty();
}
if(m_cmd != 0)
{
paintDevice()->image()->undoAdapter()->addCommand(m_cmd);
}
}
QObject* PaintDevice::fastWaveletTransformation()
{
KisMathToolbox* mathToolbox = KisMetaRegistry::instance()->mtRegistry()->value( paintDevice()->colorSpace()->mathToolboxId().id() );
QRect rect = paintDevice()->exactBounds();
KisMathToolbox::KisWavelet* wav = mathToolbox->fastWaveletTransformation(paintDevice(), rect);
return new Wavelet(wav);
}
bool PaintDevice::fastWaveletUntransformation(QObject* wavelet)
{
Wavelet* wav = dynamic_cast< Wavelet* >(wavelet);
if(! wav) {
kWarning() << "The passed argument is not a valid Wavelet-object." << endl;
return false;
}
KisMathToolbox* mathToolbox = KisMetaRegistry::instance()->mtRegistry()->value( paintDevice()->colorSpace()->mathToolboxId().id() );
QRect rect = paintDevice()->exactBounds();
mathToolbox->fastWaveletUntransformation( paintDevice(), rect, wav->wavelet() );
return true;
}
QObject* PaintDevice::clone()
{
KisPaintDeviceSP pl = new KisPaintDevice(*paintDevice());
return new PaintDevice(0, pl);
}
#if 0
QByteArray PaintDevice::bytes()
{
qint32 pixelsize = paintDevice()->colorSpace()->pixelSize();
const int w = width();
const int h = height();
const int size = w * h * pixelsize;
Q_ASSERT(size >= 0);
QByteArray bytearray;
QBuffer buffer(&bytearray);
buffer.open(QIODevice::WriteOnly);
QDataStream out(&buffer);
quint8* data = new quint8[size];
Q_CHECK_PTR(data);
paintDevice()->readBytes(data, 0, 0, w, h);
for(int i = 0; i < size; ++i)
out << data[i];
delete [] data;
// kDebug()<<"PaintDevice::bytes width="<<w<<" height="<<h<<" pixelsize="<<pixelsize<<" size="<<size<<endl;
return bytearray;
}
bool PaintDevice::setBytes(const QByteArray& bytearray)
{
qint32 pixelsize = paintDevice()->colorSpace()->pixelSize();
const int w = width();
const int h = height();
const int size = w * h * pixelsize;
if(size < 0 || bytearray.size() < size)
return false;
QBuffer buffer(&bytearray);
buffer.open(QIODevice::ReadOnly);
QDataStream in(&buffer);
quint8* data = new quint8[size];
Q_CHECK_PTR(data);
for(int i = 0; i < size; ++i)
in >> data[i];
paintDevice()->writeBytes(data, 0, 0, w, h);
delete [] data;
return true;
}
#endif
#include "krs_paint_device.moc"
/*
* Copyright (c) 2005,2007 Cyrille Berger <cberger@cberger.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KROSS_KRITACOREKRSLAYER_H
#define KROSS_KRITACOREKRSLAYER_H
#include <QObject>
#include <kis_types.h>
#include <kis_paint_layer.h>
class KisDoc2;
class KisTransaction;
namespace Scripting {
class Image;
/**
* A PaintDevice is a layer within a \a Image where you are able
* to perform paint-operations on.
*/
class PaintDevice : public QObject
{
Q_OBJECT
public:
explicit PaintDevice(Image* image, KisPaintDeviceSP layer, KisDoc2* doc = 0);
virtual ~PaintDevice();
public slots:
/**
* Return the width of the layer.
*/
int width();
/**
* Return the height of the layer.
*/
int height();
/**
* Return the id of the colorspace of this image (e.g. "RGBA" or "CMYK").
*/
QString colorSpaceId();
/**
* Convert the image to a colorspace.
* This function takes one argument :
* - the name of the destination colorspace
* This function returns true if convert to the
* colorspace was successfully else (e.g. if the
* colorspace is not available, please check your
* installation in that case) false is returned.
*
* For example (in Ruby) :
* @code
* # set the colorspace to "CMYK"
* image.convertToColorspace("CMYK")
* # following line will print "CMYK" now.
* image.colorSpaceId()
* @endcode
*/
bool convertToColorspace(const QString& colorspacename);
/**
* 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
*/
QObject* createRectIterator(uint x, uint y, uint width, uint height);
/**
* 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
*/
QObject* createHLineIterator(uint x, uint y, uint width);
/**
* 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
*/
QObject* createVLineIterator(uint x, uint y, uint height);
/**
* 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
*/
QObject* createHistogram(const QString& histoname, uint typenr);
/**
* This function create a \a Painter which will allow you to some
* painting on the layer.
*/
QObject* createPainter();
/**
* Uses this function to create a new undo entry. The \p name
* is the displayed undo-name. You should always close the
* paint-operation with \a endPainting() .
*
* For example (in Ruby) :
* @code
* require "Krita"
* layer = Krita.image().activePaintDevice()
* layer.beginPainting("invert")
* iterator = layer.createRectIterator(0, 0, layer.width(), layer.height())
* while (not iterator.isDone())
* iterator.invertColor()
* iterator.next()
* end
* layer.endPainting()
* @endcode
*/
void beginPainting(const QString& name);
/**
* Uses this function to close the current undo entry and add it to
* the history. This function closes the with \a beginPainting()
* started painting-operation.
*/
void endPainting();
/**
* Return the fast \a Wavelet transformed of the layer.
*/
QObject* fastWaveletTransformation();
/**
* Untransform a fast \a Wavelet into this layer.
* It takes one argument :
* - a wavelet object
* It returns true on success else (e.g. cause no valid \a Wavelet
* object was passed as argument) false is returned.
*
* For example (in Ruby) :
* @code
* wavelet = layer.fastWaveletTransformation()
* layer.fastWaveletUntransformation(wavelet)
* @endcode
*/
bool fastWaveletUntransformation(QObject* wavelet);
/**
* clone this paint layer, making a deep copy.
*/
QObject* clone();
#if 0
//Disabled yet cause it's not wanted to expose the Krita internals.
/**
* Returns or sets the raw-bytes the layer has.
*
* Please note, that it is NOT recommed to use that
* functionality since they bypass Krita's undo/redo
* mechanism as well as the integrated swapping-technology
* and may consume a lot of RAM cause the whole image
* is readed into it (what provides us the possibility