core/colorpipeline: add evaluate method to calculate colorpipeline results on the CPU

This is useful for autotests and some other special cases where we need to calculate
the result of a color pipeline on the CPU. Long term, this should replace
ColorDescription::mapTo
This commit is contained in:
Xaver Hugl 2024-07-08 18:56:09 +02:00
parent 4b91ac8cca
commit 3f2f3cb020
2 changed files with 18 additions and 0 deletions

View file

@ -225,6 +225,23 @@ ColorPipeline ColorPipeline::merge(const ColorPipeline &onTop)
return ret;
}
QVector3D ColorPipeline::evaluate(const QVector3D &input) const
{
QVector3D ret = input;
for (const auto &op : ops) {
if (const auto mat = std::get_if<ColorMatrix>(&op.operation)) {
ret = mat->mat * ret;
} else if (const auto mult = std::get_if<ColorMultiplier>(&op.operation)) {
ret *= mult->factors;
} else if (const auto tf = std::get_if<ColorTransferFunction>(&op.operation)) {
ret = tf->tf.encodedToNits(ret, tf->referenceLuminance);
} else if (const auto tf = std::get_if<InverseColorTransferFunction>(&op.operation)) {
ret = tf->tf.nitsToEncoded(ret, tf->referenceLuminance);
}
}
return ret;
}
ColorTransferFunction::ColorTransferFunction(TransferFunction tf, double referenceLLuminance)
: tf(tf)
, referenceLuminance(referenceLLuminance)

View file

@ -88,6 +88,7 @@ public:
bool isIdentity() const;
bool operator==(const ColorPipeline &other) const = default;
const ValueRange &currentOutputRange() const;
QVector3D evaluate(const QVector3D &input) const;
void addMultiplier(double factor);
void addMultiplier(const QVector3D &factors);