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, KoColorSpaceFactory::ProfileRegistrationInterface *registrationInterface) const
56{
59 if (const KoColorProfile* existingProfile = registrationInterface->profileByName(colorProfile->name())) {
60 delete colorProfile;
61 return existingProfile;
62 }
63 registrationInterface->registerNewProfile(colorProfile);
64 d->colorprofiles.append(colorProfile);
65 }
66 return colorProfile;
67}
68
70{
71 QMutexLocker l(&d->mutex);
72 Q_ASSERT(profile);
73 auto it = d->availableColorspaces.find(profile->name());
74 KoColorSpace* cs;
75
76 if (it == d->availableColorspaces.end()) {
77 cs = createColorSpace(profile);
78 KIS_ASSERT_X(cs != nullptr, "KoColorSpaceFactory::grabColorSpace", "createColorSpace returned nullptr.");
79 if (cs) {
80 d->availableColorspaces[profile->name()] = cs;
81 }
82 }
83 else {
84 cs = it.value();
85 }
86
87 return cs;
88}
89
#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
const KoColorProfile * colorProfile(const QByteArray &rawData, ProfileRegistrationInterface *registrationInterface) const
QHash< KoColorSpace *, QString > stackInformation
const KoColorSpace * grabColorSpace(const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()
void removeProfile(KoColorProfile *profile)