diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-02-25 12:42:08 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-02-26 07:36:14 +0000 |
commit | e8a2ca314b973fb6a5e01a678f7d4d956c3ca30e (patch) | |
tree | b7f9511209d252fe3953ec8336c6117699deea25 /src | |
parent | 627bae700f3f94d5c38ad8b9749a0d2661bc4207 (diff) |
Fix logic problems with table based grayscale ICC profiles
White-point was calculated wrongly and some tables could cause bad
behavior in the tables.
Change-Id: I24e8f5f3cc1306f5f898a4acbf7b008e26bd04e2
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
(cherry picked from commit f493d41722fc76a04f699ea26128fdf3d215d913)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/painting/qcolortransfertable_p.h | 10 | ||||
-rw-r--r-- | src/gui/painting/qicc.cpp | 2 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/gui/painting/qcolortransfertable_p.h b/src/gui/painting/qcolortransfertable_p.h index 2812ed5685..bbc9f08dcc 100644 --- a/src/gui/painting/qcolortransfertable_p.h +++ b/src/gui/painting/qcolortransfertable_p.h @@ -119,7 +119,7 @@ public: x = std::clamp(x, 0.0f, 1.0f); x *= m_tableSize - 1; const uint32_t lo = static_cast<uint32_t>(std::floor(x)); - const uint32_t hi = std::min(lo + 1, m_tableSize); + const uint32_t hi = std::min(lo + 1, m_tableSize - 1); const float frac = x - lo; if (!m_table16.isEmpty()) return (m_table16[lo] * (1.0f - frac) + m_table16[hi] * frac) * (1.0f/65535.0f); @@ -138,28 +138,28 @@ public: return 1.0f; if (!m_table16.isEmpty()) { const float v = x * 65535.0f; - uint32_t i = static_cast<uint32_t>(std::floor(resultLargerThan * (m_tableSize - 1))) + 1; + uint32_t i = static_cast<uint32_t>(std::floor(resultLargerThan * (m_tableSize - 1))); auto it = std::lower_bound(m_table16.cbegin() + i, m_table16.cend(), v); i = it - m_table16.cbegin(); if (i >= m_tableSize - 1) return 1.0f; const float y1 = m_table16[i - 1]; const float y2 = m_table16[i]; - Q_ASSERT(x >= y1 && x < y2); + Q_ASSERT(v >= y1 && v <= y2); const float fr = (v - y1) / (y2 - y1); return (i + fr) * (1.0f / (m_tableSize - 1)); } if (!m_table8.isEmpty()) { const float v = x * 255.0f; - uint32_t i = static_cast<uint32_t>(std::floor(resultLargerThan * (m_tableSize - 1))) + 1; + uint32_t i = static_cast<uint32_t>(std::floor(resultLargerThan * (m_tableSize - 1))); auto it = std::lower_bound(m_table8.cbegin() + i, m_table8.cend(), v); i = it - m_table8.cbegin(); if (i >= m_tableSize - 1) return 1.0f; const float y1 = m_table8[i - 1]; const float y2 = m_table8[i]; - Q_ASSERT(x >= y1 && x < y2); + Q_ASSERT(v >= y1 && v <= y2); const float fr = (v - y1) / (y2 - y1); return (i + fr) * (1.0f / (m_tableSize - 1)); } diff --git a/src/gui/painting/qicc.cpp b/src/gui/painting/qicc.cpp index 0acd458eff..028e800c48 100644 --- a/src/gui/painting/qicc.cpp +++ b/src/gui/painting/qicc.cpp @@ -759,7 +759,7 @@ bool fromIccProfile(const QByteArray &data, QColorSpace *colorSpace) } else { colorspaceDPtr->primaries = QColorSpace::Primaries::Custom; // Calculate chromaticity from xyz (assuming y == 1.0f). - float y = 1.0f / (1.0f + whitePoint.z - whitePoint.x); + float y = 1.0f / (1.0f + whitePoint.z + whitePoint.x); float x = whitePoint.x * y; QColorSpacePrimaries primaries(QColorSpace::Primaries::SRgb); primaries.whitePoint = QPointF(x,y); |