Krita Source Code Documentation
Loading...
Searching...
No Matches
KisGamutMapClipAdjustment< ModelType, DifferenceType > Class Template Reference
+ Inheritance diagram for KisGamutMapClipAdjustment< ModelType, DifferenceType >:

Public Member Functions

 KisGamutMapClipAdjustment (const KoColorSpace *sourceSpace)
 
int parameterId (const QString &name) const override
 
QList< QString > parameters () const override
 
void setParameter (int id, const QVariant &parameter) override
 
void transform (const quint8 *srcU8, quint8 *dstU8, qint32 nPixels) const override
 
- Public Member Functions inherited from KoColorTransformation
virtual bool isValid () const
 
void setParameters (const QHash< QString, QVariant > &parameters)
 
virtual ~KoColorTransformation ()
 

Private Attributes

QMap< float, QPointF > m_cuspDescription
 
const KoColorSpace * m_sourceSpace
 
QString m_targetColorProfileName
 

Detailed Description

template<class ModelType, class DifferenceType>
class KisGamutMapClipAdjustment< ModelType, DifferenceType >

Definition at line 110 of file kis_gamutmap_clip_adjustment.cpp.

Constructor & Destructor Documentation

◆ KisGamutMapClipAdjustment()

template<class ModelType , class DifferenceType >
KisGamutMapClipAdjustment< ModelType, DifferenceType >::KisGamutMapClipAdjustment ( const KoColorSpace * sourceSpace)
inline

Definition at line 113 of file kis_gamutmap_clip_adjustment.cpp.

114 : m_sourceSpace(sourceSpace) {}

Member Function Documentation

◆ parameterId()

template<class ModelType , class DifferenceType >
int KisGamutMapClipAdjustment< ModelType, DifferenceType >::parameterId ( const QString & name) const
inlineoverridevirtual

Get the parameter id for a parameter name

Reimplemented from KoColorTransformation.

Definition at line 227 of file kis_gamutmap_clip_adjustment.cpp.

228 {
229 if (name == "targetColorProfileName") {
230 return 0;
231 } else if (name == "cuspDescription") {
232 return 1;
233 }
234 return -1;
235 }

◆ parameters()

template<class ModelType , class DifferenceType >
QList< QString > KisGamutMapClipAdjustment< ModelType, DifferenceType >::parameters ( ) const
inlineoverridevirtual
Returns
the list of parameters

Reimplemented from KoColorTransformation.

Definition at line 219 of file kis_gamutmap_clip_adjustment.cpp.

220 {
221 QList<QString> list;
222 list << "targetColorProfileName";
223 list << "cuspDescription";
224 return list;
225 }

◆ setParameter()

template<class ModelType , class DifferenceType >
void KisGamutMapClipAdjustment< ModelType, DifferenceType >::setParameter ( int id,
const QVariant & parameter )
inlineoverridevirtual

Update one parameter of a cached transformation object.

Reimplemented from KoColorTransformation.

Definition at line 237 of file kis_gamutmap_clip_adjustment.cpp.

238 {
239 switch(id)
240 {
241 case 0:
242 m_targetColorProfileName = parameter.toString();
243 break;
244 case 1:
245
246 m_cuspDescription = QMap<float, QPointF>();
247 {
248 const QVariantMap map = parameter.toMap();
249 Q_FOREACH (QString key, map.keys()){
250 m_cuspDescription.insert(key.toFloat(), map.value(key).toPointF());
251 }
252 }
253 break;
254 default:
255 ;
256 }
257 }

References KisGamutMapClipAdjustment< ModelType, DifferenceType >::m_cuspDescription, and KisGamutMapClipAdjustment< ModelType, DifferenceType >::m_targetColorProfileName.

◆ transform()

template<class ModelType , class DifferenceType >
void KisGamutMapClipAdjustment< ModelType, DifferenceType >::transform ( const quint8 * src,
quint8 * dst,
qint32 nPixels ) const
inlineoverridevirtual

This function apply the transformation on a given number of pixels.

Parameters
srca pointer to the source pixels
dsta pointer to the destination pixels
nPixelsthe number of pixels

This function may or may not be thread safe. You need to create one KoColorTransformation per thread.

We are treating the cusp triangle as linear inside the SDR standard range. Within the standard range, cube root works better than hdr's PQ. This is good enough for RGB profiles, CMYK profiles might get better results with the MINDE method. Overall though, we just want to move the colors into gamut enough so that we don't get hue shifts when converting, and this method delivers on that nicely.

Implements KoColorTransformation.

Definition at line 118 of file kis_gamutmap_clip_adjustment.cpp.

119 {
120
121 if (!m_sourceSpace) {
122 qWarning() << "no source space!";
123 return;
124 }
126 if (!targetProfile) {
127 qWarning() << "no target profile found for..." << m_targetColorProfileName;
128 return;
129 }
130 const bool greyscale = targetProfile->colorModelID() == GrayAColorModelID.id();
131 const KoColorSpace *targetSpace = KoColorSpaceRegistry::instance()->colorSpace(targetProfile->colorModelID(), Integer16BitsColorDepthID.id(), targetProfile);
132 if (!targetSpace) {
133 qWarning() << "no target space!";
134 return;
135 }
136
137 QVector<float> originalChannels(m_sourceSpace->channelCount());
138 QVector<float> clippedChannels(m_sourceSpace->channelCount());
139 std::unique_ptr<quint8[]> tmpOriginal(new quint8[m_sourceSpace->pixelSize()]);
140 std::unique_ptr<quint8[]> tmpTarget (new quint8[targetSpace->pixelSize()]);
141 std::unique_ptr<quint8[]> tmpClipped (new quint8[m_sourceSpace->pixelSize()]);
142 std::array<qreal, 3> LCH {0.0, 0.0, 0.0};
143
144 while (nPixels > 0) {
145 // We could make good use of a LUT here.
146 m_sourceSpace->normalisedChannelsValue(srcU8, originalChannels);
147 m_sourceSpace->fromNormalisedChannelsValue(tmpOriginal.get(), originalChannels);
148
149 if (greyscale) {
150 LCH = ModelType::toLCH(originalChannels.data());
151 LCH[1] = 0;
152 ModelType::fromLCH(LCH, originalChannels.data());
153 m_sourceSpace->fromNormalisedChannelsValue(tmpOriginal.get(), originalChannels);
154 } else if (!m_cuspDescription.isEmpty()) {
155 LCH = ModelType::toLCH(originalChannels.data());
157
164 const float L = ModelType::cuberootLightness(LCH[0]);
165 const float cuspL = ModelType::cuberootLightness(cusp.y());
166 if (LCH[0] > cusp.y()) {
167 const float t = (L - cuspL) / (1.0 - cuspL);
168 const float c = qMax(0.0, cusp.x()* (1.0-t));
169
170 LCH[1] = qMin(LCH[1], qreal(c));
171
172 } else {
173 const float t = L / (cuspL);
174 const float c = qMax(0.0, cusp.x()*t);
175 LCH[1] = qMin(LCH[1], qreal(c));
176 }
177 ModelType::fromLCH(LCH, originalChannels.data());
178 m_sourceSpace->fromNormalisedChannelsValue(tmpOriginal.get(), originalChannels);
179 } else {
182
183 m_sourceSpace->normalisedChannelsValue(tmpClipped.get(), clippedChannels);
184
185 if (DifferenceType::difference(originalChannels, clippedChannels) > 0.02) {
186 LCH = ModelType::toLCH(originalChannels.data());
187
188 float min = 0;
189 float max = LCH[1];
190
191 while (max-min > 0.0001) {
192
193 LCH[1] = (max + min) * 0.5;
194 ModelType::fromLCH(LCH, originalChannels.data());
195
196
197 m_sourceSpace->fromNormalisedChannelsValue(tmpOriginal.get(), originalChannels);
200 m_sourceSpace->normalisedChannelsValue(tmpClipped.get(), clippedChannels);
201
202 if (DifferenceType::difference(originalChannels, clippedChannels) < 0.02) {
203 min = LCH[1];
204 } else {
205 max = LCH[1];
206 }
207 }
208 }
209 }
210
211 memcpy(dstU8, tmpOriginal.get(), m_sourceSpace->pixelSize());
212
213 --nPixels;
214 srcU8 += m_sourceSpace->pixelSize();
215 dstU8 += m_sourceSpace->pixelSize();
216 }
217 }
const KoID GrayAColorModelID("GRAYA", ki18n("Grayscale/Alpha"))
const KoID Integer16BitsColorDepthID("U16", ki18n("16-bit integer/channel"))
virtual quint32 pixelSize() const =0
virtual quint32 channelCount() const =0
virtual void normalisedChannelsValue(const quint8 *pixel, QVector< float > &channels) const =0
virtual void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values) const =0
virtual bool convertPixelsTo(const quint8 *src, quint8 *dst, const KoColorSpace *dstColorSpace, quint32 numPixels, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) const
QString id() const
Definition KoID.cpp:63
T min(T a, T b, T c)
QPointF KRITAPIGMENT_EXPORT cuspForHue(const QMap< float, QPointF > &gamutCuspDescription, const float hue)
constexpr std::enable_if< sizeof...(values)==0, size_t >::type max()
virtual QString colorModelID() const
const KoColorProfile * profileByName(const QString &name) const
const KoColorSpace * colorSpace(const QString &colorModelId, const QString &colorDepthId, const KoColorProfile *profile)
static KoColorSpaceRegistry * instance()

References KoColorConversionTransformation::adjustmentConversionFlags(), KoColorSpace::channelCount(), KoColorProfile::colorModelID(), KoColorSpaceRegistry::colorSpace(), KoColorSpace::convertPixelsTo(), KoGamutMappingUtils::cuspForHue(), KoColorSpace::fromNormalisedChannelsValue(), GrayAColorModelID, KoID::id(), KoColorSpaceRegistry::instance(), Integer16BitsColorDepthID, KoColorConversionTransformation::IntentRelativeColorimetric, KisGamutMapClipAdjustment< ModelType, DifferenceType >::m_cuspDescription, KisGamutMapClipAdjustment< ModelType, DifferenceType >::m_sourceSpace, KisGamutMapClipAdjustment< ModelType, DifferenceType >::m_targetColorProfileName, xsimd::max(), KoColorSpace::normalisedChannelsValue(), KoColorSpace::pixelSize(), and KoColorSpaceRegistry::profileByName().

Member Data Documentation

◆ m_cuspDescription

template<class ModelType , class DifferenceType >
QMap<float, QPointF> KisGamutMapClipAdjustment< ModelType, DifferenceType >::m_cuspDescription
private

Definition at line 262 of file kis_gamutmap_clip_adjustment.cpp.

◆ m_sourceSpace

template<class ModelType , class DifferenceType >
const KoColorSpace* KisGamutMapClipAdjustment< ModelType, DifferenceType >::m_sourceSpace
private

Definition at line 263 of file kis_gamutmap_clip_adjustment.cpp.

◆ m_targetColorProfileName

template<class ModelType , class DifferenceType >
QString KisGamutMapClipAdjustment< ModelType, DifferenceType >::m_targetColorProfileName
private

Definition at line 261 of file kis_gamutmap_clip_adjustment.cpp.


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