Warning, file /office/calligra/libs/pigment/KoColorSpaceFactory.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (c) 2010 Cyrille Berger <cberger@cberger.net> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "KoColorSpaceFactory.h" 0021 0022 #include "DebugPigment.h" 0023 0024 #include <QMutexLocker> 0025 0026 #include "KoColorProfile.h" 0027 #include "KoColorSpace.h" 0028 #include "KoColorSpaceRegistry.h" 0029 0030 struct Q_DECL_HIDDEN KoColorSpaceFactory::Private { 0031 QList<KoColorProfile*> colorprofiles; 0032 QList<KoColorSpace*> colorspaces; 0033 QHash<QString, KoColorSpace* > availableColorspaces; 0034 QMutex mutex; 0035 #ifndef NDEBUG 0036 QHash<KoColorSpace*, QString> stackInformation; 0037 #endif 0038 }; 0039 0040 KoColorSpaceFactory::KoColorSpaceFactory() : d(new Private) 0041 { 0042 } 0043 0044 KoColorSpaceFactory::~KoColorSpaceFactory() 0045 { 0046 #ifndef NDEBUG 0047 // Check that all color spaces have been released 0048 int count = 0; 0049 count += d->availableColorspaces.size(); 0050 0051 for(QHash<KoColorSpace*, QString>::const_iterator it = d->stackInformation.constBegin(); 0052 it != d->stackInformation.constEnd(); ++it) 0053 { 0054 errorPigment << "*******************************************"; 0055 errorPigment << it.key()->id() << " still in used, and grabbed in: "; 0056 errorPigment << it.value(); 0057 } 0058 if( count != d->colorspaces.size()) 0059 { 0060 errorPigment << (d->colorspaces.size() - count) << " colorspaces are still used"; 0061 } 0062 Q_ASSERT(count == d->colorspaces.size()); 0063 #endif 0064 foreach(KoColorSpace* cs, d->colorspaces) { 0065 delete cs; 0066 } 0067 foreach(KoColorProfile* profile, d->colorprofiles) { 0068 KoColorSpaceRegistry::instance()->removeProfile(profile); 0069 delete profile; 0070 } 0071 delete d; 0072 } 0073 0074 const KoColorProfile* KoColorSpaceFactory::colorProfile(const QByteArray& rawData) const 0075 { 0076 KoColorProfile* colorProfile = createColorProfile(rawData); 0077 if (colorProfile && colorProfile->valid()) { 0078 if (const KoColorProfile* existingProfile = KoColorSpaceRegistry::instance()->profileByName(colorProfile->name())) { 0079 delete colorProfile; 0080 return existingProfile; 0081 } 0082 KoColorSpaceRegistry::instance()->addProfile(colorProfile); 0083 d->colorprofiles.append(colorProfile); 0084 } 0085 return colorProfile; 0086 } 0087 0088 const KoColorSpace *KoColorSpaceFactory::grabColorSpace(const KoColorProfile * profile) 0089 { 0090 QMutexLocker l(&d->mutex); 0091 Q_ASSERT(profile); 0092 auto it = d->availableColorspaces.find(profile->name()); 0093 KoColorSpace* cs; 0094 0095 if (it == d->availableColorspaces.end()) { 0096 cs = createColorSpace(profile); 0097 if (cs) { 0098 d->availableColorspaces[profile->name()] = cs; 0099 } 0100 } 0101 else { 0102 cs = it.value(); 0103 } 0104 0105 return cs; 0106 } 0107