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

#include <IccColorSpaceEngine.h>

+ Inheritance diagram for IccColorSpaceEngine:

Classes

struct  Private
 

Public Member Functions

const KoColorProfileaddProfile (const QByteArray &data) override
 
const KoColorProfileaddProfile (const QString &filename) override
 
quint32 computeColorSpaceType (const KoColorSpace *cs) const
 
KoColorProofingConversionTransformationcreateColorProofingTransformation (const KoColorSpace *srcColorSpace, const KoColorSpace *dstColorSpace, const KoColorSpace *proofingSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::Intent proofingIntent, bool firstTransformBPC, quint8 *gamutWarning, KoColorConversionTransformation::ConversionFlags displayConversionFlags) const override
 
KoColorConversionTransformationcreateColorTransformation (const KoColorSpace *srcColorSpace, const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) const override
 
const KoColorProfilegetProfile (const KoColorProfileQuery &query) override
 getProfile This tries to generate a profile with the given characteristics and add it to the registry.
 
 IccColorSpaceEngine ()
 
void removeProfile (const QString &filename) override
 
bool supportsColorSpace (const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile) const override
 
 ~IccColorSpaceEngine () override
 
- Public Member Functions inherited from KoColorSpaceEngine
const QString & id () const
 
 KoColorSpaceEngine (const QString &id, const QString &name)
 
const QString & name () const
 
 ~KoColorSpaceEngine () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KoColorConversionTransformationAbstractFactory
 KoColorConversionTransformationAbstractFactory ()
 
virtual ~KoColorConversionTransformationAbstractFactory ()
 

Private Attributes

Private *const d
 

Additional Inherited Members

- Public Attributes inherited from KoColorSpaceEngine
QString id
 
QString name
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

Definition at line 12 of file IccColorSpaceEngine.h.

Constructor & Destructor Documentation

◆ IccColorSpaceEngine()

IccColorSpaceEngine::IccColorSpaceEngine ( )

Definition at line 151 of file IccColorSpaceEngine.cpp.

151 : KoColorSpaceEngine("icc", i18n("ICC Engine")), d(new Private)
152{
153}
KoColorSpaceEngine(const QString &id, const QString &name)

◆ ~IccColorSpaceEngine()

IccColorSpaceEngine::~IccColorSpaceEngine ( )
override

Definition at line 155 of file IccColorSpaceEngine.cpp.

156{
157 delete d;
158}

References d.

Member Function Documentation

◆ addProfile() [1/2]

const KoColorProfile * IccColorSpaceEngine::addProfile ( const QByteArray & data)
overridevirtual

Implements KoColorSpaceEngine.

Definition at line 191 of file IccColorSpaceEngine.cpp.

192{
194
195 KoColorProfile *profile = new IccColorProfile(data);
196 Q_CHECK_PTR(profile);
197
198 if (profile->valid()) {
199 dbgPigment << "Valid profile : " << profile->fileName() << profile->name();
200 registry->addProfile(profile);
201 } else {
202 dbgPigment << "Invalid profile : " << profile->fileName() << profile->name();
203 delete profile;
204 profile = 0;
205 }
206
207 return profile;
208}
#define dbgPigment
virtual bool valid() const =0
static KoColorSpaceRegistry * instance()
void addProfile(KoColorProfile *profile)

References KoColorSpaceRegistry::addProfile(), dbgPigment, KoColorProfile::fileName, KoColorSpaceRegistry::instance(), KoColorProfile::name, and KoColorProfile::valid().

◆ addProfile() [2/2]

const KoColorProfile * IccColorSpaceEngine::addProfile ( const QString & filename)
overridevirtual

Implements KoColorSpaceEngine.

Definition at line 160 of file IccColorSpaceEngine.cpp.

161{
163
164 KoColorProfile *profile = new IccColorProfile(filename);
165 Q_CHECK_PTR(profile);
166
167 // this our own loading code; sometimes it fails because of an lcms error
168 profile->load();
169
170 // and then lcms can read the profile from file itself without problems,
171 // quite often, and we can initialize it
172 if (!profile->valid()) {
173 cmsHPROFILE cmsp = cmsOpenProfileFromFile(filename.toLatin1(), "r");
174 if (cmsp) {
176 }
177 }
178
179 if (profile->valid()) {
180 dbgPigment << "Valid profile : " << profile->fileName() << profile->name();
181 registry->addProfile(profile);
182 } else {
183 dbgPigment << "Invalid profile : " << profile->fileName() << profile->name();
184 delete profile;
185 profile = 0;
186 }
187
188 return profile;
189}
static IccColorProfile * createFromLcmsProfile(const cmsHPROFILE profile)
virtual bool load()

References KoColorSpaceRegistry::addProfile(), LcmsColorProfileContainer::createFromLcmsProfile(), dbgPigment, KoColorProfile::fileName, KoColorSpaceRegistry::instance(), KoColorProfile::load(), KoColorProfile::name, and KoColorProfile::valid().

◆ computeColorSpaceType()

quint32 IccColorSpaceEngine::computeColorSpaceType ( const KoColorSpace * cs) const

Definition at line 294 of file IccColorSpaceEngine.cpp.

295{
296 Q_ASSERT(cs);
297
298 if (const KoLcmsInfo *lcmsInfo = dynamic_cast<const KoLcmsInfo *>(cs)) {
299 return lcmsInfo->colorSpaceType();
300 } else {
301 QString modelId = cs->colorModelId().id();
302 QString depthId = cs->colorDepthId().id();
303 // Compute the depth part of the type
304 quint32 depthType;
305
306 if (depthId == Integer8BitsColorDepthID.id()) {
307 depthType = BYTES_SH(1);
308 } else if (depthId == Integer16BitsColorDepthID.id()) {
309 depthType = BYTES_SH(2);
310 } else if (depthId == Float16BitsColorDepthID.id()) {
311 depthType = BYTES_SH(2) | FLOAT_SH(1);
312 } else if (depthId == Float32BitsColorDepthID.id()) {
313 depthType = BYTES_SH(4) | FLOAT_SH(1);
314 } else if (depthId == Float64BitsColorDepthID.id()) {
315 depthType = BYTES_SH(0) | FLOAT_SH(1);
316 } else {
317 qWarning() << "Unknown bit depth";
318 return 0;
319 }
320 // Compute the model part of the type
321 quint32 modelType = 0;
322
323 if (modelId == RGBAColorModelID.id()) {
324 if (depthId.startsWith(QLatin1Char('U'))) {
325 modelType = (COLORSPACE_SH(PT_RGB) | EXTRA_SH(1) | CHANNELS_SH(3) | DOSWAP_SH(1) | SWAPFIRST_SH(1));
326 } else if (depthId.startsWith(QLatin1Char('F'))) {
327 modelType = (COLORSPACE_SH(PT_RGB) | EXTRA_SH(1) | CHANNELS_SH(3));
328 }
329 } else if (modelId == XYZAColorModelID.id()) {
330 modelType = (COLORSPACE_SH(PT_XYZ) | EXTRA_SH(1) | CHANNELS_SH(3));
331 } else if (modelId == LABAColorModelID.id()) {
332 modelType = (COLORSPACE_SH(PT_Lab) | EXTRA_SH(1) | CHANNELS_SH(3));
333 } else if (modelId == CMYKAColorModelID.id()) {
334 modelType = (COLORSPACE_SH(PT_CMYK) | EXTRA_SH(1) | CHANNELS_SH(4));
335 } else if (modelId == GrayAColorModelID.id()) {
336 modelType = (COLORSPACE_SH(PT_GRAY) | EXTRA_SH(1) | CHANNELS_SH(1));
337 } else if (modelId == GrayColorModelID.id()) {
338 modelType = (COLORSPACE_SH(PT_GRAY) | CHANNELS_SH(1));
339 } else if (modelId == YCbCrAColorModelID.id()) {
340 modelType = (COLORSPACE_SH(PT_YCbCr) | EXTRA_SH(1) | CHANNELS_SH(3));
341 } else {
342 qWarning() << "Cannot convert colorspace to lcms modeltype";
343 return 0;
344 }
345 return depthType | modelType;
346 }
347}
const KoID Float32BitsColorDepthID("F32", ki18n("32-bit float/channel"))
const KoID YCbCrAColorModelID("YCbCrA", ki18n("YCbCr/Alpha"))
const KoID Float64BitsColorDepthID("F64", ki18n("64-bit float/channel"))
const KoID GrayAColorModelID("GRAYA", ki18n("Grayscale/Alpha"))
const KoID XYZAColorModelID("XYZA", ki18n("XYZ/Alpha"))
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"))
const KoID CMYKAColorModelID("CMYKA", ki18n("CMYK/Alpha"))
const KoID LABAColorModelID("LABA", ki18n("L*a*b*/Alpha"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
const KoID GrayColorModelID("GRAY", ki18n("Grayscale (without transparency)"))
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
QString id() const
Definition KoID.cpp:63

References CMYKAColorModelID, KoColorSpace::colorDepthId(), KoColorSpace::colorModelId(), Float16BitsColorDepthID, Float32BitsColorDepthID, Float64BitsColorDepthID, GrayAColorModelID, GrayColorModelID, KoID::id(), Integer16BitsColorDepthID, Integer8BitsColorDepthID, LABAColorModelID, RGBAColorModelID, XYZAColorModelID, and YCbCrAColorModelID.

◆ createColorProofingTransformation()

KoColorProofingConversionTransformation * IccColorSpaceEngine::createColorProofingTransformation ( const KoColorSpace * srcColorSpace,
const KoColorSpace * dstColorSpace,
const KoColorSpace * proofingSpace,
KoColorConversionTransformation::Intent renderingIntent,
KoColorConversionTransformation::Intent proofingIntent,
bool firstTransformBPC,
quint8 * gamutWarning,
KoColorConversionTransformation::ConversionFlags displayConversionFlags ) const
overridevirtual

Reimplemented from KoColorConversionTransformationAbstractFactory.

Definition at line 272 of file IccColorSpaceEngine.cpp.

280{
281 KIS_ASSERT(srcColorSpace);
282 KIS_ASSERT(dstColorSpace);
283 KIS_ASSERT(dynamic_cast<const IccColorProfile *>(srcColorSpace->profile()));
284 KIS_ASSERT(dynamic_cast<const IccColorProfile *>(dstColorSpace->profile()));
285
287 srcColorSpace, computeColorSpaceType(srcColorSpace),
288 dynamic_cast<const IccColorProfile *>(srcColorSpace->profile())->asLcms(), dstColorSpace, computeColorSpaceType(dstColorSpace),
289 dynamic_cast<const IccColorProfile *>(dstColorSpace->profile())->asLcms(), proofingSpace, renderingIntent, proofingIntent, firstTransformBPC, gamutWarning,
290 displayConversionFlags
291 );
292}
LcmsColorProfileContainer * asLcms() const
quint32 computeColorSpaceType(const KoColorSpace *cs) const
virtual const KoColorProfile * profile() const =0
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

References IccColorProfile::asLcms(), computeColorSpaceType(), KIS_ASSERT, and KoColorSpace::profile().

◆ createColorTransformation()

KoColorConversionTransformation * IccColorSpaceEngine::createColorTransformation ( const KoColorSpace * srcColorSpace,
const KoColorSpace * dstColorSpace,
KoColorConversionTransformation::Intent renderingIntent,
KoColorConversionTransformation::ConversionFlags conversionFlags ) const
overridevirtual

Creates a color transformation between the source color space and the destination color space.

Parameters
srcColorSpacesource color space
dstColorSpacedestination color space
renderingIntentrendering intent
conversionFlagsconversion flags

Implements KoColorConversionTransformationAbstractFactory.

Definition at line 256 of file IccColorSpaceEngine.cpp.

260{
261 KIS_ASSERT(srcColorSpace);
262 KIS_ASSERT(dstColorSpace);
263 KIS_ASSERT(dynamic_cast<const IccColorProfile *>(srcColorSpace->profile()));
264 KIS_ASSERT(dynamic_cast<const IccColorProfile *>(dstColorSpace->profile()));
265
267 srcColorSpace, computeColorSpaceType(srcColorSpace),
268 dynamic_cast<const IccColorProfile *>(srcColorSpace->profile())->asLcms(), dstColorSpace, computeColorSpaceType(dstColorSpace),
269 dynamic_cast<const IccColorProfile *>(dstColorSpace->profile())->asLcms(), renderingIntent, conversionFlags);
270
271}

References IccColorProfile::asLcms(), computeColorSpaceType(), KIS_ASSERT, and KoColorSpace::profile().

◆ getProfile()

const KoColorProfile * IccColorSpaceEngine::getProfile ( const KoColorProfileQuery & query)
overridevirtual

getProfile This tries to generate a profile with the given characteristics and add it to the registry.

Parameters
query– a KoColorProfileQuery to generate a profile for.
Returns
a profile that matches these characteristics.

Implements KoColorSpaceEngine.

Definition at line 210 of file IccColorSpaceEngine.cpp.

211{
213
214 KoColorProfileQuery modifiedQuery = query;
215 KIS_SAFE_ASSERT_RECOVER(modifiedQuery.isValid())
216 {
217 if (modifiedQuery.transfer == TRC_LINEAR) {
219 } else {
220 modifiedQuery.primaries = PRIMARIES_ITU_R_BT_709_5;
221 }
222
223 if (modifiedQuery.transfer == TRC_UNSPECIFIED) {
224 modifiedQuery.transfer = TRC_IEC_61966_2_1;
225 }
226 }
227
228 const KoColorProfile *profile = new IccColorProfile(modifiedQuery);
229 Q_CHECK_PTR(profile);
230
231 if (profile->valid()) {
232 dbgPigment << "Valid profile : " << profile->fileName() << profile->name();
233 registry->addProfile(profile);
234 } else {
235 dbgPigment << "Invalid profile : " << profile->fileName() << profile->name();
236 delete profile;
237 profile = nullptr;
238 }
239
240 return profile;
241}
@ PRIMARIES_ITU_R_BT_2020_2_AND_2100_0
@ PRIMARIES_ITU_R_BT_709_5
@ TRC_IEC_61966_2_1
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
The KoColorProfileQuery struct.
TransferCharacteristics transfer
CICP-compatible enum value representing the white point and primaries.
ColorPrimaries primaries
Rgb Primaries of the profile. When empty, this is a query for a greyscale profile.
bool isValid() const
Used for PQ profiles.

References KoColorSpaceRegistry::addProfile(), dbgPigment, KoColorProfile::fileName, KoColorSpaceRegistry::instance(), KoColorProfileQuery::isValid(), KIS_SAFE_ASSERT_RECOVER, KoColorProfile::name, 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_LINEAR, TRC_UNSPECIFIED, and KoColorProfile::valid().

◆ removeProfile()

void IccColorSpaceEngine::removeProfile ( const QString & filename)
overridevirtual

Implements KoColorSpaceEngine.

Definition at line 243 of file IccColorSpaceEngine.cpp.

244{
246
247 KoColorProfile *profile = new IccColorProfile(filename);
248 Q_CHECK_PTR(profile);
249 profile->load();
250
251 if (profile->valid() && registry->profileByName(profile->name())) {
252 registry->removeProfile(profile);
253 }
254}
const KoColorProfile * profileByName(const QString &name) const
void removeProfile(KoColorProfile *profile)

References KoColorSpaceRegistry::instance(), KoColorProfile::load(), KoColorProfile::name, KoColorSpaceRegistry::profileByName(), KoColorSpaceRegistry::removeProfile(), and KoColorProfile::valid().

◆ supportsColorSpace()

bool IccColorSpaceEngine::supportsColorSpace ( const QString & colorModelId,
const QString & colorDepthId,
const KoColorProfile * profile ) const
overridevirtual
Returns
true if the color space can be converted via this engine

Reimplemented from KoColorSpaceEngine.

Definition at line 349 of file IccColorSpaceEngine.cpp.

350{
351 Q_UNUSED(colorDepthId);
352 return colorModelId != RGBAColorModelID.id() ||
353 !profile ||
355 profile->name() != "High Dynamic Range UHDTV Wide Color Gamut Display (Rec. 2020) - SMPTE ST 2084 PQ EOTF");
356}
@ TRC_ITU_R_BT_2100_0_PQ
virtual TransferCharacteristics getTransferCharacteristics() const
getTransferCharacteristics This function should be subclassed at some point so we can get the value f...

References KoColorProfile::getTransferCharacteristics(), KoID::id(), KoColorProfile::name, RGBAColorModelID, and TRC_ITU_R_BT_2100_0_PQ.

Member Data Documentation

◆ d

Private* const IccColorSpaceEngine::d
private

Definition at line 38 of file IccColorSpaceEngine.h.


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