Fix logic problems with table based grayscale ICC profiles
White-point was calculated wrongly and some tables could cause bad behavior in the tables. Pick-to: 6.1 6.0 5.15 Change-Id: I24e8f5f3cc1306f5f898a4acbf7b008e26bd04e2 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
parent
0e22001a3b
commit
f493d41722
@ -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));
|
||||
}
|
||||
|
@ -757,7 +757,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);
|
||||
|
Loading…
Reference in New Issue
Block a user