summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2024-03-06 11:57:09 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2024-03-27 02:13:27 +0100
commitd89063646e356966329e41f058fac0583d3fe264 (patch)
tree102d7a2aee0cc9933e5a85864dee896f5ac515ea /src/gui
parent58f93994d9ffb08f7fc1fdcb1b9de6df48390124 (diff)
Add QColorSpace::isValidTarget
To indicate color spaces that can not be used as a target, but only as a source. Change-Id: Iae79e3533599c112872d171a2f45178029be89dc Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/image/qimage.cpp10
-rw-r--r--src/gui/painting/qcolorspace.cpp39
-rw-r--r--src/gui/painting/qcolorspace.h1
3 files changed, 39 insertions, 11 deletions
diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp
index 463a1e4a6d..4f91fbb8b9 100644
--- a/src/gui/image/qimage.cpp
+++ b/src/gui/image/qimage.cpp
@@ -5018,7 +5018,7 @@ void QImage::convertToColorSpace(const QColorSpace &colorSpace)
return;
if (!d->colorSpace.isValid())
return;
- if (!colorSpace.isValid()) {
+ if (!colorSpace.isValidTarget()) {
qWarning() << "QImage::convertToColorSpace: Output colorspace is not valid";
return;
}
@@ -5039,8 +5039,14 @@ void QImage::convertToColorSpace(const QColorSpace &colorSpace)
*/
QImage QImage::convertedToColorSpace(const QColorSpace &colorSpace) const
{
- if (!d || !d->colorSpace.isValid() || !colorSpace.isValid())
+ if (!d)
+ return QImage();
+ if (!d->colorSpace.isValid())
return QImage();
+ if (!colorSpace.isValidTarget()) {
+ qWarning() << "QImage::convertedToColorSpace: Output colorspace is not valid";
+ return QImage();
+ }
if (d->colorSpace == colorSpace)
return *this;
QImage image = copy();
diff --git a/src/gui/painting/qcolorspace.cpp b/src/gui/painting/qcolorspace.cpp
index 7244a8fbf0..334587fd31 100644
--- a/src/gui/painting/qcolorspace.cpp
+++ b/src/gui/painting/qcolorspace.cpp
@@ -544,12 +544,14 @@ void QColorSpacePrivate::clearElementListProcessingForEdit()
Defines the processing model used for color space transforms.
- \value ThreeComponentMatrix The transform consist of a matrix calculated from primaries and set of transfer functions for each color channel.
- This is very fast and used by all predefined color spaces.
- \value ElementListProcessing The transforms are two lists of processing elements that can do many things,
+ \value ThreeComponentMatrix The transform consist of a matrix calculated from primaries and set of transfer functions
+ for each color channel. This is very fast and used by all predefined color spaces. Any color space on this form is
+ reversible and always both valid sources and targets.
+ \value ElementListProcessing The transforms are one or two lists of processing elements that can do many things,
each list only process either to the connection color space or from it. This is very flexible, but rather
- slow, and can only be set by reading ICC profiles (See \l fromIccProfile()). When changing either primaries
- or transfer function on a color space on this type it will reset to a ThreeComponentMatrix form.
+ slow, and can only be set by reading ICC profiles (See \l fromIccProfile()). Since the two lists are
+ separate a color space on this form can be a valid source, but not necessarily also a valid target. When changing
+ either primaries or transfer function on a color space on this type it will reset to an empty ThreeComponentMatrix form.
*/
/*!
@@ -968,7 +970,12 @@ QColorSpace QColorSpace::fromIccProfile(const QByteArray &iccProfile)
}
/*!
- Returns \c true if the color space is valid.
+ Returns \c true if the color space is valid. For a color space with \c TransformModel::ThreeComponentMatrix
+ that means both primaries and transfer functions set, and implies isValidTarget().
+ For a color space with \c TransformModel::ElementListProcessing it means it has a valid source transform, to
+ check if it also a valid target color space use isValidTarget().
+
+ \sa isValidTarget()
*/
bool QColorSpace::isValid() const noexcept
{
@@ -978,6 +985,20 @@ bool QColorSpace::isValid() const noexcept
}
/*!
+ \since 6.8
+
+ Returns \c true if the color space is a valid target color space.
+*/
+bool QColorSpace::isValidTarget() const noexcept
+{
+ if (!d_ptr)
+ return false;
+ if (!d_ptr->isThreeComponentMatrix())
+ return !d_ptr->mBA.isEmpty();
+ return d_ptr->isValid();
+}
+
+/*!
\internal
*/
bool QColorSpacePrivate::isValid() const noexcept
@@ -1148,13 +1169,13 @@ bool QColorSpacePrivate::equals(const QColorSpacePrivate *other) const
*/
QColorTransform QColorSpace::transformationToColorSpace(const QColorSpace &colorspace) const
{
- if (!isValid() || !colorspace.isValid())
+ if (!isValid())
return QColorTransform();
if (*this == colorspace)
return QColorTransform();
- if (colorspace.transformModel() == TransformModel::ElementListProcessing && colorspace.d_ptr->mBA.isEmpty()) {
- qWarning() << "Attempted transform to from-only colorspace";
+ if (!colorspace.isValidTarget()) {
+ qWarning() << "QColorSpace::transformationToColorSpace: colorspace not a valid target";
return QColorTransform();
}
diff --git a/src/gui/painting/qcolorspace.h b/src/gui/painting/qcolorspace.h
index 127f18caa2..848bc0898e 100644
--- a/src/gui/painting/qcolorspace.h
+++ b/src/gui/painting/qcolorspace.h
@@ -108,6 +108,7 @@ public:
TransformModel transformModel() const noexcept;
void detach();
bool isValid() const noexcept;
+ bool isValidTarget() const noexcept;
friend inline bool operator==(const QColorSpace &colorSpace1, const QColorSpace &colorSpace2)
{ return colorSpace1.equals(colorSpace2); }