5#include "absolutecolor.h"
8#include "helperposixmath.h"
12#include <qgenericmatrix.h>
16#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
17#include <qhashfunctions.h>
31Q_GLOBAL_STATIC_WITH_ARGS(
34 (std::array<double, 9>{{
35 +0.8189330101, +0.3618667424, -0.1288597137,
36 +0.0329845436, +0.9293118715, +0.0361456387,
37 +0.0482003018, +0.2643662691, +0.6338517070}}.data()))
40Q_GLOBAL_STATIC_WITH_ARGS(
43 (std::array<
double, 9>{{
44 +0.2104542553, +0.7936177850, -0.0040720468,
45 +1.9779984951, -2.4285922050, +0.4505937099,
46 +0.0259040371, +0.7827717662, -0.8086757660}}.data()))
49Q_GLOBAL_STATIC_WITH_ARGS(
52 (std::array<double, 9>{{
53 +1.047886, +0.022919, -0.050216,
54 +0.029582, +0.990484, -0.017079,
55 -0.009252, +0.015073, +0.751678}}.data()))
59Q_GLOBAL_STATIC_WITH_ARGS(
62 (inverseMatrix(*m1).value_or(SquareMatrix3())))
64Q_GLOBAL_STATIC_WITH_ARGS(
67 (inverseMatrix(*m2).value_or(SquareMatrix3())))
69Q_GLOBAL_STATIC_WITH_ARGS(
72 (inverseMatrix(*xyzD65ToXyzD50).value_or(SquareMatrix3())))
84 for (
const auto &item : conversionList) {
85 if (item.from == model) {
106 const auto availableConversions = conversionsFrom(model);
107 const auto currentValue = values->
value(model);
108 for (
const auto &conversion : availableConversions) {
109 if (!values->
contains(conversion.to)) {
110 values->
insert(conversion.to, conversion.conversionFunction(currentValue));
111 addDirectConversionsRecursivly(values, conversion.to);
126 result.
insert(model, value);
127 addDirectConversionsRecursivly(&result, model);
155GenericColor AbsoluteColor::fromOklabToXyzD65(
const GenericColor &value)
163 auto lms = (*m2inverse) * value.toTrio();
167 lms( 0, 0) = std::pow(lms( 0, 0), 3);
168 lms( 1, 0) = std::pow(lms( 1, 0), 3);
169 lms( 2, 0) = std::pow(lms( 2, 0), 3);
171 return GenericColor((*m1inverse) * lms);
201GenericColor AbsoluteColor::fromXyzD65ToOklab(
const GenericColor &value)
208 auto lms = (*m1) * value.toTrio();
229 lms( 0, 0) = std::cbrt(lms( 0, 0));
230 lms( 1, 0) = std::cbrt(lms( 1, 0));
231 lms( 2, 0) = std::cbrt(lms( 2, 0));
234 return GenericColor((*m2) * lms);
244GenericColor AbsoluteColor::fromXyzD65ToXyzD50(
const GenericColor &value)
246 return GenericColor((*xyzD65ToXyzD50) * value.toTrio());
256GenericColor AbsoluteColor::fromXyzD50ToXyzD65(
const GenericColor &value)
258 return GenericColor((*xyzD50ToXyzD65) * value.toTrio());
268GenericColor AbsoluteColor::fromXyzD50ToCielabD50(
const GenericColor &value)
270 const cmsCIEXYZ cmsXyzD50 = value.reinterpretAsXyzToCmsciexyz();
272 cmsXYZ2Lab(cmsD50_XYZ(),
275 return GenericColor(result);
285GenericColor AbsoluteColor::fromCielabD50ToXyzD50(
const GenericColor &value)
287 const auto temp = value.reinterpretAsLabToCmscielab();
289 cmsLab2XYZ(cmsD50_XYZ(),
292 return GenericColor(xyzD50);
306GenericColor AbsoluteColor::fromCartesianToPolar(
const GenericColor &value)
308 GenericColor result = value;
309 const auto &x = value.second;
310 const auto &y = value.third;
311 const auto radius = sqrt(pow(x, 2) + pow(y, 2));
312 result.second = radius;
318 result.third = qRadiansToDegrees(acos(x / radius));
320 result.third = qRadiansToDegrees(2 * pi - acos(x / radius));
336GenericColor AbsoluteColor::fromPolarToCartesian(
const GenericColor &value)
338 const auto &radius = value.second;
339 const auto &angleDegree = value.third;
340 return GenericColor(value.first,
341 radius * cos(qDegreesToRadians(angleDegree)),
342 radius * sin(qDegreesToRadians(angleDegree)),
355std::optional<GenericColor> AbsoluteColor::convert(
const ColorModel from,
const GenericColor &value,
const ColorModel to)
357 const auto temp = allConversions(from, value);
358 if (temp.contains(to)) {
359 return temp.value(to);
The namespace of this library.
bool contains(const Key &key) const const
iterator insert(const Key &key, const T &value)
T value(const Key &key) const const
void append(QList< T > &&value)