krita
kis_change_profile_visitor.h
00001 /* 00002 * Copyright (c) 2006 Boudewijn Rempt <boud@valdyas.org 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_CHANGE_PROFILE_VISITOR_H_ 00019 #define KIS_CHANGE_PROFILE_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 00036 class KisChangeProfileVisitor :public KisLayerVisitor { 00037 public: 00038 KisChangeProfileVisitor(KisColorSpace *oldColorSpace, KisColorSpace *dstColorSpace); 00039 virtual ~KisChangeProfileVisitor(); 00040 00041 public: 00042 virtual bool visit(KisPaintLayer *layer); 00043 virtual bool visit(KisGroupLayer *layer); 00044 virtual bool visit(KisPartLayer *layer); 00045 virtual bool visit(KisAdjustmentLayer* layer); 00046 00047 private: 00048 KisColorSpace *m_oldColorSpace; 00049 KisColorSpace *m_dstColorSpace; 00050 }; 00051 00052 KisChangeProfileVisitor::KisChangeProfileVisitor(KisColorSpace * oldColorSpace, 00053 KisColorSpace *dstColorSpace) : 00054 KisLayerVisitor(), 00055 m_oldColorSpace(oldColorSpace), 00056 m_dstColorSpace(dstColorSpace) 00057 { 00058 } 00059 00060 KisChangeProfileVisitor::~KisChangeProfileVisitor() 00061 { 00062 } 00063 00064 bool KisChangeProfileVisitor::visit(KisGroupLayer * layer) 00065 { 00066 // Clear the projection, we will have to re-render everything. 00067 layer->resetProjection(); 00068 00069 KisLayerSP child = layer->firstChild(); 00070 while (child) { 00071 child->accept(*this); 00072 child = child->nextSibling(); 00073 } 00074 layer->setDirty(); 00075 return true; 00076 } 00077 00078 bool KisChangeProfileVisitor::visit(KisPaintLayer *layer) 00079 { 00080 if (!layer) return false; 00081 if (!layer->paintDevice()) return false; 00082 if (!layer->paintDevice()->colorSpace()) return false; 00083 00084 KisColorSpace * cs = layer->paintDevice()->colorSpace(); 00085 00086 if (cs == m_oldColorSpace) { 00087 00088 layer->paintDevice()->setProfile(m_dstColorSpace->getProfile()); 00089 00090 layer->setDirty(); 00091 } 00092 return true; 00093 } 00094 00095 bool KisChangeProfileVisitor::visit(KisPartLayer *) 00096 { 00097 return true; 00098 } 00099 00100 00101 bool KisChangeProfileVisitor::visit(KisAdjustmentLayer * layer) 00102 { 00103 layer->resetCache(); 00104 layer->setDirty(); 00105 return true; 00106 } 00107 00108 #endif // KIS_CHANGE_PROFILE_VISITOR_H_ 00109