Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
[win] Fix HDR support on Qt6
Dmitry Kazakov92cd9ff39199
diff --git a/libs/ui/KisSurfaceColorSpaceWrapper.h b/libs/ui/KisSurfaceColorSpaceWrapper.hnew file mode 100644index 0000000000..08ed82b009--- /dev/null+++ b/libs/ui/KisSurfaceColorSpaceWrapper.h@@ -0,0 +1,110 @@+/*+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+ #ifndef KISSURFACECOLORSPACEWRAPPER_H+ #define KISSURFACECOLORSPACEWRAPPER_H++#include <QtGlobal>+#include <QMetaObject>+#include <boost/operators.hpp>++ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)+ #include <QSurfaceFormat>+ #else+ #include <QColorSpace>+ #endif++class KisSurfaceColorSpaceWrapper : public boost::equality_comparable<KisSurfaceColorSpaceWrapper>+{+public:++ enum ColorSpace {+ DefaultColorSpace,+ sRGBColorSpace,+ scRGBColorSpace,+ bt2020PQColorSpace+ };+ Q_ENUMS(ColorSpace)++ constexpr KisSurfaceColorSpaceWrapper()+ : KisSurfaceColorSpaceWrapper(DefaultColorSpace)+ {+ }++ constexpr KisSurfaceColorSpaceWrapper(ColorSpace colorSpace)+ : m_colorSpace(colorSpace)+ {+ }++ static constexpr KisSurfaceColorSpaceWrapper makeSRGBColorSpace() {+ return { sRGBColorSpace };+ }++ static constexpr KisSurfaceColorSpaceWrapper makeSCRGBColorSpace() {+ return { scRGBColorSpace };+ }++ static constexpr KisSurfaceColorSpaceWrapper makeBt2020PQColorSpace() {+ return { bt2020PQColorSpace };+ }++#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)+ static constexpr KisSurfaceColorSpaceWrapper fromQtColorSpace(QSurfaceFormat::ColorSpace colorSpace)+ {+ return { static_cast<ColorSpace>(colorSpace) };+ }+#else+ static KisSurfaceColorSpaceWrapper fromQtColorSpace(const QColorSpace &colorSpace)+ {+ if (colorSpace == QColorSpace()) {+ return { DefaultColorSpace };+ } else if (colorSpace == QColorSpace::SRgb) {+ return { sRGBColorSpace };+ } else if (colorSpace == QColorSpace::SRgbLinear) {+ return { scRGBColorSpace };+ } else if (colorSpace == QColorSpace::Bt2100Pq) {+ return { bt2020PQColorSpace };+ } else {+ qWarning() << "WARNING: KisSurfaceColorSpaceWrapper: unsupported surface color space" << colorSpace;+ return { DefaultColorSpace };+ }+ }+#endif++ KisSurfaceColorSpaceWrapper(const KisSurfaceColorSpaceWrapper &rhs) = default;+ KisSurfaceColorSpaceWrapper(KisSurfaceColorSpaceWrapper &&rhs) = default;+ KisSurfaceColorSpaceWrapper& operator=(const KisSurfaceColorSpaceWrapper &rhs) = default;+ KisSurfaceColorSpaceWrapper& operator=(KisSurfaceColorSpaceWrapper &&rhs) = default;++ constexpr bool operator==(const KisSurfaceColorSpaceWrapper &rhs) const {+ return m_colorSpace == rhs.m_colorSpace;+ }++#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)+ constexpr operator QSurfaceFormat::ColorSpace() const {+ return static_cast<QSurfaceFormat::ColorSpace>(m_colorSpace);+ }+#else+ operator QColorSpace() const {+ switch (m_colorSpace) {+ case DefaultColorSpace:+ return QColorSpace();+ case sRGBColorSpace:+ return QColorSpace::SRgb;+ case scRGBColorSpace:+ return QColorSpace::SRgbLinear;+ case bt2020PQColorSpace:+ return QColorSpace::Bt2100Pq;+ }++ Q_UNREACHABLE_RETURN(QColorSpace());+ }+#endif++private:+ ColorSpace m_colorSpace;+};++ #endif /* KISSURFACECOLORSPACEWRAPPER_H */\ No newline at end of filediff --git a/libs/ui/dialogs/kis_dlg_preferences.cc b/libs/ui/dialogs/kis_dlg_preferences.ccindex 67a6838f48..5e103b2617 100644--- a/libs/ui/dialogs/kis_dlg_preferences.cc+++ b/libs/ui/dialogs/kis_dlg_preferences.cc@@ -79,7 +79,6 @@#include "kis_canvas_resource_provider.h"#include "kis_color_manager.h"#include "kis_config.h"-#include "kis_cursor.h"#include "kis_image_config.h"#include "kis_preference_set_registry.h"#include "KisMainWindow.h"@@ -1750,15 +1749,15 @@ void PerformanceTab::slotFrameClonesLimitChanged(int value)namespace {-QString colorSpaceString(QSurfaceFormat::ColorSpace cs, int depth)+QString colorSpaceString(const KisSurfaceColorSpaceWrapper &cs, int depth){const QString csString =#ifdef HAVE_HDR- cs == QSurfaceFormat::ColorSpace::bt2020PQColorSpace ? "Rec. 2020 PQ" :- cs == QSurfaceFormat::ColorSpace::scRGBColorSpace ? "Rec. 709 Linear" :+ cs == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace ? "Rec. 2020 PQ" :+ cs == KisSurfaceColorSpaceWrapper::scRGBColorSpace ? "Rec. 709 Linear" :#endif- cs == QSurfaceFormat::ColorSpace::sRGBColorSpace ? "sRGB" :- cs == QSurfaceFormat::ColorSpace::DefaultColorSpace ? "sRGB" :+ cs == KisSurfaceColorSpaceWrapper::sRGBColorSpace ? "sRGB" :+ cs == KisSurfaceColorSpaceWrapper::DefaultColorSpace ? "sRGB" :"Unknown Color Space";return QString("%1 (%2 bit)").arg(csString).arg(depth);@@ -1886,10 +1885,10 @@ DisplaySettingsTab::DisplaySettingsTab(QWidget *parent, const char *name)lblCurrentDisplayFormat->setText("");lblCurrentRootSurfaceFormat->setText("");grpHDRWarning->setVisible(false);- cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(QSurfaceFormat::ColorSpace::sRGBColorSpace, 8));+ cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(KisSurfaceColorSpaceWrapper::sRGBColorSpace, 8));#ifdef HAVE_HDR- cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(QSurfaceFormat::ColorSpace::bt2020PQColorSpace, 10));- cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(QSurfaceFormat::ColorSpace::scRGBColorSpace, 16));+ cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(KisSurfaceColorSpaceWrapper::bt2020PQColorSpace, 10));+ cmbPreferedRootSurfaceFormat->addItem(colorSpaceString(KisSurfaceColorSpaceWrapper::scRGBColorSpace, 16));#endifcmbPreferedRootSurfaceFormat->setCurrentIndex(formatToIndex(KisConfig::BT709_G22));slotPreferredSurfaceFormatChanged(cmbPreferedRootSurfaceFormat->currentIndex());@@ -1901,7 +1900,7 @@ DisplaySettingsTab::DisplaySettingsTab(QWidget *parent, const char *name)}if (context) {- QScreen *screen = QGuiApplication::screenAt(rect().center());+ QScreen *screen = KisPart::instance()->currentMainwindow()->screen();KisScreenInformationAdapter adapter(context);if (screen && adapter.isValid()) {KisScreenInformationAdapter::ScreenInfo info = adapter.infoForScreen(screen);@@ -1931,14 +1930,8 @@ DisplaySettingsTab::DisplaySettingsTab(QWidget *parent, const char *name)}const QSurfaceFormat currentFormat = KisOpenGLModeProber::instance()->surfaceformatInUse();-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- QSurfaceFormat::ColorSpace colorSpace = currentFormat.colorSpace();+ const auto colorSpace = KisSurfaceColorSpaceWrapper::fromQtColorSpace(currentFormat.colorSpace());lblCurrentRootSurfaceFormat->setText(colorSpaceString(colorSpace, currentFormat.redBufferSize()));-#else- // FIXME QT6: find a way to get the namedcolorspace field out of QColorSpace.- QColorSpace colorspace = currentFormat.colorSpace();- lblCurrentRootSurfaceFormat->setText(colorspace.description());-#endifcmbPreferedRootSurfaceFormat->setCurrentIndex(formatToIndex(cfg.rootSurfaceFormat()));connect(cmbPreferedRootSurfaceFormat, SIGNAL(currentIndexChanged(int)), SLOT(slotPreferredSurfaceFormatChanged(int)));slotPreferredSurfaceFormatChanged(cmbPreferedRootSurfaceFormat->currentIndex());@@ -2080,13 +2073,13 @@ void DisplaySettingsTab::slotPreferredSurfaceFormatChanged(int index)QOpenGLContext *context = QOpenGLContext::currentContext();if (context) {- QScreen *screen = QGuiApplication::screenAt(rect().center());+ QScreen *screen = KisPart::instance()->currentMainwindow()->screen();KisScreenInformationAdapter adapter(context);if (adapter.isValid()) {KisScreenInformationAdapter::ScreenInfo info = adapter.infoForScreen(screen);if (info.isValid()) {if (cmbPreferedRootSurfaceFormat->currentIndex() != formatToIndex(KisConfig::BT709_G22) &&- info.colorSpace == QSurfaceFormat::ColorSpace::sRGBColorSpace) {+ info.colorSpace == KisSurfaceColorSpaceWrapper::sRGBColorSpace) {grpHDRWarning->setVisible(true);grpHDRWarning->setPixmap(grpHDRWarning->style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(QSize(32, 32)));diff --git a/libs/ui/opengl/KisOpenGLModeProber.cpp b/libs/ui/opengl/KisOpenGLModeProber.cppindex 0dd407e968..4924230b60 100644--- a/libs/ui/opengl/KisOpenGLModeProber.cpp+++ b/libs/ui/opengl/KisOpenGLModeProber.cpp@@ -15,6 +15,7 @@#include <QColorSpace>#include <QGlobalStatic>+#include <KisSurfaceColorSpaceWrapper.h>Q_GLOBAL_STATIC(KisOpenGLModeProber, s_instance)@@ -49,31 +50,19 @@ QSurfaceFormat KisOpenGLModeProber::surfaceformatInUse() constconst KoColorProfile *KisOpenGLModeProber::rootSurfaceColorProfile() const{const KoColorProfile *profile = KoColorSpaceRegistry::instance()->p709SRGBProfile();-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- const QSurfaceFormat::ColorSpace surfaceColorSpace = surfaceformatInUse().colorSpace();- if (surfaceColorSpace == QSurfaceFormat::ColorSpace::sRGBColorSpace) {++ const auto surfaceColorSpace =+ KisSurfaceColorSpaceWrapper::fromQtColorSpace(surfaceformatInUse().colorSpace());++ if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::sRGBColorSpace) {// use the default one!#ifdef HAVE_HDR- } else if (surfaceColorSpace == QSurfaceFormat::ColorSpace::scRGBColorSpace) {+ } else if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::scRGBColorSpace) {profile = KoColorSpaceRegistry::instance()->p709G10Profile();- } else if (surfaceColorSpace == QSurfaceFormat::ColorSpace::bt2020PQColorSpace) {+ } else if (surfaceColorSpace == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace) {profile = KoColorSpaceRegistry::instance()->p2020PQProfile();#endif}-#else- const QColorSpace surfaceColorSpace = surfaceformatInUse().colorSpace();- if (surfaceColorSpace == QColorSpace(QColorSpace::NamedColorSpace::SRgb)) {- // use the default one!-// FIXME QT6: Fix this when fixing HDR!!!-// #ifdef HAVE_HDR-// } else if (surfaceColorSpace == QSurfaceFormat::ColorSpace::scRGBColorSpace) {-// profile = KoColorSpaceRegistry::instance()->p709G10Profile();-// } else if (surfaceColorSpace == QSurfaceFormat::ColorSpace::bt2020PQColorSpace) {-// profile = KoColorSpaceRegistry::instance()->p2020PQProfile();-// #endif- }-#endif-return profile;}@@ -216,7 +205,10 @@ KisOpenGLModeProber::probeFormat(const KisOpenGL::RendererConfig &rendererConfigreturn boost::none;}- if (!fuzzyCompareColorSpaces(context.format().colorSpace(), format.colorSpace())) {+ if (!fuzzyCompareColorSpaces(+ KisSurfaceColorSpaceWrapper::fromQtColorSpace(context.format().colorSpace()),+ KisSurfaceColorSpaceWrapper::fromQtColorSpace(format.colorSpace()))) {+dbgOpenGL << "Failed to create an OpenGL context with requested color space. Requested:" << format.colorSpace() << "Actual:" << context.format().colorSpace();return boost::none;}@@ -228,28 +220,15 @@ KisOpenGLModeProber::probeFormat(const KisOpenGL::RendererConfig &rendererConfigreturn result;}--#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))-bool KisOpenGLModeProber::fuzzyCompareColorSpaces(const QSurfaceFormat::ColorSpace &lhs, const QSurfaceFormat::ColorSpace &rhs)+bool KisOpenGLModeProber::fuzzyCompareColorSpaces(const KisSurfaceColorSpaceWrapper &lhs, const KisSurfaceColorSpaceWrapper &rhs){return lhs == rhs ||- ((lhs == QSurfaceFormat::ColorSpace::DefaultColorSpace ||- lhs == QSurfaceFormat::ColorSpace::sRGBColorSpace) &&- (rhs == QSurfaceFormat::ColorSpace::DefaultColorSpace ||- rhs == QSurfaceFormat::ColorSpace::sRGBColorSpace));+ ((lhs == KisSurfaceColorSpaceWrapper::DefaultColorSpace ||+ lhs == KisSurfaceColorSpaceWrapper::sRGBColorSpace) &&+ (rhs == KisSurfaceColorSpaceWrapper::DefaultColorSpace ||+ rhs == KisSurfaceColorSpaceWrapper::sRGBColorSpace));}-#else-bool KisOpenGLModeProber::fuzzyCompareColorSpaces(const QColorSpace &lhs, const QColorSpace &rhs)-{- return lhs == rhs ||- (( lhs == QColorSpace() ||- lhs == QColorSpace(QColorSpace::NamedColorSpace::SRgb)) &&- ( rhs == QColorSpace() ||- rhs == QColorSpace(QColorSpace::NamedColorSpace::SRgb)));--}-#endifvoid KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceFormat config,QSurfaceFormat *format){@@ -260,21 +239,13 @@ void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceFormformat->setGreenBufferSize(10);format->setBlueBufferSize(10);format->setAlphaBufferSize(2);-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- format->setColorSpace(QSurfaceFormat::ColorSpace::bt2020PQColorSpace);-#else- format->setColorSpace(QColorSpace(QColorSpace::NamedColorSpace::Bt2100Pq);-#endif+ format->setColorSpace(KisSurfaceColorSpaceWrapper(KisSurfaceColorSpaceWrapper::bt2020PQColorSpace));} else if (config == KisConfig::BT709_G10) {format->setRedBufferSize(16);format->setGreenBufferSize(16);format->setBlueBufferSize(16);format->setAlphaBufferSize(16);-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- format->setColorSpace(QSurfaceFormat::ColorSpace::scRGBColorSpace);-#else- format->setColorSpace(QColorSpace(QColorSpace::NamedColorSpace::SRgb);-#endif+ format->setColorSpace(KisSurfaceColorSpaceWrapper(KisSurfaceColorSpaceWrapper::scRGBColorSpace));} else#elseif (config == KisConfig::BT2020_PQ) {@@ -290,11 +261,7 @@ void KisOpenGLModeProber::initSurfaceFormatFromConfig(KisConfig::RootSurfaceFormformat->setBlueBufferSize(8);format->setAlphaBufferSize(8);// TODO: check if we can use real sRGB space here-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- format->setColorSpace(QSurfaceFormat::ColorSpace::DefaultColorSpace);-#else- format->setColorSpace(QColorSpace());-#endif+ format->setColorSpace(KisSurfaceColorSpaceWrapper());}}@@ -303,22 +270,14 @@ bool KisOpenGLModeProber::isFormatHDR(const QSurfaceFormat &format)#ifdef HAVE_HDRbool isBt2020PQ =-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- format.colorSpace() == QSurfaceFormat::ColorSpace::bt2020PQColorSpace &&-#else- format.colorSpace() == QColorSpace(QColorSpace::NamedColorSpace::Bt2100Pq) &&-#endif+ format.colorSpace() == KisSurfaceColorSpaceWrapper::makeBt2020PQColorSpace() &&format.redBufferSize() == 10 &&format.greenBufferSize() == 10 &&format.blueBufferSize() == 10 &&format.alphaBufferSize() == 2;bool isBt709G10 =-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- format.colorSpace() == QSurfaceFormat::ColorSpace::scRGBColorSpace &&-#else- format.colorSpace() == QColorSpace(QColorSpace::NamedColorSpace::SRgb) &&-#endif+ format.colorSpace() == KisSurfaceColorSpaceWrapper::makeSCRGBColorSpace() &&format.redBufferSize() == 16 &&format.greenBufferSize() == 16 &&format.blueBufferSize() == 16 &&diff --git a/libs/ui/opengl/KisOpenGLModeProber.h b/libs/ui/opengl/KisOpenGLModeProber.hindex 03aadf266a..a428eeb1ca 100644--- a/libs/ui/opengl/KisOpenGLModeProber.h+++ b/libs/ui/opengl/KisOpenGLModeProber.h@@ -12,22 +12,12 @@#include "kritaui_export.h"#include "kis_config.h"#include <QSurfaceFormat>-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))-#include <QColorSpace>-#endif#include <boost/optional.hpp>#include "kis_opengl.h"class KoColorProfile;+class KisSurfaceColorSpaceWrapper;-/**- * WARNING WARNING WARNING!!!!- *- * The use of QColorSpace for HDR in this file after porting to Qt6 is GUARANTEED TO BE WRONG.- *- * This needs porting once we know how to integrate our HDR patches into Qt6- *- */class KRITAUI_EXPORT KisOpenGLModeProber{public:@@ -46,13 +36,8 @@ public:boost::optional<Result> probeFormat(const KisOpenGL::RendererConfig &rendererConfig,bool adjustGlobalState = true);-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- static bool fuzzyCompareColorSpaces(const QSurfaceFormat::ColorSpace &lhs,- const QSurfaceFormat::ColorSpace &rhs);-#else- static bool fuzzyCompareColorSpaces(const QColorSpace &lhs,- const QColorSpace &rhs);-#endif+ static bool fuzzyCompareColorSpaces(const KisSurfaceColorSpaceWrapper &lhs,+ const KisSurfaceColorSpaceWrapper &rhs);static QString angleRendererToString(KisOpenGL::AngleRenderer renderer);public:diff --git a/libs/ui/opengl/KisScreenInformationAdapter.cpp b/libs/ui/opengl/KisScreenInformationAdapter.cppindex dbd15f2fa6..90d6613935 100644--- a/libs/ui/opengl/KisScreenInformationAdapter.cpp+++ b/libs/ui/opengl/KisScreenInformationAdapter.cpp@@ -225,19 +225,19 @@ KisScreenInformationAdapter::ScreenInfo KisScreenInformationAdapter::infoForScreinfo.maxLuminance = desc.MaxLuminance;info.maxFullFrameLuminance = desc.MaxFullFrameLuminance;- info.colorSpace = QSurfaceFormat::ColorSpace::DefaultColorSpace;+ info.colorSpace = KisSurfaceColorSpaceWrapper::DefaultColorSpace;if (desc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709) {- info.colorSpace = QSurfaceFormat::ColorSpace::sRGBColorSpace;+ info.colorSpace = KisSurfaceColorSpaceWrapper::sRGBColorSpace;} else if (desc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709) {#ifdef HAVE_HDR- info.colorSpace = QSurfaceFormat::ColorSpace::scRGBColorSpace;+ info.colorSpace = KisSurfaceColorSpaceWrapper::scRGBColorSpace;#elseqWarning("WARNING: scRGB display color space is not supported by Qt's build");#endif} else if (desc.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020) {#ifdef HAVE_HDR- info.colorSpace = QSurfaceFormat::ColorSpace::bt2020PQColorSpace;+ info.colorSpace = KisSurfaceColorSpaceWrapper::bt2020PQColorSpace;#elseqWarning("WARNING: bt2020-pq display color space is not supported by Qt's build");#endifdiff --git a/libs/ui/opengl/KisScreenInformationAdapter.h b/libs/ui/opengl/KisScreenInformationAdapter.hindex 202d18d7c1..660de1b434 100644--- a/libs/ui/opengl/KisScreenInformationAdapter.h+++ b/libs/ui/opengl/KisScreenInformationAdapter.h@@ -9,7 +9,7 @@#include "kritaui_export.h"#include <QScopedPointer>-#include <QSurfaceFormat>+#include <KisSurfaceColorSpaceWrapper.h>class QScreen;class QOpenGLContext;@@ -20,7 +20,7 @@ public:struct ScreenInfo {QScreen *screen = 0;int bitsPerColor = 0;- QSurfaceFormat::ColorSpace colorSpace = QSurfaceFormat::ColorSpace::DefaultColorSpace;+ KisSurfaceColorSpaceWrapper colorSpace;qreal redPrimary[2] = {0, 0};qreal greenPrimary[2] = {0, 0};qreal bluePrimary[2] = {0, 0};diff --git a/libs/ui/opengl/kis_opengl.cpp b/libs/ui/opengl/kis_opengl.cppindex babf2dfd52..921b17e9c9 100644--- a/libs/ui/opengl/kis_opengl.cpp+++ b/libs/ui/opengl/kis_opengl.cpp@@ -37,6 +37,7 @@#include <kis_config.h>#include <kis_debug.h>+#include <KisSurfaceColorSpaceWrapper.h>#include "KisOpenGLModeProber.h"#include "opengl/kis_opengl.h"@@ -582,7 +583,9 @@ KisOpenGL::RendererConfig generateSurfaceConfig(KisOpenGL::OpenGLRenderer renderKisOpenGL::RendererConfig config;config.angleRenderer = info.second;+dbgOpenGL << "Requesting configuration for" << info.first << info.second;+ dbgOpenGL << "Requesting root surface format" << rootSurfaceFormat;QSurfaceFormat &format = config.format;const auto openGLModuleType = determineOpenGLImplementation(info);@@ -715,11 +718,7 @@ public:}bool operator()(const KisOpenGL::RendererConfig &lhs, const KisOpenGL::RendererConfig &rhs) const {-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- KIS_SAFE_ASSERT_RECOVER_NOOP(m_preferredColorSpace != QSurfaceFormat::ColorSpace::DefaultColorSpace);-#else- KIS_SAFE_ASSERT_RECOVER_NOOP(m_preferredColorSpace != QColorSpace());-#endif+ KIS_SAFE_ASSERT_RECOVER_NOOP(m_preferredColorSpace != KisSurfaceColorSpaceWrapper::DefaultColorSpace);if (m_preferredRendererByUser != KisOpenGL::RendererSoftware) {ORDER_BY(!isFallbackOnly(lhs.rendererId()), !isFallbackOnly(rhs.rendererId()));}@@ -758,16 +757,9 @@ public:public:-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- void setPreferredColorSpace(const QSurfaceFormat::ColorSpace &preferredColorSpace) {+ void setPreferredColorSpace(const KisSurfaceColorSpaceWrapper &preferredColorSpace) {m_preferredColorSpace = preferredColorSpace;}-#else- void setPreferredColorSpace(const QColorSpace &preferredColorSpace) {- m_preferredColorSpace = preferredColorSpace;- }--#endifvoid setPreferredRendererByQt(const KisOpenGL::OpenGLRenderer &preferredRendererByQt) {m_preferredRendererByQt = preferredRendererByQt;@@ -797,11 +789,7 @@ public:return m_openGLESBlacklisted;}-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- QSurfaceFormat::ColorSpace preferredColorSpace() const {-#else- const QColorSpace &preferredColorSpace() const {-#endif+ KisSurfaceColorSpaceWrapper preferredColorSpace() const {return m_preferredColorSpace;}@@ -812,8 +800,8 @@ public:private:bool isHDRFormat(const QSurfaceFormat &f) const {#ifdef HAVE_HDR- return f.colorSpace() == QSurfaceFormat::ColorSpace::bt2020PQColorSpace ||- f.colorSpace() == QSurfaceFormat::ColorSpace::scRGBColorSpace;+ return f.colorSpace() == KisSurfaceColorSpaceWrapper::makeBt2020PQColorSpace() ||+ f.colorSpace() == KisSurfaceColorSpaceWrapper::makeSCRGBColorSpace();#elseQ_UNUSED(f);return false;@@ -838,28 +826,21 @@ private:bool doPreferHDR() const {#ifdef HAVE_HDR-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- return m_preferredColorSpace == QSurfaceFormat::ColorSpace::bt2020PQColorSpace ||- m_preferredColorSpace == QSurfaceFormat::ColorSpace::scRGBColorSpace;-#else- return m_preferredColorSpace == QColorSpace(QColorSpace::NamedColorSpace::Bt2100Pq);-#endif+ return m_preferredColorSpace == KisSurfaceColorSpaceWrapper::bt2020PQColorSpace ||+ m_preferredColorSpace == KisSurfaceColorSpaceWrapper::scRGBColorSpace;#elsereturn false;#endif}bool isPreferredColorSpace(const QSurfaceFormat & surfaceFormat) const {- return KisOpenGLModeProber::fuzzyCompareColorSpaces(m_preferredColorSpace, surfaceFormat.colorSpace());- return false;+ return KisOpenGLModeProber::fuzzyCompareColorSpaces(+ m_preferredColorSpace,+ KisSurfaceColorSpaceWrapper::fromQtColorSpace(surfaceFormat.colorSpace()));}private:-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- QSurfaceFormat::ColorSpace m_preferredColorSpace = QSurfaceFormat::ColorSpace::DefaultColorSpace;-#else- QColorSpace m_preferredColorSpace;-#endif+ KisSurfaceColorSpaceWrapper m_preferredColorSpace;KisOpenGL::OpenGLRenderer m_preferredRendererByQt = KisOpenGL::RendererDesktopGL;KisOpenGL::OpenGLRenderer m_preferredRendererByUser = KisOpenGL::RendererAuto;KisOpenGL::OpenGLRenderer m_preferredRendererByHDR = KisOpenGL::RendererAuto;@@ -945,16 +926,12 @@ KisOpenGL::RendererConfig KisOpenGL::selectSurfaceConfig(KisOpenGL::OpenGLRender#ifdef HAVE_HDRcompareOp.setPreferredColorSpace(- preferredRootSurfaceFormat == KisConfig::BT709_G22 ? QSurfaceFormat::ColorSpace::sRGBColorSpace :- preferredRootSurfaceFormat == KisConfig::BT709_G10 ? QSurfaceFormat::ColorSpace::scRGBColorSpace :- QSurfaceFormat::ColorSpace::bt2020PQColorSpace);+ preferredRootSurfaceFormat == KisConfig::BT709_G22 ? KisSurfaceColorSpaceWrapper::sRGBColorSpace :+ preferredRootSurfaceFormat == KisConfig::BT709_G10 ? KisSurfaceColorSpaceWrapper::scRGBColorSpace :+ KisSurfaceColorSpaceWrapper::bt2020PQColorSpace);#elseQ_UNUSED(preferredRootSurfaceFormat);-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- compareOp.setPreferredColorSpace(QSurfaceFormat::ColorSpace::sRGBColorSpace);-#else- compareOp.setPreferredColorSpace(QColorSpace(QColorSpace::NamedColorSpace::SRgb));-#endif+ compareOp.setPreferredColorSpace(KisSurfaceColorSpaceWrapper::sRGBColorSpace);#endif#ifdef Q_OS_WIN@@ -1070,7 +1047,7 @@ KisOpenGL::RendererConfig KisOpenGL::selectSurfaceConfig(KisOpenGL::OpenGLRender{const bool colorSpaceIsCorrect =KisOpenGLModeProber::fuzzyCompareColorSpaces(compareOp.preferredColorSpace(),- resultConfig.format.colorSpace());+ KisSurfaceColorSpaceWrapper::fromQtColorSpace(resultConfig.format.colorSpace()));const bool rendererIsCorrect =compareOp.preferredRendererByUser() == KisOpenGL::RendererAuto ||diff --git a/libs/ui/tests/CMakeLists.txt b/libs/ui/tests/CMakeLists.txtindex 824e0c7cb3..d6e314725d 100644--- a/libs/ui/tests/CMakeLists.txt+++ b/libs/ui/tests/CMakeLists.txt@@ -21,6 +21,7 @@ kis_add_tests(kis_animation_frame_cache_test.cppkis_shape_layer_test.cppKisSafeDocumentLoaderTest.cpp+ KisSurfaceColorSpaceWrapperTest.cppLINK_LIBRARIES kritaui kritatestsdkNAME_PREFIX "libs-ui-"diff --git a/libs/ui/tests/KisSurfaceColorSpaceWrapperTest.cpp b/libs/ui/tests/KisSurfaceColorSpaceWrapperTest.cppnew file mode 100644index 0000000000..2f20dd1bf3--- /dev/null+++ b/libs/ui/tests/KisSurfaceColorSpaceWrapperTest.cpp@@ -0,0 +1,90 @@+/*+ * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#include "KisSurfaceColorSpaceWrapperTest.h"++#include <simpletest.h>+#include <KisSurfaceColorSpaceWrapper.h>++void KisSurfaceColorSpaceWrapperTest::test()+{+ KisSurfaceColorSpaceWrapper w1;+ KisSurfaceColorSpaceWrapper w2(KisSurfaceColorSpaceWrapper::DefaultColorSpace);+ KisSurfaceColorSpaceWrapper w3(KisSurfaceColorSpaceWrapper::sRGBColorSpace);+ KisSurfaceColorSpaceWrapper w4(KisSurfaceColorSpaceWrapper::scRGBColorSpace);+ KisSurfaceColorSpaceWrapper w5(KisSurfaceColorSpaceWrapper::bt2020PQColorSpace);++ // test comparison operators+ QVERIFY(w1 == w2);+ QVERIFY(w1 != w3);++ // test direct conversion to QColorSpace+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)+ QSurfaceFormat::ColorSpace cs4 = w4;+ QVERIFY(cs4 == QSurfaceFormat::scRGBColorSpace);+#else+ QColorSpace cs4 = w4;+ QVERIFY(cs4 == QColorSpace::SRgbLinear);+#endif++ // test indirect conversion to QColorSpace+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)+ QVERIFY(w1 == QSurfaceFormat::DefaultColorSpace);+ QVERIFY(w2 == QSurfaceFormat::DefaultColorSpace);+ QVERIFY(w3 == QSurfaceFormat::sRGBColorSpace);+ QVERIFY(w4 == QSurfaceFormat::scRGBColorSpace);+ QVERIFY(w5 == QSurfaceFormat::bt2020PQColorSpace);+#else+ QVERIFY(w1 == QColorSpace());+ QVERIFY(w2 == QColorSpace());+ QVERIFY(w3 == QColorSpace::SRgb);+ QVERIFY(w4 == QColorSpace::SRgbLinear);+ QVERIFY(w5 == QColorSpace::Bt2100Pq);+#endif++ // test assignment+ w1 = w5;+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)+ QVERIFY(w1 == QSurfaceFormat::bt2020PQColorSpace);+#else+ QVERIFY(w1 == QColorSpace::Bt2100Pq);+#endif++ // test move assignment+ w1 = std::move(w4);+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)+ QVERIFY(w1 == QSurfaceFormat::scRGBColorSpace);+#else+ QVERIFY(w1 == QColorSpace::SRgbLinear);+#endif+}++void KisSurfaceColorSpaceWrapperTest::testConstruction()+{+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)+ auto w2 = KisSurfaceColorSpaceWrapper::fromQtColorSpace(QSurfaceFormat::DefaultColorSpace);+ auto w3 = KisSurfaceColorSpaceWrapper::fromQtColorSpace(QSurfaceFormat::sRGBColorSpace);+ auto w4 = KisSurfaceColorSpaceWrapper::fromQtColorSpace(QSurfaceFormat::scRGBColorSpace);+ auto w5 = KisSurfaceColorSpaceWrapper::fromQtColorSpace(QSurfaceFormat::bt2020PQColorSpace);++ QVERIFY(w2 == QSurfaceFormat::DefaultColorSpace);+ QVERIFY(w3 == QSurfaceFormat::sRGBColorSpace);+ QVERIFY(w4 == QSurfaceFormat::scRGBColorSpace);+ QVERIFY(w5 == QSurfaceFormat::bt2020PQColorSpace);+#else+ auto w2 = KisSurfaceColorSpaceWrapper::fromQtColorSpace(QColorSpace());+ auto w3 = KisSurfaceColorSpaceWrapper::fromQtColorSpace(QColorSpace::SRgb);+ auto w4 = KisSurfaceColorSpaceWrapper::fromQtColorSpace(QColorSpace::SRgbLinear);+ auto w5 = KisSurfaceColorSpaceWrapper::fromQtColorSpace(QColorSpace::Bt2100Pq);++ QVERIFY(w2 == QColorSpace());+ QVERIFY(w3 == QColorSpace::SRgb);+ QVERIFY(w4 == QColorSpace::SRgbLinear);+ QVERIFY(w5 == QColorSpace::Bt2100Pq);+#endif+}++SIMPLE_TEST_MAIN(KisSurfaceColorSpaceWrapperTest)diff --git a/libs/ui/tests/KisSurfaceColorSpaceWrapperTest.h b/libs/ui/tests/KisSurfaceColorSpaceWrapperTest.hnew file mode 100644index 0000000000..1b6bf2a4bd--- /dev/null+++ b/libs/ui/tests/KisSurfaceColorSpaceWrapperTest.h@@ -0,0 +1,20 @@+/*+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#ifndef __KISSURFACECOLORSPACEWRAPPERTEST_H+#define __KISSURFACECOLORSPACEWRAPPERTEST_H++#include <simpletest.h>++class KisSurfaceColorSpaceWrapperTest : public QObject+{+ Q_OBJECT+private Q_SLOTS:+ void test();+ void testConstruction();+};++#endif /* __KISSURFACECOLORSPACEWRAPPERTEST_H */diff --git a/plugins/dockers/lut/lutdocker_dock.cpp b/plugins/dockers/lut/lutdocker_dock.cppindex 03e4a56feb..eafb4fed0e 100644--- a/plugins/dockers/lut/lutdocker_dock.cpp+++ b/plugins/dockers/lut/lutdocker_dock.cpp@@ -47,6 +47,7 @@#include <KisOcioConfiguration.h>#include <opengl/KisOpenGLModeProber.h>+#include <KisSurfaceColorSpaceWrapper.h>#include "black_white_point_chooser.h"@@ -229,13 +230,15 @@ bool LutDockerDock::canChangeExposureAndGamma() const#ifdef HAVE_HDR- QSurfaceFormat::ColorSpace currentColorSpace = KisOpenGLModeProber::instance()->surfaceformatInUse().colorSpace();+ KisSurfaceColorSpaceWrapper currentColorSpace =+ KisSurfaceColorSpaceWrapper::fromQtColorSpace(+ KisOpenGLModeProber::instance()->surfaceformatInUse().colorSpace());#endifconst bool exposureManagementEnabled =externalColorManagementEnabled#ifdef HAVE_HDR- || currentColorSpace == QSurfaceFormat::ColorSpace::scRGBColorSpace+ || currentColorSpace == KisSurfaceColorSpaceWrapper::scRGBColorSpace#endif;diff --git a/plugins/dockers/smallcolorselector/KisClickableGLImageWidget.cpp b/plugins/dockers/smallcolorselector/KisClickableGLImageWidget.cppindex 278c72426f..522179cd45 100644--- a/plugins/dockers/smallcolorselector/KisClickableGLImageWidget.cpp+++ b/plugins/dockers/smallcolorselector/KisClickableGLImageWidget.cpp@@ -16,7 +16,7 @@ KisClickableGLImageWidget::KisClickableGLImageWidget(QWidget *parent){}-KisClickableGLImageWidget::KisClickableGLImageWidget(QSurfaceFormat::ColorSpace colorSpace, QWidget *parent)+KisClickableGLImageWidget::KisClickableGLImageWidget(const KisSurfaceColorSpaceWrapper &colorSpace, QWidget *parent): KisGLImageWidget(colorSpace, parent){}diff --git a/plugins/dockers/smallcolorselector/KisClickableGLImageWidget.h b/plugins/dockers/smallcolorselector/KisClickableGLImageWidget.hindex 7f2e498ba2..b17e83dd03 100644--- a/plugins/dockers/smallcolorselector/KisClickableGLImageWidget.h+++ b/plugins/dockers/smallcolorselector/KisClickableGLImageWidget.h@@ -30,7 +30,7 @@ public:public:KisClickableGLImageWidget(QWidget *parent = nullptr);- KisClickableGLImageWidget(QSurfaceFormat::ColorSpace colorSpace,+ KisClickableGLImageWidget(const KisSurfaceColorSpaceWrapper &colorSpace,QWidget *parent = nullptr);~KisClickableGLImageWidget();diff --git a/plugins/dockers/smallcolorselector/KisGLImageWidget.cpp b/plugins/dockers/smallcolorselector/KisGLImageWidget.cppindex e8ef054235..e029e2481e 100644--- a/plugins/dockers/smallcolorselector/KisGLImageWidget.cpp+++ b/plugins/dockers/smallcolorselector/KisGLImageWidget.cpp@@ -38,11 +38,11 @@ inline void rectToTexCoords(QVector2D* texCoords, const QRectF &rc)}KisGLImageWidget::KisGLImageWidget(QWidget *parent)- : KisGLImageWidget(QSurfaceFormat::ColorSpace::sRGBColorSpace, parent)+ : KisGLImageWidget(KisSurfaceColorSpaceWrapper::sRGBColorSpace, parent){}-KisGLImageWidget::KisGLImageWidget(QSurfaceFormat::ColorSpace colorSpace,+KisGLImageWidget::KisGLImageWidget(const KisSurfaceColorSpaceWrapper &colorSpace,QWidget *parent): QOpenGLWidget(parent),m_texture(QOpenGLTexture::Target2D)diff --git a/plugins/dockers/smallcolorselector/KisGLImageWidget.h b/plugins/dockers/smallcolorselector/KisGLImageWidget.hindex 847be4d116..575c1d64c1 100644--- a/plugins/dockers/smallcolorselector/KisGLImageWidget.h+++ b/plugins/dockers/smallcolorselector/KisGLImageWidget.h@@ -15,13 +15,14 @@#include <QOpenGLBuffer>#include <QTransform>#include <KisGLImageF16.h>+#include <KisSurfaceColorSpaceWrapper.h>class KisGLImageWidget : public QOpenGLWidget, protected QOpenGLFunctions{Q_OBJECTpublic:KisGLImageWidget(QWidget *parent = nullptr);- KisGLImageWidget(QSurfaceFormat::ColorSpace colorSpace,+ KisGLImageWidget(const KisSurfaceColorSpaceWrapper &colorSpace,QWidget *parent = nullptr);~KisGLImageWidget();diff --git a/plugins/dockers/smallcolorselector/kis_small_color_widget.cc b/plugins/dockers/smallcolorselector/kis_small_color_widget.ccindex 33c2473a5b..d53bba9003 100644--- a/plugins/dockers/smallcolorselector/kis_small_color_widget.cc+++ b/plugins/dockers/smallcolorselector/kis_small_color_widget.cc@@ -117,7 +117,9 @@ KisSmallColorWidget::KisSmallColorWidget(QWidget* parent)}- const QSurfaceFormat::ColorSpace colorSpace = QSurfaceFormat::ColorSpace::DefaultColorSpace;+ // default color space means that the colors will be passed through to the GPU directly+ // without any conversion+ const KisSurfaceColorSpaceWrapper colorSpace = KisSurfaceColorSpaceWrapper::DefaultColorSpace;d->hueWidget = new KisClickableGLImageWidget(colorSpace, this);d->hueWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);