Krita Source Code Documentation
Loading...
Searching...
No Matches
KoColorSpaceRegistry Class Reference

#include <KoColorSpaceRegistry.h>

+ Inheritance diagram for KoColorSpaceRegistry:

Public Types

enum  ColorSpaceListProfilesSelection { OnlyDefaultProfile = 1 , AllProfiles = 4 }
 
enum  ColorSpaceListVisibility { OnlyUserVisible = 1 , AllColorSpaces = 4 }
 
using CustomProfileNameAlias = QHash<QString, QString>
 

Public Member Functions

void add (KoColorSpaceFactory *item)
 
void addProfile (const KoColorProfile *profile)
 
void addProfile (KoColorProfile *profile)
 
void addProfileAlias (const QString &name, const QString &to)
 
void addProfileToMap (KoColorProfile *p)
 
const KoColorSpacealpha16 ()
 
const KoColorSpacealpha32f ()
 
const KoColorSpacealpha8 ()
 
KoColorConversionCachecolorConversionCache () const
 
QList< KoIDcolorDepthList (const KoID &colorModelId, ColorSpaceListVisibility option) const
 
QList< KoIDcolorDepthList (const QString &colorModelId, ColorSpaceListVisibility option) const
 
QList< KoIDcolorModelsList (ColorSpaceListVisibility option) const
 
const KoColorSpacecolorSpace (const QString &colorModelId, const QString &colorDepthId)
 
const KoColorSpacecolorSpace (const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
 
const KoColorSpacecolorSpace (const QString &colorModelId, const QString &colorDepthId, const QString &profileName)
 
const KoColorSpacecolorSpace1 (const QString &colorSpaceId, const KoColorProfile *profile)
 
template<class LockPolicy = NormalLockPolicy>
const KoColorSpacecolorSpace1 (const QString &colorSpaceId, const QString &pName=QString())
 
KoID colorSpaceColorDepthId (const QString &_colorSpaceId) const
 
KoID colorSpaceColorModelId (const QString &_colorSpaceId) const
 
QString colorSpaceId (const KoID &colorModelId, const KoID &colorDepthId) const
 
QString colorSpaceId (const QString &colorModelId, const QString &colorDepthId) const
 
QString colorSpaceIdImpl (const QString &colorModelId, const QString &colorDepthId) const
 
KoColorConversionTransformationcreateColorConverter (const KoColorSpace *srcColorSpace, const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) const
 
void createColorConverters (const KoColorSpace *colorSpace, const QList< QPair< KoID, KoID > > &possibilities, KoColorConversionTransformation *&fromCS, KoColorConversionTransformation *&toCS) const
 
const KoColorProfilecreateColorProfile (const QString &colorModelId, const QString &colorDepthId, const QByteArray &rawData)
 
const KoColorProfilecreateColorProfile (const QString &colorModelId, const QString &colorDepthId, const QByteArray &rawData, CustomProfileNameAlias customProfileNameAlias)
 
QString defaultProfileForColorSpace (const QString &colorSpaceId) const
 
QString defaultProfileForCsIdImpl (const QString &csID)
 
const KoColorSpacegetCachedColorSpaceImpl (const QString &csId, const QString &profileName) const
 
const KoColorSpacegraya16 (const KoColorProfile *profile)
 
const KoColorSpacegraya16 (const QString &profile=QString())
 
const KoColorSpacegraya8 (const KoColorProfile *profile)
 
const KoColorSpacegraya8 (const QString &profile=QString())
 
QString idsToCacheName (const QString &csId, const QString &profileName) const
 
 KoColorSpaceRegistry ()
 
const KoColorSpacelab16 (const KoColorProfile *profile)
 
const KoColorSpacelab16 (const QString &profileName=QString())
 
const KoColorSpacelazyCreateColorSpaceImpl (const QString &csID, const KoColorProfile *profile)
 
QList< KoIDlistKeys () const
 
const KoColorProfilep2020G10Profile () const
 
const KoColorProfilep2020PQProfile () const
 
const KoColorProfilep709G10Profile () const
 
const KoColorProfilep709SRGBProfile () const
 
const KoColorSpacepermanentColorspace (const KoColorSpace *_colorSpace)
 
 Private (KoColorSpaceRegistry *_q)
 
QString profileAlias (const QString &name) const
 
const KoColorProfileprofileByName (const QString &name) const
 
const KoColorProfileprofileByUniqueId (const QByteArray &id) const
 
const KoColorProfileprofileFor (const KoColorProfileQuery &query, const bool generate=true) const
 profileFor tries to find the profile that matches these characteristics, if no such profile is found, it attempts to generate one.
 
const KoColorProfileprofileForCsIdWithFallbackImpl (const QString &csID, const QString &profileName)
 
const KoColorProfileprofileForQColorSpace (const QColorSpace &space)
 profileForQColorSpace Find a KoColorProfile that matches a given QColorSpace. This will use the QColorSpace::IccProfile function as a last resort, preferring to use preexisting profiles in the registry.
 
bool profileIsCompatible (const KoColorProfile *profile, const QString &colorSpaceId)
 
QList< const KoColorProfile * > profilesFor (const QString &csID) const
 
QColorSpace QColorSpaceForProfile (const KoColorProfile *profile) const
 QColorSpaceForProfile Generate a QColorSpace for the given KoColorProfile. Will return sRGB when the profile is null.
 
void remove (KoColorSpaceFactory *item)
 
void removeProfile (KoColorProfile *profile)
 
void removeProfileAlias (const QString &name)
 
const KoColorSpacergb16 (const KoColorProfile *profile)
 
const KoColorSpacergb16 (const QString &profileName=QString())
 
const KoColorSpacergb8 (const KoColorProfile *profile)
 
const KoColorSpacergb8 (const QString &profileName=QString())
 
virtual ~KoColorSpaceRegistry ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Static Public Member Functions

static KoColorSpaceRegistryinstance ()
 

Public Attributes

const KoColorSpacealphaCs {nullptr}
 
const KoColorSpacealphaF32Cs {nullptr}
 
const KoColorSpacealphaU16Cs {nullptr}
 
KoColorConversionCachecolorConversionCache {nullptr}
 
KoColorConversionSystemcolorConversionSystem {nullptr}
 
KoGenericRegistry< KoColorSpaceFactory * > colorSpaceFactoryRegistry
 
QScopedPointer< ConversionSystemInterface > conversionSystemInterface
 
QHash< QString, const KoColorSpace * > csMap
 
const KoColorSpacelab16sLAB {nullptr}
 
KoColorProfileStorage profileStorage
 
KoColorSpaceRegistryq {nullptr}
 
QReadWriteLock registrylock
 
const KoColorSpacergbU8sRGB {nullptr}
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Private Member Functions

QList< const KoColorSpace * > allColorSpaces (ColorSpaceListVisibility visibility, ColorSpaceListProfilesSelection pSelection)
 
const KoColorConversionSystemcolorConversionSystem () const
 
void init ()
 
 KoColorSpaceRegistry (const KoColorSpaceRegistry &)
 
KoColorSpaceRegistry operator= (const KoColorSpaceRegistry &)
 
const KoColorProfileprofileForInternal (const KoColorProfileQuery &query, const bool generate) const
 

Private Attributes

Private *const d
 

Friends

struct FriendOfColorSpaceRegistry
 
class KisCrashFilterTest
 
class KisCsConversionTest
 
class KisIteratorNGTest
 
class KisIteratorTest
 
class KisPainterTest
 
class KoColorSpacesBenchmark
 
class TestColorConversionSystem
 
class TestKoColorSpaceSanity
 
class TestProfileGeneration
 

Detailed Description

The registry for colorspaces and profiles. This class contains:

  • a registry of colorspace instantiated with specific profiles.
  • a registry of singleton colorspace factories.
  • a registry of icc profiles

Locking policy details:

Basically, we have two levels of locks in the registry: 1) (outer level) is Private::registrylock, which controls the structures of the color space registry itself 2) (inner level) is KoColorProfileStorage::Private::lock controls the structures related to profiles.

The locks can be taken individually, but if you are going to take both of them, you should always follow the order 1) registry; 2) profiles. Otherwise you'll get a deadlock.

To avoid recursive deadlocks, all the dependent classes (KoColorConversionSystem and KoColorSpaceFactory) now do not use the direct links to the registry. Instead, they use special private interfaces that skip recursive locking and ensure we take a lock twice.

Definition at line 43 of file KoColorSpaceRegistry.cpp.

Member Typedef Documentation

◆ CustomProfileNameAlias

using KoColorSpaceRegistry::CustomProfileNameAlias = QHash<QString, QString>

Create a color profile from a memory array, if possible, otherwise return 0. If there is an existing profile with the same name, it will be used instead, and the binary data from rawData will be ignored

Definition at line 135 of file KoColorSpaceRegistry.h.

Member Enumeration Documentation

◆ ColorSpaceListProfilesSelection

Enumerator
OnlyDefaultProfile 

Only add the default profile.

AllProfiles 

Add all profiles.

Definition at line 62 of file KoColorSpaceRegistry.h.

62 {
64 AllProfiles = 4
65 };
@ AllProfiles
Add all profiles.
@ OnlyDefaultProfile
Only add the default profile.

◆ ColorSpaceListVisibility

Enumerator
OnlyUserVisible 

Only user visible color space.

AllColorSpaces 

All color space even those not visible to the user.

Definition at line 58 of file KoColorSpaceRegistry.h.

58 {
59 OnlyUserVisible = 1,
61 };
@ AllColorSpaces
All color space even those not visible to the user.
@ OnlyUserVisible
Only user visible color space.

Constructor & Destructor Documentation

◆ KoColorSpaceRegistry() [1/2]

KoColorSpaceRegistry::KoColorSpaceRegistry ( )

Definition at line 199 of file KoColorSpaceRegistry.cpp.

199 : d(new Private(this))
200{
201 d->colorConversionSystem = nullptr;
202 d->colorConversionCache = nullptr;
203}

References d.

◆ ~KoColorSpaceRegistry()

KoColorSpaceRegistry::~KoColorSpaceRegistry ( )
virtual

Definition at line 205 of file KoColorSpaceRegistry.cpp.

206{
207 delete d->colorConversionSystem;
208 d->colorConversionSystem = nullptr;
209
210 Q_FOREACH (const KoColorSpace * cs, d->csMap) {
211 cs->d->deletability = OwnedByRegistryRegistryDeletes;
212 delete cs;
213 }
214 d->csMap.clear();
215
216 // deleting colorspaces calls a function in the cache
217 delete d->colorConversionCache;
218 d->colorConversionCache = nullptr;
219
220 // Delete the colorspace factories
221 Q_FOREACH(KoColorSpaceFactory *f, d->colorSpaceFactoryRegistry.values()) {
222 d->colorSpaceFactoryRegistry.remove(f->id());
223 delete f;
224 }
225 Q_FOREACH(KoColorSpaceFactory *f, d->colorSpaceFactoryRegistry.doubleEntries()) {
226 delete f;
227 }
228
229 delete d;
230}
@ OwnedByRegistryRegistryDeletes
Private *const d

References KoColorSpace::d, d, and OwnedByRegistryRegistryDeletes.

◆ KoColorSpaceRegistry() [2/2]

KoColorSpaceRegistry::KoColorSpaceRegistry ( const KoColorSpaceRegistry & )
private

Member Function Documentation

◆ add()

void KoColorSpaceRegistry::add ( KoColorSpaceFactory * item)

add a color space to the registry

Parameters
itemthe color space factory to add

Definition at line 232 of file KoColorSpaceRegistry.cpp.

233{
234 {
235 QReadLocker l(&d->registrylock);
236 auto connectionProfileRequests = d->colorConversionSystem->requiredConnectionProfilesFor(item);
237
238 // the actual connection profiles should be added without any lock held
239 l.unlock();
240
241 for (auto it = connectionProfileRequests.begin(); it != connectionProfileRequests.end(); ++it) {
242 const KoColorProfile *profile = this->profileFor(*it, true); // auto-generate all the required profiles
244 }
245 }
246
247 QWriteLocker l(&d->registrylock);
248 d->colorSpaceFactoryRegistry.add(item);
249 d->colorConversionSystem->insertColorSpace(item);
250}
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
const KoColorProfile * profileFor(const KoColorProfileQuery &query, const bool generate=true) const
profileFor tries to find the profile that matches these characteristics, if no such profile is found,...

References d, KIS_SAFE_ASSERT_RECOVER_NOOP, and profileFor().

◆ addProfile() [1/2]

void KoColorSpaceRegistry::addProfile ( const KoColorProfile * profile)

Definition at line 355 of file KoColorSpaceRegistry.cpp.

356{
357 addProfile(profile->clone());
358}
virtual KoColorProfile * clone() const =0
void addProfile(KoColorProfile *profile)

References addProfile(), and KoColorProfile::clone().

◆ addProfile() [2/2]

void KoColorSpaceRegistry::addProfile ( KoColorProfile * profile)

register the profile with the color space registry

Parameters
profilethe new profile to be registered so it can be combined with colorspaces.

Definition at line 330 of file KoColorSpaceRegistry.cpp.

331{
332 if (!p->valid()) return;
333
334 {
335 QReadLocker l(&d->registrylock);
336 auto connectionProfileRequests = d->colorConversionSystem->requiredConnectionProfilesFor(p);
337
338 // the actual connection profiles should be added without any lock held
339 l.unlock();
340
341 for (auto it = connectionProfileRequests.begin(); it != connectionProfileRequests.end(); ++it) {
342 const KoColorProfile *profile = this->profileFor(*it, true); // auto-generate all the required profiles
344 }
345
346 }
347
348 QWriteLocker locker(&d->registrylock);
349 if (p->valid()) {
351 d->colorConversionSystem->insertColorProfile(p);
352 }
353}
const Params2D p
void addProfileToMap(KoColorProfile *p)

References addProfileToMap(), d, KIS_SAFE_ASSERT_RECOVER_NOOP, p, and profileFor().

◆ addProfileAlias()

void KoColorSpaceRegistry::addProfileAlias ( const QString & name,
const QString & to )

Create an alias to a profile with a different name. Then profileByName will return the profile to when passed name as a parameter.

Aliases are considered 'weak'. If a real profile with the name name is present (or added), it shadows the existing alias. If such an explicit profile gets removed, then the alias takes its place again.

Definition at line 271 of file KoColorSpaceRegistry.cpp.

272{
273 d->profileStorage.addProfileAlias(name, to);
274}

References d.

◆ addProfileToMap()

void KoColorSpaceRegistry::addProfileToMap ( KoColorProfile * p)

Add a profile to the profile map but do not add it to the color conversion system yet.

Parameters
profilethe new profile to be registered.

Definition at line 325 of file KoColorSpaceRegistry.cpp.

326{
327 d->profileStorage.addProfile(p);
328}

References d, and p.

◆ allColorSpaces()

QList< const KoColorSpace * > KoColorSpaceRegistry::allColorSpaces ( ColorSpaceListVisibility visibility,
ColorSpaceListProfilesSelection pSelection )
private
Returns
a list with an instance of all color space with their default profile.

Definition at line 1032 of file KoColorSpaceRegistry.cpp.

1033{
1034 QList<const KoColorSpace*> colorSpaces;
1035
1036 // TODO: thread-unsafe code: the factories might change right after the lock in released
1037 // HINT: used in a unittest only!
1038
1039 d->registrylock.lockForRead();
1040 QList<KoColorSpaceFactory*> factories = d->colorSpaceFactoryRegistry.values();
1041 d->registrylock.unlock();
1042
1043 Q_FOREACH (KoColorSpaceFactory* factory, factories) {
1044 // Don't test with ycbcr for now, since we don't have a default profile for it.
1045 if (factory->colorModelId().id().startsWith("Y")) continue;
1046 if (visibility == AllColorSpaces || factory->userVisible()) {
1047 if (pSelection == OnlyDefaultProfile) {
1048 const KoColorSpace *cs = d->colorSpace1(factory->id());
1049 if (cs) {
1050 colorSpaces.append(cs);
1051 }
1052 else {
1053 warnPigment << "Could not create colorspace for id" << factory->id() << "since there is no working default profile";
1054 }
1055 } else {
1057 Q_FOREACH (const KoColorProfile * profile, profiles) {
1058 const KoColorSpace *cs = d->colorSpace1(factory->id(), profile);
1059 if (cs) {
1060 colorSpaces.append(cs);
1061 }
1062 else {
1063 warnPigment << "Could not create colorspace for id" << factory->id() << "and profile" << profile->name();
1064 }
1065 }
1066 }
1067 }
1068 }
1069
1070 return colorSpaces;
1071}
#define warnPigment
QString id() const
Definition KoID.cpp:63
virtual KoID colorModelId() const =0
virtual QString id() const =0
virtual bool userVisible() const =0
static KoColorSpaceRegistry * instance()
QList< const KoColorProfile * > profilesFor(const QString &csID) const

References AllColorSpaces, KoColorSpaceFactory::colorModelId(), d, KoID::id(), KoColorSpaceFactory::id(), instance(), KoColorProfile::name, OnlyDefaultProfile, profilesFor(), KoColorSpaceFactory::userVisible(), and warnPigment.

◆ alpha16()

const KoColorSpace * KoColorSpaceRegistry::alpha16 ( )

Definition at line 575 of file KoColorSpaceRegistry.cpp.

576{
577 if (!d->alphaU16Cs) {
578 d->alphaU16Cs = d->colorSpace1(KoAlphaU16ColorSpace::colorSpaceId());
579 }
580 Q_ASSERT(d->alphaU16Cs);
581 return d->alphaU16Cs;
582}
static QString colorSpaceId()

References KoAlphaColorSpaceImpl< _CSTrait >::colorSpaceId(), and d.

◆ alpha32f()

const KoColorSpace * KoColorSpaceRegistry::alpha32f ( )

Definition at line 595 of file KoColorSpaceRegistry.cpp.

596{
597 if (!d->alphaF32Cs) {
598 d->alphaF32Cs = d->colorSpace1(KoAlphaF32ColorSpace::colorSpaceId());
599 }
600 Q_ASSERT(d->alphaF32Cs);
601 return d->alphaF32Cs;
602}

References KoAlphaColorSpaceImpl< _CSTrait >::colorSpaceId(), and d.

◆ alpha8()

const KoColorSpace * KoColorSpaceRegistry::alpha8 ( )

Convenience methods to get the often used alpha colorspaces

Definition at line 566 of file KoColorSpaceRegistry.cpp.

567{
568 if (!d->alphaCs) {
569 d->alphaCs = d->colorSpace1(KoAlphaColorSpace::colorSpaceId());
570 }
571 Q_ASSERT(d->alphaCs);
572 return d->alphaCs;
573}

References KoAlphaColorSpaceImpl< _CSTrait >::colorSpaceId(), and d.

◆ colorConversionCache()

KoColorConversionCache * KoColorSpaceRegistry::colorConversionCache ( ) const
Returns
the cache of color conversion transformation to be use by KoColorSpace

◆ colorConversionSystem()

const KoColorConversionSystem * KoColorSpaceRegistry::colorConversionSystem ( ) const
private
Returns
the color conversion system use by the registry and the color spaces to create color conversion transformation.

WARNING: conversion system is guarded by the registry locks, don't use it anywhere other than unittests!

◆ colorDepthList() [1/2]

QList< KoID > KoColorSpaceRegistry::colorDepthList ( const KoID & colorModelId,
ColorSpaceListVisibility option ) const
Returns
the list of available color models for the given colorModelId

Definition at line 893 of file KoColorSpaceRegistry.cpp.

894{
895 return colorDepthList(colorModelId.id(), option);
896}
QList< KoID > colorDepthList(const KoID &colorModelId, ColorSpaceListVisibility option) const

References colorDepthList(), and KoID::id().

◆ colorDepthList() [2/2]

QList< KoID > KoColorSpaceRegistry::colorDepthList ( const QString & colorModelId,
ColorSpaceListVisibility option ) const
Returns
the list of available color models for the given colorModelId

Definition at line 899 of file KoColorSpaceRegistry.cpp.

900{
901 QReadLocker l(&d->registrylock);
902
903 QList<KoID> ids;
904 QList<KoColorSpaceFactory*> factories = d->colorSpaceFactoryRegistry.values();
905 Q_FOREACH (KoColorSpaceFactory* factory, factories) {
906 if (!ids.contains(KoID(factory->colorDepthId()))
907 && factory->colorModelId().id() == colorModelId
908 && (option == AllColorSpaces || factory->userVisible())) {
909 ids << factory->colorDepthId();
910 }
911 }
913
919
920 return r;
921}
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID Float64BitsColorDepthID("F64", ki18n("64-bit float/channel"))
const KoID Float16BitsColorDepthID("F16", ki18n("16-bit float/channel"))
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
Definition KoID.h:30
virtual KoID colorDepthId() const =0

References AllColorSpaces, KoColorSpaceFactory::colorDepthId(), KoColorSpaceFactory::colorModelId(), d, Float16BitsColorDepthID, Float32BitsColorDepthID, Float64BitsColorDepthID, KoID::id(), Integer16BitsColorDepthID, Integer8BitsColorDepthID, and KoColorSpaceFactory::userVisible().

◆ colorModelsList()

QList< KoID > KoColorSpaceRegistry::colorModelsList ( ColorSpaceListVisibility option) const
Returns
the list of available color models

Definition at line 879 of file KoColorSpaceRegistry.cpp.

880{
881 QReadLocker l(&d->registrylock);
882
883 QList<KoID> ids;
884 QList<KoColorSpaceFactory*> factories = d->colorSpaceFactoryRegistry.values();
885 Q_FOREACH (KoColorSpaceFactory* factory, factories) {
886 if (!ids.contains(factory->colorModelId())
887 && (option == AllColorSpaces || factory->userVisible())) {
888 ids << factory->colorModelId();
889 }
890 }
891 return ids;
892}

References AllColorSpaces, KoColorSpaceFactory::colorModelId(), d, and KoColorSpaceFactory::userVisible().

◆ colorSpace() [1/3]

const KoColorSpace * KoColorSpaceRegistry::colorSpace ( const QString & colorModelId,
const QString & colorDepthId )

Definition at line 312 of file KoColorSpaceRegistry.cpp.

313{
314 return d->colorSpace1(colorSpaceId(colorModelId, colorDepthId));
315}
QString colorSpaceId(const QString &colorModelId, const QString &colorDepthId) const

References colorSpaceId(), and d.

◆ colorSpace() [2/3]

const KoColorSpace * KoColorSpaceRegistry::colorSpace ( const QString & colorModelId,
const QString & colorDepthId,
const KoColorProfile * profile )

Return a colorspace that works with the parameter profile.

Parameters
colorSpaceIdthe ID string of the colorspace that you want to have returned
profilethe profile be combined with the colorspace
Returns
the wanted colorspace, or 0 when the cs and profile can not be combined.

Definition at line 302 of file KoColorSpaceRegistry.cpp.

303{
304 return d->colorSpace1(colorSpaceId(colorModelId, colorDepthId), profile);
305}

References colorSpaceId(), and d.

◆ colorSpace() [3/3]

const KoColorSpace * KoColorSpaceRegistry::colorSpace ( const QString & colorModelId,
const QString & colorDepthId,
const QString & profileName )

Return a colorspace that works with the parameter profile.

Parameters
profileNamethe name of the KoColorProfile to be combined with the colorspace
Returns
the wanted colorspace, or 0 when the cs and profile can not be combined.

Definition at line 307 of file KoColorSpaceRegistry.cpp.

308{
309 return d->colorSpace1(colorSpaceId(colorModelId, colorDepthId), profileName);
310}

References colorSpaceId(), and d.

◆ colorSpace1() [1/2]

const KoColorSpace * KoColorSpaceRegistry::colorSpace1 ( const QString & colorSpaceId,
const KoColorProfile * profile )

Return a colorspace that works with the parameter profile.

Parameters
colorSpaceIdthe ID string of the colorspace that you want to have returned
profilethe profile be combined with the colorspace
Returns
the wanted colorspace, or 0 when the cs and profile can not be combined.

◆ colorSpace1() [2/2]

template<class LockPolicy = NormalLockPolicy>
const KoColorSpace * KoColorSpaceRegistry::colorSpace1 ( const QString & colorSpaceId,
const QString & pName = QString() )

Return a colorspace that works with the parameter profile.

Parameters
profileNamethe name of the KoColorProfile to be combined with the colorspace
Returns
the wanted colorspace, or 0 when the cs and profile can not be combined.

◆ colorSpaceColorDepthId()

KoID KoColorSpaceRegistry::colorSpaceColorDepthId ( const QString & _colorSpaceId) const
Returns
the identifier of the color depth for the given color space id.

This function is a compatibility function used to get the color space from all kra files.

Definition at line 956 of file KoColorSpaceRegistry.cpp.

957{
958 QReadLocker l(&d->registrylock);
959
960 KoColorSpaceFactory* factory = d->colorSpaceFactoryRegistry.get(_colorSpaceId);
961 if (factory) {
962 return factory->colorDepthId();
963 } else {
964 return KoID();
965 }
966}

References KoColorSpaceFactory::colorDepthId(), and d.

◆ colorSpaceColorModelId()

KoID KoColorSpaceRegistry::colorSpaceColorModelId ( const QString & _colorSpaceId) const
Returns
the identifier of the color model for the given color space id.

This function is a compatibility function used to get the color space from all kra files.

Definition at line 944 of file KoColorSpaceRegistry.cpp.

945{
946 QReadLocker l(&d->registrylock);
947
948 KoColorSpaceFactory* factory = d->colorSpaceFactoryRegistry.get(_colorSpaceId);
949 if (factory) {
950 return factory->colorModelId();
951 } else {
952 return KoID();
953 }
954}

References KoColorSpaceFactory::colorModelId(), and d.

◆ colorSpaceId() [1/2]

QString KoColorSpaceRegistry::colorSpaceId ( const KoID & colorModelId,
const KoID & colorDepthId ) const

It's a convenient function that behave like the above. Return the id of the colorspace that have the defined colorModelId with colorDepthId.

Parameters
colorModelIdid of the color model
colorDepthIdid of the color depth
Returns
the id of the wanted colorspace, or "" if no colorspace correspond to those ids

Definition at line 939 of file KoColorSpaceRegistry.cpp.

940{
941 return colorSpaceId(colorModelId.id(), colorDepthId.id());
942}

References colorSpaceId(), and KoID::id().

◆ colorSpaceId() [2/2]

QString KoColorSpaceRegistry::colorSpaceId ( const QString & colorModelId,
const QString & colorDepthId ) const

Return the id of the colorspace that have the defined colorModelId with colorDepthId.

Parameters
colorModelIdid of the color model
colorDepthIdid of the color depth
Returns
the id of the wanted colorspace, or "" if no colorspace correspond to those ids

Definition at line 933 of file KoColorSpaceRegistry.cpp.

934{
935 QReadLocker l(&d->registrylock);
936 return d->colorSpaceIdImpl(colorModelId, colorDepthId);
937}

References d.

◆ colorSpaceIdImpl()

QString KoColorSpaceRegistry::colorSpaceIdImpl ( const QString & colorModelId,
const QString & colorDepthId ) const

◆ createColorConverter()

KoColorConversionTransformation * KoColorSpaceRegistry::createColorConverter ( const KoColorSpace * srcColorSpace,
const KoColorSpace * dstColorSpace,
KoColorConversionTransformation::Intent renderingIntent,
KoColorConversionTransformation::ConversionFlags conversionFlags ) const

This function is called by the color space to create a color conversion between two color space. This function search in the graph of transformations the best possible path between the two color space.

Definition at line 388 of file KoColorSpaceRegistry.cpp.

389{
390 QWriteLocker l(&d->registrylock);
391 return d->colorConversionSystem->createColorConverter(srcColorSpace, dstColorSpace, renderingIntent, conversionFlags);
392}

References d.

◆ createColorConverters()

void KoColorSpaceRegistry::createColorConverters ( const KoColorSpace * colorSpace,
const QList< QPair< KoID, KoID > > & possibilities,
KoColorConversionTransformation *& fromCS,
KoColorConversionTransformation *& toCS ) const

This function creates two transformations, one from the color space and one to the color space. The destination color space is picked from a list of color space, such as the conversion between the two color space is of the best quality.

The typical use case of this function is for KoColorTransformationFactory which doesn't support all color spaces, so unsupported color space have to find an acceptable conversion in order to use that KoColorTransformationFactory.

Parameters
colorSpacethe source color space
possibilitiesa list of color space among which we need to find the best conversion
fromCSthe conversion from the source color space will be affected to this variable
toCSthe revert conversion to the source color space will be affected to this variable

Definition at line 394 of file KoColorSpaceRegistry.cpp.

395{
396 QWriteLocker l(&d->registrylock);
397 d->colorConversionSystem->createColorConverters(colorSpace, possibilities, fromCS, toCS);
398}
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)

References colorSpace(), and d.

◆ createColorProfile() [1/2]

const KoColorProfile * KoColorSpaceRegistry::createColorProfile ( const QString & colorModelId,
const QString & colorDepthId,
const QByteArray & rawData )

create a profile of the specified type.

Definition at line 1003 of file KoColorSpaceRegistry.cpp.

1004{
1005 return createColorProfile(colorModelId, colorDepthId, rawData, {});
1006}
const KoColorProfile * createColorProfile(const QString &colorModelId, const QString &colorDepthId, const QByteArray &rawData)

References createColorProfile().

◆ createColorProfile() [2/2]

const KoColorProfile * KoColorSpaceRegistry::createColorProfile ( const QString & colorModelId,
const QString & colorDepthId,
const QByteArray & rawData,
CustomProfileNameAlias customProfileNameAlias )

Definition at line 1008 of file KoColorSpaceRegistry.cpp.

1009{
1010 QReadLocker l(&d->registrylock);
1011
1012 KoColorSpaceFactory* factory_ = d->colorSpaceFactoryRegistry.get(d->colorSpaceIdImpl(colorModelId, colorDepthId));
1013 std::unique_ptr<KoColorProfile> profile(factory_->createColorProfile(rawData));
1014
1015 l.unlock();
1016
1017 if (profile && profile->valid()) {
1018 const QString effectiveProfileName = customProfileNameAlias.value(profile->name(), profile->name());
1019 if (const KoColorProfile* existingProfile = profileByName(effectiveProfileName)) {
1020 return existingProfile;
1021 }
1022
1023 const KoColorProfile *constProfile = profile.get();
1024 this->addProfile(profile.release());
1025
1026 return constProfile;
1027 }
1028
1029 return nullptr;
1030}
virtual KoColorProfile * createColorProfile(const QByteArray &rawData) const =0
const KoColorProfile * profileByName(const QString &name) const

References addProfile(), KoColorSpaceFactory::createColorProfile(), d, and profileByName().

◆ defaultProfileForColorSpace()

QString KoColorSpaceRegistry::defaultProfileForColorSpace ( const QString & colorSpaceId) const

Definition at line 382 of file KoColorSpaceRegistry.cpp.

383{
384 QReadLocker l(&d->registrylock);
385 return d->defaultProfileForCsIdImpl(colorSpaceId);
386}

References colorSpaceId(), and d.

◆ defaultProfileForCsIdImpl()

QString KoColorSpaceRegistry::defaultProfileForCsIdImpl ( const QString & csID)

◆ getCachedColorSpaceImpl()

const KoColorSpace * KoColorSpaceRegistry::getCachedColorSpaceImpl ( const QString & csId,
const QString & profileName ) const

The function checks if a colorspace with a certain id and profile name can be found in the cache NOTE: the function doesn't take any lock but it needs to be called inside a d->registryLock locked either in read or write.

Parameters
csIdThe colorspace id
profileNameThe colorspace profile name
Return values
KoColorSpaceThe matching colorspace
0Null pointer if not match

◆ graya16() [1/2]

const KoColorSpace * KoColorSpaceRegistry::graya16 ( const KoColorProfile * profile)

Convenience method to get a GRAYA 16 bit colorspace. If a profile is not specified, the default profile defined in the GRAY colorspace will be used

Parameters
theprofile
Returns
an 8 bit graya colorspace with the default profile or 0.

Definition at line 640 of file KoColorSpaceRegistry.cpp.

641{
642 if (!profile) {
643 return graya16();
644 }
645 else {
647 }
648}
const KoID GrayAColorModelID("GRAYA", ki18n("Grayscale/Alpha"))
const KoColorSpace * graya16(const QString &profile=QString())

References colorSpace(), graya16(), GrayAColorModelID, KoID::id(), instance(), and Integer16BitsColorDepthID.

◆ graya16() [2/2]

const KoColorSpace * KoColorSpaceRegistry::graya16 ( const QString & profile = QString())

Convenience method to get a GRAYA 16 bit colorspace. If a profile is not specified, the default profile defined in the GRAY colorspace will be used

Parameters
theprofile
Returns
an 8 bit graya colorspace with the default profile or 0.

Definition at line 628 of file KoColorSpaceRegistry.cpp.

629{
630 if (profile.isEmpty()) {
631 KoColorSpaceFactory* factory = d->colorSpaceFactoryRegistry.get(GrayAColorModelID.id());
633 }
634 else {
636 }
637
638}
virtual QString defaultProfile() const =0

References colorSpace(), d, KoColorSpaceFactory::defaultProfile(), GrayAColorModelID, KoID::id(), instance(), and Integer16BitsColorDepthID.

◆ graya8() [1/2]

const KoColorSpace * KoColorSpaceRegistry::graya8 ( const KoColorProfile * profile)

Convenience method to get a GRAYA 8 bit colorspace. If a profile is not specified, the default profile defined in the GRAY colorspace will be used

Parameters
profilethe profile
Returns
an 8 bit graya colorspace with the default profile or 0.

Definition at line 617 of file KoColorSpaceRegistry.cpp.

618{
619 if (!profile) {
620 return graya8();
621 }
622 else {
624 }
625
626}
const KoColorSpace * graya8(const QString &profile=QString())

References colorSpace(), graya8(), GrayAColorModelID, KoID::id(), instance(), and Integer8BitsColorDepthID.

◆ graya8() [2/2]

const KoColorSpace * KoColorSpaceRegistry::graya8 ( const QString & profile = QString())

Convenience method to get a GRAYA 8 bit colorspace. If a profile is not specified, the default profile defined in the GRAY colorspace will be used

Parameters
profilethe profile name
Returns
an 8 bit graya colorspace with the default profile or 0.

Definition at line 604 of file KoColorSpaceRegistry.cpp.

605{
606
607 if (profile.isEmpty()) {
608 KoColorSpaceFactory* factory = d->colorSpaceFactoryRegistry.get(GrayAColorModelID.id());
610 }
611 else {
613 }
614
615}

References colorSpace(), d, KoColorSpaceFactory::defaultProfile(), GrayAColorModelID, KoID::id(), instance(), and Integer8BitsColorDepthID.

◆ idsToCacheName()

QString KoColorSpaceRegistry::idsToCacheName ( const QString & csId,
const QString & profileName ) const

◆ init()

void KoColorSpaceRegistry::init ( )
private

Definition at line 146 of file KoColorSpaceRegistry.cpp.

147{
148 d->rgbU8sRGB = 0;
149 d->lab16sLAB = 0;
150 d->alphaCs = 0;
151 d->alphaU16Cs = 0;
152#ifdef HAVE_OPENEXR
153 d->alphaF16Cs = 0;
154#endif
155 d->alphaF32Cs = 0;
156
157 d->conversionSystemInterface.reset(new Private::ConversionSystemInterface(this));
158 d->colorConversionSystem = new KoColorConversionSystem(d->conversionSystemInterface.data());
159 d->colorConversionCache = new KoColorConversionCache;
160
162
164
165 // Create the built-in colorspaces
166 QList<KoColorSpaceFactory *> localFactories;
167 localFactories
170 #ifdef HAVE_OPENEXR
171 << new KoAlphaF16ColorSpaceFactory()
172 #endif
177
178 Q_FOREACH (KoColorSpaceFactory *factory, localFactories) {
179 add(factory);
180 }
181
183 config.blacklist = "ColorSpacePluginsDisabled";
184 config.group = "krita";
185 KoPluginLoader::instance()->load("Krita/ColorSpace", config);
186
187 KoPluginLoader::PluginsConfig configExtensions;
188 configExtensions.blacklist = "ColorSpaceExtensionsPluginsDisabled";
189 configExtensions.group = "krita";
190 KoPluginLoader::instance()->load("Krita/ColorSpaceExtension", configExtensions);
191
192
193 dbgPigment << "Loaded the following colorspaces:";
194 Q_FOREACH (const KoID& id, listKeys()) {
195 dbgPigment << "\t" << id.id() << "," << id.name();
196 }
197}
#define dbgPigment
KoAlphaColorSpaceFactoryImpl< AlphaU16Traits > KoAlphaU16ColorSpaceFactory
KoAlphaColorSpaceFactoryImpl< AlphaU8Traits > KoAlphaColorSpaceFactory
KoAlphaColorSpaceFactoryImpl< AlphaF32Traits > KoAlphaF32ColorSpaceFactory
static KoColorSpaceEngineRegistry * instance()
void load(const QString &serviceType, const PluginsConfig &config=PluginsConfig(), QObject *owner=0, bool cache=true)
static KoPluginLoader * instance()
void add(KoColorSpaceFactory *item)
QList< KoID > listKeys() const
const char * blacklist
This contains the variable name for the list of plugins (by library name) that will not be loaded.

References add(), KoGenericRegistry< T >::add(), addProfile(), KoPluginLoader::PluginsConfig::blacklist, d, dbgPigment, KoPluginLoader::PluginsConfig::group, KoPluginLoader::instance(), KoColorSpaceEngineRegistry::instance(), listKeys(), and KoPluginLoader::load().

◆ instance()

KoColorSpaceRegistry * KoColorSpaceRegistry::instance ( )
static

Return an instance of the KoColorSpaceRegistry Creates an instance if that has never happened before and returns the singleton instance.

Definition at line 137 of file KoColorSpaceRegistry.cpp.

138{
139 if (!s_instance.exists()) {
140 s_instance->init();
141 }
142 return s_instance;
143}

References init().

◆ lab16() [1/2]

const KoColorSpace * KoColorSpaceRegistry::lab16 ( const KoColorProfile * profile)

Convenience method to get an Lab 16bit colorspace with the given profile.

Parameters
profilean Lab profile
Returns
the wanted colorspace, or 0 if the color space and profile can not be combined.

Definition at line 696 of file KoColorSpaceRegistry.cpp.

697{
698 if (profile == 0) {
699 if (!d->lab16sLAB) {
700 d->lab16sLAB = d->colorSpace1(KoLabColorSpace::colorSpaceId());
701 }
702 Q_ASSERT(d->lab16sLAB);
703 return d->lab16sLAB;
704 }
705 return d->colorSpace1(KoLabColorSpace::colorSpaceId(), profile);
706}
static QString colorSpaceId()

References KoLabColorSpace::colorSpaceId(), and d.

◆ lab16() [2/2]

const KoColorSpace * KoColorSpaceRegistry::lab16 ( const QString & profileName = QString())

Convenience method to get an Lab 16bit colorspace. If a profile is not specified, an Lab profile with a D50 whitepoint will be used.

Parameters
profileNamethe name of an Lab color profile
Returns
the wanted colorspace, or 0 if the color space and profile can not be combined.

Definition at line 685 of file KoColorSpaceRegistry.cpp.

686{
687 if (profileName.isEmpty()) {
688 if (!d->lab16sLAB) {
689 d->lab16sLAB = d->colorSpace1(KoLabColorSpace::colorSpaceId());
690 }
691 return d->lab16sLAB;
692 }
693 return d->colorSpace1(KoLabColorSpace::colorSpaceId(), profileName);
694}

References KoLabColorSpace::colorSpaceId(), and d.

◆ lazyCreateColorSpaceImpl()

const KoColorSpace * KoColorSpaceRegistry::lazyCreateColorSpaceImpl ( const QString & csID,
const KoColorProfile * profile )

◆ listKeys()

QList< KoID > KoColorSpaceRegistry::listKeys ( ) const

This function return a list of all the keys in KoID format by using the name() method on the objects stored in the registry.

Definition at line 992 of file KoColorSpaceRegistry.cpp.

993{
994 QReadLocker l(&d->registrylock);
995 QList<KoID> answer;
996 Q_FOREACH (const QString& key, d->colorSpaceFactoryRegistry.keys()) {
997 answer.append(KoID(key, d->colorSpaceFactoryRegistry.get(key)->name()));
998 }
999
1000 return answer;
1001}

References d.

◆ operator=()

KoColorSpaceRegistry KoColorSpaceRegistry::operator= ( const KoColorSpaceRegistry & )
private

◆ p2020G10Profile()

const KoColorProfile * KoColorSpaceRegistry::p2020G10Profile ( ) const

Convenience method to get a standard profile for Rec.2020 linear light color space

Definition at line 708 of file KoColorSpaceRegistry.cpp.

709{
710 return profileByName("Rec2020-elle-V4-g10.icc");
711}

References profileByName().

◆ p2020PQProfile()

const KoColorProfile * KoColorSpaceRegistry::p2020PQProfile ( ) const

Convenience method to get a standard profile for Rec.2020 PQ color space

Definition at line 713 of file KoColorSpaceRegistry.cpp.

714{
715 return profileByName("Krita Rec. 2100 Perceptual Quantizer (203cd/m²)");
716}

References profileByName().

◆ p709G10Profile()

const KoColorProfile * KoColorSpaceRegistry::p709G10Profile ( ) const

Convenience method to get a standard profile for Rec. 709 linear light color space

Definition at line 718 of file KoColorSpaceRegistry.cpp.

719{
720 return profileByName("sRGB-elle-V2-g10.icc");
721}

References profileByName().

◆ p709SRGBProfile()

const KoColorProfile * KoColorSpaceRegistry::p709SRGBProfile ( ) const

Convenience method to get a standard profile for Rec. 709 sRGB-tone- response-curve profile

Definition at line 723 of file KoColorSpaceRegistry.cpp.

724{
725 return profileByName("sRGB-elle-V2-srgbtrc.icc");
726}

References profileByName().

◆ permanentColorspace()

const KoColorSpace * KoColorSpaceRegistry::permanentColorspace ( const KoColorSpace * _colorSpace)
Returns
a permanent colorspace owned by the registry, of the same type and profile as the one given in argument

Definition at line 978 of file KoColorSpaceRegistry.cpp.

979{
980 if (_colorSpace->d->deletability != NotOwnedByRegistry) {
981 return _colorSpace;
982 } else if (*_colorSpace == *d->alphaCs) {
983 return d->alphaCs;
984 } else {
985 const KoColorSpace* cs = d->colorSpace1(_colorSpace->id(), _colorSpace->profile());
986 Q_ASSERT(cs);
987 Q_ASSERT(*cs == *_colorSpace);
988 return cs;
989 }
990}
@ NotOwnedByRegistry
virtual const KoColorProfile * profile() const =0

References KoColorSpace::d, d, KoColorSpace::id, NotOwnedByRegistry, and KoColorSpace::profile().

◆ Private()

KoColorSpaceRegistry::Private ( KoColorSpaceRegistry * _q)
inline

Definition at line 49 of file KoColorSpaceRegistry.cpp.

49: q(_q) {}
KoColorSpaceRegistry * q

◆ profileAlias()

QString KoColorSpaceRegistry::profileAlias ( const QString & name) const
Returns
the profile alias, or name if not aliased

Definition at line 281 of file KoColorSpaceRegistry.cpp.

282{
283 return d->profileStorage.profileAlias(name);
284}

References d.

◆ profileByName()

const KoColorProfile * KoColorSpaceRegistry::profileByName ( const QString & name) const

Return a profile by its given name, or 0 if none registered.

Returns
a profile by its given name, or 0 if none registered.
Parameters
namethe product name as set on the profile.
See also
addProfile()
KoColorProfile::productName()

Definition at line 286 of file KoColorSpaceRegistry.cpp.

287{
288 return d->profileStorage.profileByName(name);
289}

References d.

◆ profileByUniqueId()

const KoColorProfile * KoColorSpaceRegistry::profileByUniqueId ( const QByteArray & id) const

Returns a profile by its unique id stored/calculated in the header. The first call to this function might take long, because the map is created on the first use only (atm used by SVG only)

Parameters
idunique ProfileID of the profile (MD5 sum of its header)
Returns
the profile or 0 if not found

Definition at line 291 of file KoColorSpaceRegistry.cpp.

292{
293 return d->profileStorage.profileByUniqueId(id);
294}

References d.

◆ profileFor()

const KoColorProfile * KoColorSpaceRegistry::profileFor ( const KoColorProfileQuery & query,
const bool generate = true ) const

profileFor tries to find the profile that matches these characteristics, if no such profile is found, it attempts to generate one.

Parameters
query– profile characteristics to get the profile for.
generate– whether to try to generate a profile if no match was found.
Returns
a profile that matches these characteristics.

Definition at line 728 of file KoColorSpaceRegistry.cpp.

729{
730 // We're currently disabling on-the-fly generation of PQ profiles, because it can cause
731 // some issues with inconsistent hdr-reference-white value, i.e. the user of this
732 // code may get nits value he/she didn't expect
733 return profileForInternal(query, generate && query.transfer != TRC_ITU_R_BT_2100_0_PQ);
734}
@ TRC_ITU_R_BT_2100_0_PQ
TransferCharacteristics transfer
CICP-compatible enum value representing the white point and primaries.
const KoColorProfile * profileForInternal(const KoColorProfileQuery &query, const bool generate) const

References profileForInternal(), KoColorProfileQuery::transfer, and TRC_ITU_R_BT_2100_0_PQ.

◆ profileForCsIdWithFallbackImpl()

const KoColorProfile * KoColorSpaceRegistry::profileForCsIdWithFallbackImpl ( const QString & csID,
const QString & profileName )

◆ profileForInternal()

const KoColorProfile * KoColorSpaceRegistry::profileForInternal ( const KoColorProfileQuery & query,
const bool generate ) const
private

Definition at line 736 of file KoColorSpaceRegistry.cpp.

737{
738 if (query.primaries == PRIMARIES_ITU_R_BT_709_5) {
739 if (query.transfer == TRC_IEC_61966_2_1) {
740 return p709SRGBProfile();
741 } else if (query.transfer == TRC_LINEAR) {
742 return p709G10Profile();
743 }
744 }
745
748 && query.hdrReferenceWhite
749 && qFuzzyCompare(*query.hdrReferenceWhite, 203.0)) {
750 return p2020PQProfile();
751 } else if (query.transfer == TRC_LINEAR) {
752 return p2020G10Profile();
753 }
754 }
755
756 QList<const KoColorProfile*> list = d->profileStorage.profilesFor(query);
757 if (!list.empty()) {
758 return list.first();
759 }
760
762
763 if (engine && generate) {
764 return engine->getProfile(query);
765 }
766
767 return nullptr;
768}
@ PRIMARIES_ITU_R_BT_2020_2_AND_2100_0
@ PRIMARIES_ITU_R_BT_709_5
@ TRC_IEC_61966_2_1
T get(const QString &id) const
ColorPrimaries primaries
Rgb Primaries of the profile. When empty, this is a query for a greyscale profile.
std::optional< double > hdrReferenceWhite
CICP-compatible enum value representing the transfer function.
virtual const KoColorProfile * getProfile(const KoColorProfileQuery &query)=0
getProfile This tries to generate a profile with the given characteristics and add it to the registry...
const KoColorProfile * p709G10Profile() const
const KoColorProfile * p709SRGBProfile() const
const KoColorProfile * p2020PQProfile() const
const KoColorProfile * p2020G10Profile() const

References d, KoGenericRegistry< T >::get(), KoColorSpaceEngine::getProfile(), KoColorProfileQuery::hdrReferenceWhite, KoColorSpaceEngineRegistry::instance(), p2020G10Profile(), p2020PQProfile(), p709G10Profile(), p709SRGBProfile(), KoColorProfileQuery::primaries, PRIMARIES_ITU_R_BT_2020_2_AND_2100_0, PRIMARIES_ITU_R_BT_709_5, KoColorProfileQuery::transfer, TRC_IEC_61966_2_1, TRC_ITU_R_BT_2100_0_PQ, and TRC_LINEAR.

◆ profileForQColorSpace()

const KoColorProfile * KoColorSpaceRegistry::profileForQColorSpace ( const QColorSpace & space)

profileForQColorSpace Find a KoColorProfile that matches a given QColorSpace. This will use the QColorSpace::IccProfile function as a last resort, preferring to use preexisting profiles in the registry.

Parameters
space– space to return the profile for.
Returns
A Profile for the given QColorSpace, may be null if nothing was found.

Definition at line 793 of file KoColorSpaceRegistry.cpp.

794{
795 if (!space.isValid()) return p709SRGBProfile();
796 const KoColorProfile *profile = nullptr;
797#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
798 ColorPrimaries primaries = mapQColorSpaceColorPrimaries.value(space.primaries(), PRIMARIES_UNSPECIFIED);
799 TransferCharacteristics transfer = mapQColorSpaceColorTransfer.value(space.transferFunction(), TRC_UNSPECIFIED);
800 if (space.transferFunction() == QColorSpace::TransferFunction::Gamma || (transfer == TRC_UNSPECIFIED && primaries == PRIMARIES_UNSPECIFIED)) {
801 // load icc profile.
802 QByteArray profileData = space.iccProfile();
804 } else {
805 QVector<double> colorants;
806 profile = profileFor(KoColorProfileQuery(primaries, transfer));
807 }
808#else
809 // We want to test RGB before testing wether we are dealing with a LUT, because we want to funnel rec2020 pq into loading our profile.
810
811 if (space.colorModel() == QColorSpace::ColorModel::Rgb) {
812 if (space.transferFunction() == QColorSpace::TransferFunction::Gamma) {
813 // load icc profile.
814 QByteArray profileData = space.iccProfile();
816 }
817 ColorPrimaries primaries = mapQColorSpaceColorPrimaries.value(space.primaries(), PRIMARIES_UNSPECIFIED);
818 TransferCharacteristics transfer = mapQColorSpaceColorTransfer.value(space.transferFunction(), TRC_UNSPECIFIED);
819 // In qt6.9 we can get the 'primary points'.
820 if (!profile && (primaries != PRIMARIES_UNSPECIFIED) && transfer != TRC_UNSPECIFIED) {
821 profile = profileFor(KoColorProfileQuery(primaries, transfer));
822 }
823 } else if (space.colorModel() == QColorSpace::ColorModel::Gray) {
824 TransferCharacteristics transfer = mapQColorSpaceColorTransfer.value(space.transferFunction(), TRC_UNSPECIFIED);
825 if (space.transferFunction() == QColorSpace::TransferFunction::Gamma) {
826 QByteArray profileData = space.iccProfile();
828
829 }
830 QVector<double> colorants;
832 query.whitePoint = {space.whitePoint().x(), space.whitePoint().y()};
833 if (!profile && query.isValid()) {
834 profile = profileFor(query);
835 }
836 }
837#endif
838 if (!profile) {
839 // We might now have a non-qt supported colormodel. Let's load the raw data directly.
841 if (engine) {
842 QByteArray profileData = space.iccProfile();
843 profile = engine->addProfile(profileData);
844 }
845 }
846 if (profile) {
847 const KoColorProfile *preExisting = profileByUniqueId(profile->uniqueId());
848 if (!preExisting) {
849 preExisting = profileByName(profile->name());
850 }
851 if (preExisting) {
852 return preExisting;
853 } else {
854 addProfile(profile);
855 }
856 }
857
858 return profile;
859}
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
ColorPrimaries
The colorPrimaries enum Enum of colorants, follows ITU H.273 for values 0 to 255, and has extra known...
@ PRIMARIES_UNSPECIFIED
TransferCharacteristics
The transferCharacteristics enum Enum of transfer characteristics, follows ITU H.273 for values 0 to ...
static QMap< QColorSpace::Primaries, ColorPrimaries > mapQColorSpaceColorPrimaries
static QMap< QColorSpace::TransferFunction, TransferCharacteristics > mapQColorSpaceColorTransfer
The KoColorProfileQuery struct.
virtual QByteArray uniqueId() const =0
virtual const KoColorProfile * addProfile(const QString &filename)=0
const KoColorProfile * profileByUniqueId(const QByteArray &id) const

References KoColorSpaceEngine::addProfile(), addProfile(), createColorProfile(), KoGenericRegistry< T >::get(), GrayAColorModelID, KoID::id(), KoColorSpaceEngineRegistry::instance(), Integer8BitsColorDepthID, KoColorProfileQuery::isValid(), mapQColorSpaceColorPrimaries, mapQColorSpaceColorTransfer, KoColorProfile::name, p709SRGBProfile(), PRIMARIES_UNSPECIFIED, profileByName(), profileByUniqueId(), profileFor(), RGBAColorModelID, TRC_UNSPECIFIED, KoColorProfile::uniqueId(), KoColorProfileQuery::whitePoint, and KoColorimetryUtils::xy::x.

◆ profileIsCompatible()

bool KoColorSpaceRegistry::profileIsCompatible ( const KoColorProfile * profile,
const QString & colorSpaceId )

Definition at line 317 of file KoColorSpaceRegistry.cpp.

318{
319 QReadLocker l(&d->registrylock);
320 KoColorSpaceFactory *csf = d->colorSpaceFactoryRegistry.value(colorSpaceId);
321
322 return csf ? csf->profileIsCompatible(profile) : false;
323}
virtual bool profileIsCompatible(const KoColorProfile *profile) const =0

References colorSpaceId(), d, and KoColorSpaceFactory::profileIsCompatible().

◆ profilesFor()

QList< const KoColorProfile * > KoColorSpaceRegistry::profilesFor ( const QString & csID) const

Return the list of profiles for a colorspace with the argument id. Profiles will not work with any color space, you can query which profiles that are registered with this registry can be used in combination with the argument factory.

Parameters
colorSpaceIdthe colorspace-id with which all the returned profiles will work.
Returns
a list of profiles for the factory

Definition at line 296 of file KoColorSpaceRegistry.cpp.

297{
298 QReadLocker l(&d->registrylock);
299 return d->profileStorage.profilesFor(d->colorSpaceFactoryRegistry.value(csID));
300}

References d.

◆ QColorSpaceForProfile()

QColorSpace KoColorSpaceRegistry::QColorSpaceForProfile ( const KoColorProfile * profile) const

QColorSpaceForProfile Generate a QColorSpace for the given KoColorProfile. Will return sRGB when the profile is null.

Parameters
profile– source profile
Returns
a QColorSpace loaded from the profile. May not be RGB!

Definition at line 861 of file KoColorSpaceRegistry.cpp.

862{
863 if (!profile) return QColorSpace(QColorSpace::SRgb);
864 if (profile == p709SRGBProfile()) {
865 return QColorSpace(QColorSpace::SRgb);
866 }
867#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
868 if (profile == p2020PQProfile()
871 return QColorSpace(QColorSpace::Bt2100Pq);
872 }
873 // TODO: we'll need to fine tune the conversion between non "rec 2100" pq profiles and qcolorspace.
874 // Though, arguably, these probably don't show up in a QColorSpace way, and should roundtrip in the icc cicp values.
875#endif
876 return QColorSpace::fromIccProfile(profile->rawData());
877}
virtual QByteArray rawData() const
virtual ColorPrimaries getColorPrimaries() const
getColorPrimaries
virtual TransferCharacteristics getTransferCharacteristics() const
getTransferCharacteristics This function should be subclassed at some point so we can get the value f...

References KoColorProfile::getColorPrimaries(), KoColorProfile::getTransferCharacteristics(), p2020PQProfile(), p709SRGBProfile(), PRIMARIES_ITU_R_BT_2020_2_AND_2100_0, KoColorProfile::rawData(), and TRC_ITU_R_BT_2100_0_PQ.

◆ remove()

void KoColorSpaceRegistry::remove ( KoColorSpaceFactory * item)

Remove a color space factory from the registry. Note that it is the responsibility of the caller to ensure that the colorspaces are not used anymore.

Definition at line 252 of file KoColorSpaceRegistry.cpp.

253{
254 QWriteLocker l(&d->registrylock);
255
256 QList<QString> toremove;
257 Q_FOREACH (const KoColorSpace * cs, d->csMap) {
258 if (cs->id() == item->id()) {
259 toremove.push_back(d->idsToCacheName(cs->id(), cs->profile()->name()));
260 cs->d->deletability = OwnedByRegistryRegistryDeletes;
261 }
262 }
263
264 Q_FOREACH (const QString& id, toremove) {
265 d->csMap.remove(id);
266 // TODO: should not it delete the color space when removing it from the map ?
267 }
268 d->colorSpaceFactoryRegistry.remove(item->id());
269}

References KoColorSpace::d, d, KoColorSpace::id, KoColorSpaceFactory::id(), KoColorProfile::name, OwnedByRegistryRegistryDeletes, and KoColorSpace::profile().

◆ removeProfile()

void KoColorSpaceRegistry::removeProfile ( KoColorProfile * profile)

Definition at line 360 of file KoColorSpaceRegistry.cpp.

361{
362 d->profileStorage.removeProfile(profile);
363 // FIXME: how about removing it from conversion system?
364}

References d.

◆ removeProfileAlias()

void KoColorSpaceRegistry::removeProfileAlias ( const QString & name)

Remove profile alias name if exists

Definition at line 276 of file KoColorSpaceRegistry.cpp.

277{
278 d->profileStorage.removeProfileAlias(name);
279}

References d.

◆ rgb16() [1/2]

const KoColorSpace * KoColorSpaceRegistry::rgb16 ( const KoColorProfile * profile)

Convenience method to get an RGBA 16bit colorspace with the given profile.

Parameters
profilean RGB profile
Returns
the wanted colorspace, or 0 if the color space and profile can not be combined.

Definition at line 680 of file KoColorSpaceRegistry.cpp.

681{
682 return d->colorSpace1(KoRgbU16ColorSpace::colorSpaceId(), profile);
683}
static QString colorSpaceId()

References KoRgbU16ColorSpace::colorSpaceId(), and d.

◆ rgb16() [2/2]

const KoColorSpace * KoColorSpaceRegistry::rgb16 ( const QString & profileName = QString())

Convenience method to get an RGBA 16bit colorspace. If a profile is not specified, an sRGB profile will be used.

Parameters
profileNamethe name of an RGB color profile
Returns
the wanted colorspace, or 0 if the color space and profile can not be combined.

Definition at line 675 of file KoColorSpaceRegistry.cpp.

676{
677 return d->colorSpace1(KoRgbU16ColorSpace::colorSpaceId(), profileName);
678}

References KoRgbU16ColorSpace::colorSpaceId(), and d.

◆ rgb8() [1/2]

const KoColorSpace * KoColorSpaceRegistry::rgb8 ( const KoColorProfile * profile)

Convenience method to get an RGBA 8bit colorspace with the given profile.

Parameters
profilean RGB profile
Returns
the wanted colorspace, or 0 if the color space and profile can not be combined.

Definition at line 663 of file KoColorSpaceRegistry.cpp.

664{
665 if (profile == 0) {
666 if (!d->rgbU8sRGB) {
667 d->rgbU8sRGB = d->colorSpace1(KoRgbU8ColorSpace::colorSpaceId());
668 }
669 Q_ASSERT(d->rgbU8sRGB);
670 return d->rgbU8sRGB;
671 }
672 return d->colorSpace1(KoRgbU8ColorSpace::colorSpaceId(), profile);
673}
static QString colorSpaceId()

References KoRgbU8ColorSpace::colorSpaceId(), and d.

◆ rgb8() [2/2]

const KoColorSpace * KoColorSpaceRegistry::rgb8 ( const QString & profileName = QString())

Convenience method to get an RGBA 8bit colorspace. If a profile is not specified, an sRGB profile will be used.

Parameters
profileNamethe name of an RGB color profile
Returns
the wanted colorspace, or 0 if the color space and profile can not be combined.

Definition at line 651 of file KoColorSpaceRegistry.cpp.

652{
653 if (profileName.isEmpty()) {
654 if (!d->rgbU8sRGB) {
655 d->rgbU8sRGB = d->colorSpace1(KoRgbU8ColorSpace::colorSpaceId());
656 }
657 Q_ASSERT(d->rgbU8sRGB);
658 return d->rgbU8sRGB;
659 }
660 return d->colorSpace1(KoRgbU8ColorSpace::colorSpaceId(), profileName);
661}

References KoRgbU8ColorSpace::colorSpaceId(), and d.

Friends And Related Symbol Documentation

◆ FriendOfColorSpaceRegistry

friend struct FriendOfColorSpaceRegistry
friend

Definition at line 426 of file KoColorSpaceRegistry.h.

◆ KisCrashFilterTest

friend class KisCrashFilterTest
friend

Definition at line 422 of file KoColorSpaceRegistry.h.

◆ KisCsConversionTest

friend class KisCsConversionTest
friend

Definition at line 418 of file KoColorSpaceRegistry.h.

◆ KisIteratorNGTest

friend class KisIteratorNGTest
friend

Definition at line 420 of file KoColorSpaceRegistry.h.

◆ KisIteratorTest

friend class KisIteratorTest
friend

Definition at line 419 of file KoColorSpaceRegistry.h.

◆ KisPainterTest

friend class KisPainterTest
friend

Definition at line 421 of file KoColorSpaceRegistry.h.

◆ KoColorSpacesBenchmark

friend class KoColorSpacesBenchmark
friend

Definition at line 423 of file KoColorSpaceRegistry.h.

◆ TestColorConversionSystem

friend class TestColorConversionSystem
friend

Definition at line 425 of file KoColorSpaceRegistry.h.

◆ TestKoColorSpaceSanity

friend class TestKoColorSpaceSanity
friend

Definition at line 424 of file KoColorSpaceRegistry.h.

◆ TestProfileGeneration

friend class TestProfileGeneration
friend

Definition at line 427 of file KoColorSpaceRegistry.h.

Member Data Documentation

◆ alphaCs

const KoColorSpace* KoColorSpaceRegistry::alphaCs {nullptr}

Definition at line 61 of file KoColorSpaceRegistry.cpp.

61{nullptr};

◆ alphaF32Cs

const KoColorSpace* KoColorSpaceRegistry::alphaF32Cs {nullptr}

Definition at line 66 of file KoColorSpaceRegistry.cpp.

66{nullptr};

◆ alphaU16Cs

const KoColorSpace* KoColorSpaceRegistry::alphaU16Cs {nullptr}

Definition at line 62 of file KoColorSpaceRegistry.cpp.

62{nullptr};

◆ colorConversionCache

KoColorConversionCache * KoColorSpaceRegistry::colorConversionCache {nullptr}

Definition at line 58 of file KoColorSpaceRegistry.cpp.

58{nullptr};

◆ colorConversionSystem

const KoColorConversionSystem * KoColorSpaceRegistry::colorConversionSystem {nullptr}

Definition at line 57 of file KoColorSpaceRegistry.cpp.

57{nullptr};

◆ colorSpaceFactoryRegistry

KoGenericRegistry<KoColorSpaceFactory *> KoColorSpaceRegistry::colorSpaceFactoryRegistry

Definition at line 53 of file KoColorSpaceRegistry.cpp.

◆ conversionSystemInterface

QScopedPointer<ConversionSystemInterface> KoColorSpaceRegistry::conversionSystemInterface

Definition at line 56 of file KoColorSpaceRegistry.cpp.

◆ csMap

QHash<QString, const KoColorSpace *> KoColorSpaceRegistry::csMap

Definition at line 55 of file KoColorSpaceRegistry.cpp.

◆ d

Private* const KoColorSpaceRegistry::d
private

Definition at line 452 of file KoColorSpaceRegistry.h.

◆ lab16sLAB

const KoColorSpace* KoColorSpaceRegistry::lab16sLAB {nullptr}

Definition at line 60 of file KoColorSpaceRegistry.cpp.

60{nullptr};

◆ profileStorage

KoColorProfileStorage KoColorSpaceRegistry::profileStorage

Definition at line 54 of file KoColorSpaceRegistry.cpp.

◆ q

KoColorSpaceRegistry* KoColorSpaceRegistry::q {nullptr}

Definition at line 51 of file KoColorSpaceRegistry.cpp.

51{nullptr};

◆ registrylock

QReadWriteLock KoColorSpaceRegistry::registrylock

Definition at line 67 of file KoColorSpaceRegistry.cpp.

◆ rgbU8sRGB

const KoColorSpace* KoColorSpaceRegistry::rgbU8sRGB {nullptr}

Definition at line 59 of file KoColorSpaceRegistry.cpp.

59{nullptr};

The documentation for this class was generated from the following files: