Color adaptation for XYZ color space

This commit is contained in:
Jakub Melka
2021-05-08 18:16:28 +02:00
parent a34ee620b9
commit d607c24459
3 changed files with 195 additions and 8 deletions

View File

@ -218,6 +218,10 @@ public:
{
return m_values[row * Cols + column];
}
inline void setValue(size_t row, size_t column, PDFColorComponent value)
{
m_values[row * Cols + column] = value;
}
void transpose()
{
@ -234,6 +238,33 @@ public:
}
}
void makeIdentity()
{
Q_ASSERT(Rows == Cols);
m_values = { };
for (size_t row = 0; row < Rows; ++row)
{
const size_t index = row * Cols + row;
m_values[index] = PDFColorComponent(1.0f);
}
}
void makeDiagonal(auto diagonalItems)
{
Q_ASSERT(Rows == Cols);
Q_ASSERT(diagonalItems.size() == Rows);
m_values = { };
for (size_t row = 0; row < Rows; ++row)
{
const size_t index = row * Cols + row;
m_values[index] = diagonalItems[row];
}
}
void multiplyByFactor(PDFColorComponent factor)
{
for (auto it = begin(); it != end(); ++it)
@ -249,6 +280,29 @@ private:
std::array<PDFColorComponent, Rows * Cols> m_values;
};
template<size_t i, size_t k, size_t j>
static inline PDFColorComponentMatrix<i, j> operator*(const PDFColorComponentMatrix<i, k>& left, const PDFColorComponentMatrix<k, j>& right)
{
PDFColorComponentMatrix<i, j> result;
for (size_t ci = 0; ci < i; ++ci)
{
for (size_t cj = 0; cj < j; ++cj)
{
PDFColorComponent value = 0.0f;
for (size_t ck = 0; ck < k; ++ck)
{
value += left.getValue(ci, ck) * right.getValue(ck, cj);
}
result.setValue(ci, cj, value);
}
}
return result;
}
using PDFColorComponentMatrix_3x3 = PDFColorComponentMatrix<3, 3>;
/// Represents PDF's color space (abstract class). Contains functions for parsing