Krita Source Code Documentation
Loading...
Searching...
No Matches
KoColorSpaceFactory.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2010 Cyrille Berger <cberger@cberger.net>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6
8
9#include "DebugPigment.h"
10
11#include <QMutex>
12#include <QMutexLocker>
13
14#include "KoColorProfile.h"
15#include "KoColorSpace.h"
17
18#include "kis_assert.h"
19
20struct Q_DECL_HIDDEN KoColorSpaceFactory::Private {
22 QHash<QString, KoColorSpace* > availableColorspaces;
23 QMutex mutex;
24#ifndef NDEBUG
25 QHash<KoColorSpace*, QString> stackInformation;
26#endif
27};
28
32
34{
35#ifndef NDEBUG
36 // Check that all color spaces have been released
37 int count = 0;
38 count += d->availableColorspaces.size();
39
40 for(QHash<KoColorSpace*, QString>::const_iterator it = d->stackInformation.constBegin();
41 it != d->stackInformation.constEnd(); ++it)
42 {
43 errorPigment << "*******************************************";
44 errorPigment << it.key()->id() << " still in used, and grabbed in: ";
45 errorPigment << it.value();
46 }
47#endif
48 Q_FOREACH (KoColorProfile* profile, d->colorprofiles) {
50 delete profile;
51 }
52 delete d;
53}
54
55const KoColorProfile *KoColorSpaceFactory::colorProfile(const QByteArray& rawData, ProfileRegistrationInterface *registrationInterface, const CustomProfileNameAlias &customProfileNameAlias) const
56{
59 const QString effectiveProfileName = customProfileNameAlias.value(colorProfile->name(), colorProfile->name());
60 if (const KoColorProfile* existingProfile = registrationInterface->profileByName(effectiveProfileName)) {
61 delete colorProfile;
62 return existingProfile;
63 }
64 registrationInterface->registerNewProfile(colorProfile);
65 d->colorprofiles.append(colorProfile);
66 }
67 return colorProfile;
68}
69
71{
72 QMutexLocker l(&d->mutex);
73 Q_ASSERT(profile);
74 auto it = d->availableColorspaces.find(profile->name());
75 KoColorSpace* cs;
76
77 if (it == d->availableColorspaces.end()) {
78 cs = createColorSpace(profile);
79 KIS_ASSERT_X(cs != nullptr, "KoColorSpaceFactory::grabColorSpace", "createColorSpace returned nullptr.");
80 if (cs) {
81 d->availableColorspaces[profile->name()] = cs;
82 }
83 }
84 else {
85 cs = it.value();
86 }
87
88 return cs;
89}
90
#define errorPigment
#define KIS_ASSERT_X(cond, where, what)
Definition kis_assert.h:40
virtual bool valid() const =0
virtual void registerNewProfile(KoColorProfile *profile)=0
virtual const KoColorProfile * profileByName(const QString &profileName) const =0
virtual KoColorSpace * createColorSpace(const KoColorProfile *) const =0
QHash< QString, KoColorSpace * > availableColorspaces
virtual KoColorProfile * createColorProfile(const QByteArray &rawData) const =0
QList< KoColorProfile * > colorprofiles
QHash< QString, QString > CustomProfileNameAlias
QHash< KoColorSpace *, QString > stackInformation
const KoColorSpace * grabColorSpace(const KoColorProfile *profile)
const KoColorProfile * colorProfile(const QByteArray &rawData, ProfileRegistrationInterface *registrationInterface, const CustomProfileNameAlias &customProfileNameAlias) const
static KoColorSpaceRegistry * instance()
void removeProfile(KoColorProfile *profile)