summaryrefslogtreecommitdiffstats
path: root/src/gui/painting
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/painting')
-rw-r--r--src/gui/painting/qbackingstore.cpp29
-rw-r--r--src/gui/painting/qbackingstorerhisupport.cpp4
-rw-r--r--src/gui/painting/qcmyk_p.h6
-rw-r--r--src/gui/painting/qcolormatrix_p.h6
-rw-r--r--src/gui/painting/qcolorspace.cpp103
-rw-r--r--src/gui/painting/qcolorspace.h13
-rw-r--r--src/gui/painting/qcolortransferfunction_p.h5
-rw-r--r--src/gui/painting/qcolortransfergeneric_p.h109
-rw-r--r--src/gui/painting/qcolortransform.cpp509
-rw-r--r--src/gui/painting/qcolortransform_p.h12
-rw-r--r--src/gui/painting/qcolortrc_p.h101
-rw-r--r--src/gui/painting/qcolortrclut.cpp67
-rw-r--r--src/gui/painting/qcolortrclut_p.h11
-rw-r--r--src/gui/painting/qdatabuffer_p.h3
-rw-r--r--src/gui/painting/qdrawhelper.cpp8
-rw-r--r--src/gui/painting/qicc.cpp895
-rw-r--r--src/gui/painting/qimagescale.cpp2
-rw-r--r--src/gui/painting/qpagelayout.h2
-rw-r--r--src/gui/painting/qpagesize.h2
-rw-r--r--src/gui/painting/qpaintdevice.cpp35
-rw-r--r--src/gui/painting/qpaintdevice.h16
-rw-r--r--src/gui/painting/qpaintdevice.qdoc20
-rw-r--r--src/gui/painting/qpdf.cpp70
-rw-r--r--src/gui/painting/qpdf_p.h4
-rw-r--r--src/gui/painting/qplatformbackingstore.cpp65
-rw-r--r--src/gui/painting/qplatformbackingstore.h9
-rw-r--r--src/gui/painting/qregion.cpp64
-rw-r--r--src/gui/painting/qregion.h4
-rw-r--r--src/gui/painting/qrhibackingstore.cpp23
29 files changed, 1575 insertions, 622 deletions
diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp
index 2304ee2256..3b709ec77b 100644
--- a/src/gui/painting/qbackingstore.cpp
+++ b/src/gui/painting/qbackingstore.cpp
@@ -50,6 +50,7 @@ public:
QScopedPointer<QImage> highDpiBackingstore;
QRegion staticContents;
QSize size;
+ QSize nativeSize;
bool downscale = qEnvironmentVariableIntValue("QT_WIDGETS_HIGHDPI_DOWNSCALE") > 0;
};
@@ -115,14 +116,13 @@ QWindow* QBackingStore::window() const
void QBackingStore::beginPaint(const QRegion &region)
{
- const qreal dpr = d_ptr->backingStoreDevicePixelRatio();
+ const qreal toNativeFactor = d_ptr->deviceIndependentToNativeFactor();
- if (d_ptr->highDpiBackingstore &&
- d_ptr->highDpiBackingstore->devicePixelRatio() != dpr)
+ if (d_ptr->nativeSize != QHighDpi::scale(size(), toNativeFactor))
resize(size());
QPlatformBackingStore *platformBackingStore = handle();
- platformBackingStore->beginPaint(QHighDpi::scale(region, d_ptr->deviceIndependentToNativeFactor()));
+ platformBackingStore->beginPaint(QHighDpi::scale(region, toNativeFactor));
// When QtGui is applying a high-dpi scale factor the backing store
// creates a "large" backing store image. This image needs to be
@@ -131,18 +131,20 @@ void QBackingStore::beginPaint(const QRegion &region)
// the image data to avoid having the new devicePixelRatio be propagated
// back to the platform plugin.
QPaintDevice *device = platformBackingStore->paintDevice();
- if (QHighDpiScaling::isActive() && device->devType() == QInternal::Image) {
+ if (!qFuzzyCompare(toNativeFactor, qreal(1)) && device->devType() == QInternal::Image) {
QImage *source = static_cast<QImage *>(device);
const bool needsNewImage = d_ptr->highDpiBackingstore.isNull()
- || source->data_ptr() != d_ptr->highDpiBackingstore->data_ptr()
+ || source->constBits() != d_ptr->highDpiBackingstore->constBits()
|| source->size() != d_ptr->highDpiBackingstore->size()
- || source->devicePixelRatio() != d_ptr->highDpiBackingstore->devicePixelRatio();
- if (needsNewImage) {
+ || source->bytesPerLine() != d_ptr->highDpiBackingstore->bytesPerLine()
+ || source->format() != d_ptr->highDpiBackingstore->format();
+ if (needsNewImage)
d_ptr->highDpiBackingstore.reset(
new QImage(source->bits(), source->width(), source->height(), source->bytesPerLine(), source->format()));
- d_ptr->highDpiBackingstore->setDevicePixelRatio(dpr);
- }
+ d_ptr->highDpiBackingstore->setDevicePixelRatio(d_ptr->backingStoreDevicePixelRatio());
+ } else {
+ d_ptr->highDpiBackingstore.reset();
}
}
@@ -156,7 +158,7 @@ QPaintDevice *QBackingStore::paintDevice()
{
QPaintDevice *device = handle()->paintDevice();
- if (QHighDpiScaling::isActive() && device->devType() == QInternal::Image)
+ if (!qFuzzyCompare(d_ptr->deviceIndependentToNativeFactor(), qreal(1)) && device->devType() == QInternal::Image)
return d_ptr->highDpiBackingstore.data();
return device;
@@ -229,9 +231,10 @@ void QBackingStore::flush(const QRegion &region, QWindow *window, const QPoint &
*/
void QBackingStore::resize(const QSize &size)
{
- d_ptr->size = size;
const qreal factor = d_ptr->deviceIndependentToNativeFactor();
- handle()->resize(QHighDpi::scale(size, factor), QHighDpi::scale(d_ptr->staticContents, factor));
+ d_ptr->size = size;
+ d_ptr->nativeSize = QHighDpi::scale(size, factor);
+ handle()->resize(d_ptr->nativeSize, QHighDpi::scale(d_ptr->staticContents, factor));
}
/*!
diff --git a/src/gui/painting/qbackingstorerhisupport.cpp b/src/gui/painting/qbackingstorerhisupport.cpp
index fe5589dc2d..37c52155eb 100644
--- a/src/gui/painting/qbackingstorerhisupport.cpp
+++ b/src/gui/painting/qbackingstorerhisupport.cpp
@@ -114,8 +114,8 @@ bool QBackingStoreRhiSupport::create()
if (QRhi::probe(QRhi::Metal, &params)) {
rhi = QRhi::create(QRhi::Metal, &params, flags);
} else {
- qCDebug(lcQpaBackingStore, "Metal does not seem to be supported. Falling back to OpenGL.");
- rhi = QRhi::create(QRhi::OpenGLES2, &params, flags);
+ qCDebug(lcQpaBackingStore, "Metal does not seem to be supported");
+ return false;
}
}
#endif
diff --git a/src/gui/painting/qcmyk_p.h b/src/gui/painting/qcmyk_p.h
index d00a4b5a6e..1294a18244 100644
--- a/src/gui/painting/qcmyk_p.h
+++ b/src/gui/painting/qcmyk_p.h
@@ -24,6 +24,10 @@ class QCmyk32
{
private:
uint m_cmyk = 0;
+ friend constexpr bool comparesEqual(const QCmyk32 &lhs, const QCmyk32 &rhs) noexcept
+ {
+ return lhs.m_cmyk == rhs.m_cmyk;
+ }
public:
QCmyk32() = default;
@@ -77,6 +81,8 @@ public:
QColor c = color.toCmyk();
return QCmyk32(c.cyan(), c.magenta(), c.yellow(), c.black());
}
+
+ Q_DECLARE_EQUALITY_COMPARABLE_LITERAL_TYPE(QCmyk32)
};
static_assert(sizeof(QCmyk32) == sizeof(int));
diff --git a/src/gui/painting/qcolormatrix_p.h b/src/gui/painting/qcolormatrix_p.h
index 6a9b9f4f9a..0c85222a9a 100644
--- a/src/gui/painting/qcolormatrix_p.h
+++ b/src/gui/painting/qcolormatrix_p.h
@@ -336,6 +336,12 @@ public:
{ 0.1351922452f, 0.7118769884f, 0.0000000000f },
{ 0.0313525312f, 0.0000856627f, 0.8251883388f } };
}
+ static QColorMatrix toXyzFromBt2020()
+ {
+ return QColorMatrix { { 0.673447f, 0.279037f, -0.00192261f },
+ { 0.165665f, 0.675339f, 0.0299835f },
+ { 0.125092f, 0.0456238f, 0.797134f } };
+ }
friend inline bool comparesEqual(const QColorMatrix &lhs, const QColorMatrix &rhs);
Q_DECLARE_EQUALITY_COMPARABLE(QColorMatrix);
};
diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp
index 7a1d34a408..3d763d577c 100644
--- a/src/gui/painting/qcolorspace.cpp
+++ b/src/gui/painting/qcolorspace.cpp
@@ -21,7 +21,7 @@ QT_BEGIN_NAMESPACE
Q_CONSTINIT QBasicMutex QColorSpacePrivate::s_lutWriteLock;
-Q_CONSTINIT static QAtomicPointer<QColorSpacePrivate> s_predefinedColorspacePrivates[QColorSpace::ProPhotoRgb] = {};
+Q_CONSTINIT static QAtomicPointer<QColorSpacePrivate> s_predefinedColorspacePrivates[QColorSpace::Bt2100Hlg] = {};
static void cleanupPredefinedColorspaces()
{
for (QAtomicPointer<QColorSpacePrivate> &ptr : s_predefinedColorspacePrivates) {
@@ -60,6 +60,12 @@ QColorSpacePrimaries::QColorSpacePrimaries(QColorSpace::Primaries primaries)
bluePoint = QPointF(0.0366, 0.0001);
whitePoint = QColorVector::D50Chromaticity();
break;
+ case QColorSpace::Primaries::Bt2020:
+ redPoint = QPointF(0.708, 0.292);
+ greenPoint = QPointF(0.170, 0.797);
+ bluePoint = QPointF(0.131, 0.046);
+ whitePoint = QColorVector::D65Chromaticity();
+ break;
default:
Q_UNREACHABLE();
}
@@ -132,6 +138,21 @@ QColorSpacePrivate::QColorSpacePrivate(QColorSpace::NamedColorSpace namedColorSp
transferFunction = QColorSpace::TransferFunction::ProPhotoRgb;
description = QStringLiteral("ProPhoto RGB");
break;
+ case QColorSpace::Bt2020:
+ primaries = QColorSpace::Primaries::Bt2020;
+ transferFunction = QColorSpace::TransferFunction::Bt2020;
+ description = QStringLiteral("BT.2020");
+ break;
+ case QColorSpace::Bt2100Pq:
+ primaries = QColorSpace::Primaries::Bt2020;
+ transferFunction = QColorSpace::TransferFunction::St2084;
+ description = QStringLiteral("BT.2100(PQ)");
+ break;
+ case QColorSpace::Bt2100Hlg:
+ primaries = QColorSpace::Primaries::Bt2020;
+ transferFunction = QColorSpace::TransferFunction::Hlg;
+ description = QStringLiteral("BT.2100(HLG)");
+ break;
default:
Q_UNREACHABLE();
}
@@ -292,6 +313,26 @@ void QColorSpacePrivate::identifyColorSpace()
}
}
break;
+ case QColorSpace::Primaries::Bt2020:
+ if (transferFunction == QColorSpace::TransferFunction::Bt2020) {
+ namedColorSpace = QColorSpace::Bt2020;
+ if (description.isEmpty())
+ description = QStringLiteral("BT.2020");
+ return;
+ }
+ if (transferFunction == QColorSpace::TransferFunction::St2084) {
+ namedColorSpace = QColorSpace::Bt2100Pq;
+ if (description.isEmpty())
+ description = QStringLiteral("BT.2100(PQ)");
+ return;
+ }
+ if (transferFunction == QColorSpace::TransferFunction::Hlg) {
+ namedColorSpace = QColorSpace::Bt2100Hlg;
+ if (description.isEmpty())
+ description = QStringLiteral("BT.2100(HLG)");
+ return;
+ }
+ break;
default:
break;
}
@@ -337,7 +378,7 @@ void QColorSpacePrivate::setTransferFunctionTable(const QList<uint16_t> &transfe
} else if (curve.isSRgb()) {
transferFunction = QColorSpace::TransferFunction::SRgb;
}
- trc[0].m_type = QColorTrc::Type::Function;
+ trc[0].m_type = QColorTrc::Type::ParameterizedFunction;
trc[0].m_fun = curve;
} else {
trc[0].m_type = QColorTrc::Type::Table;
@@ -363,21 +404,21 @@ void QColorSpacePrivate::setTransferFunctionTables(const QList<uint16_t> &redTra
transferFunction = QColorSpace::TransferFunction::Custom;
QColorTransferFunction curve;
if (redTable.asColorTransferFunction(&curve)) {
- trc[0].m_type = QColorTrc::Type::Function;
+ trc[0].m_type = QColorTrc::Type::ParameterizedFunction;
trc[0].m_fun = curve;
} else {
trc[0].m_type = QColorTrc::Type::Table;
trc[0].m_table = redTable;
}
if (greenTable.asColorTransferFunction(&curve)) {
- trc[1].m_type = QColorTrc::Type::Function;
+ trc[1].m_type = QColorTrc::Type::ParameterizedFunction;
trc[1].m_fun = curve;
} else {
trc[1].m_type = QColorTrc::Type::Table;
trc[1].m_table = greenTable;
}
if (blueTable.asColorTransferFunction(&curve)) {
- trc[2].m_type = QColorTrc::Type::Function;
+ trc[2].m_type = QColorTrc::Type::ParameterizedFunction;
trc[2].m_fun = curve;
} else {
trc[2].m_type = QColorTrc::Type::Table;
@@ -390,27 +431,34 @@ void QColorSpacePrivate::setTransferFunction()
{
switch (transferFunction) {
case QColorSpace::TransferFunction::Linear:
- trc[0].m_type = QColorTrc::Type::Function;
- trc[0].m_fun = QColorTransferFunction();
+ trc[0] = QColorTransferFunction();
if (qFuzzyIsNull(gamma))
gamma = 1.0f;
break;
case QColorSpace::TransferFunction::Gamma:
- trc[0].m_type = QColorTrc::Type::Function;
- trc[0].m_fun = QColorTransferFunction::fromGamma(gamma);
+ trc[0] = QColorTransferFunction::fromGamma(gamma);
break;
case QColorSpace::TransferFunction::SRgb:
- trc[0].m_type = QColorTrc::Type::Function;
- trc[0].m_fun = QColorTransferFunction::fromSRgb();
+ trc[0] = QColorTransferFunction::fromSRgb();
if (qFuzzyIsNull(gamma))
gamma = 2.31f;
break;
case QColorSpace::TransferFunction::ProPhotoRgb:
- trc[0].m_type = QColorTrc::Type::Function;
- trc[0].m_fun = QColorTransferFunction::fromProPhotoRgb();
+ trc[0] = QColorTransferFunction::fromProPhotoRgb();
if (qFuzzyIsNull(gamma))
gamma = 1.8f;
break;
+ case QColorSpace::TransferFunction::Bt2020:
+ trc[0] = QColorTransferFunction::fromBt2020();
+ if (qFuzzyIsNull(gamma))
+ gamma = 2.1f;
+ break;
+ case QColorSpace::TransferFunction::St2084:
+ trc[0] = QColorTransferGenericFunction::pq();
+ break;
+ case QColorSpace::TransferFunction::Hlg:
+ trc[0] = QColorTransferGenericFunction::hlg();
+ break;
case QColorSpace::TransferFunction::Custom:
break;
default:
@@ -448,11 +496,13 @@ QColorTransform QColorSpacePrivate::transformationToXYZ() const
transform.d = ptr;
ptr->colorSpaceIn = this;
ptr->colorSpaceOut = this;
- // Convert to XYZ relative to our white point, not the regular D50 white point.
if (isThreeComponentMatrix())
- ptr->colorMatrix = QColorMatrix::chromaticAdaptation(whitePoint).inverted() * toXyz;
+ ptr->colorMatrix = toXyz;
else
ptr->colorMatrix = QColorMatrix::identity();
+ // Convert to XYZ relative to our white point, not the regular D50 white point.
+ if (!chad.isNull())
+ ptr->colorMatrix = chad.inverted() * ptr->colorMatrix;
return transform;
}
@@ -526,6 +576,13 @@ void QColorSpacePrivate::clearElementListProcessingForEdit()
\l{http://www.color.org/chardata/rgb/DCIP3.xalter}{ICC registration of DCI-P3}
\value ProPhotoRgb The Pro Photo RGB color space, also known as ROMM RGB is a very wide gamut color space.
\l{http://www.color.org/chardata/rgb/rommrgb.xalter}{ICC registration of ROMM RGB}
+ \value [since 6.8] Bt2020 BT.2020, also known as Rec.2020 is a basic colorspace of HDR TVs.
+ \l{http://www.color.org/chardata/rgb/BT2020.xalter}{ICC registration of BT.2020}
+ \value [since 6.8] Bt2100Pq BT.2100(PQ), also known as Rec.2100 or HDR10 is an HDR encoding with the same
+ primaries as Bt2020 but using the Perceptual Quantizer transfer function.
+ \l{http://www.color.org/chardata/rgb/BT2100.xalter}{ICC registration of BT.2100}
+ \value [since 6.8] Bt2100Hlg BT.2100 (HLG) is an HDR encoding with the same
+ primaries as Bt2020 but using the Hybrid Log-Gamma transfer function.
*/
/*!
@@ -538,6 +595,7 @@ void QColorSpacePrivate::clearElementListProcessingForEdit()
\value AdobeRgb The Adobe RGB primaries
\value DciP3D65 The DCI-P3 primaries with the D65 whitepoint
\value ProPhotoRgb The ProPhoto RGB primaries with the D50 whitepoint
+ \value [since 6.8] Bt2020 The BT.2020 primaries with a D65 whitepoint
*/
/*!
@@ -550,6 +608,10 @@ void QColorSpacePrivate::clearElementListProcessingForEdit()
\value Gamma A transfer function that is a real gamma curve based on the value of gamma()
\value SRgb The sRGB transfer function, composed of linear and gamma parts
\value ProPhotoRgb The ProPhoto RGB transfer function, composed of linear and gamma parts
+ \value [since 6.8] Bt2020 The BT.2020 transfer function, composited of linear and gamma parts
+ \value [since 6.8] St2084 The SMPTE ST 2084 transfer function, also known Perceptual Quantizer(PQ).
+ \value [since 6.8] Hlg The Hybrid log-gamma transfer function.
+
*/
/*!
@@ -592,7 +654,7 @@ void QColorSpacePrivate::clearElementListProcessingForEdit()
*/
QColorSpace::QColorSpace(NamedColorSpace namedColorSpace)
{
- if (namedColorSpace < QColorSpace::SRgb || namedColorSpace > QColorSpace::ProPhotoRgb) {
+ if (namedColorSpace < QColorSpace::SRgb || namedColorSpace > QColorSpace::Bt2100Hlg) {
qWarning() << "QColorSpace attempted constructed from invalid QColorSpace::NamedColorSpace: " << int(namedColorSpace);
return;
}
@@ -1129,9 +1191,11 @@ bool QColorSpacePrivate::isValid() const noexcept
if (colorModel == QColorSpace::ColorModel::Gray) {
if (!trc[0].isValid())
return false;
- } else {
+ } else if (colorModel == QColorSpace::ColorModel::Rgb){
if (!trc[0].isValid() || !trc[1].isValid() || !trc[2].isValid())
return false;
+ } else {
+ return false;
}
return true;
}
@@ -1419,13 +1483,16 @@ QDebug operator<<(QDebug dbg, const QColorSpace &colorSpace)
if (colorSpace.d_ptr) {
if (colorSpace.d_ptr->namedColorSpace)
dbg << colorSpace.d_ptr->namedColorSpace << ", ";
+ else
+ dbg << colorSpace.colorModel() << ", ";
if (!colorSpace.isValid()) {
dbg << "Invalid";
if (!colorSpace.d_ptr->iccProfile.isEmpty())
dbg << " with profile data";
} else if (colorSpace.d_ptr->isThreeComponentMatrix()) {
dbg << colorSpace.primaries() << ", " << colorSpace.transferFunction();
- dbg << ", gamma=" << colorSpace.gamma();
+ if (colorSpace.transferFunction() == QColorSpace::TransferFunction::Gamma)
+ dbg << "=" << colorSpace.gamma();
} else {
if (colorSpace.d_ptr->isPcsLab)
dbg << "PCSLab, ";
diff --git a/src/gui/painting/qcolorspace.h b/src/gui/painting/qcolorspace.h
index 488cbd6a53..ecf6614561 100644
--- a/src/gui/painting/qcolorspace.h
+++ b/src/gui/painting/qcolorspace.h
@@ -26,7 +26,10 @@ public:
SRgbLinear,
AdobeRgb,
DisplayP3,
- ProPhotoRgb
+ ProPhotoRgb,
+ Bt2020,
+ Bt2100Pq,
+ Bt2100Hlg,
};
Q_ENUM(NamedColorSpace)
enum class Primaries {
@@ -34,7 +37,8 @@ public:
SRgb,
AdobeRgb,
DciP3D65,
- ProPhotoRgb
+ ProPhotoRgb,
+ Bt2020,
};
Q_ENUM(Primaries)
enum class TransferFunction {
@@ -42,7 +46,10 @@ public:
Linear,
Gamma,
SRgb,
- ProPhotoRgb
+ ProPhotoRgb,
+ Bt2020,
+ St2084,
+ Hlg,
};
Q_ENUM(TransferFunction)
enum class TransformModel : uint8_t {
diff --git a/src/gui/painting/qcolortransferfunction_p.h b/src/gui/painting/qcolortransferfunction_p.h
index 484cc69114..b9a09b4646 100644
--- a/src/gui/painting/qcolortransferfunction_p.h
+++ b/src/gui/painting/qcolortransferfunction_p.h
@@ -114,6 +114,11 @@ public:
return QColorTransferFunction(1.0f, 0.0f, 1.0f / 16.0f, 16.0f / 512.0f, 0.0f, 0.0f, 1.8f,
Hints(Hint::Calculated));
}
+ static QColorTransferFunction fromBt2020()
+ {
+ return QColorTransferFunction(1.0f / 1.0993f, 0.0993f / 1.0993f, 1.0f / 4.5f, 0.08145f, 0.0f, 0.0f, 2.2f,
+ Hints(Hint::Calculated));
+ }
bool matches(const QColorTransferFunction &o) const
{
return paramCompare(m_a, o.m_a) && paramCompare(m_b, o.m_b)
diff --git a/src/gui/painting/qcolortransfergeneric_p.h b/src/gui/painting/qcolortransfergeneric_p.h
new file mode 100644
index 0000000000..b4e6e8dec7
--- /dev/null
+++ b/src/gui/painting/qcolortransfergeneric_p.h
@@ -0,0 +1,109 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#ifndef QCOLORTRANSFERGENERIC_P_H
+#define QCOLORTRANSFERGENERIC_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QtGui/private/qtguiglobal_p.h>
+
+#include <cmath>
+
+QT_BEGIN_NAMESPACE
+
+// Defines the a generic transfer function for our HDR functions
+class QColorTransferGenericFunction
+{
+public:
+ using ConverterPtr = float (*)(float);
+ constexpr QColorTransferGenericFunction(ConverterPtr toLinear = nullptr, ConverterPtr fromLinear = nullptr) noexcept
+ : m_toLinear(toLinear), m_fromLinear(fromLinear)
+ {}
+
+ static QColorTransferGenericFunction hlg()
+ {
+ return QColorTransferGenericFunction(hlgToLinear, hlgFromLinear);
+ }
+ static QColorTransferGenericFunction pq()
+ {
+ return QColorTransferGenericFunction(pqToLinear, pqFromLinear);
+ }
+
+ float apply(float x) const
+ {
+ return m_toLinear(x);
+ }
+
+ float applyInverse(float x) const
+ {
+ return m_fromLinear(x);
+ }
+
+ bool operator==(const QColorTransferGenericFunction &o) const noexcept
+ {
+ return m_toLinear == o.m_toLinear && m_fromLinear == o.m_fromLinear;
+ }
+ bool operator!=(const QColorTransferGenericFunction &o) const noexcept
+ {
+ return m_toLinear != o.m_toLinear || m_fromLinear != o.m_fromLinear;
+ }
+
+private:
+ ConverterPtr m_toLinear = nullptr;
+ ConverterPtr m_fromLinear = nullptr;
+
+ // HLG from linear [0-12] -> [0-1]
+ static float hlgFromLinear(float x)
+ {
+ if (x > 1.f)
+ return m_hlg_a * std::log(x - m_hlg_b) + m_hlg_c;
+ return std::sqrt(x * 0.25f);
+ }
+
+ // HLG to linear [0-1] -> [0-12]
+ static float hlgToLinear(float x)
+ {
+ if (x < 0.5f)
+ return (x * x) * 4.f;
+ return std::exp((x - m_hlg_c) / m_hlg_a) + m_hlg_b;
+ }
+
+ constexpr static float m_hlg_a = 0.17883277f;
+ constexpr static float m_hlg_b = 1.f - (4.f * m_hlg_a);
+ constexpr static float m_hlg_c = 0.55991073f; // 0.5 - a * ln(4 * a)
+
+ // PQ from linear [0-64] -> [0-1]
+ static float pqFromLinear(float x)
+ {
+ x = std::pow(x * (1.f / m_pq_f), (1.f / m_pq_m1));
+ return std::pow((m_pq_c1 - x) / (m_pq_c3 * x - m_pq_c2), (1.f / m_pq_m2));
+ }
+
+ // PQ from linear [0-1] -> [0-64]
+ static float pqToLinear(float x)
+ {
+ x = std::pow(x, m_pq_m1);
+ return std::pow((m_pq_c1 + m_pq_c2 * x) / (1.f + m_pq_c3 * x), m_pq_m2) * m_pq_f;
+ }
+
+ constexpr static float m_pq_c1 = 107.f / 128.f; // c3 - c2 + 1
+ constexpr static float m_pq_c2 = 2413.f / 128.f;
+ constexpr static float m_pq_c3 = 2392.f / 128.f;
+ constexpr static float m_pq_m1 = 1305.f / 8192.f;
+ constexpr static float m_pq_m2 = 2523.f / 32.f;
+ constexpr static float m_pq_f = 64.f; // This might need to be set based on scene metadata
+};
+
+QT_END_NAMESPACE
+
+#endif // QCOLORTRANSFERGENERIC_P_H
diff --git a/src/gui/painting/qcolortransform.cpp b/src/gui/painting/qcolortransform.cpp
index aac07bdc09..f54dac9f26 100644
--- a/src/gui/painting/qcolortransform.cpp
+++ b/src/gui/painting/qcolortransform.cpp
@@ -22,16 +22,6 @@
QT_BEGIN_NAMESPACE
-std::shared_ptr<QColorTrcLut> lutFromTrc(const QColorTrc &trc)
-{
- if (trc.m_type == QColorTrc::Type::Table)
- return QColorTrcLut::fromTransferTable(trc.m_table);
- if (trc.m_type == QColorTrc::Type::Function)
- return QColorTrcLut::fromTransferFunction(trc.m_fun);
- qWarning() << "TRC uninitialized";
- return nullptr;
-}
-
void QColorTransformPrivate::updateLutsIn() const
{
if (colorSpaceIn->lut.generated.loadAcquire())
@@ -46,12 +36,12 @@ void QColorTransformPrivate::updateLutsIn() const
}
if (colorSpaceIn->trc[0] == colorSpaceIn->trc[1] && colorSpaceIn->trc[0] == colorSpaceIn->trc[2]) {
- colorSpaceIn->lut[0] = lutFromTrc(colorSpaceIn->trc[0]);
+ colorSpaceIn->lut[0] = QColorTrcLut::fromTrc(colorSpaceIn->trc[0]);
colorSpaceIn->lut[1] = colorSpaceIn->lut[0];
colorSpaceIn->lut[2] = colorSpaceIn->lut[0];
} else {
for (int i = 0; i < 3; ++i)
- colorSpaceIn->lut[i] = lutFromTrc(colorSpaceIn->trc[i]);
+ colorSpaceIn->lut[i] = QColorTrcLut::fromTrc(colorSpaceIn->trc[i]);
}
colorSpaceIn->lut.generated.storeRelease(1);
@@ -70,12 +60,12 @@ void QColorTransformPrivate::updateLutsOut() const
}
if (colorSpaceOut->trc[0] == colorSpaceOut->trc[1] && colorSpaceOut->trc[0] == colorSpaceOut->trc[2]) {
- colorSpaceOut->lut[0] = lutFromTrc(colorSpaceOut->trc[0]);
+ colorSpaceOut->lut[0] = QColorTrcLut::fromTrc(colorSpaceOut->trc[0]);
colorSpaceOut->lut[1] = colorSpaceOut->lut[0];
colorSpaceOut->lut[2] = colorSpaceOut->lut[0];
} else {
for (int i = 0; i < 3; ++i)
- colorSpaceOut->lut[i] = lutFromTrc(colorSpaceOut->trc[i]);
+ colorSpaceOut->lut[i] = QColorTrcLut::fromTrc(colorSpaceOut->trc[i]);
}
colorSpaceOut->lut.generated.storeRelease(1);
@@ -390,6 +380,14 @@ template<>
inline int getAlpha<QRgba64>(const QRgba64 &p)
{ return p.alpha(); }
+template<typename T>
+static inline constexpr int getFactor();
+template<>
+inline constexpr int getFactor<QRgb>()
+{ return 255; }
+template<>
+inline constexpr int getFactor<QRgba64>()
+{ return 65535; }
#endif
template<typename T>
@@ -823,8 +821,9 @@ static void storePremultiplied(D *dst, const S *src, const QColorVector *buffer,
const __m128 vTrcRes = _mm_set1_ps(float(QColorTrcLut::Resolution));
const __m128 iFF00 = _mm_set1_ps(1.0f / (255 * 256));
constexpr bool isARGB = isArgb<D>();
+ static_assert(getFactor<D>() >= getFactor<S>());
for (qsizetype i = 0; i < len; ++i) {
- const int a = getAlpha<S>(src[i]);
+ const int a = getAlpha<S>(src[i]) * (getFactor<D>() / getFactor<S>());
__m128 vf = _mm_loadu_ps(&buffer[i].x);
__m128i v = _mm_cvtps_epi32(_mm_mul_ps(vf, vTrcRes));
__m128 va = _mm_mul_ps(_mm_set1_ps(a), iFF00);
@@ -905,8 +904,9 @@ static void storeUnpremultiplied(D *dst, const S *src, const QColorVector *buffe
{
const __m128 vTrcRes = _mm_set1_ps(float(QColorTrcLut::Resolution));
constexpr bool isARGB = isArgb<D>();
+ static_assert(getFactor<D>() >= getFactor<S>());
for (qsizetype i = 0; i < len; ++i) {
- const int a = getAlpha<S>(src[i]);
+ const int a = getAlpha<S>(src[i]) * (getFactor<D>() / getFactor<S>());
__m128 vf = _mm_loadu_ps(&buffer[i].x);
__m128i v = _mm_cvtps_epi32(_mm_mul_ps(vf, vTrcRes));
const int ridx = _mm_extract_epi16(v, 0);
@@ -1029,8 +1029,9 @@ static void storePremultiplied(D *dst, const S *src, const QColorVector *buffer,
{
const float iFF00 = 1.0f / (255 * 256);
constexpr bool isARGB = isArgb<D>();
+ static_assert(getFactor<D>() >= getFactor<S>());
for (qsizetype i = 0; i < len; ++i) {
- const int a = getAlpha<S>(src[i]);
+ const int a = getAlpha<S>(src[i]) * (getFactor<D>() / getFactor<S>());
float32x4_t vf = vld1q_f32(&buffer[i].x);
uint32x4_t v = vcvtq_u32_f32(vaddq_f32(vmulq_n_f32(vf, float(QColorTrcLut::Resolution)), vdupq_n_f32(0.5f)));
const int ridx = vgetq_lane_u32(v, 0);
@@ -1073,8 +1074,9 @@ static void storeUnpremultiplied(D *dst, const S *src, const QColorVector *buffe
const QColorTransformPrivate *d_ptr)
{
constexpr bool isARGB = isArgb<D>();
+ static_assert(getFactor<D>() >= getFactor<S>());
for (qsizetype i = 0; i < len; ++i) {
- const int a = getAlpha<S>(src[i]);
+ const int a = getAlpha<S>(src[i]) * (getFactor<D>() / getFactor<S>());
float32x4_t vf = vld1q_f32(&buffer[i].x);
uint16x4_t v = vmovn_u32(vcvtq_u32_f32(vaddq_f32(vmulq_n_f32(vf, float(QColorTrcLut::Resolution)), vdupq_n_f32(0.5f))));
const int ridx = vget_lane_u16(v, 0);
@@ -1219,17 +1221,41 @@ static void storeOpaque(QRgbaFloat32 *dst, const QColorVector *buffer, const qsi
static void loadGray(QColorVector *buffer, const quint8 *src, const qsizetype len, const QColorTransformPrivate *d_ptr)
{
- for (qsizetype i = 0; i < len; ++i) {
- const float y = d_ptr->colorSpaceIn->lut[0]->u8ToLinearF32(src[i]);
- buffer[i] = d_ptr->colorSpaceIn->whitePoint * y;
+ if (d_ptr->colorSpaceIn->colorModel == QColorSpace::ColorModel::Gray ||
+ (d_ptr->colorSpaceIn->lut[0] == d_ptr->colorSpaceIn->lut[1] &&
+ d_ptr->colorSpaceIn->lut[0] == d_ptr->colorSpaceIn->lut[2])) {
+ for (qsizetype i = 0; i < len; ++i) {
+ const float y = d_ptr->colorSpaceIn->lut[0]->u8ToLinearF32(src[i]);
+ buffer[i] = d_ptr->colorSpaceIn->whitePoint * y;
+ }
+ } else {
+ for (qsizetype i = 0; i < len; ++i) {
+ QColorVector v;
+ v.x = d_ptr->colorSpaceIn->lut[0]->u8ToLinearF32(src[i]);
+ v.y = d_ptr->colorSpaceIn->lut[1]->u8ToLinearF32(src[i]);
+ v.z = d_ptr->colorSpaceIn->lut[2]->u8ToLinearF32(src[i]);
+ buffer[i] = d_ptr->colorSpaceIn->toXyz.map(v);
+ }
}
}
static void loadGray(QColorVector *buffer, const quint16 *src, const qsizetype len, const QColorTransformPrivate *d_ptr)
{
- for (qsizetype i = 0; i < len; ++i) {
- const float y = d_ptr->colorSpaceIn->lut[0]->u16ToLinearF32(src[i]);
- buffer[i] = d_ptr->colorSpaceIn->whitePoint * y;
+ if (d_ptr->colorSpaceIn->colorModel == QColorSpace::ColorModel::Gray ||
+ (d_ptr->colorSpaceIn->lut[0] == d_ptr->colorSpaceIn->lut[1] &&
+ d_ptr->colorSpaceIn->lut[0] == d_ptr->colorSpaceIn->lut[2])) {
+ for (qsizetype i = 0; i < len; ++i) {
+ const float y = d_ptr->colorSpaceIn->lut[0]->u16ToLinearF32(src[i]);
+ buffer[i] = d_ptr->colorSpaceIn->whitePoint * y;
+ }
+ } else {
+ for (qsizetype i = 0; i < len; ++i) {
+ QColorVector v;
+ v.x = d_ptr->colorSpaceIn->lut[0]->u16ToLinearF32(src[i]);
+ v.y = d_ptr->colorSpaceIn->lut[1]->u16ToLinearF32(src[i]);
+ v.z = d_ptr->colorSpaceIn->lut[2]->u16ToLinearF32(src[i]);
+ buffer[i] = d_ptr->colorSpaceIn->toXyz.map(v);
+ }
}
}
@@ -1258,6 +1284,28 @@ private:
alignas(T) char data[sizeof(T) * Count];
};
+void loadUnpremultipliedLUT(QColorVector *buffer, const uchar *src, const qsizetype len)
+{
+ const float f = 1.0f / 255.f;
+ for (qsizetype i = 0; i < len; ++i) {
+ const float p = src[i] * f;
+ buffer[i].x = p;
+ buffer[i].y = p;
+ buffer[i].z = p;
+ }
+}
+
+void loadUnpremultipliedLUT(QColorVector *buffer, const quint16 *src, const qsizetype len)
+{
+ const float f = 1.0f / 65535.f;
+ for (qsizetype i = 0; i < len; ++i) {
+ const float p = src[i] * f;
+ buffer[i].x = p;
+ buffer[i].y = p;
+ buffer[i].z = p;
+ }
+}
+
void loadUnpremultipliedLUT(QColorVector *buffer, const QRgb *src, const qsizetype len)
{
const float f = 1.0f / 255.f;
@@ -1300,6 +1348,16 @@ void loadUnpremultipliedLUT(QColorVector *buffer, const QRgbaFloat32 *src, const
}
}
+void loadPremultipliedLUT(QColorVector *, const uchar *, const qsizetype)
+{
+ Q_UNREACHABLE();
+}
+
+void loadPremultipliedLUT(QColorVector *, const quint16 *, const qsizetype)
+{
+ Q_UNREACHABLE();
+}
+
void loadPremultipliedLUT(QColorVector *buffer, const QRgb *src, const qsizetype len)
{
for (qsizetype i = 0; i < len; ++i) {
@@ -1420,7 +1478,15 @@ static void storeUnpremultipliedLUT(QRgbaFloat32 *dst, const T *src,
}
template<typename T>
-static void storePremultipliedLUT(QRgb *, const T *, const QColorVector *, const qsizetype);
+static void storePremultipliedLUT(QRgb *dst, const T *, const QColorVector *buffer, const qsizetype len)
+{
+ for (qsizetype i = 0; i < len; ++i) {
+ const int r = buffer[i].x * 255.f;
+ const int g = buffer[i].y * 255.f;
+ const int b = buffer[i].z * 255.f;
+ dst[i] = 0xff000000 | (r << 16) | (g << 8) | (b << 0);
+ }
+}
template<>
void storePremultipliedLUT(QRgb *dst, const QRgb *src, const QColorVector *buffer, const qsizetype len)
@@ -1434,18 +1500,6 @@ void storePremultipliedLUT(QRgb *dst, const QRgb *src, const QColorVector *buffe
}
}
-template<>
-void storePremultipliedLUT(QRgb *dst, const QCmyk32 *, const QColorVector *buffer, const qsizetype len)
-{
- for (qsizetype i = 0; i < len; ++i) {
- const int r = buffer[i].x * 255.f;
- const int g = buffer[i].y * 255.f;
- const int b = buffer[i].z * 255.f;
- dst[i] = 0xff000000 | (r << 16) | (g << 8) | (b << 0);
- }
-}
-
-
template<typename T>
static void storePremultipliedLUT(QCmyk32 *dst, const T *src, const QColorVector *buffer, const qsizetype len)
{
@@ -1453,7 +1507,15 @@ static void storePremultipliedLUT(QCmyk32 *dst, const T *src, const QColorVector
}
template<typename T>
-static void storePremultipliedLUT(QRgba64 *, const T *, const QColorVector *, const qsizetype);
+static void storePremultipliedLUT(QRgba64 *dst, const T *, const QColorVector *buffer, const qsizetype len)
+{
+ for (qsizetype i = 0; i < len; ++i) {
+ const int r = buffer[i].x * 65535.f;
+ const int g = buffer[i].y * 65535.f;
+ const int b = buffer[i].z * 65535.f;
+ dst[i] = qRgba64(r, g, b, 65535);
+ }
+}
template<>
void storePremultipliedLUT(QRgba64 *dst, const QRgb *src, const QColorVector *buffer, const qsizetype len)
@@ -1468,17 +1530,6 @@ void storePremultipliedLUT(QRgba64 *dst, const QRgb *src, const QColorVector *bu
}
template<>
-void storePremultipliedLUT(QRgba64 *dst, const QCmyk32 *, const QColorVector *buffer, const qsizetype len)
-{
- for (qsizetype i = 0; i < len; ++i) {
- const int r = buffer[i].x * 65535.f;
- const int g = buffer[i].y * 65535.f;
- const int b = buffer[i].z * 65535.f;
- dst[i] = qRgba64(r, g, b, 65535);
- }
-}
-
-template<>
void storePremultipliedLUT(QRgba64 *dst, const QRgba64 *src, const QColorVector *buffer, const qsizetype len)
{
for (qsizetype i = 0; i < len; ++i) {
@@ -1628,11 +1679,43 @@ QColorVector QColorTransformPrivate::mapExtended(QColorVector c) const
return c;
}
+template<typename T>
+constexpr bool IsGrayscale = std::is_same_v<T, uchar> || std::is_same_v<T, quint16>;
+template<typename T>
+constexpr bool IsAlwaysOpaque = std::is_same_v<T, QCmyk32> || IsGrayscale<T>;
+template<typename T>
+constexpr bool CanUseThreeComponent = !std::is_same_v<T, QCmyk32>;
+template<typename T>
+constexpr bool UnclampedValues = std::is_same_v<T, QRgbaFloat16> || std::is_same_v<T, QRgbaFloat32>;
+
+// Possible combos for data and color spaces:
+// DataCM ColorSpaceCM ColorSpacePM Notes
+// Gray Gray ThreeMatrix
+// Gray Rgb ThreeMatrix Invalid colorMatrix
+// Rgb Rgb ThreeMatrix
+// Rgb Rgb ElementProc
+// Gray Rgb ElementProc Only possible for input data
+// Cmyk Cmyk ElementProc
+//
+// Gray data can be uchar, quint16, and is always Opaque
+// Rgb data can be QRgb, QRgba64, or QRgbaFloat32, and is Unpremultiplied, Premultiplied, or Opaque
+// Cmyk data can be Cmyk32, and is always Opaque
+//
+// colorMatrix as setup for Gray on Gray or Rgb on Rgb, but not Gray data on Rgb colorspace.
+
template<typename S>
void QColorTransformPrivate::applyConvertIn(const S *src, QColorVector *buffer, qsizetype len, TransformFlags flags) const
{
- // Avoid compiling this part for S=QCmyk32:
- if constexpr (!std::is_same_v<S, QCmyk32>) {
+ if constexpr (IsGrayscale<S>) {
+ if (colorSpaceIn->isThreeComponentMatrix()) {
+ loadGray(buffer, src, len, this);
+ if (!colorSpaceOut->isThreeComponentMatrix() || colorSpaceIn->colorModel != QColorSpace::ColorModel::Gray) {
+ if (!colorSpaceIn->chad.isNull())
+ applyMatrix<DoClamp>(buffer, len, colorSpaceIn->chad);
+ }
+ return;
+ }
+ } else if constexpr (CanUseThreeComponent<S>) {
if (colorSpaceIn->isThreeComponentMatrix()) {
if (flags & InputPremultiplied)
loadPremultiplied(buffer, src, len, this);
@@ -1640,7 +1723,7 @@ void QColorTransformPrivate::applyConvertIn(const S *src, QColorVector *buffer,
loadUnpremultiplied(buffer, src, len, this);
if (!colorSpaceOut->isThreeComponentMatrix())
- applyMatrix<DoClamp>(buffer, len, colorMatrix); // colorMatrix should have the first half only.
+ applyMatrix<DoClamp>(buffer, len, colorMatrix);
return;
}
}
@@ -1651,9 +1734,6 @@ void QColorTransformPrivate::applyConvertIn(const S *src, QColorVector *buffer,
else
loadUnpremultipliedLUT(buffer, src, len);
- if constexpr (std::is_same_v<S, QRgbaFloat16> || std::is_same_v<S, QRgbaFloat32>)
- clampIfNeeded<DoClamp>(buffer, len);
-
// Do element based conversion
for (auto &&element : colorSpaceIn->mAB)
std::visit([&buffer, len](auto &&elm) { visitElement(elm, buffer, len); }, element);
@@ -1662,13 +1742,44 @@ void QColorTransformPrivate::applyConvertIn(const S *src, QColorVector *buffer,
template<typename D, typename S>
void QColorTransformPrivate::applyConvertOut(D *dst, const S *src, QColorVector *buffer, qsizetype len, TransformFlags flags) const
{
- constexpr ApplyMatrixForm doClamp = (std::is_same_v<D, QRgbaFloat16> || std::is_same_v<D, QRgbaFloat32>) ? DoNotClamp : DoClamp;
- // Avoid compiling this part for D=QCmyk32:
- if constexpr (!std::is_same_v<D, QCmyk32>) {
+ constexpr ApplyMatrixForm doClamp = UnclampedValues<D> ? DoNotClamp : DoClamp;
+ if constexpr (IsGrayscale<D>) {
+ Q_UNUSED(src); // dealing with buggy warnings in gcc 9
+ Q_UNUSED(flags);
+ // Calculate the matrix for grayscale conversion
+ QColorMatrix grayMatrix;
+ if (colorSpaceIn == colorSpaceOut ||
+ (colorSpaceIn->colorModel == QColorSpace::ColorModel::Gray &&
+ colorSpaceOut->colorModel == QColorSpace::ColorModel::Gray)) {
+ // colorMatrix already has the right form
+ grayMatrix = colorMatrix;
+ } else {
+ if constexpr (IsGrayscale<S>) {
+ if (colorSpaceIn->colorModel == QColorSpace::ColorModel::Gray)
+ grayMatrix = colorSpaceIn->chad;
+ else
+ grayMatrix = QColorMatrix::identity(); // Otherwise already handled in applyConvertIn
+ } else {
+ if (colorSpaceIn->isThreeComponentMatrix())
+ grayMatrix = colorSpaceIn->toXyz;
+ else
+ grayMatrix = QColorMatrix::identity();
+ }
+ if (!colorSpaceOut->chad.isNull())
+ grayMatrix = colorSpaceOut->chad.inverted() * grayMatrix;
+ }
+
+ applyMatrix<doClamp>(buffer, len, grayMatrix);
+ storeOpaque(dst, buffer, len, this);
+ return;
+ } else if constexpr (CanUseThreeComponent<D>) {
if (colorSpaceOut->isThreeComponentMatrix()) {
- applyMatrix<doClamp>(buffer, len, colorMatrix); // colorMatrix should have the latter half only.
+ if (IsGrayscale<S> && colorSpaceIn->colorModel != QColorSpace::ColorModel::Gray)
+ applyMatrix<doClamp>(buffer, len, colorSpaceOut->toXyz.inverted()); // colorMatrix wasnt prepared for gray input
+ else
+ applyMatrix<doClamp>(buffer, len, colorMatrix);
- if constexpr (std::is_same_v<S, QCmyk32>) {
+ if constexpr (IsAlwaysOpaque<S>) {
storeOpaque(dst, buffer, len, this);
} else {
if (flags & InputOpaque)
@@ -1681,91 +1792,37 @@ void QColorTransformPrivate::applyConvertOut(D *dst, const S *src, QColorVector
return;
}
}
- Q_ASSERT(!colorSpaceOut->isThreeComponentMatrix());
+ if constexpr (!IsGrayscale<D>) {
+ Q_ASSERT(!colorSpaceOut->isThreeComponentMatrix());
- // Do element based conversion
- for (auto &&element : colorSpaceOut->mBA)
- std::visit([&buffer, len](auto &&elm) { visitElement(elm, buffer, len); }, element);
-
- clampIfNeeded<doClamp>(buffer, len);
-
- if (flags & OutputPremultiplied)
- storePremultipliedLUT(dst, src, buffer, len);
- else
- storeUnpremultipliedLUT(dst, src, buffer, len);
-}
-
-template<typename D, typename S>
-void QColorTransformPrivate::applyElementListTransform(D *dst, const S *src, qsizetype count, TransformFlags flags) const
-{
- Q_ASSERT(!colorSpaceIn->isThreeComponentMatrix() || !colorSpaceOut->isThreeComponentMatrix());
-
- if (!colorMatrix.isValid())
- return;
-
- if (colorSpaceIn->isThreeComponentMatrix())
- updateLutsIn();
- if (colorSpaceOut->isThreeComponentMatrix())
- updateLutsOut();
-
- QUninitialized<QColorVector, WorkBlockSize> buffer;
- qsizetype i = 0;
- while (i < count) {
- const qsizetype len = qMin(count - i, WorkBlockSize);
-
- applyConvertIn(src + i, buffer, len, flags);
-
- // Match Profile Connection Spaces (PCS):
- if (colorSpaceOut->isPcsLab && !colorSpaceIn->isPcsLab) {
- for (qsizetype j = 0; j < len; ++j)
- buffer[j] = buffer[j].xyzToLab();
- } else if (colorSpaceIn->isPcsLab && !colorSpaceOut->isPcsLab) {
- for (qsizetype j = 0; j < len; ++j)
- buffer[j] = buffer[j].labToXyz();
- }
+ // Do element based conversion
+ for (auto &&element : colorSpaceOut->mBA)
+ std::visit([&buffer, len](auto &&elm) { visitElement(elm, buffer, len); }, element);
- applyConvertOut(dst + i, src + i, buffer, len, flags);
+ clampIfNeeded<doClamp>(buffer, len);
- i += len;
+ if (flags & OutputPremultiplied)
+ storePremultipliedLUT(dst, src, buffer, len);
+ else
+ storeUnpremultipliedLUT(dst, src, buffer, len);
+ } else {
+ Q_UNREACHABLE();
}
}
-template<typename D, typename S>
-void QColorTransformPrivate::applyThreeComponentMatrix(D *dst, const S *src, qsizetype count, TransformFlags flags) const
+/*!
+ \internal
+ Adapt Profile Connection Spaces.
+*/
+void QColorTransformPrivate::pcsAdapt(QColorVector *buffer, qsizetype count) const
{
- Q_ASSERT(colorSpaceIn->isThreeComponentMatrix() && colorSpaceOut->isThreeComponentMatrix());
-
- if (!colorMatrix.isValid())
- return;
-
- updateLutsIn();
- updateLutsOut();
-
- bool doApplyMatrix = !colorMatrix.isIdentity();
- constexpr ApplyMatrixForm doClamp = (std::is_same_v<D, QRgbaFloat16> || std::is_same_v<D, QRgbaFloat32>) ? DoNotClamp : DoClamp;
-
- QUninitialized<QColorVector, WorkBlockSize> buffer;
- qsizetype i = 0;
- while (i < count) {
- const qsizetype len = qMin(count - i, WorkBlockSize);
- if (flags & InputPremultiplied)
- loadPremultiplied(buffer, src + i, len, this);
- else
- loadUnpremultiplied(buffer, src + i, len, this);
-
- if (doApplyMatrix)
- applyMatrix<doClamp>(buffer, len, colorMatrix);
- else
- clampIfNeeded<doClamp>(buffer, len);
-
- if (flags & InputOpaque)
- storeOpaque(dst + i, buffer, len, this);
- else if (flags & OutputPremultiplied)
- storePremultiplied(dst + i, src + i, buffer, len, this);
- else
- storeUnpremultiplied(dst + i, src + i, buffer, len, this);
-
- i += len;
+ // Match Profile Connection Spaces (PCS):
+ if (colorSpaceOut->isPcsLab && !colorSpaceIn->isPcsLab) {
+ for (qsizetype j = 0; j < count; ++j)
+ buffer[j] = buffer[j].xyzToLab();
+ } else if (colorSpaceIn->isPcsLab && !colorSpaceOut->isPcsLab) {
+ for (qsizetype j = 0; j < count; ++j)
+ buffer[j] = buffer[j].labToXyz();
}
}
@@ -1781,137 +1838,23 @@ void QColorTransformPrivate::applyThreeComponentMatrix(D *dst, const S *src, qsi
template<typename D, typename S>
void QColorTransformPrivate::apply(D *dst, const S *src, qsizetype count, TransformFlags flags) const
{
- if constexpr (!std::is_same_v<D, QCmyk32> && !std::is_same_v<S, QCmyk32>) {
- if (isThreeComponentMatrix())
- return applyThreeComponentMatrix<D, S>(dst, src, count, flags);
- }
- applyElementListTransform<D, S>(dst, src, count, flags);
-}
-
-/*!
- \internal
- Is to be called on a color-transform to XYZ, returns only luminance values.
-
- */
-template<typename D, typename S>
-void QColorTransformPrivate::applyReturnGray(D *dst, const S *src, qsizetype count, TransformFlags flags) const
-{
- Q_ASSERT(colorSpaceOut->isThreeComponentMatrix());
- updateLutsOut();
- if (!colorSpaceIn->isThreeComponentMatrix()) {
- QUninitialized<QColorVector, WorkBlockSize> buffer;
-
- qsizetype i = 0;
- while (i < count) {
- const qsizetype len = qMin(count - i, WorkBlockSize);
-
- applyConvertIn(src, buffer, len, flags);
-
- // Match Profile Connection Spaces (PCS):
- if (colorSpaceOut->isPcsLab && !colorSpaceIn->isPcsLab) {
- for (qsizetype j = 0; j < len; ++j)
- buffer[j] = buffer[j].xyzToLab();
- } else if (colorSpaceIn->isPcsLab && !colorSpaceOut->isPcsLab) {
- for (qsizetype j = 0; j < len; ++j)
- buffer[j] = buffer[j].labToXyz();
- }
-
- applyMatrix<DoClamp>(buffer, len, colorMatrix);
- storeOpaque(dst + i, buffer, len, this);
-
- i += len;
- }
- return;
- }
- if constexpr (!std::is_same_v<S, QCmyk32>) {
- if (!colorMatrix.isValid())
- return;
-
+ if (colorSpaceIn->isThreeComponentMatrix())
updateLutsIn();
-
- QUninitialized<QColorVector, WorkBlockSize> buffer;
-
- qsizetype i = 0;
- while (i < count) {
- const qsizetype len = qMin(count - i, WorkBlockSize);
- if (flags & InputPremultiplied)
- loadPremultiplied(buffer, src + i, len, this);
- else
- loadUnpremultiplied(buffer, src + i, len, this);
-
- applyMatrix<DoClamp>(buffer, len, colorMatrix);
-
- storeOpaque(dst + i, buffer, len, this);
-
- i += len;
- }
- } else {
- Q_UNREACHABLE();
- }
-}
-
-/*!
- \internal
-*/
-template<typename D, typename S>
-void QColorTransformPrivate::applyGray(D *dst, const S *src, qsizetype count, TransformFlags) const
-{
- Q_ASSERT(colorSpaceIn->isThreeComponentMatrix());
- updateLutsIn();
- if constexpr (std::is_same_v<D, QRgb> || std::is_same_v<D, QRgba64> || std::is_same_v<D, QRgbaFloat32> || std::is_same_v<D, QCmyk32>) {
- if (!colorSpaceOut->isThreeComponentMatrix()) {
- QUninitialized<QColorVector, WorkBlockSize> buffer;
-
- qsizetype i = 0;
- while (i < count) {
- const qsizetype len = qMin(count - i, WorkBlockSize);
- loadGray(buffer, src + i, len, this);
-
- applyMatrix<DoClamp>(buffer, len, colorMatrix);
-
- // Match Profile Connection Spaces (PCS):
- if (colorSpaceOut->isPcsLab && !colorSpaceIn->isPcsLab) {
- for (qsizetype j = 0; j < len; ++j)
- buffer[j] = buffer[j].xyzToLab();
- } else if (colorSpaceIn->isPcsLab && !colorSpaceOut->isPcsLab) {
- for (qsizetype j = 0; j < len; ++j)
- buffer[j] = buffer[j].labToXyz();
- }
-
- // Do element based conversion
- for (auto &&element : colorSpaceOut->mBA)
- std::visit([&buffer, len](auto &&elm) { visitElement(elm, buffer, len); }, element);
-
- clampIfNeeded<DoClamp>(buffer, len);
-
- storeUnpremultipliedLUT(dst, src, buffer, len); // input is always opaque
-
- i += len;
- }
- return;
- }
- }
- Q_ASSERT(colorSpaceOut->isThreeComponentMatrix());
- if constexpr (!std::is_same_v<D, QCmyk32>) {
- if (!colorMatrix.isValid())
- return;
-
+ if (colorSpaceOut->isThreeComponentMatrix())
updateLutsOut();
- QUninitialized<QColorVector, WorkBlockSize> buffer;
+ QUninitialized<QColorVector, WorkBlockSize> buffer;
+ qsizetype i = 0;
+ while (i < count) {
+ const qsizetype len = qMin(count - i, WorkBlockSize);
- qsizetype i = 0;
- while (i < count) {
- const qsizetype len = qMin(count - i, WorkBlockSize);
- loadGray(buffer, src + i, len, this);
+ applyConvertIn(src + i, buffer, len, flags);
- applyMatrix<DoClamp>(buffer, len, colorMatrix);
+ pcsAdapt(buffer, len);
- storeOpaque(dst + i, buffer, len, this);
- i += len;
- }
- } else {
- Q_UNREACHABLE();
+ applyConvertOut(dst + i, src + i, buffer, len, flags);
+
+ i += len;
}
}
@@ -1943,25 +1886,24 @@ void QColorTransformPrivate::prepare()
updateLutsOut();
}
-// Only allow versions increasing precision
-template void QColorTransformPrivate::applyReturnGray<quint8, QRgb>(quint8 *dst, const QRgb *src, qsizetype count, TransformFlags flags) const;
-template void QColorTransformPrivate::applyReturnGray<quint8, QCmyk32>(quint8 *dst, const QCmyk32 *src, qsizetype count, TransformFlags flags) const;
-template void QColorTransformPrivate::applyReturnGray<quint16, QCmyk32>(quint16 *dst, const QCmyk32 *src, qsizetype count, TransformFlags flags) const;
-template void QColorTransformPrivate::applyReturnGray<quint16, QRgba64>(quint16 *dst, const QRgba64 *src, qsizetype count, TransformFlags flags) const;
-template void QColorTransformPrivate::applyGray<quint8, quint8>(quint8 *dst, const quint8 *src, qsizetype count, TransformFlags flags) const;
-template void QColorTransformPrivate::applyGray<quint16, quint8>(quint16 *dst, const quint8 *src, qsizetype count, TransformFlags flags) const;
-template void QColorTransformPrivate::applyGray<quint16, quint16>(quint16 *dst, const quint16 *src, qsizetype count, TransformFlags flags) const;
-template void QColorTransformPrivate::applyGray<QRgb, quint8>(QRgb *dst, const quint8 *src, qsizetype count, TransformFlags flags) const;
-template void QColorTransformPrivate::applyGray<QCmyk32, quint8>(QCmyk32 *dst, const quint8 *src, qsizetype count, TransformFlags flags) const;
-template void QColorTransformPrivate::applyGray<QCmyk32, quint16>(QCmyk32 *dst, const quint16 *src, qsizetype count, TransformFlags flags) const;
-template void QColorTransformPrivate::applyGray<QRgba64, quint16>(QRgba64 *dst, const quint16 *src, qsizetype count, TransformFlags flags) const;
-
+// Only some versions increasing precision 14/36 combos
+template void QColorTransformPrivate::apply<quint8, quint8>(quint8 *dst, const quint8 *src, qsizetype count, TransformFlags flags) const;
+template void QColorTransformPrivate::apply<quint8, QRgb>(quint8 *dst, const QRgb *src, qsizetype count, TransformFlags flags) const;
+template void QColorTransformPrivate::apply<quint8, QCmyk32>(quint8 *dst, const QCmyk32 *src, qsizetype count, TransformFlags flags) const;
+template void QColorTransformPrivate::apply<quint16, quint8>(quint16 *dst, const quint8 *src, qsizetype count, TransformFlags flags) const;
+template void QColorTransformPrivate::apply<quint16, quint16>(quint16 *dst, const quint16 *src, qsizetype count, TransformFlags flags) const;
+template void QColorTransformPrivate::apply<quint16, QCmyk32>(quint16 *dst, const QCmyk32 *src, qsizetype count, TransformFlags flags) const;
+template void QColorTransformPrivate::apply<quint16, QRgba64>(quint16 *dst, const QRgba64 *src, qsizetype count, TransformFlags flags) const;
+template void QColorTransformPrivate::apply<QRgb, quint8>(QRgb *dst, const quint8 *src, qsizetype count, TransformFlags flags) const;
template void QColorTransformPrivate::apply<QRgb, QRgb>(QRgb *dst, const QRgb *src, qsizetype count, TransformFlags flags) const;
template void QColorTransformPrivate::apply<QRgb, QCmyk32>(QRgb *dst, const QCmyk32 *src, qsizetype count, TransformFlags flags) const;
+template void QColorTransformPrivate::apply<QCmyk32, quint8>(QCmyk32 *dst, const quint8 *src, qsizetype count, TransformFlags flags) const;
+template void QColorTransformPrivate::apply<QCmyk32, quint16>(QCmyk32 *dst, const quint16 *src, qsizetype count, TransformFlags flags) const;
template void QColorTransformPrivate::apply<QCmyk32, QRgb>(QCmyk32 *dst, const QRgb *src, qsizetype count, TransformFlags flags) const;
template void QColorTransformPrivate::apply<QCmyk32, QCmyk32>(QCmyk32 *dst, const QCmyk32 *src, qsizetype count, TransformFlags flags) const;
template void QColorTransformPrivate::apply<QCmyk32, QRgba64>(QCmyk32 *dst, const QRgba64 *src, qsizetype count, TransformFlags flags) const;
template void QColorTransformPrivate::apply<QCmyk32, QRgbaFloat32>(QCmyk32 *dst, const QRgbaFloat32 *src, qsizetype count, TransformFlags flags) const;
+template void QColorTransformPrivate::apply<QRgba64, quint16>(QRgba64 *dst, const quint16 *src, qsizetype count, TransformFlags flags) const;
template void QColorTransformPrivate::apply<QRgba64, QRgb>(QRgba64 *dst, const QRgb *src, qsizetype count, TransformFlags flags) const;
template void QColorTransformPrivate::apply<QRgba64, QCmyk32>(QRgba64 *dst, const QCmyk32 *src, qsizetype count, TransformFlags flags) const;
template void QColorTransformPrivate::apply<QRgba64, QRgba64>(QRgba64 *dst, const QRgba64 *src, qsizetype count, TransformFlags flags) const;
@@ -1970,15 +1912,6 @@ template void QColorTransformPrivate::apply<QRgbaFloat32, QCmyk32>(QRgbaFloat32
template void QColorTransformPrivate::apply<QRgbaFloat32, QRgba64>(QRgbaFloat32 *dst, const QRgba64 *src, qsizetype count, TransformFlags flags) const;
template void QColorTransformPrivate::apply<QRgbaFloat32, QRgbaFloat32>(QRgbaFloat32 *dst, const QRgbaFloat32 *src, qsizetype count, TransformFlags flags) const;
-bool QColorTransformPrivate::isThreeComponentMatrix() const
-{
- if (colorSpaceIn && !colorSpaceIn->isThreeComponentMatrix())
- return false;
- if (colorSpaceOut && !colorSpaceOut->isThreeComponentMatrix())
- return false;
- return true;
-}
-
/*!
\internal
*/
@@ -1991,7 +1924,7 @@ bool QColorTransformPrivate::isIdentity() const
if (colorSpaceIn && colorSpaceOut) {
if (colorSpaceIn->equals(colorSpaceOut.constData()))
return true;
- if (!isThreeComponentMatrix())
+ if (!colorSpaceIn->isThreeComponentMatrix() || !colorSpaceOut->isThreeComponentMatrix())
return false;
if (colorSpaceIn->transferFunction != colorSpaceOut->transferFunction)
return false;
@@ -2001,7 +1934,9 @@ bool QColorTransformPrivate::isIdentity() const
&& colorSpaceIn->trc[2] == colorSpaceOut->trc[2];
}
} else {
- if (!isThreeComponentMatrix())
+ if (colorSpaceIn && !colorSpaceIn->isThreeComponentMatrix())
+ return false;
+ if (colorSpaceOut && !colorSpaceOut->isThreeComponentMatrix())
return false;
if (colorSpaceIn && colorSpaceIn->transferFunction != QColorSpace::TransferFunction::Linear)
return false;
diff --git a/src/gui/painting/qcolortransform_p.h b/src/gui/painting/qcolortransform_p.h
index 59ea6a2405..3f11603420 100644
--- a/src/gui/painting/qcolortransform_p.h
+++ b/src/gui/painting/qcolortransform_p.h
@@ -27,7 +27,7 @@ class QCmyk32;
class QColorTransformPrivate : public QSharedData
{
public:
- QColorMatrix colorMatrix;
+ QColorMatrix colorMatrix; // Combined colorSpaceIn->toXyz and colorSpaceOut->toXyz.inverted()
QExplicitlySharedDataPointer<const QColorSpacePrivate> colorSpaceIn;
QExplicitlySharedDataPointer<const QColorSpacePrivate> colorSpaceOut;
@@ -37,7 +37,6 @@ public:
void updateLutsIn() const;
void updateLutsOut() const;
bool isIdentity() const;
- bool isThreeComponentMatrix() const;
Q_GUI_EXPORT void prepare();
enum TransformFlag {
@@ -54,20 +53,13 @@ public:
template<typename D, typename S>
void apply(D *dst, const S *src, qsizetype count, TransformFlags flags) const;
- template<typename D, typename S>
- void applyGray(D *dst, const S *src, qsizetype count, TransformFlags flags) const;
- template<typename D, typename S>
- void applyReturnGray(D *dst, const S *src, qsizetype count, TransformFlags flags) const;
private:
+ void pcsAdapt(QColorVector *buffer, qsizetype len) const;
template<typename S>
void applyConvertIn(const S *src, QColorVector *buffer, qsizetype len, TransformFlags flags) const;
template<typename D, typename S>
void applyConvertOut(D *dst, const S *src, QColorVector *buffer, qsizetype len, TransformFlags flags) const;
- template<typename D, typename S>
- void applyElementListTransform(D *dst, const S *src, qsizetype count, TransformFlags flags) const;
- template<typename D, typename S>
- void applyThreeComponentMatrix(D *dst, const S *src, qsizetype count, TransformFlags flags) const;
};
QT_END_NAMESPACE
diff --git a/src/gui/painting/qcolortrc_p.h b/src/gui/painting/qcolortrc_p.h
index d1ad1987df..dbca91c7f6 100644
--- a/src/gui/painting/qcolortrc_p.h
+++ b/src/gui/painting/qcolortrc_p.h
@@ -17,6 +17,7 @@
#include <QtGui/private/qtguiglobal_p.h>
#include "qcolortransferfunction_p.h"
+#include "qcolortransfergeneric_p.h"
#include "qcolortransfertable_p.h"
QT_BEGIN_NAMESPACE
@@ -26,20 +27,23 @@ class Q_GUI_EXPORT QColorTrc
{
public:
QColorTrc() noexcept : m_type(Type::Uninitialized) { }
- QColorTrc(const QColorTransferFunction &fun) : m_type(Type::Function), m_fun(fun) { }
+ QColorTrc(const QColorTransferFunction &fun) : m_type(Type::ParameterizedFunction), m_fun(fun) { }
QColorTrc(const QColorTransferTable &table) : m_type(Type::Table), m_table(table) { }
- QColorTrc(QColorTransferFunction &&fun) noexcept : m_type(Type::Function), m_fun(std::move(fun)) { }
+ QColorTrc(const QColorTransferGenericFunction &hdr) : m_type(Type::GenericFunction), m_hdr(hdr) { }
+ QColorTrc(QColorTransferFunction &&fun) noexcept : m_type(Type::ParameterizedFunction), m_fun(std::move(fun)) { }
QColorTrc(QColorTransferTable &&table) noexcept : m_type(Type::Table), m_table(std::move(table)) { }
+ QColorTrc(QColorTransferGenericFunction &&hdr) noexcept : m_type(Type::GenericFunction), m_hdr(std::move(hdr)) { }
enum class Type {
Uninitialized,
- Function,
- Table
+ ParameterizedFunction,
+ GenericFunction,
+ Table,
};
bool isIdentity() const
{
- return (m_type == Type::Function && m_fun.isIdentity())
+ return (m_type == Type::ParameterizedFunction && m_fun.isIdentity())
|| (m_type == Type::Table && m_table.isIdentity());
}
bool isValid() const
@@ -48,62 +52,87 @@ public:
}
float apply(float x) const
{
- if (m_type == Type::Table)
- return m_table.apply(x);
- if (m_type == Type::Function)
- return m_fun.apply(x);
+ switch (m_type) {
+ case Type::ParameterizedFunction:
+ return fun().apply(x);
+ case Type::GenericFunction:
+ return hdr().apply(x);
+ case Type::Table:
+ return table().apply(x);
+ default:
+ break;
+ }
return x;
}
float applyExtended(float x) const
{
- if (x >= 0.0f && x <= 1.0f)
- return apply(x);
- if (m_type == Type::Function)
- return std::copysign(m_fun.apply(std::abs(x)), x);
- if (m_type == Type::Table)
- return x < 0.0f ? 0.0f : 1.0f;
+ switch (m_type) {
+ case Type::ParameterizedFunction:
+ return std::copysign(fun().apply(std::abs(x)), x);
+ case Type::GenericFunction:
+ return hdr().apply(x);
+ case Type::Table:
+ return table().apply(x);
+ default:
+ break;
+ }
return x;
}
float applyInverse(float x) const
{
- if (m_type == Type::Table)
- return m_table.applyInverse(x);
- if (m_type == Type::Function)
- return m_fun.inverted().apply(x);
+ switch (m_type) {
+ case Type::ParameterizedFunction:
+ return fun().inverted().apply(x);
+ case Type::GenericFunction:
+ return hdr().applyInverse(x);
+ case Type::Table:
+ return table().applyInverse(x);
+ default:
+ break;
+ }
return x;
}
float applyInverseExtended(float x) const
{
- if (x >= 0.0f && x <= 1.0f)
- return applyInverse(x);
- if (m_type == Type::Function)
+ switch (m_type) {
+ case Type::ParameterizedFunction:
return std::copysign(applyInverse(std::abs(x)), x);
- if (m_type == Type::Table)
- return x < 0.0f ? 0.0f : 1.0f;
+ case Type::GenericFunction:
+ return hdr().applyInverse(x);
+ case Type::Table:
+ return table().applyInverse(x);
+ default:
+ break;
+ }
return x;
}
- friend inline bool operator!=(const QColorTrc &o1, const QColorTrc &o2);
- friend inline bool operator==(const QColorTrc &o1, const QColorTrc &o2);
+ const QColorTransferTable &table() const { return m_table; }
+ const QColorTransferFunction &fun() const{ return m_fun; }
+ const QColorTransferGenericFunction &hdr() const { return m_hdr; }
+ Type type() const noexcept { return m_type; }
Type m_type;
+
+ friend inline bool comparesEqual(const QColorTrc &lhs, const QColorTrc &rhs);
+ Q_DECLARE_EQUALITY_COMPARABLE(QColorTrc);
+
QColorTransferFunction m_fun;
QColorTransferTable m_table;
+ QColorTransferGenericFunction m_hdr;
};
-inline bool operator!=(const QColorTrc &o1, const QColorTrc &o2)
+inline bool comparesEqual(const QColorTrc &o1, const QColorTrc &o2)
{
if (o1.m_type != o2.m_type)
- return true;
- if (o1.m_type == QColorTrc::Type::Function)
- return o1.m_fun != o2.m_fun;
+ return false;
+ if (o1.m_type == QColorTrc::Type::ParameterizedFunction)
+ return o1.m_fun == o2.m_fun;
if (o1.m_type == QColorTrc::Type::Table)
- return o1.m_table != o2.m_table;
- return false;
-}
-inline bool operator==(const QColorTrc &o1, const QColorTrc &o2)
-{
- return !(o1 != o2);
+ return o1.m_table == o2.m_table;
+ if (o1.m_type == QColorTrc::Type::GenericFunction)
+ return o1.m_hdr == o2.m_hdr;
+ return true;
}
QT_END_NAMESPACE
diff --git a/src/gui/painting/qcolortrclut.cpp b/src/gui/painting/qcolortrclut.cpp
index 8a7673bc00..1357aa41a6 100644
--- a/src/gui/painting/qcolortrclut.cpp
+++ b/src/gui/painting/qcolortrclut.cpp
@@ -3,7 +3,9 @@
#include "qcolortrclut_p.h"
#include "qcolortransferfunction_p.h"
+#include "qcolortransfergeneric_p.h"
#include "qcolortransfertable_p.h"
+#include "qcolortrc_p.h"
#include <qmath.h>
QT_BEGIN_NAMESPACE
@@ -13,69 +15,86 @@ std::shared_ptr<QColorTrcLut> QColorTrcLut::create()
return std::make_shared<Access>();
}
-std::shared_ptr<QColorTrcLut> QColorTrcLut::fromGamma(qreal gamma, Direction dir)
+std::shared_ptr<QColorTrcLut> QColorTrcLut::fromGamma(float gamma, Direction dir)
{
auto cp = create();
cp->setFromGamma(gamma, dir);
return cp;
}
-std::shared_ptr<QColorTrcLut> QColorTrcLut::fromTransferFunction(const QColorTransferFunction &fun, Direction dir)
+std::shared_ptr<QColorTrcLut> QColorTrcLut::fromTrc(const QColorTrc &trc, Direction dir)
{
+ if (!trc.isValid())
+ return nullptr;
auto cp = create();
- cp->setFromTransferFunction(fun, dir);
+ cp->setFromTrc(trc, dir);
return cp;
}
-std::shared_ptr<QColorTrcLut> QColorTrcLut::fromTransferTable(const QColorTransferTable &table, Direction dir)
+void QColorTrcLut::setFromGamma(float gamma, Direction dir)
{
- auto cp = create();
- cp->setFromTransferTable(table, dir);
- return cp;
+ constexpr float iRes = 1.f / float(Resolution);
+ if (dir & ToLinear) {
+ if (!m_toLinear)
+ m_toLinear.reset(new ushort[Resolution + 1]);
+ for (int i = 0; i <= Resolution; ++i)
+ m_toLinear[i] = ushort(qRound(qBound(0.f, qPow(i * iRes, gamma), 1.f) * (255 * 256)));
+ }
+
+ if (dir & FromLinear) {
+ const float iGamma = 1.f / gamma;
+ if (!m_fromLinear)
+ m_fromLinear.reset(new ushort[Resolution + 1]);
+ for (int i = 0; i <= Resolution; ++i)
+ m_fromLinear[i] = ushort(qRound(qBound(0.f, qPow(i * iRes, iGamma), 1.f) * (255 * 256)));
+ }
}
-void QColorTrcLut::setFromGamma(qreal gamma, Direction dir)
+void QColorTrcLut::setFromTransferFunction(const QColorTransferFunction &fun, Direction dir)
{
+ constexpr float iRes = 1.f / float(Resolution);
if (dir & ToLinear) {
if (!m_toLinear)
m_toLinear.reset(new ushort[Resolution + 1]);
for (int i = 0; i <= Resolution; ++i)
- m_toLinear[i] = ushort(qRound(qPow(i / qreal(Resolution), gamma) * (255 * 256)));
+ m_toLinear[i] = ushort(qRound(qBound(0.f, fun.apply(i * iRes), 1.f) * (255 * 256)));
}
if (dir & FromLinear) {
if (!m_fromLinear)
m_fromLinear.reset(new ushort[Resolution + 1]);
+ QColorTransferFunction inv = fun.inverted();
for (int i = 0; i <= Resolution; ++i)
- m_fromLinear[i] = ushort(qRound(qPow(i / qreal(Resolution), qreal(1) / gamma) * (255 * 256)));
+ m_fromLinear[i] = ushort(qRound(qBound(0.f, inv.apply(i * iRes), 1.f) * (255 * 256)));
}
}
-void QColorTrcLut::setFromTransferFunction(const QColorTransferFunction &fun, Direction dir)
+void QColorTrcLut::setFromTransferGenericFunction(const QColorTransferGenericFunction &fun, Direction dir)
{
+ constexpr float iRes = 1.f / float(Resolution);
if (dir & ToLinear) {
if (!m_toLinear)
m_toLinear.reset(new ushort[Resolution + 1]);
for (int i = 0; i <= Resolution; ++i)
- m_toLinear[i] = ushort(qRound(fun.apply(i / qreal(Resolution)) * (255 * 256)));
+ m_toLinear[i] = ushort(qRound(qBound(0.f, fun.apply(i * iRes), 1.f) * (255 * 256)));
}
if (dir & FromLinear) {
if (!m_fromLinear)
m_fromLinear.reset(new ushort[Resolution + 1]);
- QColorTransferFunction inv = fun.inverted();
for (int i = 0; i <= Resolution; ++i)
- m_fromLinear[i] = ushort(qRound(inv.apply(i / qreal(Resolution)) * (255 * 256)));
+ m_fromLinear[i] = ushort(qRound(qBound(0.f, fun.applyInverse(i * iRes), 1.f) * (255 * 256)));
}
}
void QColorTrcLut::setFromTransferTable(const QColorTransferTable &table, Direction dir)
{
+ constexpr float iRes = 1.f / float(Resolution);
if (dir & ToLinear) {
if (!m_toLinear)
m_toLinear.reset(new ushort[Resolution + 1]);
for (int i = 0; i <= Resolution; ++i)
- m_toLinear[i] = ushort(qBound(0, qRound(table.apply(i / qreal(Resolution)) * (255 * 256)), 65280));
+ m_toLinear[i] = ushort(qRound(table.apply(i * iRes) * (255 * 256)));
}
if (dir & FromLinear) {
@@ -83,10 +102,24 @@ void QColorTrcLut::setFromTransferTable(const QColorTransferTable &table, Direct
m_fromLinear.reset(new ushort[Resolution + 1]);
float minInverse = 0.0f;
for (int i = 0; i <= Resolution; ++i) {
- minInverse = table.applyInverse(i / qreal(Resolution), minInverse);
- m_fromLinear[i] = ushort(qBound(0, qRound(minInverse * (255 * 256)), 65280));
+ minInverse = table.applyInverse(i * iRes, minInverse);
+ m_fromLinear[i] = ushort(qRound(minInverse * (255 * 256)));
}
}
}
+void QColorTrcLut::setFromTrc(const QColorTrc &trc, Direction dir)
+{
+ switch (trc.m_type) {
+ case QColorTrc::Type::ParameterizedFunction:
+ return setFromTransferFunction(trc.fun(), dir);
+ case QColorTrc::Type::Table:
+ return setFromTransferTable(trc.table(), dir);
+ case QColorTrc::Type::GenericFunction:
+ return setFromTransferGenericFunction(trc.hdr(), dir);
+ case QColorTrc::Type::Uninitialized:
+ break;
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/gui/painting/qcolortrclut_p.h b/src/gui/painting/qcolortrclut_p.h
index 3ebab42809..15f7348836 100644
--- a/src/gui/painting/qcolortrclut_p.h
+++ b/src/gui/painting/qcolortrclut_p.h
@@ -30,8 +30,10 @@
QT_BEGIN_NAMESPACE
+class QColorTransferGenericFunction;
class QColorTransferFunction;
class QColorTransferTable;
+class QColorTrc;
class Q_GUI_EXPORT QColorTrcLut
{
@@ -46,12 +48,13 @@ public:
BiLinear = ToLinear | FromLinear
};
- static std::shared_ptr<QColorTrcLut> fromGamma(qreal gamma, Direction dir = BiLinear);
- static std::shared_ptr<QColorTrcLut> fromTransferFunction(const QColorTransferFunction &transFn, Direction dir = BiLinear);
- static std::shared_ptr<QColorTrcLut> fromTransferTable(const QColorTransferTable &transTable, Direction dir = BiLinear);
- void setFromGamma(qreal gamma, Direction dir = BiLinear);
+ static std::shared_ptr<QColorTrcLut> fromGamma(float gamma, Direction dir = BiLinear);
+ static std::shared_ptr<QColorTrcLut> fromTrc(const QColorTrc &trc, Direction dir = BiLinear);
+ void setFromGamma(float gamma, Direction dir = BiLinear);
void setFromTransferFunction(const QColorTransferFunction &transFn, Direction dir = BiLinear);
void setFromTransferTable(const QColorTransferTable &transTable, Direction dir = BiLinear);
+ void setFromTransferGenericFunction(const QColorTransferGenericFunction &transfn, Direction dir);
+ void setFromTrc(const QColorTrc &trc, Direction dir);
// The following methods all convert opaque or unpremultiplied colors:
diff --git a/src/gui/painting/qdatabuffer_p.h b/src/gui/painting/qdatabuffer_p.h
index 8f467afe4e..aa8335542d 100644
--- a/src/gui/painting/qdatabuffer_p.h
+++ b/src/gui/painting/qdatabuffer_p.h
@@ -16,7 +16,9 @@
//
#include <QtGui/private/qtguiglobal_p.h>
+
#include "QtCore/qbytearray.h"
+#include "QtCore/qtypeinfo.h"
#include <stdlib.h>
@@ -43,6 +45,7 @@ public:
~QDataBuffer()
{
+ static_assert(!QTypeInfo<Type>::isComplex);
if (buffer)
free(buffer);
}
diff --git a/src/gui/painting/qdrawhelper.cpp b/src/gui/painting/qdrawhelper.cpp
index b7a943be38..aaf57e19d1 100644
--- a/src/gui/painting/qdrawhelper.cpp
+++ b/src/gui/painting/qdrawhelper.cpp
@@ -644,7 +644,7 @@ static void QT_FASTCALL destStoreGray8(QRasterBuffer *rasterBuffer, int x, int y
QColorTransform tf = QColorSpacePrivate::get(fromCS)->transformationToXYZ();
QColorTransformPrivate *tfd = QColorTransformPrivate::get(tf);
- tfd->applyReturnGray(data, buffer, length, QColorTransformPrivate::InputPremultiplied);
+ tfd->apply(data, buffer, length, QColorTransformPrivate::InputPremultiplied);
}
}
@@ -668,7 +668,7 @@ static void QT_FASTCALL destStoreGray16(QRasterBuffer *rasterBuffer, int x, int
QRgba64 tmp_line[BufferSize];
for (int k = 0; k < length; ++k)
tmp_line[k] = QRgba64::fromArgb32(buffer[k]);
- tfd->applyReturnGray(data, tmp_line, length, QColorTransformPrivate::InputPremultiplied);
+ tfd->apply(data, tmp_line, length, QColorTransformPrivate::InputPremultiplied);
}
}
@@ -749,7 +749,7 @@ static void QT_FASTCALL destStore64Gray8(QRasterBuffer *rasterBuffer, int x, int
QColorTransformPrivate *tfd = QColorTransformPrivate::get(tf);
quint16 gray_line[BufferSize];
- tfd->applyReturnGray(gray_line, buffer, length, QColorTransformPrivate::InputPremultiplied);
+ tfd->apply(gray_line, buffer, length, QColorTransformPrivate::InputPremultiplied);
for (int k = 0; k < length; ++k)
data[k] = qt_div_257(gray_line[k]);
}
@@ -771,7 +771,7 @@ static void QT_FASTCALL destStore64Gray16(QRasterBuffer *rasterBuffer, int x, in
QColorSpace fromCS = rasterBuffer->colorSpace.isValid() ? rasterBuffer->colorSpace : QColorSpace::SRgb;
QColorTransform tf = QColorSpacePrivate::get(fromCS)->transformationToXYZ();
QColorTransformPrivate *tfd = QColorTransformPrivate::get(tf);
- tfd->applyReturnGray(data, buffer, length, QColorTransformPrivate::InputPremultiplied);
+ tfd->apply(data, buffer, length, QColorTransformPrivate::InputPremultiplied);
}
}
diff --git a/src/gui/painting/qicc.cpp b/src/gui/painting/qicc.cpp
index c01fa433ea..70bdf28b21 100644
--- a/src/gui/painting/qicc.cpp
+++ b/src/gui/painting/qicc.cpp
@@ -116,6 +116,7 @@ enum class Tag : quint32 {
mAB_ = IccTag('m', 'A', 'B', ' '),
mBA_ = IccTag('m', 'B', 'A', ' '),
chad = IccTag('c', 'h', 'a', 'd'),
+ cicp = IccTag('c', 'i', 'c', 'p'),
gamt = IccTag('g', 'a', 'm', 't'),
sf32 = IccTag('s', 'f', '3', '2'),
@@ -247,6 +248,13 @@ struct Sf32TagData : GenericTagData {
quint32_be value[9];
};
+struct CicpTagData : GenericTagData {
+ quint8 colorPrimaries;
+ quint8 transferCharacteristics;
+ quint8 matrixCoefficients;
+ quint8 videoFullRangeFlag;
+};
+
struct MatrixElement {
qint32_be e0;
qint32_be e1;
@@ -264,7 +272,11 @@ struct MatrixElement {
static int toFixedS1516(float x)
{
- return int(x * 65536.0f + 0.5f);
+ if (x < float(SHRT_MIN))
+ return INT_MIN;
+ if (x > float(SHRT_MAX))
+ return INT_MAX;
+ return qRound(x * 65536.0f);
}
static float fromFixedS1516(int x)
@@ -327,7 +339,7 @@ static int writeColorTrc(QDataStream &stream, const QColorTrc &trc)
return 12;
}
- if (trc.m_type == QColorTrc::Type::Function) {
+ if (trc.m_type == QColorTrc::Type::ParameterizedFunction) {
const QColorTransferFunction &fun = trc.m_fun;
stream << uint(Tag::para) << uint(0);
if (fun.isGamma()) {
@@ -348,6 +360,14 @@ static int writeColorTrc(QDataStream &stream, const QColorTrc &trc)
stream << toFixedS1516(fun.m_f);
return 12 + 7 * 4;
}
+ if (trc.m_type != QColorTrc::Type::Table) {
+ stream << uint(Tag::curv) << uint(0);
+ stream << uint(16);
+ for (uint i = 0; i < 16; ++i) {
+ stream << ushort(qBound(0, qRound(trc.apply(i / 15.f) * 65535.f), 65535));
+ }
+ return 12 + 16 * 2;
+ }
Q_ASSERT(trc.m_type == QColorTrc::Type::Table);
stream << uint(Tag::curv) << uint(0);
@@ -368,31 +388,442 @@ static int writeColorTrc(QDataStream &stream, const QColorTrc &trc)
return 12 + 2 * trc.m_table.m_tableSize;
}
+// very simple version for small values (<=4) of exp.
+static constexpr qsizetype intPow(qsizetype x, qsizetype exp)
+{
+ return (exp <= 1) ? x : x * intPow(x, exp - 1);
+}
+
+struct ElementCombo
+{
+ const QColorMatrix *inMatrix = nullptr;
+ const QColorSpacePrivate::TransferElement *inTable = nullptr;
+ const QColorCLUT *clut = nullptr;
+ const QColorSpacePrivate::TransferElement *midTable = nullptr;
+ const QColorMatrix *midMatrix = nullptr;
+ const QColorVector *midOffset = nullptr;
+ const QColorSpacePrivate::TransferElement *outTable = nullptr;
+};
+
+static void visitElement(ElementCombo &combo, const QColorSpacePrivate::TransferElement &element, int number,
+ const QList<QColorSpacePrivate::Element> &list)
+{
+ if (number == 0)
+ combo.inTable = &element;
+ else if (number == list.size() - 1)
+ combo.outTable = &element;
+ else if (number == 1 && combo.inMatrix)
+ combo.inTable = &element;
+ else
+ combo.midTable = &element;
+}
+
+static void visitElement(ElementCombo &combo, const QColorMatrix &element, int number,
+ const QList<QColorSpacePrivate::Element> &)
+{
+ if (number == 0)
+ combo.inMatrix = &element;
+ else
+ combo.midMatrix = &element;
+}
+
+static void visitElement(ElementCombo &combo, const QColorVector &element, int,
+ const QList<QColorSpacePrivate::Element> &)
+{
+ combo.midOffset = &element;
+}
+
+static void visitElement(ElementCombo &combo, const QColorCLUT &element, int,
+ const QList<QColorSpacePrivate::Element> &)
+{
+ combo.clut = &element;
+}
+
+static bool isTableTrc(const QColorSpacePrivate::TransferElement *transfer)
+{
+ int i = 0;
+ while (i < 4 && transfer->trc[i].isValid()) {
+ if (transfer->trc[i].m_type != QColorTrc::Type::Table)
+ return false;
+ i++;
+ }
+ return i > 0;
+}
+
+static bool isTableTrcSingleSize(const QColorSpacePrivate::TransferElement *transfer)
+{
+ Q_ASSERT(transfer->trc[0].m_type == QColorTrc::Type::Table);
+ int i = 1;
+ const uint32_t size = transfer->trc[0].table().m_tableSize;
+ while (i < 4 && transfer->trc[i].isValid()) {
+ if (transfer->trc[i].table().m_tableSize != size)
+ return false;
+ i++;
+ }
+ return true;
+}
+
+static int writeMab(QDataStream &stream, const QList<QColorSpacePrivate::Element> &abList, bool isAb, bool pcsLab, bool isCmyk)
+{
+ int number = 0;
+ ElementCombo combo;
+ for (auto &&element : abList)
+ std::visit([&](auto &&elm) { visitElement(combo, elm, number++, abList); }, element);
+
+ Q_ASSERT(!(combo.inMatrix && combo.midMatrix));
+
+ // qWarning() << Q_FUNC_INFO << bool(combo.inMatrix) << bool(combo.inTable) << bool(combo.clut) << bool(combo.midTable) << bool(combo.midMatrix) << bool(combo.midOffset) << bool(combo.outTable);
+ bool lut16 = true;
+ if (combo.midMatrix || combo.midTable || combo.midOffset)
+ lut16 = false;
+ if (combo.clut && (combo.clut->gridPointsX != combo.clut->gridPointsY ||
+ combo.clut->gridPointsX != combo.clut->gridPointsZ ||
+ (combo.clut->gridPointsW > 1 && combo.clut->gridPointsX != combo.clut->gridPointsW)))
+ lut16 = false;
+ if (lut16 && combo.inTable)
+ lut16 = isTableTrc(combo.inTable) && isTableTrcSingleSize(combo.inTable);
+ if (lut16 && combo.outTable)
+ lut16 = isTableTrc(combo.outTable) && isTableTrcSingleSize(combo.outTable);
+
+ if (!lut16) {
+ if (combo.inMatrix)
+ qSwap(combo.inMatrix, combo.midMatrix);
+ if (isAb)
+ stream << uint(Tag::mAB_) << uint(0);
+ else
+ stream << uint(Tag::mBA_) << uint(0);
+ } else {
+ stream << uint(Tag::mft2) << uint(0);
+ }
+
+ const int inChannels = (isCmyk && isAb) ? 4 : 3;
+ const int outChannels = (isCmyk && !isAb) ? 4 : 3;
+ stream << uchar(inChannels) << uchar(outChannels);
+ qsizetype gridPointsLut16 = 0;
+ if (lut16 && combo.clut)
+ gridPointsLut16 = combo.clut->gridPointsX;
+ if (lut16)
+ stream << uchar(gridPointsLut16) << uchar(0);
+ else
+ stream << quint16(0);
+ if (lut16) {
+ if (combo.inMatrix) {
+ stream << toFixedS1516(combo.inMatrix->r.x);
+ stream << toFixedS1516(combo.inMatrix->g.x);
+ stream << toFixedS1516(combo.inMatrix->b.x);
+ stream << toFixedS1516(combo.inMatrix->r.y);
+ stream << toFixedS1516(combo.inMatrix->g.y);
+ stream << toFixedS1516(combo.inMatrix->b.y);
+ stream << toFixedS1516(combo.inMatrix->r.z);
+ stream << toFixedS1516(combo.inMatrix->g.z);
+ stream << toFixedS1516(combo.inMatrix->b.z);
+ } else {
+ stream << toFixedS1516(1.0f);
+ stream << toFixedS1516(0.0f);
+ stream << toFixedS1516(0.0f);
+ stream << toFixedS1516(0.0f);
+ stream << toFixedS1516(1.0f);
+ stream << toFixedS1516(0.0f);
+ stream << toFixedS1516(0.0f);
+ stream << toFixedS1516(0.0f);
+ stream << toFixedS1516(1.0f);
+ }
+ int inputEntries = 0, outputEntries = 0;
+ if (combo.inTable)
+ inputEntries = combo.inTable->trc[0].table().m_tableSize;
+ else
+ inputEntries = 2;
+ if (combo.outTable)
+ outputEntries = combo.outTable->trc[0].table().m_tableSize;
+ else
+ outputEntries = 2;
+ stream << quint16(inputEntries);
+ stream << quint16(outputEntries);
+ auto writeTable = [&](const QColorSpacePrivate::TransferElement *table, int entries, int channels) {
+ if (table) {
+ for (int j = 0; j < channels; ++j) {
+ if (!table->trc[j].table().m_table16.isEmpty()) {
+ for (int i = 0; i < entries; ++i)
+ stream << table->trc[j].table().m_table16[i];
+ } else {
+ for (int i = 0; i < entries; ++i)
+ stream << quint16(table->trc[j].table().m_table8[i] * 257);
+ }
+ }
+ } else {
+ for (int j = 0; j < channels; ++j)
+ stream << quint16(0) << quint16(65535);
+ }
+ };
+
+ writeTable(combo.inTable, inputEntries, inChannels);
+
+ if (combo.clut) {
+ if (isAb && pcsLab) {
+ for (const QColorVector &v : combo.clut->table) {
+ stream << quint16(v.x * 65280.0f + 0.5f);
+ stream << quint16(v.y * 65280.0f + 0.5f);
+ stream << quint16(v.z * 65280.0f + 0.5f);
+ }
+ } else {
+ if (outChannels == 4) {
+ for (const QColorVector &v : combo.clut->table) {
+ stream << quint16(v.x * 65535.0f + 0.5f);
+ stream << quint16(v.y * 65535.0f + 0.5f);
+ stream << quint16(v.z * 65535.0f + 0.5f);
+ stream << quint16(v.w * 65535.0f + 0.5f);
+ }
+ } else {
+ for (const QColorVector &v : combo.clut->table) {
+ stream << quint16(v.x * 65535.0f + 0.5f);
+ stream << quint16(v.y * 65535.0f + 0.5f);
+ stream << quint16(v.z * 65535.0f + 0.5f);
+ }
+ }
+ }
+ }
+
+ writeTable(combo.outTable, outputEntries, outChannels);
+
+ qsizetype offset = sizeof(Lut16TagData) + 2 * inChannels * inputEntries
+ + 2 * outChannels * outputEntries
+ + 2 * outChannels * intPow(gridPointsLut16, inChannels);
+ if (offset & 0x2) {
+ stream << quint16(0);
+ offset += 2;
+ }
+ return offset;
+ } else {
+ // mAB/mBA tag:
+ if (isAb) {
+ if (!combo.clut && combo.inTable && combo.midMatrix && !combo.midTable)
+ std::swap(combo.inTable, combo.midTable);
+ } else {
+ if (!combo.clut && combo.outTable && combo.midMatrix && !combo.midTable)
+ std::swap(combo.outTable, combo.midTable);
+ }
+ quint32 offset = sizeof(mABTagData);
+ QBuffer buffer2;
+ buffer2.open(QIODevice::WriteOnly);
+ QDataStream stream2(&buffer2);
+ quint32 bOffset = offset;
+ quint32 matrixOffset = 0;
+ quint32 mOffset = 0;
+ quint32 clutOffset = 0;
+ quint32 aOffset = 0;
+ // Tags must start on 4 byte offsets, but sampled curves might have sizes 2-byte aligned
+ auto alignTag = [&]() {
+ if (offset & 0x2) {
+ stream2 << quint16(0);
+ offset += 2;
+ }
+ };
+
+ const QColorSpacePrivate::TransferElement *aCurve, *bCurve;
+ int aChannels;
+ if (isAb) {
+ aCurve = combo.inTable;
+ aChannels = inChannels;
+ bCurve = combo.outTable;
+ Q_ASSERT(outChannels == 3);
+ } else {
+ aCurve = combo.outTable;
+ aChannels = outChannels;
+ bCurve = combo.inTable;
+ Q_ASSERT(inChannels == 3);
+ }
+ if (bCurve) {
+ offset += writeColorTrc(stream2, bCurve->trc[0]);
+ alignTag();
+ offset += writeColorTrc(stream2, bCurve->trc[1]);
+ alignTag();
+ offset += writeColorTrc(stream2, bCurve->trc[2]);
+ alignTag();
+ } else {
+ stream2 << uint(Tag::curv) << uint(0) << uint(0);
+ stream2 << uint(Tag::curv) << uint(0) << uint(0);
+ stream2 << uint(Tag::curv) << uint(0) << uint(0);
+ offset += 12 * 3;
+ }
+ if (combo.midMatrix || combo.midOffset || combo.midTable) {
+ matrixOffset = offset;
+ if (combo.midMatrix) {
+ stream2 << toFixedS1516(combo.midMatrix->r.x);
+ stream2 << toFixedS1516(combo.midMatrix->g.x);
+ stream2 << toFixedS1516(combo.midMatrix->b.x);
+ stream2 << toFixedS1516(combo.midMatrix->r.y);
+ stream2 << toFixedS1516(combo.midMatrix->g.y);
+ stream2 << toFixedS1516(combo.midMatrix->b.y);
+ stream2 << toFixedS1516(combo.midMatrix->r.z);
+ stream2 << toFixedS1516(combo.midMatrix->g.z);
+ stream2 << toFixedS1516(combo.midMatrix->b.z);
+ } else {
+ stream2 << toFixedS1516(1.0f);
+ stream2 << toFixedS1516(0.0f);
+ stream2 << toFixedS1516(0.0f);
+ stream2 << toFixedS1516(0.0f);
+ stream2 << toFixedS1516(1.0f);
+ stream2 << toFixedS1516(0.0f);
+ stream2 << toFixedS1516(0.0f);
+ stream2 << toFixedS1516(0.0f);
+ stream2 << toFixedS1516(1.0f);
+ }
+ if (combo.midOffset) {
+ stream2 << toFixedS1516(combo.midOffset->x);
+ stream2 << toFixedS1516(combo.midOffset->y);
+ stream2 << toFixedS1516(combo.midOffset->z);
+ } else {
+ stream2 << toFixedS1516(0.0f);
+ stream2 << toFixedS1516(0.0f);
+ stream2 << toFixedS1516(0.0f);
+ }
+ offset += 12 * 4;
+ mOffset = offset;
+ if (combo.midTable) {
+ offset += writeColorTrc(stream2, combo.midTable->trc[0]);
+ alignTag();
+ offset += writeColorTrc(stream2, combo.midTable->trc[1]);
+ alignTag();
+ offset += writeColorTrc(stream2, combo.midTable->trc[2]);
+ alignTag();
+ } else {
+ stream2 << uint(Tag::curv) << uint(0) << uint(0);
+ stream2 << uint(Tag::curv) << uint(0) << uint(0);
+ stream2 << uint(Tag::curv) << uint(0) << uint(0);
+ offset += 12 * 3;
+ }
+ }
+ if (combo.clut || aCurve) {
+ clutOffset = offset;
+ if (combo.clut) {
+ stream2 << uchar(combo.clut->gridPointsX);
+ stream2 << uchar(combo.clut->gridPointsY);
+ stream2 << uchar(combo.clut->gridPointsZ);
+ if (inChannels == 4)
+ stream2 << uchar(combo.clut->gridPointsW);
+ else
+ stream2 << uchar(0);
+ for (int i = 0; i < 12; ++i)
+ stream2 << uchar(0);
+ stream2 << uchar(2) << uchar(0) << uchar(0) << uchar(0);
+ offset += 20;
+ if (outChannels == 4) {
+ for (const QColorVector &v : combo.clut->table) {
+ stream2 << quint16(v.x * 65535.0f + 0.5f);
+ stream2 << quint16(v.y * 65535.0f + 0.5f);
+ stream2 << quint16(v.z * 65535.0f + 0.5f);
+ stream2 << quint16(v.w * 65535.0f + 0.5f);
+ }
+ } else {
+ for (const QColorVector &v : combo.clut->table) {
+ stream2 << quint16(v.x * 65535.0f + 0.5f);
+ stream2 << quint16(v.y * 65535.0f + 0.5f);
+ stream2 << quint16(v.z * 65535.0f + 0.5f);
+ }
+ }
+ offset += 2 * outChannels * combo.clut->table.size();
+ alignTag();
+ } else {
+ for (int i = 0; i < 16; ++i)
+ stream2 << uchar(0);
+ stream2 << uchar(1) << uchar(0) << uchar(0) << uchar(0);
+ offset += 20;
+ }
+ aOffset = offset;
+ if (aCurve) {
+ offset += writeColorTrc(stream2, aCurve->trc[0]);
+ alignTag();
+ offset += writeColorTrc(stream2, aCurve->trc[1]);
+ alignTag();
+ offset += writeColorTrc(stream2, aCurve->trc[2]);
+ alignTag();
+ if (aChannels == 4) {
+ offset += writeColorTrc(stream2, aCurve->trc[3]);
+ alignTag();
+ }
+ } else {
+ stream2 << uint(Tag::curv) << uint(0) << uint(0);
+ stream2 << uint(Tag::curv) << uint(0) << uint(0);
+ stream2 << uint(Tag::curv) << uint(0) << uint(0);
+ if (aChannels == 4)
+ stream2 << uint(Tag::curv) << uint(0) << uint(0);
+ offset += 12 * aChannels;
+ }
+ }
+ buffer2.close();
+ QByteArray tagData = buffer2.buffer();
+ stream << quint32(bOffset);
+ stream << quint32(matrixOffset);
+ stream << quint32(mOffset);
+ stream << quint32(clutOffset);
+ stream << quint32(aOffset);
+ stream.writeRawData(tagData.data(), tagData.size());
+
+ return int(sizeof(mABTagData) + tagData.size());
+ }
+}
+
QByteArray toIccProfile(const QColorSpace &space)
{
if (!space.isValid())
return QByteArray();
const QColorSpacePrivate *spaceDPtr = QColorSpacePrivate::get(space);
- // This should catch anything not three component matrix based as we can only get that from parsed ICC
if (!spaceDPtr->iccProfile.isEmpty())
return spaceDPtr->iccProfile;
- Q_ASSERT(spaceDPtr->isThreeComponentMatrix());
int fixedLengthTagCount = 5;
+ if (!spaceDPtr->isThreeComponentMatrix())
+ fixedLengthTagCount = 2;
+ else if (spaceDPtr->colorModel == QColorSpace::ColorModel::Gray)
+ fixedLengthTagCount = 2;
bool writeChad = false;
- if (!spaceDPtr->whitePoint.isNull() && spaceDPtr->whitePoint != QColorVector::D50()) {
+ bool writeB2a = true;
+ bool writeCicp = false;
+ if (spaceDPtr->isThreeComponentMatrix() && !spaceDPtr->chad.isIdentity()) {
writeChad = true;
fixedLengthTagCount++;
}
+ int varLengthTagCount = 4;
+ if (!spaceDPtr->isThreeComponentMatrix())
+ varLengthTagCount = 3;
+ else if (spaceDPtr->colorModel == QColorSpace::ColorModel::Gray)
+ varLengthTagCount = 2;
+
+ if (!space.isValidTarget()) {
+ writeB2a = false;
+ Q_ASSERT(!spaceDPtr->isThreeComponentMatrix());
+ varLengthTagCount--;
+ }
+ switch (spaceDPtr->transferFunction) {
+ case QColorSpace::TransferFunction::St2084:
+ case QColorSpace::TransferFunction::Hlg:
+ writeCicp = true;
+ fixedLengthTagCount++;
+ break;
+ default:
+ break;
+ }
- const int tagCount = fixedLengthTagCount + 4;
+ const int tagCount = fixedLengthTagCount + varLengthTagCount;
const uint profileDataOffset = 128 + 4 + 12 * tagCount;
- const uint variableTagTableOffsets = 128 + 4 + 12 * fixedLengthTagCount;
+ uint variableTagTableOffsets = 128 + 4 + 12 * fixedLengthTagCount;
+
uint currentOffset = 0;
- uint rTrcOffset, gTrcOffset, bTrcOffset;
- uint rTrcSize, gTrcSize, bTrcSize;
- uint descOffset, descSize;
+ uint rTrcOffset = 0;
+ uint gTrcOffset = 0;
+ uint bTrcOffset = 0;
+ uint kTrcOffset = 0;
+ uint rTrcSize = 0;
+ uint gTrcSize = 0;
+ uint bTrcSize = 0;
+ uint kTrcSize = 0;
+ uint descOffset = 0;
+ uint descSize = 0;
+ uint mA2bOffset = 0;
+ uint mB2aOffset = 0;
+ uint mA2bSize = 0;
+ uint mB2aSize = 0;
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
@@ -403,13 +834,25 @@ QByteArray toIccProfile(const QColorSpace &space)
stream << uint(0);
stream << uint(0x04400000); // Version 4.4
stream << uint(ProfileClass::Display);
- stream << uint(Tag::RGB_);
+ switch (spaceDPtr->colorModel) {
+ case QColorSpace::ColorModel::Rgb:
+ stream << uint(ColorSpaceType::Rgb);
+ break;
+ case QColorSpace::ColorModel::Gray:
+ stream << uint(ColorSpaceType::Gray);
+ break;
+ case QColorSpace::ColorModel::Cmyk:
+ stream << uint(ColorSpaceType::Cmyk);
+ break;
+ case QColorSpace::ColorModel::Undefined:
+ Q_UNREACHABLE();
+ }
stream << (spaceDPtr->isPcsLab ? uint(Tag::Lab_) : uint(Tag::XYZ_));
stream << uint(0) << uint(0) << uint(0);
stream << uint(Tag::acsp);
stream << uint(0) << uint(0) << uint(0);
stream << uint(0) << uint(0) << uint(0);
- stream << uint(1); // Rendering intent
+ stream << uint(0); // Rendering intent
stream << uint(0x0000f6d6); // D50 X
stream << uint(0x00010000); // D50 Y
stream << uint(0x0000d32d); // D50 Z
@@ -417,81 +860,148 @@ QByteArray toIccProfile(const QColorSpace &space)
stream << uint(0) << uint(0) << uint(0) << uint(0);
stream << uint(0) << uint(0) << uint(0) << uint(0) << uint(0) << uint(0) << uint(0);
- // Tag table:
currentOffset = profileDataOffset;
- stream << uint(tagCount);
- stream << uint(Tag::rXYZ) << uint(profileDataOffset + 00) << uint(20);
- stream << uint(Tag::gXYZ) << uint(profileDataOffset + 20) << uint(20);
- stream << uint(Tag::bXYZ) << uint(profileDataOffset + 40) << uint(20);
- stream << uint(Tag::wtpt) << uint(profileDataOffset + 60) << uint(20);
- stream << uint(Tag::cprt) << uint(profileDataOffset + 80) << uint(34);
- currentOffset += 20 + 20 + 20 + 20 + 34 + 2;
- if (writeChad) {
- stream << uint(Tag::chad) << uint(currentOffset) << uint(44);
- currentOffset += 44;
- }
- // From here the offset and size will be updated later:
- stream << uint(Tag::rTRC) << uint(0) << uint(0);
- stream << uint(Tag::gTRC) << uint(0) << uint(0);
- stream << uint(Tag::bTRC) << uint(0) << uint(0);
- stream << uint(Tag::desc) << uint(0) << uint(0);
-
- // Tag data:
- stream << uint(Tag::XYZ_) << uint(0);
- stream << toFixedS1516(spaceDPtr->toXyz.r.x);
- stream << toFixedS1516(spaceDPtr->toXyz.r.y);
- stream << toFixedS1516(spaceDPtr->toXyz.r.z);
- stream << uint(Tag::XYZ_) << uint(0);
- stream << toFixedS1516(spaceDPtr->toXyz.g.x);
- stream << toFixedS1516(spaceDPtr->toXyz.g.y);
- stream << toFixedS1516(spaceDPtr->toXyz.g.z);
- stream << uint(Tag::XYZ_) << uint(0);
- stream << toFixedS1516(spaceDPtr->toXyz.b.x);
- stream << toFixedS1516(spaceDPtr->toXyz.b.y);
- stream << toFixedS1516(spaceDPtr->toXyz.b.z);
- stream << uint(Tag::XYZ_) << uint(0);
- stream << toFixedS1516(spaceDPtr->whitePoint.x);
- stream << toFixedS1516(spaceDPtr->whitePoint.y);
- stream << toFixedS1516(spaceDPtr->whitePoint.z);
- stream << uint(Tag::mluc) << uint(0);
- stream << uint(1) << uint(12);
- stream << uchar('e') << uchar('n') << uchar('U') << uchar('S');
- stream << uint(6) << uint(28);
- stream << ushort('N') << ushort('/') << ushort('A');
- stream << ushort(0); // 4-byte alignment
- if (writeChad) {
- QColorMatrix chad = QColorMatrix::chromaticAdaptation(spaceDPtr->whitePoint);
- stream << uint(Tag::sf32) << uint(0);
- stream << toFixedS1516(chad.r.x);
- stream << toFixedS1516(chad.g.x);
- stream << toFixedS1516(chad.b.x);
- stream << toFixedS1516(chad.r.y);
- stream << toFixedS1516(chad.g.y);
- stream << toFixedS1516(chad.b.y);
- stream << toFixedS1516(chad.r.z);
- stream << toFixedS1516(chad.g.z);
- stream << toFixedS1516(chad.b.z);
- }
-
- // From now on the data is variable sized:
- rTrcOffset = currentOffset;
- rTrcSize = writeColorTrc(stream, spaceDPtr->trc[0]);
- currentOffset += rTrcSize;
- if (spaceDPtr->trc[0] == spaceDPtr->trc[1]) {
- gTrcOffset = rTrcOffset;
- gTrcSize = rTrcSize;
- } else {
- gTrcOffset = currentOffset;
- gTrcSize = writeColorTrc(stream, spaceDPtr->trc[1]);
- currentOffset += gTrcSize;
- }
- if (spaceDPtr->trc[0] == spaceDPtr->trc[2]) {
- bTrcOffset = rTrcOffset;
- bTrcSize = rTrcSize;
+ if (spaceDPtr->isThreeComponentMatrix()) {
+ // Tag table:
+ stream << uint(tagCount);
+ if (spaceDPtr->colorModel == QColorSpace::ColorModel::Rgb) {
+ stream << uint(Tag::rXYZ) << uint(currentOffset + 00) << uint(20);
+ stream << uint(Tag::gXYZ) << uint(currentOffset + 20) << uint(20);
+ stream << uint(Tag::bXYZ) << uint(currentOffset + 40) << uint(20);
+ currentOffset += 20 + 20 + 20;
+ }
+ stream << uint(Tag::wtpt) << uint(currentOffset + 00) << uint(20);
+ stream << uint(Tag::cprt) << uint(currentOffset + 20) << uint(34);
+ currentOffset += 20 + 34 + 2;
+ if (writeChad) {
+ stream << uint(Tag::chad) << uint(currentOffset) << uint(44);
+ currentOffset += 44;
+ }
+ if (writeCicp) {
+ stream << uint(Tag::cicp) << uint(currentOffset) << uint(12);
+ currentOffset += 12;
+ }
+ // From here the offset and size will be updated later:
+ if (spaceDPtr->colorModel == QColorSpace::ColorModel::Rgb) {
+ stream << uint(Tag::rTRC) << uint(0) << uint(0);
+ stream << uint(Tag::gTRC) << uint(0) << uint(0);
+ stream << uint(Tag::bTRC) << uint(0) << uint(0);
+ } else {
+ stream << uint(Tag::kTRC) << uint(0) << uint(0);
+ }
+ stream << uint(Tag::desc) << uint(0) << uint(0);
+
+ // Tag data:
+ if (spaceDPtr->colorModel == QColorSpace::ColorModel::Rgb) {
+ stream << uint(Tag::XYZ_) << uint(0);
+ stream << toFixedS1516(spaceDPtr->toXyz.r.x);
+ stream << toFixedS1516(spaceDPtr->toXyz.r.y);
+ stream << toFixedS1516(spaceDPtr->toXyz.r.z);
+ stream << uint(Tag::XYZ_) << uint(0);
+ stream << toFixedS1516(spaceDPtr->toXyz.g.x);
+ stream << toFixedS1516(spaceDPtr->toXyz.g.y);
+ stream << toFixedS1516(spaceDPtr->toXyz.g.z);
+ stream << uint(Tag::XYZ_) << uint(0);
+ stream << toFixedS1516(spaceDPtr->toXyz.b.x);
+ stream << toFixedS1516(spaceDPtr->toXyz.b.y);
+ stream << toFixedS1516(spaceDPtr->toXyz.b.z);
+ }
+ stream << uint(Tag::XYZ_) << uint(0);
+ stream << toFixedS1516(spaceDPtr->whitePoint.x);
+ stream << toFixedS1516(spaceDPtr->whitePoint.y);
+ stream << toFixedS1516(spaceDPtr->whitePoint.z);
+ stream << uint(Tag::mluc) << uint(0);
+ stream << uint(1) << uint(12);
+ stream << uchar('e') << uchar('n') << uchar('U') << uchar('S');
+ stream << uint(6) << uint(28);
+ stream << ushort('N') << ushort('/') << ushort('A');
+ stream << ushort(0); // 4-byte alignment
+ if (writeChad) {
+ const QColorMatrix &chad = spaceDPtr->chad;
+ stream << uint(Tag::sf32) << uint(0);
+ stream << toFixedS1516(chad.r.x);
+ stream << toFixedS1516(chad.g.x);
+ stream << toFixedS1516(chad.b.x);
+ stream << toFixedS1516(chad.r.y);
+ stream << toFixedS1516(chad.g.y);
+ stream << toFixedS1516(chad.b.y);
+ stream << toFixedS1516(chad.r.z);
+ stream << toFixedS1516(chad.g.z);
+ stream << toFixedS1516(chad.b.z);
+ }
+ if (writeCicp) {
+ stream << uint(Tag::cicp) << uint(0);
+ stream << uchar(2); // Unspecified primaries
+ if (spaceDPtr->transferFunction == QColorSpace::TransferFunction::St2084)
+ stream << uchar(16);
+ else if (spaceDPtr->transferFunction == QColorSpace::TransferFunction::Hlg)
+ stream << uchar(18);
+ else
+ Q_UNREACHABLE();
+ stream << uchar(0); // Only for YCbCr, otherwise 0
+ stream << uchar(1); // Video full range
+ }
+
+ // From now on the data is variable sized:
+ if (spaceDPtr->colorModel == QColorSpace::ColorModel::Rgb) {
+ rTrcOffset = currentOffset;
+ rTrcSize = writeColorTrc(stream, spaceDPtr->trc[0]);
+ currentOffset += rTrcSize;
+ if (spaceDPtr->trc[0] == spaceDPtr->trc[1]) {
+ gTrcOffset = rTrcOffset;
+ gTrcSize = rTrcSize;
+ } else {
+ gTrcOffset = currentOffset;
+ gTrcSize = writeColorTrc(stream, spaceDPtr->trc[1]);
+ currentOffset += gTrcSize;
+ }
+ if (spaceDPtr->trc[0] == spaceDPtr->trc[2]) {
+ bTrcOffset = rTrcOffset;
+ bTrcSize = rTrcSize;
+ } else {
+ bTrcOffset = currentOffset;
+ bTrcSize = writeColorTrc(stream, spaceDPtr->trc[2]);
+ currentOffset += bTrcSize;
+ }
+ } else {
+ Q_ASSERT(spaceDPtr->colorModel == QColorSpace::ColorModel::Gray);
+ kTrcOffset = currentOffset;
+ kTrcSize = writeColorTrc(stream, spaceDPtr->trc[0]);
+ currentOffset += kTrcSize;
+ }
} else {
- bTrcOffset = currentOffset;
- bTrcSize = writeColorTrc(stream, spaceDPtr->trc[2]);
- currentOffset += bTrcSize;
+ // Tag table:
+ stream << uint(tagCount);
+ stream << uint(Tag::wtpt) << uint(profileDataOffset + 00) << uint(20);
+ stream << uint(Tag::cprt) << uint(profileDataOffset + 20) << uint(34);
+ currentOffset += 20 + 34 + 2;
+ // From here the offset and size will be updated later:
+ stream << uint(Tag::A2B0) << uint(0) << uint(0);
+ if (writeB2a)
+ stream << uint(Tag::B2A0) << uint(0) << uint(0);
+ stream << uint(Tag::desc) << uint(0) << uint(0);
+
+ // Fixed tag data
+ stream << uint(Tag::XYZ_) << uint(0);
+ stream << toFixedS1516(spaceDPtr->whitePoint.x);
+ stream << toFixedS1516(spaceDPtr->whitePoint.y);
+ stream << toFixedS1516(spaceDPtr->whitePoint.z);
+ stream << uint(Tag::mluc) << uint(0);
+ stream << uint(1) << uint(12);
+ stream << uchar('e') << uchar('n') << uchar('U') << uchar('S');
+ stream << uint(6) << uint(28);
+ stream << ushort('N') << ushort('/') << ushort('A');
+ stream << ushort(0); // 4-byte alignment
+
+ // From now on the data is variable sized:
+ mA2bOffset = currentOffset;
+ mA2bSize = writeMab(stream, spaceDPtr->mAB, true, spaceDPtr->isPcsLab, spaceDPtr->colorModel == QColorSpace::ColorModel::Cmyk);
+ currentOffset += mA2bSize;
+ if (writeB2a) {
+ mB2aOffset = currentOffset;
+ mB2aSize = writeMab(stream, spaceDPtr->mBA, false, spaceDPtr->isPcsLab, spaceDPtr->colorModel == QColorSpace::ColorModel::Cmyk);
+ currentOffset += mB2aSize;
+ }
}
// Writing description
@@ -515,14 +1025,34 @@ QByteArray toIccProfile(const QColorSpace &space)
// Now write final size
*(quint32_be *)iccProfile.data() = iccProfile.size();
// And the final indices and sizes of variable size tags:
- *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 4) = rTrcOffset;
- *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 8) = rTrcSize;
- *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 12 + 4) = gTrcOffset;
- *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 12 + 8) = gTrcSize;
- *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 2 * 12 + 4) = bTrcOffset;
- *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 2 * 12 + 8) = bTrcSize;
- *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 3 * 12 + 4) = descOffset;
- *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 3 * 12 + 8) = descSize;
+ if (spaceDPtr->isThreeComponentMatrix()) {
+ if (spaceDPtr->colorModel == QColorSpace::ColorModel::Rgb) {
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 4) = rTrcOffset;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 8) = rTrcSize;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 12 + 4) = gTrcOffset;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 12 + 8) = gTrcSize;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 2 * 12 + 4) = bTrcOffset;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 2 * 12 + 8) = bTrcSize;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 3 * 12 + 4) = descOffset;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 3 * 12 + 8) = descSize;
+ } else {
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 4) = kTrcOffset;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 8) = kTrcSize;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 12 + 4) = descOffset;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 12 + 8) = descSize;
+ }
+ } else {
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 4) = mA2bOffset;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 8) = mA2bSize;
+ variableTagTableOffsets += 12;
+ if (writeB2a) {
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 4) = mB2aOffset;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 8) = mB2aSize;
+ variableTagTableOffsets += 12;
+ }
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 4) = descOffset;
+ *(quint32_be *)(iccProfile.data() + variableTagTableOffsets + 8) = descSize;
+ }
#if !defined(QT_NO_DEBUG) || defined(QT_FORCE_ASSERTS)
const ICCProfileHeader *iccHeader = (const ICCProfileHeader *)iccProfile.constData();
@@ -559,21 +1089,27 @@ static bool parseXyzData(const QByteArray &data, const TagEntry &tagEntry, QColo
static quint32 parseTRC(const QByteArrayView &tagData, QColorTrc &gamma, QColorTransferTable::Type type = QColorTransferTable::TwoWay)
{
+ if (tagData.size() < 12)
+ return 0;
const GenericTagData trcData = qFromUnaligned<GenericTagData>(tagData.constData());
if (trcData.type == quint32(Tag::curv)) {
Q_STATIC_ASSERT(sizeof(CurvTagData) == 12);
const CurvTagData curv = qFromUnaligned<CurvTagData>(tagData.constData());
- if (curv.valueCount > (1 << 16))
+ if (curv.valueCount > (1 << 16)) {
+ qCWarning(lcIcc) << "Invalid count in curv table";
return 0;
- if (tagData.size() < qsizetype(12 + 2 * curv.valueCount))
+ }
+ if (tagData.size() < qsizetype(12 + 2 * curv.valueCount)) {
+ qCWarning(lcIcc) << "Truncated curv table";
return 0;
+ }
const auto valueOffset = sizeof(CurvTagData);
if (curv.valueCount == 0) {
- gamma.m_type = QColorTrc::Type::Function;
+ gamma.m_type = QColorTrc::Type::ParameterizedFunction;
gamma.m_fun = QColorTransferFunction(); // Linear
} else if (curv.valueCount == 1) {
const quint16 v = qFromBigEndian<quint16>(tagData.constData() + valueOffset);
- gamma.m_type = QColorTrc::Type::Function;
+ gamma.m_type = QColorTrc::Type::ParameterizedFunction;
gamma.m_fun = QColorTransferFunction::fromGamma(v * (1.0f / 256.0f));
} else {
QList<quint16> tabl;
@@ -591,7 +1127,7 @@ static quint32 parseTRC(const QByteArrayView &tagData, QColorTrc &gamma, QColorT
gamma.m_table = table;
} else {
qCDebug(lcIcc) << "Detected curv table as function";
- gamma.m_type = QColorTrc::Type::Function;
+ gamma.m_type = QColorTrc::Type::ParameterizedFunction;
gamma.m_fun = curve;
}
}
@@ -608,7 +1144,7 @@ static quint32 parseTRC(const QByteArrayView &tagData, QColorTrc &gamma, QColorT
return 0;
qFromBigEndian<quint32>(tagData.constData() + parametersOffset, 1, parameters);
float g = fromFixedS1516(parameters[0]);
- gamma.m_type = QColorTrc::Type::Function;
+ gamma.m_type = QColorTrc::Type::ParameterizedFunction;
gamma.m_fun = QColorTransferFunction::fromGamma(g);
return 12 + 1 * 4;
}
@@ -622,7 +1158,7 @@ static quint32 parseTRC(const QByteArrayView &tagData, QColorTrc &gamma, QColorT
float a = fromFixedS1516(parameters[1]);
float b = fromFixedS1516(parameters[2]);
float d = -b / a;
- gamma.m_type = QColorTrc::Type::Function;
+ gamma.m_type = QColorTrc::Type::ParameterizedFunction;
gamma.m_fun = QColorTransferFunction(a, b, 0.0f, d, 0.0f, 0.0f, g);
return 12 + 3 * 4;
}
@@ -637,7 +1173,7 @@ static quint32 parseTRC(const QByteArrayView &tagData, QColorTrc &gamma, QColorT
float b = fromFixedS1516(parameters[2]);
float c = fromFixedS1516(parameters[3]);
float d = -b / a;
- gamma.m_type = QColorTrc::Type::Function;
+ gamma.m_type = QColorTrc::Type::ParameterizedFunction;
gamma.m_fun = QColorTransferFunction(a, b, 0.0f, d, c, c, g);
return 12 + 4 * 4;
}
@@ -650,7 +1186,7 @@ static quint32 parseTRC(const QByteArrayView &tagData, QColorTrc &gamma, QColorT
float b = fromFixedS1516(parameters[2]);
float c = fromFixedS1516(parameters[3]);
float d = fromFixedS1516(parameters[4]);
- gamma.m_type = QColorTrc::Type::Function;
+ gamma.m_type = QColorTrc::Type::ParameterizedFunction;
gamma.m_fun = QColorTransferFunction(a, b, c, d, 0.0f, 0.0f, g);
return 12 + 5 * 4;
}
@@ -665,7 +1201,7 @@ static quint32 parseTRC(const QByteArrayView &tagData, QColorTrc &gamma, QColorT
float d = fromFixedS1516(parameters[4]);
float e = fromFixedS1516(parameters[5]);
float f = fromFixedS1516(parameters[6]);
- gamma.m_type = QColorTrc::Type::Function;
+ gamma.m_type = QColorTrc::Type::ParameterizedFunction;
gamma.m_fun = QColorTransferFunction(a, b, c, d, e, f, g);
return 12 + 7 * 4;
}
@@ -700,12 +1236,6 @@ static void parseCLUT(const T *tableData, const float f, QColorCLUT *clut, uchar
}
}
-// very simple version for small values (<=4) of exp.
-static constexpr qsizetype intPow(qsizetype x, qsizetype exp)
-{
- return (exp <= 1) ? x : x * intPow(x, exp - 1);
-}
-
// Parses lut8 and lut16 type elements
template<typename T>
static bool parseLutData(const QByteArray &data, const TagEntry &tagEntry, QColorSpacePrivate *colorSpacePrivate, bool isAb)
@@ -761,20 +1291,23 @@ static bool parseLutData(const QByteArray &data, const TagEntry &tagEntry, QColo
return false;
}
- if (lut.inputChannels != 3 && !(isAb && colorSpacePrivate->colorModel == QColorSpace::ColorModel::Cmyk && lut.inputChannels == 4)) {
+ const int inputChannels = (isAb && colorSpacePrivate->colorModel == QColorSpace::ColorModel::Cmyk) ? 4 : 3;
+ const int outputChannels = (!isAb && colorSpacePrivate->colorModel == QColorSpace::ColorModel::Cmyk) ? 4 : 3;
+
+ if (lut.inputChannels != inputChannels) {
qCWarning(lcIcc) << "Unsupported lut8/lut16 input channel count" << lut.inputChannels;
return false;
}
- if (lut.outputChannels != 3 && !(!isAb && colorSpacePrivate->colorModel == QColorSpace::ColorModel::Cmyk && lut.outputChannels == 4)) {
+ if (lut.outputChannels != outputChannels) {
qCWarning(lcIcc) << "Unsupported lut8/lut16 output channel count" << lut.outputChannels;
return false;
}
- const qsizetype clutTableSize = intPow(lut.clutGridPoints, lut.inputChannels);
- if (tagEntry.size < (sizeof(T) + precision * lut.inputChannels * inputTableEntries
- + precision * lut.outputChannels * outputTableEntries
- + precision * lut.outputChannels * clutTableSize)) {
+ const qsizetype clutTableSize = intPow(lut.clutGridPoints, inputChannels);
+ if (tagEntry.size < (sizeof(T) + precision * inputChannels * inputTableEntries
+ + precision * outputChannels * outputTableEntries
+ + precision * outputChannels * clutTableSize)) {
qCWarning(lcIcc) << "Undersized lut8/lut16 tag, no room for tables";
return false;
}
@@ -785,7 +1318,7 @@ static bool parseLutData(const QByteArray &data, const TagEntry &tagEntry, QColo
const uint8_t *tableData = reinterpret_cast<const uint8_t *>(data.constData() + tagEntry.offset + sizeof(T));
- for (int j = 0; j < lut.inputChannels; ++j) {
+ for (int j = 0; j < inputChannels; ++j) {
QList<S> input(inputTableEntries);
qFromBigEndian<S>(tableData, inputTableEntries, input.data());
QColorTransferTable table(inputTableEntries, input, QColorTransferTable::OneWay);
@@ -801,22 +1334,22 @@ static bool parseLutData(const QByteArray &data, const TagEntry &tagEntry, QColo
clutElement.table.resize(clutTableSize);
clutElement.gridPointsX = clutElement.gridPointsY = clutElement.gridPointsZ = lut.clutGridPoints;
- if (lut.inputChannels == 4)
+ if (inputChannels == 4)
clutElement.gridPointsW = lut.clutGridPoints;
if constexpr (std::is_same_v<T, Lut8TagData>) {
- parseCLUT(tableData, 1.f / 255.f, &clutElement, lut.outputChannels);
+ parseCLUT(tableData, 1.f / 255.f, &clutElement, outputChannels);
} else {
float f = 1.0f / 65535.f;
if (colorSpacePrivate->isPcsLab && isAb) // Legacy lut16 conversion to Lab
f = 1.0f / 65280.f;
- QList<S> clutTable(clutTableSize * lut.outputChannels);
+ QList<S> clutTable(clutTableSize * outputChannels);
qFromBigEndian<S>(tableData, clutTable.size(), clutTable.data());
- parseCLUT(clutTable.constData(), f, &clutElement, lut.outputChannels);
+ parseCLUT(clutTable.constData(), f, &clutElement, outputChannels);
}
- tableData += clutTableSize * lut.outputChannels * precision;
+ tableData += clutTableSize * outputChannels * precision;
- for (int j = 0; j < lut.outputChannels; ++j) {
+ for (int j = 0; j < outputChannels; ++j) {
QList<S> output(outputTableEntries);
qFromBigEndian<S>(tableData, outputTableEntries, output.data());
QColorTransferTable table(outputTableEntries, output, QColorTransferTable::OneWay);
@@ -868,12 +1401,15 @@ static bool parseMabData(const QByteArray &data, const TagEntry &tagEntry, QColo
return false;
}
- if (mab.inputChannels != 3 && !(isAb && colorSpacePrivate->colorModel == QColorSpace::ColorModel::Cmyk && mab.inputChannels == 4)) {
+ const int inputChannels = (isAb && colorSpacePrivate->colorModel == QColorSpace::ColorModel::Cmyk) ? 4 : 3;
+ const int outputChannels = (!isAb && colorSpacePrivate->colorModel == QColorSpace::ColorModel::Cmyk) ? 4 : 3;
+
+ if (mab.inputChannels != inputChannels) {
qCWarning(lcIcc) << "Unsupported mAB/mBA input channel count" << mab.inputChannels;
return false;
}
- if (mab.outputChannels != 3 && !(!isAb && colorSpacePrivate->colorModel == QColorSpace::ColorModel::Cmyk && mab.outputChannels == 4)) {
+ if (mab.outputChannels != outputChannels) {
qCWarning(lcIcc) << "Unsupported mAB/mBA output channel count" << mab.outputChannels;
return false;
}
@@ -923,7 +1459,7 @@ static bool parseMabData(const QByteArray &data, const TagEntry &tagEntry, QColo
bool bCurvesAreLinear = true, aCurvesAreLinear = true, mCurvesAreLinear = true;
// B Curves
- if (!parseCurves(mab.bCurvesOffset, bTableElement.trc, isAb ? mab.outputChannels : mab.inputChannels)) {
+ if (!parseCurves(mab.bCurvesOffset, bTableElement.trc, isAb ? outputChannels : inputChannels)) {
qCWarning(lcIcc) << "Invalid B curves";
return false;
} else {
@@ -932,7 +1468,7 @@ static bool parseMabData(const QByteArray &data, const TagEntry &tagEntry, QColo
// A Curves
if (mab.aCurvesOffset) {
- if (!parseCurves(mab.aCurvesOffset, aTableElement.trc, isAb ? mab.inputChannels : mab.outputChannels)) {
+ if (!parseCurves(mab.aCurvesOffset, aTableElement.trc, isAb ? inputChannels : outputChannels)) {
qCWarning(lcIcc) << "Invalid A curves";
return false;
} else {
@@ -987,19 +1523,19 @@ static bool parseMabData(const QByteArray &data, const TagEntry &tagEntry, QColo
return false;
}
const qsizetype clutTableSize = clutElement.gridPointsX * clutElement.gridPointsY * clutElement.gridPointsZ * clutElement.gridPointsW;
- if ((mab.clutOffset + 20 + clutTableSize * mab.outputChannels * precision) > tagEntry.size) {
+ if ((mab.clutOffset + 20 + clutTableSize * outputChannels * precision) > tagEntry.size) {
qCWarning(lcIcc) << "CLUT oversized for tag";
return false;
}
clutElement.table.resize(clutTableSize);
if (precision == 2) {
- QList<uint16_t> clutTable(clutTableSize * mab.outputChannels);
+ QList<uint16_t> clutTable(clutTableSize * outputChannels);
qFromBigEndian<uint16_t>(data.constData() + tagEntry.offset + mab.clutOffset + 20, clutTable.size(), clutTable.data());
- parseCLUT(clutTable.constData(), (1.f/65535.f), &clutElement, mab.outputChannels);
+ parseCLUT(clutTable.constData(), (1.f/65535.f), &clutElement, outputChannels);
} else {
const uint8_t *clutTable = reinterpret_cast<const uint8_t *>(data.constData() + tagEntry.offset + mab.clutOffset + 20);
- parseCLUT(clutTable, (1.f/255.f), &clutElement, mab.outputChannels);
+ parseCLUT(clutTable, (1.f/255.f), &clutElement, outputChannels);
}
} else if (colorSpacePrivate->colorModel == QColorSpace::ColorModel::Cmyk) {
qCWarning(lcIcc) << "Cmyk conversion must have a CLUT";
@@ -1013,7 +1549,7 @@ static bool parseMabData(const QByteArray &data, const TagEntry &tagEntry, QColo
if (!clutElement.isEmpty())
colorSpacePrivate->mAB.append(std::move(clutElement));
}
- if (mab.mCurvesOffset && mab.outputChannels == 3) {
+ if (mab.mCurvesOffset && outputChannels == 3) {
if (!mCurvesAreLinear)
colorSpacePrivate->mAB.append(std::move(mTableElement));
if (!matrixElement.isIdentity())
@@ -1026,7 +1562,7 @@ static bool parseMabData(const QByteArray &data, const TagEntry &tagEntry, QColo
} else {
if (!bCurvesAreLinear)
colorSpacePrivate->mBA.append(std::move(bTableElement));
- if (mab.mCurvesOffset && mab.inputChannels == 3) {
+ if (mab.mCurvesOffset && inputChannels == 3) {
if (!matrixElement.isIdentity())
colorSpacePrivate->mBA.append(std::move(matrixElement));
if (!offsetElement.isNull())
@@ -1067,6 +1603,8 @@ static bool parseDesc(const QByteArray &data, const TagEntry &tagEntry, QString
// Either 'desc' (ICCv2) or 'mluc' (ICCv4)
if (tag.type == quint32(Tag::desc)) {
+ if (tagEntry.size < sizeof(DescTagData))
+ return false;
Q_STATIC_ASSERT(sizeof(DescTagData) == 12);
const DescTagData desc = qFromUnaligned<DescTagData>(data.constData() + tagEntry.offset);
const quint32 len = desc.asciiDescriptionLength;
@@ -1134,10 +1672,12 @@ static bool parseRgbMatrix(const QByteArray &data, const QHash<Tag, TagEntry> &t
} else if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromDciP3D65()) {
qCDebug(lcIcc) << "fromIccProfile: DCI-P3 D65 primaries detected";
colorspaceDPtr->primaries = QColorSpace::Primaries::DciP3D65;
- }
- if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromProPhotoRgb()) {
+ } else if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromProPhotoRgb()) {
qCDebug(lcIcc) << "fromIccProfile: ProPhoto RGB primaries detected";
colorspaceDPtr->primaries = QColorSpace::Primaries::ProPhotoRgb;
+ } else if (colorspaceDPtr->toXyz == QColorMatrix::toXyzFromBt2020()) {
+ qCDebug(lcIcc) << "fromIccProfile: BT.2020 primaries detected";
+ colorspaceDPtr->primaries = QColorSpace::Primaries::Bt2020;
}
return true;
}
@@ -1225,12 +1765,12 @@ static bool parseTRCs(const QByteArray &data, const QHash<Tag, TagEntry> &tagInd
colorspaceDPtr->trc[0] = QColorTransferFunction();
colorspaceDPtr->transferFunction = QColorSpace::TransferFunction::Linear;
colorspaceDPtr->gamma = 1.0f;
- } else if (rCurve.m_type == QColorTrc::Type::Function && rCurve.m_fun.isGamma()) {
+ } else if (rCurve.m_type == QColorTrc::Type::ParameterizedFunction && rCurve.m_fun.isGamma()) {
qCDebug(lcIcc) << "fromIccProfile: Simple gamma detected";
colorspaceDPtr->trc[0] = QColorTransferFunction::fromGamma(rCurve.m_fun.m_g);
colorspaceDPtr->transferFunction = QColorSpace::TransferFunction::Gamma;
colorspaceDPtr->gamma = rCurve.m_fun.m_g;
- } else if (rCurve.m_type == QColorTrc::Type::Function && rCurve.m_fun.isSRgb()) {
+ } else if (rCurve.m_type == QColorTrc::Type::ParameterizedFunction && rCurve.m_fun.isSRgb()) {
qCDebug(lcIcc) << "fromIccProfile: sRGB gamma detected";
colorspaceDPtr->trc[0] = QColorTransferFunction::fromSRgb();
colorspaceDPtr->transferFunction = QColorSpace::TransferFunction::SRgb;
@@ -1249,6 +1789,63 @@ static bool parseTRCs(const QByteArray &data, const QHash<Tag, TagEntry> &tagInd
return true;
}
+static bool parseCicp(const QByteArray &data, const TagEntry &tagEntry, QColorSpacePrivate *colorspaceDPtr)
+{
+ if (colorspaceDPtr->isPcsLab)
+ return false;
+ if (tagEntry.size < sizeof(CicpTagData) || qsizetype(tagEntry.size) > data.size())
+ return false;
+ const CicpTagData cicp = qFromUnaligned<CicpTagData>(data.constData() + tagEntry.offset);
+ if (cicp.type != uint32_t(Tag::cicp)) {
+ qCWarning(lcIcc, "fromIccProfile: bad cicp data type");
+ return false;
+ }
+ switch (cicp.transferCharacteristics) {
+ case 4:
+ colorspaceDPtr->transferFunction = QColorSpace::TransferFunction::Gamma;
+ colorspaceDPtr->gamma = 2.2f;
+ break;
+ case 5:
+ colorspaceDPtr->transferFunction = QColorSpace::TransferFunction::Gamma;
+ colorspaceDPtr->gamma = 2.8f;
+ break;
+ case 8:
+ colorspaceDPtr->transferFunction = QColorSpace::TransferFunction::Linear;
+ break;
+ case 13:
+ colorspaceDPtr->transferFunction = QColorSpace::TransferFunction::SRgb;
+ break;
+ case 1:
+ case 6:
+ case 14:
+ case 15:
+ colorspaceDPtr->transferFunction = QColorSpace::TransferFunction::Bt2020;
+ break;
+ case 16:
+ colorspaceDPtr->transferFunction = QColorSpace::TransferFunction::St2084;
+ break;
+ case 18:
+ colorspaceDPtr->transferFunction = QColorSpace::TransferFunction::Hlg;
+ break;
+ default:
+ return false;
+ }
+ switch (cicp.colorPrimaries) {
+ case 1:
+ colorspaceDPtr->primaries = QColorSpace::Primaries::SRgb;
+ break;
+ case 9:
+ colorspaceDPtr->primaries = QColorSpace::Primaries::Bt2020;
+ break;
+ case 12:
+ colorspaceDPtr->primaries = QColorSpace::Primaries::DciP3D65;
+ break;
+ default:
+ return false;
+ }
+ return true;
+}
+
bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace)
{
if (data.size() < qsizetype(sizeof(ICCProfileHeader))) {
@@ -1287,7 +1884,7 @@ bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace)
qCWarning(lcIcc) << "fromIccProfile: failed tag offset sanity 2";
return false;
}
- if (tagTable.size < 12) {
+ if (tagTable.size < 8) {
qCWarning(lcIcc) << "fromIccProfile: failed minimal tag size sanity";
return false;
}
@@ -1337,12 +1934,22 @@ bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace)
colorSpace->detach();
QColorSpacePrivate *colorspaceDPtr = QColorSpacePrivate::get(*colorSpace);
+ colorspaceDPtr->isPcsLab = (header.pcs == uint(Tag::Lab_));
+ if (tagIndex.contains(Tag::cicp)) {
+ // Let cicp override nLut profiles if we fully recognize it.
+ if (parseCicp(data, tagIndex[Tag::cicp], colorspaceDPtr))
+ threeComponentMatrix = true;
+ if (colorspaceDPtr->primaries != QColorSpace::Primaries::Custom)
+ colorspaceDPtr->setToXyzMatrix();
+ if (colorspaceDPtr->transferFunction != QColorSpace::TransferFunction::Custom)
+ colorspaceDPtr->setTransferFunction();
+ }
+
if (threeComponentMatrix) {
- colorspaceDPtr->isPcsLab = false;
colorspaceDPtr->transformModel = QColorSpace::TransformModel::ThreeComponentMatrix;
if (header.inputColorSpace == uint(ColorSpaceType::Rgb)) {
- if (!parseRgbMatrix(data, tagIndex, colorspaceDPtr))
+ if (colorspaceDPtr->primaries == QColorSpace::Primaries::Custom && !parseRgbMatrix(data, tagIndex, colorspaceDPtr))
return false;
colorspaceDPtr->colorModel = QColorSpace::ColorModel::Rgb;
} else if (header.inputColorSpace == uint(ColorSpaceType::Gray)) {
@@ -1365,10 +1972,10 @@ bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace)
if (colorspaceDPtr->primaries != QColorSpace::Primaries::Custom)
colorspaceDPtr->setToXyzMatrix();
- if (!parseTRCs(data, tagIndex, colorspaceDPtr, header.inputColorSpace == uint(ColorSpaceType::Gray)))
+ if (colorspaceDPtr->transferFunction == QColorSpace::TransferFunction::Custom &&
+ !parseTRCs(data, tagIndex, colorspaceDPtr, header.inputColorSpace == uint(ColorSpaceType::Gray)))
return false;
} else {
- colorspaceDPtr->isPcsLab = (header.pcs == uint(Tag::Lab_));
colorspaceDPtr->transformModel = QColorSpace::TransformModel::ElementListProcessing;
if (header.inputColorSpace == uint(ColorSpaceType::Cmyk))
colorspaceDPtr->colorModel = QColorSpace::ColorModel::Cmyk;
@@ -1387,6 +1994,12 @@ bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace)
if (!parseXyzData(data, it.value(), colorspaceDPtr->whitePoint))
return false;
}
+ if (auto it = tagIndex.constFind(Tag::chad); it != tagIndex.constEnd()) {
+ if (!parseChad(data, it.value(), colorspaceDPtr))
+ return false;
+ } else if (!colorspaceDPtr->whitePoint.isNull()) {
+ colorspaceDPtr->chad = QColorMatrix::chromaticAdaptation(colorspaceDPtr->whitePoint);
+ }
}
if (auto it = tagIndex.constFind(Tag::desc); it != tagIndex.constEnd()) {
diff --git a/src/gui/painting/qimagescale.cpp b/src/gui/painting/qimagescale.cpp
index a636635fd5..eb5f12389f 100644
--- a/src/gui/painting/qimagescale.cpp
+++ b/src/gui/painting/qimagescale.cpp
@@ -1208,7 +1208,7 @@ QImage qSmoothScaleImage(const QImage &src, int dw, int dh)
dw, dh, dw, src.bytesPerLine() / 8);
else
#endif
- if (src.hasAlphaChannel())
+ if (src.hasAlphaChannel() || src.format() == QImage::Format_CMYK8888)
qt_qimageScaleAARGBA(scaleinfo, (unsigned int *)buffer.scanLine(0),
dw, dh, dw, src.bytesPerLine() / 4);
else
diff --git a/src/gui/painting/qpagelayout.h b/src/gui/painting/qpagelayout.h
index 1e340b6d75..c812f92625 100644
--- a/src/gui/painting/qpagelayout.h
+++ b/src/gui/painting/qpagelayout.h
@@ -42,7 +42,7 @@ public:
enum class OutOfBoundsPolicy {
Reject,
- Clamp
+ Clamp,
};
QPageLayout();
diff --git a/src/gui/painting/qpagesize.h b/src/gui/painting/qpagesize.h
index b3629bb8d2..221863aad7 100644
--- a/src/gui/painting/qpagesize.h
+++ b/src/gui/painting/qpagesize.h
@@ -203,7 +203,9 @@ public:
void swap(QPageSize &other) noexcept { d.swap(other.d); }
+#if QT_GUI_REMOVED_SINCE(6, 4)
friend Q_GUI_EXPORT bool operator==(const QPageSize &lhs, const QPageSize &rhs);
+#endif
bool isEquivalentTo(const QPageSize &other) const;
bool isValid() const;
diff --git a/src/gui/painting/qpaintdevice.cpp b/src/gui/painting/qpaintdevice.cpp
index 14e2d7cd8e..de21901e23 100644
--- a/src/gui/painting/qpaintdevice.cpp
+++ b/src/gui/painting/qpaintdevice.cpp
@@ -17,6 +17,39 @@ QPaintDevice::~QPaintDevice()
"painted");
}
+/*!
+ \internal
+*/
+// ### Qt 7: Replace this workaround mechanism: virtual devicePixelRatio() and virtual metricF()
+inline double QPaintDevice::getDecodedMetricF(PaintDeviceMetric metricA, PaintDeviceMetric metricB) const
+{
+ qint32 buf[2];
+ // The Encoded metric enum values come in pairs of one odd and one even value.
+ // We map those to the 0 and 1 indexes of buf by taking just the least significant bit.
+ // Same mapping here as in the encodeMetricF() function, to ensure correct order.
+ buf[metricA & 1] = metric(metricA);
+ buf[metricB & 1] = metric(metricB);
+ double res;
+ memcpy(&res, buf, sizeof(res));
+ return res;
+}
+
+qreal QPaintDevice::devicePixelRatio() const
+{
+ Q_STATIC_ASSERT((PdmDevicePixelRatioF_EncodedA & 1) != (PdmDevicePixelRatioF_EncodedB & 1));
+ double res;
+ int scaledDpr = metric(PdmDevicePixelRatioScaled);
+ if (scaledDpr == int(devicePixelRatioFScale())) {
+ res = 1; // Shortcut for common case
+ } else if (scaledDpr == 2 * int(devicePixelRatioFScale())) {
+ res = 2; // Shortcut for common case
+ } else {
+ res = getDecodedMetricF(PdmDevicePixelRatioF_EncodedA, PdmDevicePixelRatioF_EncodedB);
+ if (res <= 0) // These metrics not implemented, fall back to PdmDevicePixelRatioScaled
+ res = scaledDpr / devicePixelRatioFScale();
+ }
+ return res;
+}
/*!
\internal
@@ -64,6 +97,8 @@ int QPaintDevice::metric(PaintDeviceMetric m) const
return 256;
} else if (m == PdmDevicePixelRatio) {
return 1;
+ } else if (m == PdmDevicePixelRatioF_EncodedA || m == PdmDevicePixelRatioF_EncodedB) {
+ return 0;
} else {
qDebug("Unrecognised metric %d!",m);
return 0;
diff --git a/src/gui/painting/qpaintdevice.h b/src/gui/painting/qpaintdevice.h
index ceccac5e7e..7011684df7 100644
--- a/src/gui/painting/qpaintdevice.h
+++ b/src/gui/painting/qpaintdevice.h
@@ -29,7 +29,9 @@ public:
PdmPhysicalDpiX,
PdmPhysicalDpiY,
PdmDevicePixelRatio,
- PdmDevicePixelRatioScaled
+ PdmDevicePixelRatioScaled,
+ PdmDevicePixelRatioF_EncodedA,
+ PdmDevicePixelRatioF_EncodedB,
};
virtual ~QPaintDevice();
@@ -46,18 +48,20 @@ public:
int logicalDpiY() const { return metric(PdmDpiY); }
int physicalDpiX() const { return metric(PdmPhysicalDpiX); }
int physicalDpiY() const { return metric(PdmPhysicalDpiY); }
- qreal devicePixelRatio() const { return metric(PdmDevicePixelRatioScaled) / devicePixelRatioFScale(); }
+ qreal devicePixelRatio() const;
qreal devicePixelRatioF() const { return devicePixelRatio(); }
int colorCount() const { return metric(PdmNumColors); }
int depth() const { return metric(PdmDepth); }
static inline qreal devicePixelRatioFScale() { return 0x10000; }
+ static inline int encodeMetricF(PaintDeviceMetric metric, double value);
protected:
QPaintDevice() noexcept;
virtual int metric(PaintDeviceMetric metric) const;
virtual void initPainter(QPainter *painter) const;
virtual QPaintDevice *redirected(QPoint *offset) const;
virtual QPainter *sharedPainter() const;
+ double getDecodedMetricF(PaintDeviceMetric metricA, PaintDeviceMetric metricB) const;
ushort painters; // refcount
private:
@@ -80,6 +84,14 @@ inline int QPaintDevice::devType() const
inline bool QPaintDevice::paintingActive() const
{ return painters != 0; }
+inline int QPaintDevice::encodeMetricF(PaintDeviceMetric metric, double value)
+{
+ qint32 buf[2];
+ Q_STATIC_ASSERT(sizeof(buf) == sizeof(double));
+ memcpy(buf, &value, sizeof(buf));
+ return buf[metric & 1];
+}
+
QT_END_NAMESPACE
#endif // QPAINTDEVICE_H
diff --git a/src/gui/painting/qpaintdevice.qdoc b/src/gui/painting/qpaintdevice.qdoc
index d63fdcb92b..9b9a6facb8 100644
--- a/src/gui/painting/qpaintdevice.qdoc
+++ b/src/gui/painting/qpaintdevice.qdoc
@@ -99,6 +99,14 @@
The constant scaling factor used is devicePixelRatioFScale(). This enum value
has been introduced in Qt 5.6.
+ \value [since 6.8] PdmDevicePixelRatioF_EncodedA This enum item, together with the
+ corresponding \c B item, are used together for the device pixel ratio of the device, as an
+ encoded \c double floating point value. A QPaintDevice subclass that supports \e fractional DPR
+ values should implement support for these two enum items in its override of the metric()
+ function. The return value is expected to be the result of the encodeMetricF() function.
+
+ \value [since 6.8] PdmDevicePixelRatioF_EncodedB See PdmDevicePixelRatioF_EncodedA.
+
\sa metric(), devicePixelRatio()
*/
@@ -288,3 +296,15 @@
\since 5.6
*/
+
+/*!
+ \fn int QPaintDevice::encodeMetricF(PaintDeviceMetric metric, double value)
+
+ \internal
+
+ Returns \a value encoded for the metric \a metric. Subclasses implementing metric() should use
+ this function to encode \value as an integer return value when the query metric specifies an
+ encoded floating-point value.
+
+ \since 6.8
+*/
diff --git a/src/gui/painting/qpdf.cpp b/src/gui/painting/qpdf.cpp
index 38f2a9b803..716cf35ee6 100644
--- a/src/gui/painting/qpdf.cpp
+++ b/src/gui/painting/qpdf.cpp
@@ -20,8 +20,11 @@
#include <qimagewriter.h>
#include <qnumeric.h>
#include <qtemporaryfile.h>
+#include <qtimezone.h>
#include <quuid.h>
+#include <map>
+
#ifndef QT_NO_COMPRESS
#include <zlib.h>
#endif
@@ -1035,6 +1038,7 @@ void QPdfEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
*d->currentPage << "Q\n";
}
+// Used by QtWebKit
void QPdfEngine::drawHyperlink(const QRectF &r, const QUrl &url)
{
Q_D(QPdfEngine);
@@ -1564,7 +1568,7 @@ void QPdfEnginePrivate::writeHeader()
int metaDataObj = -1;
int outputIntentObj = -1;
if (pdfVersion == QPdfEngine::Version_A1b || !xmpDocumentMetadata.isEmpty()) {
- metaDataObj = writeXmpDcumentMetaData();
+ metaDataObj = writeXmpDocumentMetaData();
}
if (pdfVersion == QPdfEngine::Version_A1b) {
outputIntentObj = writeOutputIntent();
@@ -1740,11 +1744,12 @@ void QPdfEnginePrivate::writeInfo()
xprintf("+%02d'%02d')\n", hours , mins);
else
xprintf("Z)\n");
+ xprintf("/Trapped /False\n");
xprintf(">>\n"
"endobj\n");
}
-int QPdfEnginePrivate::writeXmpDcumentMetaData()
+int QPdfEnginePrivate::writeXmpDocumentMetaData()
{
const int metaDataObj = addXrefEntry(-1);
QByteArray metaDataContent;
@@ -1752,26 +1757,12 @@ int QPdfEnginePrivate::writeXmpDcumentMetaData()
if (xmpDocumentMetadata.isEmpty()) {
const QString producer(QString::fromLatin1("Qt " QT_VERSION_STR));
- const QDateTime now = QDateTime::currentDateTime();
- const QDate date = now.date();
- const QTime time = now.time();
- const QString timeStr =
- QString::asprintf("%d-%02d-%02dT%02d:%02d:%02d",
- date.year(), date.month(), date.day(),
- time.hour(), time.minute(), time.second());
-
- const int offset = now.offsetFromUtc();
- const int hours = (offset / 60) / 60;
- const int mins = (offset / 60) % 60;
- QString tzStr;
- if (offset < 0)
- tzStr = QString::asprintf("-%02d:%02d", -hours, -mins);
- else if (offset > 0)
- tzStr = QString::asprintf("+%02d:%02d", hours , mins);
- else
- tzStr = "Z"_L1;
-
- const QString metaDataDate = timeStr + tzStr;
+#if QT_CONFIG(timezone)
+ const QDateTime now = QDateTime::currentDateTime(QTimeZone::systemTimeZone());
+#else
+ const QDateTime now = QDateTime::currentDateTimeUtc();
+#endif
+ const QString metaDataDate = now.toString(Qt::ISODate);
QFile metaDataFile(":/qpdf/qpdfa_metadata.xml"_L1);
bool ok = metaDataFile.open(QIODevice::ReadOnly);
@@ -1813,7 +1804,8 @@ int QPdfEnginePrivate::writeOutputIntent()
s << "/N 3\n";
s << "/Alternate /DeviceRGB\n";
s << "/Length " << length_object << "0 R\n";
- s << "/Filter /FlateDecode\n";
+ if (do_compress)
+ s << "/Filter /FlateDecode\n";
s << ">>\n";
s << "stream\n";
write(data);
@@ -1867,7 +1859,7 @@ void QPdfEnginePrivate::writeDestsRoot()
if (destCache.isEmpty())
return;
- QHash<QString, int> destObjects;
+ std::map<QString, int> destObjects;
QByteArray xs, ys;
for (const DestInfo &destInfo : std::as_const(destCache)) {
int destObj = addXrefEntry(-1);
@@ -1875,21 +1867,19 @@ void QPdfEnginePrivate::writeDestsRoot()
ys.setNum(static_cast<double>(destInfo.coords.y()), 'f');
xprintf("[%d 0 R /XYZ %s %s 0]\n", destInfo.pageObj, xs.constData(), ys.constData());
xprintf("endobj\n");
- destObjects.insert(destInfo.anchor, destObj);
+ destObjects.insert_or_assign(destInfo.anchor, destObj);
}
// names
destsRoot = addXrefEntry(-1);
- QStringList anchors = destObjects.keys();
- anchors.sort();
xprintf("<<\n/Limits [");
- printString(anchors.constFirst());
+ printString(destObjects.begin()->first);
xprintf(" ");
- printString(anchors.constLast());
+ printString(destObjects.rbegin()->first);
xprintf("]\n/Names [\n");
- for (const QString &anchor : std::as_const(anchors)) {
+ for (const auto &[anchor, destObject] : destObjects) {
printString(anchor);
- xprintf(" %d 0 R\n", destObjects[anchor]);
+ xprintf(" %d 0 R\n", destObject);
}
xprintf("]\n>>\n"
"endobj\n");
@@ -1922,7 +1912,8 @@ void QPdfEnginePrivate::writeAttachmentRoot()
attachments.push_back(addXrefEntry(-1));
xprintf("<<\n"
- "/F (%s)", attachment.fileName.toLatin1().constData());
+ "/F ");
+ printString(attachment.fileName);
xprintf("\n/EF <</F %d 0 R>>\n"
"/Type/Filespec\n"
@@ -2135,17 +2126,24 @@ void QPdfEnginePrivate::writePage()
qreal userUnit = calcUserUnit();
addXrefEntry(pages.constLast());
+
+ // make sure we use the pagesize from when we started the page, since the user may have changed it
+ const QByteArray formattedPageWidth = QByteArray::number(currentPage->pageSize.width() / userUnit, 'f');
+ const QByteArray formattedPageHeight = QByteArray::number(currentPage->pageSize.height() / userUnit, 'f');
+
xprintf("<<\n"
"/Type /Page\n"
"/Parent %d 0 R\n"
"/Contents %d 0 R\n"
"/Resources %d 0 R\n"
"/Annots %d 0 R\n"
- "/MediaBox [0 0 %s %s]\n",
+ "/MediaBox [0 0 %s %s]\n"
+ "/TrimBox [0 0 %s %s]\n",
pageRoot, pageStream, resources, annots,
- // make sure we use the pagesize from when we started the page, since the user may have changed it
- QByteArray::number(currentPage->pageSize.width() / userUnit, 'f').constData(),
- QByteArray::number(currentPage->pageSize.height() / userUnit, 'f').constData());
+ formattedPageWidth.constData(),
+ formattedPageHeight.constData(),
+ formattedPageWidth.constData(),
+ formattedPageHeight.constData());
if (pdfVersion >= QPdfEngine::Version_1_6)
xprintf("/UserUnit %s\n", QByteArray::number(userUnit, 'f').constData());
diff --git a/src/gui/painting/qpdf_p.h b/src/gui/painting/qpdf_p.h
index 3c34e0bd7a..54d37b00a8 100644
--- a/src/gui/painting/qpdf_p.h
+++ b/src/gui/painting/qpdf_p.h
@@ -290,7 +290,7 @@ private:
QPdfEngine::ColorModel colorModelForColor(const QColor &color) const;
void writeColor(ColorDomain domain, const QColor &color);
void writeInfo();
- int writeXmpDcumentMetaData();
+ int writeXmpDocumentMetaData();
int writeOutputIntent();
void writePageRoot();
void writeDestsRoot();
@@ -319,7 +319,7 @@ private:
int addXrefEntry(int object, bool printostr = true);
void printString(QStringView string);
void xprintf(const char* fmt, ...);
- inline void write(const QByteArray &data) {
+ inline void write(QByteArrayView data) {
stream->writeRawData(data.constData(), data.size());
streampos += data.size();
}
diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp
index f7c4df40c8..21e89d67fd 100644
--- a/src/gui/painting/qplatformbackingstore.cpp
+++ b/src/gui/painting/qplatformbackingstore.cpp
@@ -10,6 +10,8 @@
#include <QtCore/private/qobject_p.h>
+#include <unordered_map>
+
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcQpaBackingStore, "qt.qpa.backingstore", QtWarningMsg);
@@ -26,11 +28,14 @@ public:
QWindow *window;
QBackingStore *backingStore;
- // The order matters. if it needs to be rearranged in the future, call
- // reset() explicitly from the dtor in the correct order.
- // (first the compositor, then the rhiSupport)
- QBackingStoreRhiSupport rhiSupport;
- QBackingStoreDefaultCompositor compositor;
+ struct SurfaceSupport {
+ // The order matters. if it needs to be rearranged in the future, call
+ // reset() explicitly from the dtor in the correct order.
+ // (first the compositor, then the rhiSupport)
+ QBackingStoreRhiSupport rhiSupport;
+ QBackingStoreDefaultCompositor compositor;
+ };
+ std::unordered_map<QSurface::SurfaceType, SurfaceSupport> surfaceSupport;
};
struct QBackingstoreTextureInfo
@@ -210,8 +215,12 @@ QPlatformBackingStore::FlushResult QPlatformBackingStore::rhiFlush(QWindow *wind
QPlatformTextureList *textures,
bool translucentBackground)
{
- return d_ptr->compositor.flush(this, d_ptr->rhiSupport.rhi(), d_ptr->rhiSupport.swapChainForWindow(window),
- window, sourceDevicePixelRatio, region, offset, textures, translucentBackground);
+ auto &surfaceSupport = d_ptr->surfaceSupport[window->surfaceType()];
+ return surfaceSupport.compositor.flush(this,
+ surfaceSupport.rhiSupport.rhi(),
+ surfaceSupport.rhiSupport.swapChainForWindow(window),
+ window, sourceDevicePixelRatio, region, offset, textures,
+ translucentBackground);
}
/*!
@@ -261,7 +270,10 @@ QRhiTexture *QPlatformBackingStore::toTexture(QRhiResourceUpdateBatch *resourceU
const QRegion &dirtyRegion,
TextureFlags *flags) const
{
- return d_ptr->compositor.toTexture(this, d_ptr->rhiSupport.rhi(), resourceUpdates, dirtyRegion, flags);
+ auto &surfaceSupport = d_ptr->surfaceSupport[window()->surfaceType()];
+ return surfaceSupport.compositor.toTexture(this,
+ surfaceSupport.rhiSupport.rhi(), resourceUpdates,
+ dirtyRegion, flags);
}
/*!
@@ -356,33 +368,44 @@ bool QPlatformBackingStore::scroll(const QRegion &area, int dx, int dy)
return false;
}
-void QPlatformBackingStore::setRhiConfig(const QPlatformBackingStoreRhiConfig &config)
+void QPlatformBackingStore::createRhi(QWindow *window, QPlatformBackingStoreRhiConfig config)
{
if (!config.isEnabled())
return;
- d_ptr->rhiSupport.setConfig(config);
- d_ptr->rhiSupport.setWindow(d_ptr->window);
- d_ptr->rhiSupport.setFormat(d_ptr->window->format());
- d_ptr->rhiSupport.create();
+ qCDebug(lcQpaBackingStore) << "Setting up RHI support in" << this
+ << "for" << window << "with" << window->surfaceType()
+ << "and requested API" << config.api();
+
+ auto &support = d_ptr->surfaceSupport[window->surfaceType()];
+ if (!support.rhiSupport.rhi()) {
+ support.rhiSupport.setConfig(config);
+ support.rhiSupport.setWindow(window);
+ support.rhiSupport.setFormat(window->format());
+ support.rhiSupport.create();
+ } else {
+ qCDebug(lcQpaBackingStore) << "Window already has RHI support"
+ << "with backend" << support.rhiSupport.rhi()->backendName();
+ }
}
-QRhi *QPlatformBackingStore::rhi() const
+QRhi *QPlatformBackingStore::rhi(QWindow *window) const
{
// Returning null is valid, and means this is not a QRhi-capable backingstore.
- return d_ptr->rhiSupport.rhi();
+ return d_ptr->surfaceSupport[window->surfaceType()].rhiSupport.rhi();
}
-void QPlatformBackingStore::graphicsDeviceReportedLost()
+void QPlatformBackingStore::graphicsDeviceReportedLost(QWindow *window)
{
- if (!d_ptr->rhiSupport.rhi())
+ auto &surfaceSupport = d_ptr->surfaceSupport[window->surfaceType()];
+ if (!surfaceSupport.rhiSupport.rhi())
return;
qWarning("Rhi backingstore: graphics device lost, attempting to reinitialize");
- d_ptr->compositor.reset();
- d_ptr->rhiSupport.reset();
- d_ptr->rhiSupport.create();
- if (!d_ptr->rhiSupport.rhi())
+ surfaceSupport.compositor.reset();
+ surfaceSupport.rhiSupport.reset();
+ surfaceSupport.rhiSupport.create();
+ if (!surfaceSupport.rhiSupport.rhi())
qWarning("Rhi backingstore: failed to reinitialize after losing the device");
}
diff --git a/src/gui/painting/qplatformbackingstore.h b/src/gui/painting/qplatformbackingstore.h
index 1d55e9ab6a..2f27a2aa2c 100644
--- a/src/gui/painting/qplatformbackingstore.h
+++ b/src/gui/painting/qplatformbackingstore.h
@@ -39,6 +39,8 @@ class QRhiResourceUpdateBatch;
struct Q_GUI_EXPORT QPlatformBackingStoreRhiConfig
{
+ Q_GADGET
+public:
enum Api {
OpenGL,
Metal,
@@ -47,6 +49,7 @@ struct Q_GUI_EXPORT QPlatformBackingStoreRhiConfig
D3D12,
Null
};
+ Q_ENUM(Api)
QPlatformBackingStoreRhiConfig()
: m_enable(false)
@@ -171,10 +174,10 @@ public:
virtual void beginPaint(const QRegion &);
virtual void endPaint();
- void setRhiConfig(const QPlatformBackingStoreRhiConfig &config);
- QRhi *rhi() const;
+ void createRhi(QWindow *window, QPlatformBackingStoreRhiConfig config);
+ QRhi *rhi(QWindow *window) const;
void surfaceAboutToBeDestroyed();
- void graphicsDeviceReportedLost();
+ void graphicsDeviceReportedLost(QWindow *window);
private:
QPlatformBackingStorePrivate *d_ptr;
diff --git a/src/gui/painting/qregion.cpp b/src/gui/painting/qregion.cpp
index 8b712ee46d..f9089d7bba 100644
--- a/src/gui/painting/qregion.cpp
+++ b/src/gui/painting/qregion.cpp
@@ -876,9 +876,15 @@ QRegion QRegion::intersect(const QRect &r) const
/*!
\fn void QRegion::setRects(const QRect *rects, int number)
+ \overload
+ \obsolete Use the QSpan overload instead.
+*/
+
+/*!
+ \fn void QRegion::setRects(QSpan<const QRect> rects)
+ \since 6.8
- Sets the region using the array of rectangles specified by \a rects and
- \a number.
+ Sets the region using the array of rectangles specified by \a rects.
The rectangles \e must be optimally Y-X sorted and follow these restrictions:
\list
@@ -892,6 +898,11 @@ QRegion QRegion::intersect(const QRect &r) const
\omit
Only some platforms have these restrictions (Qt for Embedded Linux, X11 and \macos).
\endomit
+
+ \note For historical reasons, \c{rects.size()} must be less than \c{INT_MAX}
+ (see rectCount()).
+
+ \sa rects()
*/
namespace {
@@ -4214,18 +4225,39 @@ QRegion::const_iterator QRegion::end() const noexcept
return d->qt_rgn ? d->qt_rgn->end() : nullptr;
}
-void QRegion::setRects(const QRect *rects, int num)
+static Q_DECL_COLD_FUNCTION
+void set_rects_warn(const char *what)
+{
+ qWarning("QRegion::setRects(): %s", what);
+}
+
+void QRegion::setRects(const QRect *r, int n)
{
+ if (!r && n) { // old setRects() allowed this, but QSpan doesn't
+ set_rects_warn("passing num != 0 when rects == nullptr is deprecated.");
+ n = 0;
+ }
+ setRects(QSpan<const QRect>(r, n));
+}
+
+void QRegion::setRects(QSpan<const QRect> rects)
+{
+ const auto num = int(rects.size());
+ if (num != rects.size()) {
+ set_rects_warn("span size exceeds INT_MAX, ignoring");
+ return;
+ }
+
*this = QRegion();
- if (!rects || num == 0 || (num == 1 && rects->isEmpty()))
+ if (!rects.data() || num == 0 || (num == 1 && rects.front().isEmpty()))
return;
detach();
d->qt_rgn->numRects = num;
if (num == 1) {
- d->qt_rgn->extents = *rects;
- d->qt_rgn->innerRect = *rects;
+ d->qt_rgn->extents = rects.front();
+ d->qt_rgn->innerRect = rects.front();
} else {
d->qt_rgn->rects.resize(num);
@@ -4246,12 +4278,30 @@ void QRegion::setRects(const QRect *rects, int num)
}
}
+/*!
+ \since 6.8
+
+ Returns a span of non-overlapping rectangles that make up the region. The
+ span remains valid until the next call of a mutating (non-const) method on
+ this region.
+
+ The union of all the rectangles is equal to the original region.
+
+ \note This functions existed in Qt 5, too, but returned QVector<QRect>
+ instead.
+
+ \sa setRects()
+*/
+QSpan<const QRect> QRegion::rects() const noexcept
+{
+ return {begin(), end()};
+};
+
int QRegion::rectCount() const noexcept
{
return (d->qt_rgn ? d->qt_rgn->numRects : 0);
}
-
bool QRegion::operator==(const QRegion &r) const
{
if (!d->qt_rgn)
diff --git a/src/gui/painting/qregion.h b/src/gui/painting/qregion.h
index b0051b6067..4b852815f3 100644
--- a/src/gui/painting/qregion.h
+++ b/src/gui/painting/qregion.h
@@ -8,11 +8,11 @@
#include <QtCore/qatomic.h>
#include <QtCore/qrect.h>
#include <QtGui/qwindowdefs.h>
-#include <QtCore/qcontainerfwd.h>
#ifndef QT_NO_DATASTREAM
#include <QtCore/qdatastream.h>
#endif
+#include <QtCore/qspan.h>
QT_BEGIN_NAMESPACE
@@ -75,6 +75,8 @@ public:
QRect boundingRect() const noexcept;
void setRects(const QRect *rect, int num);
+ void setRects(QSpan<const QRect> r);
+ QSpan<const QRect> rects() const noexcept;
int rectCount() const noexcept;
QRegion operator|(const QRegion &r) const;
diff --git a/src/gui/painting/qrhibackingstore.cpp b/src/gui/painting/qrhibackingstore.cpp
index 586dfb44a4..d59cc2d83c 100644
--- a/src/gui/painting/qrhibackingstore.cpp
+++ b/src/gui/painting/qrhibackingstore.cpp
@@ -20,30 +20,27 @@ void QRhiBackingStore::flush(QWindow *flushedWindow, const QRegion &region, cons
Q_UNUSED(region);
Q_UNUSED(offset);
- if (flushedWindow->surfaceType() != window()->surfaceType()) {
- qWarning() << "Cannot flush child window" << flushedWindow
- << "with surface type" << flushedWindow->surfaceType() << ";"
- << "Must match" << window()->surfaceType() << "of" << window();
-
- // FIXME: Support different surface types by not tying the
- // RHI config to the backing store itself (per window config).
- return;
- }
-
- if (!rhi()) {
+ if (!rhi(flushedWindow)) {
QPlatformBackingStoreRhiConfig rhiConfig;
- switch (window()->surfaceType()) {
+ switch (flushedWindow->surfaceType()) {
case QSurface::OpenGLSurface:
rhiConfig.setApi(QPlatformBackingStoreRhiConfig::OpenGL);
break;
case QSurface::MetalSurface:
rhiConfig.setApi(QPlatformBackingStoreRhiConfig::Metal);
break;
+ case QSurface::Direct3DSurface:
+ rhiConfig.setApi(QPlatformBackingStoreRhiConfig::D3D11);
+ break;
+ case QSurface::VulkanSurface:
+ rhiConfig.setApi(QPlatformBackingStoreRhiConfig::Vulkan);
+ break;
default:
Q_UNREACHABLE();
}
+
rhiConfig.setEnabled(true);
- setRhiConfig(rhiConfig);
+ createRhi(flushedWindow, rhiConfig);
}
static QPlatformTextureList emptyTextureList;