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 152 of file IccColorSpaceEngine.cpp.

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

◆ ~IccColorSpaceEngine()

IccColorSpaceEngine::~IccColorSpaceEngine ( )
override

Definition at line 156 of file IccColorSpaceEngine.cpp.

157{
158 delete d;
159}

References d.

Member Function Documentation

◆ addProfile() [1/2]

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

Implements KoColorSpaceEngine.

Definition at line 192 of file IccColorSpaceEngine.cpp.

193{
195
196 KoColorProfile *profile = new IccColorProfile(data);
197 Q_CHECK_PTR(profile);
198
199 if (profile->valid()) {
200 dbgPigment << "Valid profile : " << profile->fileName() << profile->name();
201 registry->addProfile(profile);
202 } else {
203 dbgPigment << "Invalid profile : " << profile->fileName() << profile->name();
204 delete profile;
205 profile = 0;
206 }
207
208 return profile;
209}
#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 161 of file IccColorSpaceEngine.cpp.

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

296{
297 Q_ASSERT(cs);
298
299 if (const KoLcmsInfo *lcmsInfo = dynamic_cast<const KoLcmsInfo *>(cs)) {
300 return lcmsInfo->colorSpaceType();
301 } else {
302 QString modelId = cs->colorModelId().id();
303 QString depthId = cs->colorDepthId().id();
304 // Compute the depth part of the type
305 quint32 depthType;
306
307 if (depthId == Integer8BitsColorDepthID.id()) {
308 depthType = BYTES_SH(1);
309 } else if (depthId == Integer16BitsColorDepthID.id()) {
310 depthType = BYTES_SH(2);
311 } else if (depthId == Float16BitsColorDepthID.id()) {
312 depthType = BYTES_SH(2) | FLOAT_SH(1);
313 } else if (depthId == Float32BitsColorDepthID.id()) {
314 depthType = BYTES_SH(4) | FLOAT_SH(1);
315 } else if (depthId == Float64BitsColorDepthID.id()) {
316 depthType = BYTES_SH(0) | FLOAT_SH(1);
317 } else {
318 qWarning() << "Unknown bit depth";
319 return 0;
320 }
321 // Compute the model part of the type
322 quint32 modelType = 0;
323
324 if (modelId == RGBAColorModelID.id()) {
325 if (depthId.startsWith(QLatin1Char('U'))) {
326 modelType = (COLORSPACE_SH(PT_RGB) | EXTRA_SH(1) | CHANNELS_SH(3) | DOSWAP_SH(1) | SWAPFIRST_SH(1));
327 } else if (depthId.startsWith(QLatin1Char('F'))) {
328 modelType = (COLORSPACE_SH(PT_RGB) | EXTRA_SH(1) | CHANNELS_SH(3));
329 }
330 } else if (modelId == XYZAColorModelID.id()) {
331 modelType = (COLORSPACE_SH(PT_XYZ) | EXTRA_SH(1) | CHANNELS_SH(3));
332 } else if (modelId == LABAColorModelID.id()) {
333 modelType = (COLORSPACE_SH(PT_Lab) | EXTRA_SH(1) | CHANNELS_SH(3));
334 } else if (modelId == CMYKAColorModelID.id()) {
335 modelType = (COLORSPACE_SH(PT_CMYK) | EXTRA_SH(1) | CHANNELS_SH(4));
336 } else if (modelId == GrayAColorModelID.id()) {
337 modelType = (COLORSPACE_SH(PT_GRAY) | EXTRA_SH(1) | CHANNELS_SH(1));
338 } else if (modelId == GrayColorModelID.id()) {
339 modelType = (COLORSPACE_SH(PT_GRAY) | CHANNELS_SH(1));
340 } else if (modelId == YCbCrAColorModelID.id()) {
341 modelType = (COLORSPACE_SH(PT_YCbCr) | EXTRA_SH(1) | CHANNELS_SH(3));
342 } else {
343 qWarning() << "Cannot convert colorspace to lcms modeltype";
344 return 0;
345 }
346 return depthType | modelType;
347 }
348}
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 273 of file IccColorSpaceEngine.cpp.

281{
282 KIS_ASSERT(srcColorSpace);
283 KIS_ASSERT(dstColorSpace);
284 KIS_ASSERT(dynamic_cast<const IccColorProfile *>(srcColorSpace->profile()));
285 KIS_ASSERT(dynamic_cast<const IccColorProfile *>(dstColorSpace->profile()));
286
288 srcColorSpace, computeColorSpaceType(srcColorSpace),
289 dynamic_cast<const IccColorProfile *>(srcColorSpace->profile())->asLcms(), dstColorSpace, computeColorSpaceType(dstColorSpace),
290 dynamic_cast<const IccColorProfile *>(dstColorSpace->profile())->asLcms(), proofingSpace, renderingIntent, proofingIntent, firstTransformBPC, gamutWarning,
291 displayConversionFlags
292 );
293}
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 257 of file IccColorSpaceEngine.cpp.

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

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 211 of file IccColorSpaceEngine.cpp.

212{
214
215 KoColorProfileQuery modifiedQuery = query;
216 KIS_SAFE_ASSERT_RECOVER(modifiedQuery.isValid())
217 {
218 if (modifiedQuery.transfer == TRC_LINEAR) {
220 } else {
221 modifiedQuery.primaries = PRIMARIES_ITU_R_BT_709_5;
222 }
223
224 if (modifiedQuery.transfer == TRC_UNSPECIFIED) {
225 modifiedQuery.transfer = TRC_IEC_61966_2_1;
226 }
227 }
228
229 const KoColorProfile *profile = new IccColorProfile(modifiedQuery);
230 Q_CHECK_PTR(profile);
231
232 if (profile->valid()) {
233 dbgPigment << "Valid profile : " << profile->fileName() << profile->name();
234 registry->addProfile(profile);
235 } else {
236 dbgPigment << "Invalid profile : " << profile->fileName() << profile->name();
237 delete profile;
238 profile = nullptr;
239 }
240
241 return profile;
242}
@ 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
CICP-compatible enum value representing the transfer function.

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 244 of file IccColorSpaceEngine.cpp.

245{
247
248 KoColorProfile *profile = new IccColorProfile(filename);
249 Q_CHECK_PTR(profile);
250 profile->load();
251
252 if (profile->valid() && registry->profileByName(profile->name())) {
253 registry->removeProfile(profile);
254 }
255}
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 350 of file IccColorSpaceEngine.cpp.

351{
352 Q_UNUSED(colorDepthId);
353 return colorModelId != RGBAColorModelID.id() ||
354 !profile ||
356 profile->name() != "High Dynamic Range UHDTV Wide Color Gamut Display (Rec. 2020) - SMPTE ST 2084 PQ EOTF");
357}
@ 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: