diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-12-14 17:48:57 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-01-25 17:21:54 +0100 |
commit | fdc7eb80dd5753bc1fc145dc9bd0689cd65e251d (patch) | |
tree | f8f80675b1187cb899c2bab90f3d53f950ca9108 /src/gui/util | |
parent | 4e2a94236998cd05753167953d9167793baf9942 (diff) |
Add QPlatformScreen::colorSpace()
Added for macOS and X11 screens
Task-number: QTBUG-90535
Change-Id: Ifafe7a07ee2abc3c42cd12785db2d7329878375b
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/gui/util')
-rw-r--r-- | src/gui/util/qedidparser.cpp | 84 | ||||
-rw-r--r-- | src/gui/util/qedidparser_p.h | 11 |
2 files changed, 94 insertions, 1 deletions
diff --git a/src/gui/util/qedidparser.cpp b/src/gui/util/qedidparser.cpp index 7ca514e7c6..553ca20807 100644 --- a/src/gui/util/qedidparser.cpp +++ b/src/gui/util/qedidparser.cpp @@ -52,6 +52,9 @@ #define EDID_OFFSET_SERIAL 0x0c #define EDID_PHYSICAL_WIDTH 0x15 #define EDID_OFFSET_PHYSICAL_HEIGHT 0x16 +#define EDID_TRANSFER_FUNCTION 0x17 +#define EDID_FEATURE_SUPPORT 0x18 +#define EDID_CHROMATICITIES_BLOCK 0x19 QT_BEGIN_NAMESPACE @@ -152,6 +155,87 @@ bool QEdidParser::parse(const QByteArray &blob) // Physical size physicalSize = QSizeF(data[EDID_PHYSICAL_WIDTH], data[EDID_OFFSET_PHYSICAL_HEIGHT]) * 10; + // Gamma and transfer function + const uint igamma = data[EDID_TRANSFER_FUNCTION]; + if (igamma != 0xff) { + gamma = 1.0 + (igamma / 100.0f); + useTables = false; + } else { + gamma = 0.0; // Defined in DI-EXT + useTables = true; + } + sRgb = data[EDID_FEATURE_SUPPORT] & 0x04; + + // Chromaticities + int rx = (data[EDID_CHROMATICITIES_BLOCK] >> 6) & 0x03; + int ry = (data[EDID_CHROMATICITIES_BLOCK] >> 4) & 0x03; + int gx = (data[EDID_CHROMATICITIES_BLOCK] >> 2) & 0x03; + int gy = (data[EDID_CHROMATICITIES_BLOCK] >> 0) & 0x03; + int bx = (data[EDID_CHROMATICITIES_BLOCK + 1] >> 6) & 0x03; + int by = (data[EDID_CHROMATICITIES_BLOCK + 1] >> 4) & 0x03; + int wx = (data[EDID_CHROMATICITIES_BLOCK + 1] >> 2) & 0x03; + int wy = (data[EDID_CHROMATICITIES_BLOCK + 1] >> 0) & 0x03; + rx |= data[EDID_CHROMATICITIES_BLOCK + 2] << 2; + ry |= data[EDID_CHROMATICITIES_BLOCK + 3] << 2; + gx |= data[EDID_CHROMATICITIES_BLOCK + 4] << 2; + gy |= data[EDID_CHROMATICITIES_BLOCK + 5] << 2; + bx |= data[EDID_CHROMATICITIES_BLOCK + 6] << 2; + by |= data[EDID_CHROMATICITIES_BLOCK + 7] << 2; + wx |= data[EDID_CHROMATICITIES_BLOCK + 8] << 2; + wy |= data[EDID_CHROMATICITIES_BLOCK + 9] << 2; + + redChromaticity.setX(rx * (1.0f / 1024.0f)); + redChromaticity.setY(ry * (1.0f / 1024.0f)); + greenChromaticity.setX(gx * (1.0f / 1024.0f)); + greenChromaticity.setY(gy * (1.0f / 1024.0f)); + blueChromaticity.setX(bx * (1.0f / 1024.0f)); + blueChromaticity.setY(by * (1.0f / 1024.0f)); + whiteChromaticity.setX(wx * (1.0f / 1024.0f)); + whiteChromaticity.setY(wy * (1.0f / 1024.0f)); + + // Find extensions + for (uint i = 1; i < length / 128; ++i) { + uint extensionId = data[i * 128]; + if (extensionId == 0x40) { // DI-EXT + // 0x0E (sub-pixel layout) + // 0x20->0x22 (bits per color) + // 0x51->0x7e Transfer characteristics + const uchar desc = data[i * 128 + 0x51]; + const uchar len = desc & 0x3f; + if ((desc & 0xc0) == 0x40) { + if (len > 45) + return false; + QList<uint16_t> whiteTRC; + whiteTRC.reserve(len + 1); + for (uint j = 0; j < len; ++j) + whiteTRC[j] = data[0x52 + j] * 0x101; + whiteTRC[len] = 0xffff; + tables.append(whiteTRC); + } else if ((desc & 0xc0) == 0x80) { + if (len > 15) + return false; + QList<uint16_t> redTRC; + QList<uint16_t> greenTRC; + QList<uint16_t> blueTRC; + blueTRC.reserve(len + 1); + greenTRC.reserve(len + 1); + redTRC.reserve(len + 1); + for (uint j = 0; j < len; ++j) + blueTRC[j] = data[0x52 + j] * 0x101; + blueTRC[len] = 0xffff; + for (uint j = 0; j < len; ++j) + greenTRC[j] = data[0x61 + j] * 0x101; + greenTRC[len] = 0xffff; + for (uint j = 0; j < len; ++j) + redTRC[j] = data[0x70 + j] * 0x101; + redTRC[len] = 0xffff; + tables.append(redTRC); + tables.append(greenTRC); + tables.append(blueTRC); + } + } + } + return true; } diff --git a/src/gui/util/qedidparser_p.h b/src/gui/util/qedidparser_p.h index 363ab251af..14c736f4cc 100644 --- a/src/gui/util/qedidparser_p.h +++ b/src/gui/util/qedidparser_p.h @@ -40,8 +40,9 @@ #ifndef QEDIDPARSER_P_H #define QEDIDPARSER_P_H -#include <QtCore/QSize> #include <QtCore/QMap> +#include <QtCore/QPointF> +#include <QtCore/QSize> // // W A R N I N G @@ -72,6 +73,14 @@ public: QString model; QString serialNumber; QSizeF physicalSize; + qreal gamma; + QPointF redChromaticity; + QPointF greenChromaticity; + QPointF blueChromaticity; + QPointF whiteChromaticity; + QList<QList<uint16_t>> tables; + bool sRgb; + bool useTables; private: QMap<QString, QString> m_vendorCache; |