chalk

kis_colorspace_convert_visitor.h
1/*
2 * Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#ifndef KIS_COLORSPACE_CONVERT_VISITOR_H_
19#define KIS_COLORSPACE_CONVERT_VISITOR_H_
20
21#include "kis_global.h"
22#include "kis_types.h"
23#include "kis_layer_visitor.h"
24#include "kis_paint_layer.h"
25#include "kis_paint_device.h"
26#include "kis_adjustment_layer.h"
27#include "kis_group_layer.h"
28
29class KisColorSpaceConvertVisitor :public KisLayerVisitor {
30public:
31 KisColorSpaceConvertVisitor(KisColorSpace *dstColorSpace, TQ_INT32 renderingIntent);
32 virtual ~KisColorSpaceConvertVisitor();
33
34public:
35 virtual bool visit(KisPaintLayer *layer);
36 virtual bool visit(KisGroupLayer *layer);
37 virtual bool visit(KisPartLayer *layer);
38 virtual bool visit(KisAdjustmentLayer* layer);
39
40private:
41 KisColorSpace *m_dstColorSpace;
42 TQ_INT32 m_renderingIntent;
43};
44
45KisColorSpaceConvertVisitor::KisColorSpaceConvertVisitor(KisColorSpace *dstColorSpace, TQ_INT32 renderingIntent) :
46 KisLayerVisitor(),
47 m_dstColorSpace(dstColorSpace),
48 m_renderingIntent(renderingIntent)
49{
50}
51
52KisColorSpaceConvertVisitor::~KisColorSpaceConvertVisitor()
53{
54}
55
56bool KisColorSpaceConvertVisitor::visit(KisGroupLayer * layer)
57{
58 // Clear the projection, we will have to re-render everything.
59 // The image is already set to the new colorspace, so this'll work.
60 layer->resetProjection();
61
62 KisLayerSP child = layer->firstChild();
63 while (child) {
64 child->accept(*this);
65 child = child->nextSibling();
66 }
67 layer->setDirty();
68 return true;
69}
70
71bool KisColorSpaceConvertVisitor::visit(KisPaintLayer *layer)
72{
73 layer->paintDevice()->convertTo(m_dstColorSpace, m_renderingIntent);
74
75 layer->setDirty();
76 return true;
77}
78
79bool KisColorSpaceConvertVisitor::visit(KisPartLayer *)
80{
81 return true;
82}
83
84
85bool KisColorSpaceConvertVisitor::visit(KisAdjustmentLayer * layer)
86{
87 if (layer->filter()->name() == "perchannel") {
88 // Per-channel filters need to be reset because of different number
89 // of channels. This makes undo very tricky, but so be it.
90 // XXX: Make this more generic for after 1.6, when we'll have many
91 // channel-specific filters.
92 KisFilter * f = KisFilterRegistry::instance()->get("perchannel");
93 layer->setFilter(f->configuration());
94 }
95 layer->resetCache();
96 layer->setDirty();
97 return true;
98}
99
100#endif // KIS_COLORSPACE_CONVERT_VISITOR_H_
101
Class that contains a KisFilter and optionally a KisSelection.
A colorspace is the definition of a certain color model in Chalk.
const TQString & name() const
Get the unique, language independent name of the filter.
Basic interface of a Chalk filter.
Definition kis_filter.h:46
virtual KisFilterConfiguration * configuration(TQWidget *)
A KisLayer that bundles child layers into a single layer.
virtual KisLayerSP firstChild() const
Returns the first child layer of this layer (if it supports that).
virtual void resetProjection(KisPaintDevice *to=0)
virtual void setDirty(bool propagate=true)
Set the entire layer extent dirty; this percolates up to parent layers all the way to the root layer.
virtual void setDirty(bool propagate=true)
Set the entire layer extent dirty; this percolates up to parent layers all the way to the root layer.
This layer is of a type that can be painted on.
virtual void setDirty(bool propagate=true)
Overridden to call the private convertMaskToSelection.
An interface for the Part Layer so that we can use it in core/, but can implement it in ui/.