Commit 05c86757 authored by Boudewijn Rempt's avatar Boudewijn Rempt

* remove obsolete extent visitor (which was used way back when we had the

cool feature that you could see the contents of layers outside the image boundaries)
* make sure all visitors implement all node types
* some more fixes for saving and loading (but local selections aren't saved yet, don't
know why yet)

svn path=/trunk/koffice/; revision=891620
parent e6adcc4c
......@@ -75,6 +75,7 @@ set(kritaimage_LIB_SRCS
kis_bottom_up_update_strategy.cpp
kis_boundary.cc
kis_clone_layer.cpp
kis_colorspace_convert_visitor.cpp
kis_config_widget.cpp
kis_convolution_kernel.cc
kis_convolution_painter.cc
......
......@@ -341,6 +341,13 @@ public:
}
bool visit(KisNode*) { return true; }
bool visit(KisFilterMask*) { return true; }
bool visit(KisTransparencyMask*) { return true; }
bool visit(KisTransformationMask*) { return true; }
bool visit(KisSelectionMask*) { return true; }
private:
// Helper for the indirect painting
template<class Target>
......
......@@ -85,6 +85,13 @@ public:
return true;
}
bool visit(KisNode*) { return true; }
bool visit( KisCloneLayer* ) { return true; }
bool visit(KisFilterMask*) { return true; }
bool visit(KisTransparencyMask*) { return true; }
bool visit(KisTransformationMask*) { return true; }
bool visit(KisSelectionMask*) { return true; }
private:
bool updatePaintDevice(KisLayer * layer) {
......
/*
* Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
*
* 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 "kis_colorspace_convert_visitor.h"
KisColorSpaceConvertVisitor::KisColorSpaceConvertVisitor(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent) :
KisNodeVisitor(),
m_dstColorSpace(dstColorSpace),
m_renderingIntent(renderingIntent)
{
}
KisColorSpaceConvertVisitor::~KisColorSpaceConvertVisitor()
{
}
bool KisColorSpaceConvertVisitor::visit(KisGroupLayer * layer)
{
// Clear the projection, we will have to re-render everything.
// The image is already set to the new colorspace, so this'll work.
layer->resetProjection();
layer->setChannelFlags(m_emptyChannelFlags);
KisLayerSP child = dynamic_cast<KisLayer*>(layer->firstChild().data());
while (child) {
child->accept(*this);
child = dynamic_cast<KisLayer*>(child->nextSibling().data());
}
layer->setCompositeOp(m_dstColorSpace->compositeOp(layer->compositeOp()->id()));
return true;
}
bool KisColorSpaceConvertVisitor::visit(KisPaintLayer *layer)
{
layer->paintDevice()->convertTo(m_dstColorSpace, m_renderingIntent);
layer->setChannelFlags(m_emptyChannelFlags);
layer->setCompositeOp(m_dstColorSpace->compositeOp(layer->compositeOp()->id()));
Q_ASSERT(!layer->temporaryTarget() );
return true;
}
bool KisColorSpaceConvertVisitor::visit(KisGeneratorLayer *layer)
{
layer->paintDevice()->convertTo(m_dstColorSpace, m_renderingIntent);
layer->setChannelFlags(m_emptyChannelFlags);
layer->setCompositeOp(m_dstColorSpace->compositeOp(layer->compositeOp()->id()));
return true;
}
bool KisColorSpaceConvertVisitor::visit(KisAdjustmentLayer * layer)
{
if (layer->filter()->name() == "perchannel") {
// Per-channel filters need to be reset because of different number
// of channels. This makes undo very tricky, but so be it.
// XXX: Make this more generic for after 1.6, when we'll have many
// channel-specific filters.
KisFilterSP f = KisFilterRegistry::instance()->value("perchannel");
layer->setFilter(f->defaultConfiguration(0));
}
layer->setChannelFlags(m_emptyChannelFlags);
layer->resetCache();
return true;
}
bool KisColorSpaceConvertVisitor::visit(KisExternalLayer *layer) {
layer->setCompositeOp(m_dstColorSpace->compositeOp(layer->compositeOp()->id()));
return true;
}
......@@ -123,76 +123,20 @@ public:
bool visit(KisAdjustmentLayer* layer);
bool visit(KisGeneratorLayer * layer);
bool visit(KisExternalLayer *);
bool visit(KisNode*) { return true; }
bool visit(KisCloneLayer*) { return true; }
bool visit(KisFilterMask*) { return true; }
bool visit(KisTransparencyMask*) { return true; }
bool visit(KisTransformationMask*) { return true; }
bool visit(KisSelectionMask*) { return true; }
private:
const KoColorSpace *m_dstColorSpace;
KoColorConversionTransformation::Intent m_renderingIntent;
QBitArray m_emptyChannelFlags;
};
KisColorSpaceConvertVisitor::KisColorSpaceConvertVisitor(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent) :
KisNodeVisitor(),
m_dstColorSpace(dstColorSpace),
m_renderingIntent(renderingIntent)
{
}
KisColorSpaceConvertVisitor::~KisColorSpaceConvertVisitor()
{
}
bool KisColorSpaceConvertVisitor::visit(KisGroupLayer * layer)
{
// Clear the projection, we will have to re-render everything.
// The image is already set to the new colorspace, so this'll work.
layer->resetProjection();
layer->setChannelFlags(m_emptyChannelFlags);
KisLayerSP child = dynamic_cast<KisLayer*>(layer->firstChild().data());
while (child) {
child->accept(*this);
child = dynamic_cast<KisLayer*>(child->nextSibling().data());
}
layer->setCompositeOp(m_dstColorSpace->compositeOp(layer->compositeOp()->id()));
return true;
}
bool KisColorSpaceConvertVisitor::visit(KisPaintLayer *layer)
{
layer->paintDevice()->convertTo(m_dstColorSpace, m_renderingIntent);
layer->setChannelFlags(m_emptyChannelFlags);
layer->setCompositeOp(m_dstColorSpace->compositeOp(layer->compositeOp()->id()));
Q_ASSERT(!layer->temporaryTarget() );
return true;
}
bool KisColorSpaceConvertVisitor::visit(KisGeneratorLayer *layer)
{
layer->paintDevice()->convertTo(m_dstColorSpace, m_renderingIntent);
layer->setChannelFlags(m_emptyChannelFlags);
layer->setCompositeOp(m_dstColorSpace->compositeOp(layer->compositeOp()->id()));
return true;
}
bool KisColorSpaceConvertVisitor::visit(KisAdjustmentLayer * layer)
{
if (layer->filter()->name() == "perchannel") {
// Per-channel filters need to be reset because of different number
// of channels. This makes undo very tricky, but so be it.
// XXX: Make this more generic for after 1.6, when we'll have many
// channel-specific filters.
KisFilterSP f = KisFilterRegistry::instance()->value("perchannel");
layer->setFilter(f->defaultConfiguration(0));
}
layer->setChannelFlags(m_emptyChannelFlags);
layer->resetCache();
return true;
}
bool KisColorSpaceConvertVisitor::visit(KisExternalLayer *layer) {
layer->setCompositeOp(m_dstColorSpace->compositeOp(layer->compositeOp()->id()));
return true;
}
#endif // KIS_COLORSPACE_CONVERT_VISITOR_H_
......@@ -32,6 +32,7 @@
#include "kis_clone_layer.h"
#include "kis_filter_mask.h"
#include "kis_transparency_mask.h"
#include "kis_selection_mask.h"
#include "kis_transformation_mask.h"
#include "generator/kis_generator_layer.h"
/**
......@@ -103,6 +104,10 @@ public:
return check(layer);
}
bool visit( KisSelectionMask* mask ) {
return check( mask );
}
private:
bool inList(KisNode* node) {
......
......@@ -90,6 +90,14 @@ public:
return cropPaintDeviceLayer(layer);
}
bool visit(KisNode*) { return true; }
bool visit( KisCloneLayer* ) {return false;}
bool visit(KisFilterMask*) { return true; }
bool visit(KisTransparencyMask*) { return true; }
bool visit(KisTransformationMask*) { return true; }
bool visit(KisSelectionMask*) { return true; }
private:
bool cropPaintDeviceLayer(KisLayer * layer) {
......
......@@ -20,7 +20,6 @@
#include <kdebug.h>
/**
* In krita code, include kis_debug.h instead of kdebug.h. Then use one of the areas #defined here
* instead of the raw numbers. Also, try not to check in code outside of tests that uses kDebug
......
/*
* Copyright (c) 2006 Boudewijn Rempt (boud@valdyas.org)
*
* 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 KIS_EXTENT_VISITOR_H_
#define KIS_EXTENT_VISITOR_H_
#include "kis_node_visitor.h"
#include "kis_paint_layer.h"
#include "kis_group_layer.h"
#include "kis_adjustment_layer.h"
#include "kis_external_layer_iface.h"
#include "kis_clone_layer.h"
#include "kis_filter_mask.h"
#include "kis_transparency_mask.h"
#include "kis_transformation_mask.h"
#include "generator/kis_generator_layer.h"
/**
* The ExtentVisitor determines the total extent of all layers
* that comprise the image: the union therefore of their extents.
*/
class KisExtentVisitor : public KisNodeVisitor
{
public:
using KisNodeVisitor::visit;
/**
* @param rc: the extent of the image
* @param exact: if exact is true, we use the very slow exactBounds
* function.
*/
KisExtentVisitor(QRect rc, bool exact)
: m_imageRect(rc)
, m_region(rc)
, m_exact(exact) {
}
virtual ~KisExtentVisitor() {}
QRegion region() {
return m_region;
}
bool visit(KisExternalLayer *) {
return true;
}
bool visit(KisPaintLayer *layer) {
return updateExtent(layer);
}
bool visit(KisGroupLayer *layer) {
KisNodeSP child = layer->firstChild();
while (child) {
child->accept(*this);
child = child->nextSibling();
}
return true;
}
bool visit(KisAdjustmentLayer *layer) {
return updateExtent(layer);
}
bool visit(KisCloneLayer *layer) {
return updateExtent(layer);
}
bool visit(KisGeneratorLayer * layer) {
return updateExtent(layer);
}
private:
bool updateExtent(KisLayer * layer) {
if (m_exact) {
m_region = m_region.united(layer->exactBounds());
} else {
m_region = m_region.united(layer->extent());
}
return true;
}
QRect m_imageRect;
QRegion m_region;
bool m_exact;
};
#endif // KIS_EXTENT_VISITOR_H_
......@@ -49,7 +49,6 @@
#include "kis_change_profile_visitor.h"
#include "kis_colorspace_convert_visitor.h"
#include "kis_count_visitor.h"
#include "kis_extent_visitor.h"
#include "kis_filter_strategy.h"
#include "kis_group_layer.h"
#include "commands/kis_image_commands.h"
......
......@@ -38,39 +38,27 @@ public:
virtual ~KisNodeVisitor() {}
public:
virtual bool visit(KisNode *node) {
Q_UNUSED(node); return false;
}
virtual bool visit(KisPaintLayer *layer) {
Q_UNUSED(layer); return false;
}
virtual bool visit(KisGroupLayer *layer) {
Q_UNUSED(layer); return false;
}
virtual bool visit(KisAdjustmentLayer *layer) {
Q_UNUSED(layer); return false;
}
virtual bool visit(KisExternalLayer *layer) {
Q_UNUSED(layer); return false;
}
virtual bool visit(KisGeneratorLayer *layer) {
Q_UNUSED(layer); return false;
}
virtual bool visit(KisCloneLayer *layer) {
Q_UNUSED(layer); return false;
}
virtual bool visit(KisFilterMask *mask) {
Q_UNUSED(mask); return false;
}
virtual bool visit(KisTransparencyMask *mask) {
Q_UNUSED(mask); return false;
}
virtual bool visit(KisTransformationMask *mask) {
Q_UNUSED(mask); return false;
}
virtual bool visit(KisSelectionMask *mask) {
Q_UNUSED(mask); return false;
}
virtual bool visit(KisNode *node) = 0;
virtual bool visit(KisPaintLayer *layer) = 0;
virtual bool visit(KisGroupLayer *layer) = 0;
virtual bool visit(KisAdjustmentLayer *layer) = 0;
virtual bool visit(KisExternalLayer *layer) = 0;
virtual bool visit(KisGeneratorLayer *layer) = 0;
virtual bool visit(KisCloneLayer *layer) = 0;
virtual bool visit(KisFilterMask *mask) = 0;
virtual bool visit(KisTransparencyMask *mask) = 0;
virtual bool visit(KisTransformationMask *mask) = 0;
virtual bool visit(KisSelectionMask *mask) = 0;
protected:
......
......@@ -101,9 +101,15 @@ public:
return true;
}
bool visit(KisAdjustmentLayer *) {
return true;
}
bool visit(KisAdjustmentLayer *) {return true;}
bool visit(KisNode*) { return true; }
bool visit(KisGeneratorLayer*) { return true; }
bool visit(KisCloneLayer*) { return true; }
bool visit(KisFilterMask*) { return true; }
bool visit(KisTransparencyMask*) { return true; }
bool visit(KisTransformationMask*) { return true; }
bool visit(KisSelectionMask*) { return true; }
private:
double m_xshear;
double m_yshear;
......
......@@ -83,7 +83,7 @@ public:
{
dev->convertTo( m_projection->colorSpace() );
}*/
KisPainter gc(m_projection);
gc.setChannelFlags(layer->channelFlags());
gc.bitBlt(rc.left(), rc.top(), layer->compositeOp() , dev, layer->opacity(), rc.left(), rc.top(), rc.width(), rc.height());
......@@ -268,6 +268,13 @@ public:
}
bool visit(KisNode*) { return true; }
bool visit(KisFilterMask*) { return true; }
bool visit(KisTransparencyMask*) { return true; }
bool visit(KisTransformationMask*) { return true; }
bool visit(KisSelectionMask*) { return true; }
private:
// Helper for the indirect painting
template<class Target>
......
......@@ -100,6 +100,14 @@ public:
return true;
}
bool visit(KisNode*) { return true; }
bool visit(KisCloneLayer*) { return true; }
bool visit(KisFilterMask*) { return true; }
bool visit(KisTransparencyMask*) { return true; }
bool visit(KisTransformationMask*) { return true; }
bool visit(KisSelectionMask*) { return true; }
private:
void transformPaintDevice(KisNode * node) {
......
......@@ -243,12 +243,6 @@ target_link_libraries(KisDatamanagerTest ${KDE4_KDEUI_LIBS} kritaimage ${QT_QTT
########### next target ###############
set(kis_extent_visitor_test_SRCS kis_extent_visitor_test.cpp )
kde4_add_unit_test(KisExtentVisitorTest TESTNAME krita-image-KisExtentVisitorTest ${kis_extent_visitor_test_SRCS})
target_link_libraries(KisExtentVisitorTest ${KDE4_KDEUI_LIBS} kritaimage ${QT_QTTEST_LIBRARY})
########### next target ###############
set(kis_fill_painter_test_SRCS kis_fill_painter_test.cpp )
kde4_add_unit_test(KisFillPainterTest TESTNAME krita-image-KisFillPainterTest ${kis_fill_painter_test_SRCS})
target_link_libraries(KisFillPainterTest ${KDE4_KDEUI_LIBS} kritaimage ${QT_QTTEST_LIBRARY})
......
/*
* Copyright (c) 2007 Boudewijn Rempt boud@valdyas.org
*
* 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 "kis_extent_visitor_test.h"
#include <qtest_kde.h>
#include "kis_extent_visitor.h"
#include "kis_image.h"
void KisExtentVisitorTest::testCreation()
{
QRect rc(0, 0, 100, 100);
KisExtentVisitor test(rc, true);
}
QTEST_KDEMAIN(KisExtentVisitorTest, GUI)
#include "kis_extent_visitor_test.moc"
/*
* Copyright (c) 2007 Boudewijn Rempt boud@valdyas.org
*
* 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 KIS_EXTENT_VISITOR_TEST_H
#define KIS_EXTENT_VISITOR_TEST_H
#include <QtTest/QtTest>
class KisExtentVisitorTest : public QObject
{
Q_OBJECT
private slots:
void testCreation();
};
#endif
......@@ -21,9 +21,45 @@
#include <qtest_kde.h>
#include "kis_node_visitor.h"
class TestNodeVisitor : public KisNodeVisitor
{
public:
TestNodeVisitor() {}
~TestNodeVisitor() {}
bool visit(KisNode *node) { return true; }
bool visit(KisPaintLayer *layer) { return true; }
bool visit(KisGroupLayer *layer) { return true; }
bool visit(KisAdjustmentLayer *layer) { return true; }
bool visit(KisExternalLayer *layer) { return true; }
bool visit(KisGeneratorLayer *layer) { return true; }
bool visit(KisCloneLayer *layer) { return true; }
bool visit(KisFilterMask *mask) { return true; }
bool visit(KisTransparencyMask *mask) { return true; }
bool visit(KisTransformationMask *mask) { return true; }
bool visit(KisSelectionMask *mask) { return true; }
};
void KisNodeVisitorTest::testCreation()
{
KisNodeVisitor test;
TestNodeVisitor v;
}
void KisNodeVisitorTest::testFullImage()
{
}
......
......@@ -27,7 +27,11 @@ class KisNodeVisitorTest : public QObject
private slots:
void testCreation();
void testFullImage();
};
#endif
......@@ -38,6 +38,13 @@ public:
virtual bool visit(KisGroupLayer *layer);
virtual bool visit(KisAdjustmentLayer* layer);
virtual bool visit(KisGeneratorLayer* layer);
bool visit(KisNode*) { return true; }
bool visit(KisCloneLayer*) { return true; }
bool visit(KisFilterMask*) { return true; }
bool visit(KisTransparencyMask*) { return true; }
bool visit(KisTransformationMask*) { return true; }
bool visit(KisSelectionMask*) { return true; }
protected:
void setExposureToProfile(KoColorProfile* profile);
private:
......
......@@ -47,6 +47,8 @@ public:
public:
bool visit( KisNode* ) { return true; }
bool visit(KisExternalLayer * layer);
bool visit(KisPaintLayer *layer);
......
......@@ -637,6 +637,7 @@ KisImageBuilder_Result KisPNGConverter::buildImage(QIODevice* iod)
++it;
}
}
//FIXME:should be able to read 1 and 4 bits depth and scale them to 8 bits
break;
case PNG_COLOR_TYPE_RGB:
......@@ -894,8 +895,11 @@ KisImageBuilder_Result KisPNGConverter::buildFile(QIODevice* iodevice, KisImageS
dbgFile << "Trying to store annotation of type " << (*it) -> type() << " of size " << (*it) -> annotation() . size();
if ((*it) -> type().startsWith("krita_attribute:")) { // Attribute
// FIXME: it should be possible to save krita_attributes in the "CHUNKs"
if ((*it) -> type().startsWith("krita_attribute:")) { //
// Attribute
#ifdef __GNUC__ \
#warning "it should be possible to save krita_attributes in the "CHUNKs""
#endif
dbgFile << "cannot save this annotation : " << (*it) -> type();
} else { // Profile
char* name = new char[(*it)->type().length()+1];
......
......@@ -39,6 +39,7 @@ public:
public:
void setExternalUri(const QString &uri);
bool visit( KisNode* ) { return true; }
bool visit(KisExternalLayer *);
bool visit(KisPaintLayer *layer);
bool visit(KisGroupLayer *layer);
......
......@@ -107,7 +107,7 @@ bool KisKraSaveVisitor::visit(KisGeneratorLayer * layer)
bool KisKraSaveVisitor::visit(KisCloneLayer *layer)
{
if (!saveAnnotations( layer )) return false;
// Clone layers do not have a profile
return visitAllInverse(layer);
}
......@@ -159,6 +159,9 @@ bool KisKraSaveVisitor::savePaintDevice(KisNode * node)
bool KisKraSaveVisitor::saveAnnotations(KisLayer* layer)
{
if ( !layer ) return false;
if ( !layer->paintDevice() ) return false;
if ( !layer->paintDevice()->colorSpace() ) return false;
if (layer->paintDevice()->colorSpace()->profile()) {
const KoColorProfile *profile = layer->paintDevice()->colorSpace()->profile();
......@@ -203,7 +206,7 @@ bool KisKraSaveVisitor::saveSelection(KisNode* node)
bool KisKraSaveVisitor::saveFilterConfiguration(KisNode* node)
{
if (node->inherits( "KisNodeFilterInterface" )) {
KisFilterConfiguration* filter = dynamic_cast<KisNodeFilterInterface*>(node)->filter();
if (filter) {
.