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 be1c4f08 authored by Cyrille Berger's avatar Cyrille Berger

reintroduce a paint layer

svn path=/trunk/koffice/; revision=663995
parent 60d8a814
......@@ -17,7 +17,7 @@
*/
#include "krs_image.h"
#include "krs_paint_device.h"
#include "krs_paint_layer.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 PaintDevice(this, activePaintLayer->paintDevice(), m_doc);
return new PaintLayer(this, activePaintLayer, m_doc);
kWarning() << "The active layer is not paintable." << endl;
return 0;
}
......@@ -113,8 +113,8 @@ QObject* Image::createPaintLayer(const QString& name, int opacity, const QString
KisPaintLayer* layer = cs ? new KisPaintLayer(m_image.data(), name, opacity, cs)
: new KisPaintLayer(m_image.data(), name, opacity);
layer->setVisible(true);
m_image->addLayer(KisLayerSP(layer), m_image->rootLayer(), KisLayerSP(0));
return new PaintDevice(this, layer->paintDevice() );
m_image->addLayer(layer, m_image->rootLayer(), 0);
return new PaintLayer(this, layer, m_doc);
}
#include "krs_image.moc"
......@@ -16,8 +16,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KROSS_KRITACOREKRSLAYER_H
#define KROSS_KRITACOREKRSLAYER_H
#ifndef KROSS_KRITACOREKRSPAINTDEVICE_H
#define KROSS_KRITACOREKRSPAINTDEVICE_H
#include <QObject>
......
#if 0
/*
* Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
* Copyright (c) 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
......@@ -19,29 +17,19 @@
*/
#include "krs_paint_layer.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"
#include "krs_image.h"
#include "krs_paint_device.h"
using namespace Scripting;
PaintLayer::PaintLayer(Image* image, KisPaintLayerSP layer, KisDoc2* doc)
: QObject(image)
, m_image(image)
, m_layer(layer)
, m_doc(doc)
, m_cmd(0)
......@@ -54,191 +42,9 @@ PaintLayer::~PaintLayer()
{
}
int PaintLayer::width()
{
QRect r1 = paintLayer()->extent();
QRect r2 = paintLayer()->image()->bounds();
QRect rect = r1.intersect(r2);
return rect.width();
}
int PaintLayer::height()
{
QRect r1 = paintLayer()->extent();
QRect r2 = paintLayer()->image()->bounds();
QRect rect = r1.intersect(r2);
return rect.height();
}
QString PaintLayer::colorSpaceId()
{
return paintLayer()->paintDevice()->colorSpace()->id();
}
bool PaintLayer::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;
}
paintLayer()->paintDevice()->convertTo(dstCS);
return true;
}
QObject* PaintLayer::createRectIterator(uint x, uint y, uint width, uint height)
QObject* PaintLayer::paintDevice()
{
return new Iterator<KisRectIteratorPixel>(this,
paintLayer()->paintDevice()->createRectIterator(x, y, width, height));
return new PaintDevice(m_image, paintLayer()->paintDevice(), m_doc);
}
QObject* PaintLayer::createHLineIterator(uint x, uint y, uint width)
{
return new Iterator<KisHLineIteratorPixel>(this,
paintLayer()->paintDevice()->createHLineIterator(x, y, width));
}
QObject* PaintLayer::createVLineIterator(uint x, uint y, uint height)
{
return new Iterator<KisVLineIteratorPixel>(this,
paintLayer()->paintDevice()->createVLineIterator(x, y, height));
}
QObject* PaintLayer::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( paintLayer()->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* PaintLayer::createPainter()
{
return new Painter(this);
}
void PaintLayer::beginPainting(const QString& name)
{
if(m_cmd != 0)
{
delete m_cmd;
}
m_cmd = new KisTransaction(name, paintLayer()->paintDevice());
Q_CHECK_PTR(m_cmd);
}
void PaintLayer::endPainting()
{
if(doc() !=0)
{
doc()->setModified(true);
doc()->image()->activeLayer()->setDirty();
}
if(m_cmd != 0)
{
paintLayer()->image()->undoAdapter()->addCommand(m_cmd);
}
}
QObject* PaintLayer::fastWaveletTransformation()
{
KisMathToolbox* mathToolbox = KisMetaRegistry::instance()->mtRegistry()->value( paintLayer()->paintDevice()->colorSpace()->mathToolboxId().id() );
QRect rect = paintLayer()->exactBounds();
KisMathToolbox::KisWavelet* wav = mathToolbox->fastWaveletTransformation(paintLayer()->paintDevice(), rect);
return new Wavelet(wav);
}
bool PaintLayer::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( paintLayer()->paintDevice()->colorSpace()->mathToolboxId().id() );
QRect rect = paintLayer()->exactBounds();
mathToolbox->fastWaveletUntransformation( paintLayer()->paintDevice(), rect, wav->wavelet() );
return true;
}
QObject* PaintLayer::clone()
{
KisPaintLayerSP pl = new KisPaintLayer(*paintLayer());
return new PaintLayer(0, pl);
}
#if 0
QByteArray PaintLayer::bytes()
{
qint32 pixelsize = paintLayer()->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);
paintLayer()->paintDevice()->readBytes(data, 0, 0, w, h);
for(int i = 0; i < size; ++i)
out << data[i];
delete [] data;
// kDebug()<<"PaintLayer::bytes width="<<w<<" height="<<h<<" pixelsize="<<pixelsize<<" size="<<size<<endl;
return bytearray;
}
bool PaintLayer::setBytes(const QByteArray& bytearray)
{
qint32 pixelsize = paintLayer()->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];
paintLayer()->paintDevice()->writeBytes(data, 0, 0, w, h);
delete [] data;
return true;
}
#endif
#include "krs_paint_layer.moc"
#endif
#if 0
/*
* Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
* Copyright (c) 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
......@@ -18,8 +16,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KROSS_KRITACOREKRSLAYER_H
#define KROSS_KRITACOREKRSLAYER_H
#ifndef KROSS_KRITACOREKRSPAINTLAYER_H
#define KROSS_KRITACOREKRSPAINTLAYER_H
#include <QObject>
......@@ -45,171 +43,14 @@ class PaintLayer : public QObject
virtual ~PaintLayer();
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().activePaintLayer()
* 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
* to work direct on the mem-data from within
* scripting-languages).
*
* The returned array of bytes has n items where n is
* height * width * number of bytes per pixel. Each pixel
* is represented by >= 1 bytes depending on the used
* colorspace (e.g. for RGBA we have 4 bytes per pixel).
*
* For example (in Python) :
* @code
* import Krita, struct, array
* layer = Krita.image().activePaintLayer()
* ba = layer.bytes()
* a = array.array('B', [ (255 - struct.unpack("B",ba[i])[0]) for i in range(len(ba)) ] )
* layer.setBytes( a.tostring() )
* @endcode
*/
QByteArray bytes();
bool setBytes(const QByteArray& bytearray);
#endif
QObject* paintDevice();
public:
inline KisPaintLayerSP paintLayer() { return m_layer; }
inline const KisPaintLayerSP paintLayer() const { return m_layer; }
inline KisDoc2* doc() { return m_doc; }
private:
Image* m_image;
KisPaintLayerSP m_layer;
KisDoc2* m_doc;
KisTransaction* m_cmd;
......@@ -218,5 +59,3 @@ class PaintLayer : public QObject
}
#endif
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment