QColorVector: make the (QPointF) ctor a named one
Instead of an explicit ctor, make conversion from QPointF an explicitly-named ctor. This prepares the class for being converted to a pure struct, alleviating its use in arrays without the additional QUninitialized kludge that Coverity doesn't seem to understand. Amends 78a7e54f8f5c4ca6ce1ee6b0ac82c42b21738ac5. As a drive-by, take the QPointF by value, fixing clazy-function-args-by-value. Coverity-Id: 444249 Coverity-Id: 425860 Change-Id: I925e94b21bf041a6fb03c56ef9a2da85d8285982 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
parent
447a82ebe4
commit
01ee796b96
@ -29,11 +29,8 @@ class QColorVector
|
||||
public:
|
||||
QColorVector() = default;
|
||||
constexpr QColorVector(float x, float y, float z, float w = 0.0f) noexcept : x(x), y(y), z(z), w(w) { }
|
||||
explicit constexpr QColorVector(const QPointF &chr) // from XY chromaticity
|
||||
: x(chr.x() / chr.y())
|
||||
, y(1.0f)
|
||||
, z((1.0f - chr.x() - chr.y()) / chr.y())
|
||||
{ }
|
||||
static constexpr QColorVector fromXYChromaticity(QPointF chr)
|
||||
{ return {float(chr.x() / chr.y()), 1.0f, float((1.0f - chr.x() - chr.y()) / chr.y())}; }
|
||||
float x = 0.0f; // X, x, L, or red/cyan
|
||||
float y = 0.0f; // Y, y, a, or green/magenta
|
||||
float z = 0.0f; // Z, Y, b, or blue/yellow
|
||||
@ -75,8 +72,8 @@ public:
|
||||
// Common whitepoints:
|
||||
static constexpr QPointF D50Chromaticity() { return QPointF(0.34567, 0.35850); }
|
||||
static constexpr QPointF D65Chromaticity() { return QPointF(0.31271, 0.32902); }
|
||||
static constexpr QColorVector D50() { return QColorVector(D50Chromaticity()); }
|
||||
static constexpr QColorVector D65() { return QColorVector(D65Chromaticity()); }
|
||||
static constexpr QColorVector D50() { return fromXYChromaticity(D50Chromaticity()); }
|
||||
static constexpr QColorVector D65() { return fromXYChromaticity(D65Chromaticity()); }
|
||||
|
||||
QColorVector xyzToLab() const
|
||||
{
|
||||
|
@ -81,14 +81,14 @@ bool QColorSpacePrimaries::areValid() const
|
||||
QColorMatrix QColorSpacePrimaries::toXyzMatrix() const
|
||||
{
|
||||
// This converts to XYZ in some undefined scale.
|
||||
QColorMatrix toXyz = { QColorVector(redPoint),
|
||||
QColorVector(greenPoint),
|
||||
QColorVector(bluePoint) };
|
||||
QColorMatrix toXyz = { QColorVector::fromXYChromaticity(redPoint),
|
||||
QColorVector::fromXYChromaticity(greenPoint),
|
||||
QColorVector::fromXYChromaticity(bluePoint) };
|
||||
|
||||
// Since the white point should be (1.0, 1.0, 1.0) in the
|
||||
// input, we can figure out the scale by using the
|
||||
// inverse conversion on the white point.
|
||||
QColorVector wXyz(whitePoint);
|
||||
const auto wXyz = QColorVector::fromXYChromaticity(whitePoint);
|
||||
QColorVector whiteScale = toXyz.inverted().map(wXyz);
|
||||
|
||||
// Now we have scaled conversion to XYZ relative to the given whitepoint
|
||||
@ -155,7 +155,7 @@ QColorSpacePrivate::QColorSpacePrivate(const QColorSpacePrimaries &primaries,
|
||||
, transferFunction(transferFunction)
|
||||
, colorModel(QColorSpace::ColorModel::Rgb)
|
||||
, gamma(gamma)
|
||||
, whitePoint(primaries.whitePoint)
|
||||
, whitePoint(QColorVector::fromXYChromaticity(primaries.whitePoint))
|
||||
{
|
||||
Q_ASSERT(primaries.areValid());
|
||||
toXyz = primaries.toXyzMatrix();
|
||||
@ -173,7 +173,7 @@ QColorSpacePrivate::QColorSpacePrivate(const QPointF &whitePoint,
|
||||
, transferFunction(transferFunction)
|
||||
, colorModel(QColorSpace::ColorModel::Gray)
|
||||
, gamma(gamma)
|
||||
, whitePoint(whitePoint)
|
||||
, whitePoint(QColorVector::fromXYChromaticity(whitePoint))
|
||||
{
|
||||
chad = QColorMatrix::chromaticAdaptation(this->whitePoint);
|
||||
toXyz = chad;
|
||||
@ -185,7 +185,7 @@ QColorSpacePrivate::QColorSpacePrivate(const QPointF &whitePoint, const QList<ui
|
||||
, transferFunction(QColorSpace::TransferFunction::Custom)
|
||||
, colorModel(QColorSpace::ColorModel::Gray)
|
||||
, gamma(0)
|
||||
, whitePoint(whitePoint)
|
||||
, whitePoint(QColorVector::fromXYChromaticity(whitePoint))
|
||||
{
|
||||
chad = QColorMatrix::chromaticAdaptation(this->whitePoint);
|
||||
toXyz = chad;
|
||||
@ -209,7 +209,7 @@ QColorSpacePrivate::QColorSpacePrivate(const QColorSpacePrimaries &primaries, co
|
||||
, transferFunction(QColorSpace::TransferFunction::Custom)
|
||||
, colorModel(QColorSpace::ColorModel::Rgb)
|
||||
, gamma(0)
|
||||
, whitePoint(primaries.whitePoint)
|
||||
, whitePoint(QColorVector::fromXYChromaticity(primaries.whitePoint))
|
||||
{
|
||||
Q_ASSERT(primaries.areValid());
|
||||
toXyz = primaries.toXyzMatrix();
|
||||
@ -231,7 +231,7 @@ QColorSpacePrivate::QColorSpacePrivate(const QColorSpacePrimaries &primaries,
|
||||
{
|
||||
Q_ASSERT(primaries.areValid());
|
||||
toXyz = primaries.toXyzMatrix();
|
||||
whitePoint = QColorVector(primaries.whitePoint);
|
||||
whitePoint = QColorVector::fromXYChromaticity(primaries.whitePoint);
|
||||
chad = QColorMatrix::chromaticAdaptation(whitePoint);
|
||||
toXyz = chad * toXyz;
|
||||
setTransferFunctionTables(redTransferFunctionTable,
|
||||
@ -314,7 +314,7 @@ void QColorSpacePrivate::setToXyzMatrix()
|
||||
}
|
||||
QColorSpacePrimaries colorSpacePrimaries(primaries);
|
||||
toXyz = colorSpacePrimaries.toXyzMatrix();
|
||||
whitePoint = QColorVector(colorSpacePrimaries.whitePoint);
|
||||
whitePoint = QColorVector::fromXYChromaticity(colorSpacePrimaries.whitePoint);
|
||||
chad = QColorMatrix::chromaticAdaptation(whitePoint);
|
||||
toXyz = chad * toXyz;
|
||||
}
|
||||
@ -940,9 +940,10 @@ void QColorSpace::setPrimaries(const QPointF &whitePoint, const QPointF &redPoin
|
||||
return;
|
||||
}
|
||||
QColorMatrix toXyz = primaries.toXyzMatrix();
|
||||
QColorMatrix chad = QColorMatrix::chromaticAdaptation(QColorVector(whitePoint));
|
||||
QColorMatrix chad = QColorMatrix::chromaticAdaptation(QColorVector::fromXYChromaticity(whitePoint));
|
||||
toXyz = chad * toXyz;
|
||||
if (QColorVector(primaries.whitePoint) == d_ptr->whitePoint && toXyz == d_ptr->toXyz && chad == d_ptr->chad)
|
||||
if (QColorVector::fromXYChromaticity(primaries.whitePoint) == d_ptr->whitePoint
|
||||
&& toXyz == d_ptr->toXyz && chad == d_ptr->chad)
|
||||
return;
|
||||
detach();
|
||||
if (d_ptr->transformModel == TransformModel::ElementListProcessing)
|
||||
@ -953,7 +954,7 @@ void QColorSpace::setPrimaries(const QPointF &whitePoint, const QPointF &redPoin
|
||||
d_ptr->colorModel = QColorSpace::ColorModel::Rgb;
|
||||
d_ptr->toXyz = toXyz;
|
||||
d_ptr->chad = chad;
|
||||
d_ptr->whitePoint = QColorVector(primaries.whitePoint);
|
||||
d_ptr->whitePoint = QColorVector::fromXYChromaticity(primaries.whitePoint);
|
||||
d_ptr->identifyColorSpace();
|
||||
}
|
||||
|
||||
@ -980,7 +981,7 @@ void QColorSpace::setWhitePoint(const QPointF &whitePoint)
|
||||
d_ptr = new QColorSpacePrivate(whitePoint, TransferFunction::Custom, 0.0f);
|
||||
return;
|
||||
}
|
||||
if (QColorVector(whitePoint) == d_ptr->whitePoint)
|
||||
if (QColorVector::fromXYChromaticity(whitePoint) == d_ptr->whitePoint)
|
||||
return;
|
||||
detach();
|
||||
if (d_ptr->transformModel == TransformModel::ElementListProcessing)
|
||||
@ -991,7 +992,7 @@ void QColorSpace::setWhitePoint(const QPointF &whitePoint)
|
||||
// An RGB color model stays RGB, a gray stays gray, but an undefined one can now be considered gray
|
||||
if (d_ptr->colorModel == QColorSpace::ColorModel::Undefined)
|
||||
d_ptr->colorModel = QColorSpace::ColorModel::Gray;
|
||||
QColorVector wXyz(whitePoint);
|
||||
QColorVector wXyz(QColorVector::fromXYChromaticity(whitePoint));
|
||||
if (d_ptr->transformModel == QColorSpace::TransformModel::ThreeComponentMatrix) {
|
||||
if (d_ptr->colorModel == QColorSpace::ColorModel::Rgb) {
|
||||
// Rescale toXyz to new whitepoint
|
||||
|
Loading…
x
Reference in New Issue
Block a user