16#include <KSharedConfig>
17#include <KConfigGroup>
41 qreal
lumaRGB[3] {0.2126, 0.7152, 0.0722};
53 KConfigGroup cfg = KSharedConfig::openConfig()->group(
"advancedColorSelector");
64 if (!
m_d->allowUpdates) {
68 if (!
m_d->currentCS) {
69 m_d->currentcolor = c;
81 if (!
m_d->currentCS || *
m_d->currentCS != *cs) {
105 if (!
m_d->allowUpdates) {
109 quint32 changeFlags = 0;
110 QVector4D newValues(0, 0, 0, 0);
111 for (
int i = 0; i <
m_d->colorChannelCount; i++) {
112 newValues[i] = values[i];
113 changeFlags |= quint32(values[i] !=
m_d->channelValues[i]) << i;
115 if (changeFlags != 0) {
116 m_d->allowUpdates =
false;
117 m_d->channelValues = newValues;
121 m_d->allowUpdates =
true;
127 return m_d->currentcolor;
132 return m_d->channelValues;
137 return m_d->colorChannelCount;
147 return m_d->channelMaxValues;
152 if (maxValues ==
m_d->channelMaxValues) {
155 m_d->channelMaxValues = maxValues;
156 if (
m_d->exposureSupported) {
165 m_d->channelMaxValues = other.
m_d->channelMaxValues;
175 if (model ==
m_d->modelRGB) {
179 m_d->modelRGB = model;
192 return m_d->currentCS;
202 return (
m_d->exposureSupported);
208 QVector4D baseValues(values);
210 channelVec.fill(1.0);
215 HSVToRGB(values.x()*360, values.y(), values.z(), &baseValues[0], &baseValues[1], &baseValues[2]);
218 HSLToRGB(values.x()*360, values.y(), values.z(), &baseValues[0], &baseValues[1], &baseValues[2]);
223 HSIToRGB(values.x(), values.y(), values.z(), &temp[0], &temp[1], &temp[2]);
224 baseValues.setX(temp[0]);
225 baseValues.setY(temp[1]);
226 baseValues.setZ(temp[2]);
230 qreal Y = pow(values.z(),
m_d->gamma);
231 HSYToRGB(values.x(), values.y(), Y, &temp[0], &temp[1], &temp[2],
232 m_d->lumaRGB[0],
m_d->lumaRGB[1],
m_d->lumaRGB[2]);
233 baseValues.setX(temp[0]);
234 baseValues.setY(temp[1]);
235 baseValues.setZ(temp[2]);
236 if (!
m_d->isLinear) {
239 QVector<qreal> tempVec({baseValues[0], baseValues[1], baseValues[2]});
240 if (
m_d->exposureSupported) {
241 m_d->currentCS->profile()->delinearizeFloatValue(tempVec);
244 m_d->currentCS->profile()->delinearizeFloatValueFast(tempVec);
246 baseValues = QVector4D(tempVec[0], tempVec[1], tempVec[2], 0);
249 if (
m_d->applyGamma) {
250 for (
int i=0; i<3; i++) {
251 baseValues[i] = pow(baseValues[i], 2.2);
255 QVector<qreal> tempVec({baseValues[0], baseValues[1], baseValues[2]});
256 LCHToLab(values.z(), values.y(), values.x(), &tempVec[0], &tempVec[1], &tempVec[2]);
257 baseValues = QVector4D(tempVec[0], tempVec[1], tempVec[2], 0);
260 if (
m_d->exposureSupported) {
261 for (
int i = 0; i <
m_d->colorChannelCount; i++) {
262 baseValues[i] *=
m_d->channelMaxValues[i];
266 for (
int i=0; i<
m_d->colorChannelCount; i++) {
267 channelVec[
m_d->logicalToMemoryPosition[i]] = baseValues[i];
282 channelVec.fill(1.0);
283 m_d->currentCS->normalisedChannelsValue(c.
data(), channelVec);
284 QVector4D channelValuesDisplay(0, 0, 0, 0), coordinates(0, 0, 0, 0);
286 for (
int i =0; i<
m_d->colorChannelCount; i++) {
287 channelValuesDisplay[i] = channelVec[
m_d->logicalToMemoryPosition[i]];
290 if (
m_d->exposureSupported) {
291 for (
int i = 0; i <
m_d->colorChannelCount; i++) {
292 channelValuesDisplay[i] /=
m_d->channelMaxValues[i];
296 if (
m_d->applyGamma) {
297 for (
int i=0; i<3; i++) {
298 channelValuesDisplay[i] = pow(channelValuesDisplay[i], 1/2.2);
303 RGBToHSV(channelValuesDisplay[0], channelValuesDisplay[1], channelValuesDisplay[2], &hsv[0], &hsv[1], &hsv[2]);
305 coordinates = QVector4D(hsv, 0.f);
308 RGBToHSL(channelValuesDisplay[0], channelValuesDisplay[1], channelValuesDisplay[2], &hsl[0], &hsl[1], &hsl[2]);
310 coordinates = QVector4D(hsl, 0.f);
313 RGBToHSI(channelValuesDisplay[0], channelValuesDisplay[1], channelValuesDisplay[2], &hsi[0], &hsi[1], &hsi[2]);
314 coordinates = QVector4D(hsi[0], hsi[1], hsi[2], 0.f);
316 if (!
m_d->isLinear) {
319 QVector<qreal> temp({channelValuesDisplay[0], channelValuesDisplay[1], channelValuesDisplay[2]});
320 m_d->currentCS->profile()->linearizeFloatValue(temp);
321 channelValuesDisplay = QVector4D(temp[0], temp[1], temp[2], 0);
324 RGBToHSY(channelValuesDisplay[0], channelValuesDisplay[1], channelValuesDisplay[2], &hsy[0], &hsy[1], &hsy[2],
325 m_d->lumaRGB[0],
m_d->lumaRGB[1],
m_d->lumaRGB[2]);
326 hsy[2] = pow(hsy[2], 1/
m_d->gamma);
327 coordinates = QVector4D(hsy[0], hsy[1], hsy[2], 0.f);
330 if (coordinates[0] < 0) {
331 coordinates[0] =
m_d->channelValues[0];
333 for (
int i=0; i<3; i++) {
334 coordinates[i] = qBound(0.f, coordinates[i], 1.f);
338 LabToLCH(channelValuesDisplay[0], channelValuesDisplay[1], channelValuesDisplay[2], &lch[0], &lch[1], &lch[2]);
339 coordinates = QVector4D(lch[2], lch[1], lch[0], 0.f);
341 if (coordinates[0] < 0) {
342 coordinates[0] =
m_d->channelValues[0];
344 for (
int i=0; i<3; i++) {
345 coordinates[i] = qBound(0.f, coordinates[i], 1.f);
348 for (
int i=0; i<4; i++) {
349 coordinates[i] = qBound(0.f, channelValuesDisplay[i], 1.f);
357 KConfigGroup cfg = KSharedConfig::openConfig()->group(
"advancedColorSelector");
360 m_d->gamma = cfg.readEntry(
"gamma", 2.2);
364 switch(
m_d->acs_config.mainTypeParameter) {
407 for (
int i = 0; i < channelList.size(); i++) {
414 m_d->logicalToMemoryPosition[logical] = i;
415 m_d->channelMaxValues[logical] = channel->
getUIMax();
419 KIS_ASSERT_X(cCount < 5,
"",
"unsupported channel count!");
421 m_d->colorChannelCount = cCount;
428 m_d->exposureSupported =
true;
430 m_d->exposureSupported =
false;
443 memcpy(
m_d->lumaRGB, luma.constData(), 3*
sizeof(qreal));
444 m_d->model =
m_d->modelRGB;
445 }
else if (
m_d->isLABlike) {
446 m_d->model =
m_d->modelRGB;
461 bool updatesAllowed =
m_d->allowUpdates;
462 m_d->allowUpdates =
false;
464 m_d->allowUpdates = updatesAllowed;
void LabToLCH(const qreal l, const qreal a, const qreal b, qreal *L, qreal *C, qreal *H)
void HSYToRGB(const qreal h, const qreal s, const qreal y, qreal *red, qreal *green, qreal *blue, qreal R, qreal G, qreal B)
void RGBToHSV(float r, float g, float b, float *h, float *s, float *v)
void RGBToHSI(qreal r, qreal g, qreal b, qreal *h, qreal *s, qreal *i)
void LCHToLab(const qreal L, const qreal C, const qreal H, qreal *l, qreal *a, qreal *b)
void HSIToRGB(const qreal h, const qreal s, const qreal i, qreal *red, qreal *green, qreal *blue)
void RGBToHSL(float r, float g, float b, float *h, float *s, float *l)
void RGBToHSY(const qreal r, const qreal g, const qreal b, qreal *h, qreal *s, qreal *y, qreal R, qreal G, qreal B)
void HSVToRGB(float h, float s, float v, float *r, float *g, float *b)
void HSLToRGB(float h, float sl, float l, float *r, float *g, float *b)
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 Float16BitsColorDepthID("F16", ki18n("16-bit float/channel"))
const KoID CMYKAColorModelID("CMYKA", ki18n("CMYK/Alpha"))
const KoID LABAColorModelID("LABA", ki18n("L*a*b*/Alpha"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
static KisColorSelectorConfiguration fromString(QString string)
The KisVisualColorModel class allows manipulating a KoColor using various color models.
void setMaxChannelValues(const QVector4D &maxValues)
void sigColorModelChanged()
sigColorModelChanged is emitted whenever the color model changes.
const KoColorSpace * colorSpace() const
void copyState(const KisVisualColorModel &other)
Copy the internal state of another KisVisualColorModel.
int colorChannelCount() const
KoColor currentColor() const
void slotSetColorSpace(const KoColorSpace *cs)
void slotLoadACSConfig()
slotLoadACSConfig loads supported settings from Advanced Color Selector
QVector4D convertKoColorToChannelValues(KoColor c) const
QVector4D channelValues() const
QVector4D maxChannelValues() const
bool supportsExposure() const
void loadColorSpace(const KoColorSpace *cs)
KoColor convertChannelValuesToKoColor(const QVector4D &values) const
void slotSetChannelValues(const QVector4D &values)
void setRGBColorModel(ColorModel model)
Set the HSX color model used for RGB color spaces.
~KisVisualColorModel() override
void sigNewColor(const KoColor &c)
const QScopedPointer< Private > m_d
ColorModel colorModel() const
void slotSetColor(const KoColor &c)
void sigChannelValuesChanged(const QVector4D &values, quint32 channelFlags)
void sigColorSpaceChanged()
sigColorSpaceChanged notifies that the color space from which the channel values are derived changed,...
@ ALPHA
The channel represents the opacity of a pixel.
enumChannelType channelType() const
qint32 displayPosition() const
double getUIMax(void) const
virtual quint32 alphaPos() const =0
QList< KoChannelInfo * > channels
virtual KoID colorModelId() const =0
QVector< qreal > lumaCoefficients
virtual quint32 channelCount() const =0
virtual KoID colorDepthId() const =0
virtual void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values) const =0
virtual const KoColorProfile * profile() const =0
void convertTo(const KoColorSpace *cs, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)
KoColor convertedTo(const KoColorSpace *cs, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags) const
const KoColorSpace * colorSpace() const
return the current colorSpace
#define KIS_ASSERT_X(cond, where, what)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
QVector4D channelMaxValues
const KoColorSpace * currentCS
KisColorSelectorConfiguration acs_config
int logicalToMemoryPosition[4]
virtual QByteArray uniqueId() const =0
virtual bool isLinear() const =0
static KoColorSpaceRegistry * instance()
const KoColorProfile * p2020PQProfile() const
const KoColorProfile * p2020G10Profile() const