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 QVector< double > &colorants, ColorPrimaries colorPrimaries, TransferCharacteristics transferFunction) 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 149 of file IccColorSpaceEngine.cpp.

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

◆ ~IccColorSpaceEngine()

IccColorSpaceEngine::~IccColorSpaceEngine ( )
override

Definition at line 153 of file IccColorSpaceEngine.cpp.

154{
155 delete d;
156}

References d.

Member Function Documentation

◆ addProfile() [1/2]

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

Implements KoColorSpaceEngine.

Definition at line 189 of file IccColorSpaceEngine.cpp.

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

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

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

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

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

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

◆ getProfile()

const KoColorProfile * IccColorSpaceEngine::getProfile ( const QVector< double > & colorants,
ColorPrimaries colorPrimaries,
TransferCharacteristics transferFunction )
overridevirtual

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

Parameters
colorantsa double of xy (for xyY) values, this expects the first two as the white point, then the red, green and blue. Will only be used if primaries is unspecified. If there's only a whitepoint, a grayscale profile will be returned.
colorPrimariesthe color primaries type as defined in KoColorProfile.
transferFunctionthe transfer function, as defined in KoColorProfile.
Returns
a profile that matches these characteristics.

Implements KoColorSpaceEngine.

Definition at line 208 of file IccColorSpaceEngine.cpp.

209{
211
213 (!colorants.isEmpty() || colorPrimaries != PRIMARIES_UNSPECIFIED)
214 && transferFunction != TRC_UNSPECIFIED)
215 {
216 if (transferFunction == TRC_LINEAR) {
218 } else {
219 colorPrimaries = PRIMARIES_ITU_R_BT_709_5;
220 }
221
222 if (transferFunction == TRC_UNSPECIFIED) {
223 transferFunction = TRC_IEC_61966_2_1;
224 }
225 }
226
227 const KoColorProfile *profile = new IccColorProfile(colorants, colorPrimaries, transferFunction);
228 Q_CHECK_PTR(profile);
229
230 if (profile->valid()) {
231 dbgPigment << "Valid profile : " << profile->fileName() << profile->name();
232 registry->addProfile(profile);
233 } else {
234 dbgPigment << "Invalid profile : " << profile->fileName() << profile->name();
235 delete profile;
236 profile = nullptr;
237 }
238
239 return profile;
240}
@ PRIMARIES_ITU_R_BT_2020_2_AND_2100_0
@ PRIMARIES_UNSPECIFIED
@ PRIMARIES_ITU_R_BT_709_5
@ TRC_IEC_61966_2_1
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126

References KoColorSpaceRegistry::addProfile(), dbgPigment, KoColorProfile::fileName, KoColorSpaceRegistry::instance(), KIS_SAFE_ASSERT_RECOVER, KoColorProfile::name, PRIMARIES_ITU_R_BT_2020_2_AND_2100_0, PRIMARIES_ITU_R_BT_709_5, PRIMARIES_UNSPECIFIED, 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 242 of file IccColorSpaceEngine.cpp.

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

349{
350 Q_UNUSED(colorDepthId);
351 return colorModelId != RGBAColorModelID.id() || !profile || profile->name() != "High Dynamic Range UHDTV Wide Color Gamut Display (Rec. 2020) - SMPTE ST 2084 PQ EOTF";
352}

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

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: