krita

kis_colorspace_convert_visitor.h

00001 /*
00002  *  Copyright (c) 2005 Casper Boemann <cbr@boemann.dk>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 #ifndef KIS_COLORSPACE_CONVERT_VISITOR_H_
00019 #define KIS_COLORSPACE_CONVERT_VISITOR_H_
00020 
00021 #include "kis_global.h"
00022 #include "kis_types.h"
00023 #include "kis_layer_visitor.h"
00024 #include "kis_paint_layer.h"
00025 #include "kis_paint_device.h"
00026 #include "kis_adjustment_layer.h"
00027 #include "kis_group_layer.h"
00028 
00029 class KisColorSpaceConvertVisitor :public KisLayerVisitor {
00030 public:
00031     KisColorSpaceConvertVisitor(KisColorSpace *dstColorSpace, Q_INT32 renderingIntent);
00032     virtual ~KisColorSpaceConvertVisitor();
00033 
00034 public:
00035     virtual bool visit(KisPaintLayer *layer);
00036     virtual bool visit(KisGroupLayer *layer);
00037     virtual bool visit(KisPartLayer *layer);
00038     virtual bool visit(KisAdjustmentLayer* layer);
00039     
00040 private:
00041     KisColorSpace *m_dstColorSpace;
00042     Q_INT32 m_renderingIntent;
00043 };
00044 
00045 KisColorSpaceConvertVisitor::KisColorSpaceConvertVisitor(KisColorSpace *dstColorSpace, Q_INT32 renderingIntent) :
00046     KisLayerVisitor(),
00047     m_dstColorSpace(dstColorSpace),
00048     m_renderingIntent(renderingIntent)
00049 {
00050 }
00051 
00052 KisColorSpaceConvertVisitor::~KisColorSpaceConvertVisitor()
00053 {
00054 }
00055 
00056 bool KisColorSpaceConvertVisitor::visit(KisGroupLayer * layer)
00057 {
00058     // Clear the projection, we will have to re-render everything.
00059     // The image is already set to the new colorspace, so this'll work.
00060     layer->resetProjection();
00061     
00062     KisLayerSP child = layer->firstChild();
00063     while (child) {
00064         child->accept(*this);
00065         child = child->nextSibling();
00066     }
00067     layer->setDirty();
00068     return true;
00069 }
00070 
00071 bool KisColorSpaceConvertVisitor::visit(KisPaintLayer *layer)
00072 {
00073     layer->paintDevice()->convertTo(m_dstColorSpace, m_renderingIntent);
00074 
00075     layer->setDirty();
00076     return true;
00077 }
00078 
00079 bool KisColorSpaceConvertVisitor::visit(KisPartLayer *)
00080 {
00081     return true;
00082 }
00083 
00084 
00085 bool KisColorSpaceConvertVisitor::visit(KisAdjustmentLayer * layer)
00086 {
00087     if (layer->filter()->name() == "perchannel") {
00088         // Per-channel filters need to be reset because of different number
00089         // of channels. This makes undo very tricky, but so be it.
00090         // XXX: Make this more generic for after 1.6, when we'll have many
00091         // channel-specific filters. 
00092         KisFilter * f = KisFilterRegistry::instance()->get("perchannel");
00093         layer->setFilter(f->configuration());
00094     }
00095     layer->resetCache();
00096     layer->setDirty();
00097     return true;
00098 }
00099 
00100 #endif // KIS_COLORSPACE_CONVERT_VISITOR_H_
00101 
KDE Home | KDE Accessibility Home | Description of Access Keys