added possibility to specify extra working spaces via a json file
The JSON file is called workingspaces.json, it can be either in the global iccprofiles directory, or in the user's ICC profiles dir (set in preferences). The format is the following: {"working_spaces": [ { "name" : "ACES", "file" : "/path/to/ACES.icc" }, { "name" : "ACEScg", "matrix" : [0.7184354, 0.16578523, 0.09882643, 0.29728935, 0.66958117, 0.03571544, -0.00647622, 0.01469771, 0.66732561] } ]} if "matrix" is present, "file" is ignored. If only "file" is present, the matrix is extracted from the ICC profile. For this, we look only at the R, G, and B matrix columns and the white point set in the profile. Bradford adaptation is used to convert the matrix to D50. Anything else (LUT, TRC, ...) in the profile is ignored. It is the user's responsibility to ensure that the profile is suitable to be used as a working space.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
|
||||
namespace rtengine
|
||||
{
|
||||
@@ -138,3 +139,65 @@ constexpr std::uint8_t uint16ToUint8Rounded(std::uint16_t i)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
bool invertMatrix(const std::array<std::array<T, 3>, 3> &in, std::array<std::array<T, 3>, 3> &out)
|
||||
{
|
||||
const T res00 = in[1][1] * in[2][2] - in[2][1] * in[1][2];
|
||||
const T res10 = in[2][0] * in[1][2] - in[1][0] * in[2][2];
|
||||
const T res20 = in[1][0] * in[2][1] - in[2][0] * in[1][1];
|
||||
|
||||
const T det = in[0][0] * res00 + in[0][1] * res10 + in[0][2] * res20;
|
||||
|
||||
if (std::abs(det) < 1.0e-10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
out[0][0] = res00 / det;
|
||||
out[0][1] = (in[2][1] * in[0][2] - in[0][1] * in[2][2]) / det;
|
||||
out[0][2] = (in[0][1] * in[1][2] - in[1][1] * in[0][2]) / det;
|
||||
out[1][0] = res10 / det;
|
||||
out[1][1] = (in[0][0] * in[2][2] - in[2][0] * in[0][2]) / det;
|
||||
out[1][2] = (in[1][0] * in[0][2] - in[0][0] * in[1][2]) / det;
|
||||
out[2][0] = res20 / det;
|
||||
out[2][1] = (in[2][0] * in[0][1] - in[0][0] * in[2][1]) / det;
|
||||
out[2][2] = (in[0][0] * in[1][1] - in[1][0] * in[0][1]) / det;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::array<std::array<T, 3>, 3> dotProduct(const std::array<std::array<T, 3>, 3> &a, const std::array<std::array<T, 3>, 3> &b)
|
||||
{
|
||||
std::array<std::array<T, 3>, 3> res;
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
res[i][j] = 0;
|
||||
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
res[i][j] += a[i][k] * b[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
std::array<T, 3> dotProduct(const std::array<std::array<T, 3>, 3> &a, const std::array<T, 3> &b)
|
||||
{
|
||||
std::array<T, 3> res;
|
||||
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
res[i] = 0;
|
||||
for (int k = 0; k < 3; ++k) {
|
||||
res[i] += a[i][k] * b[k];
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user