Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
xyz.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
4 * Authors:
5 * 2015 Alexei Boronine (original idea, JavaScript implementation)
6 * 2015 Roger Tallada (Obj-C implementation)
7 * 2017 Martin Mitas (C implementation, based on Obj-C implementation)
8 * 2021 Massinissa Derriche (C++ implementation for Inkscape, based on C implementation)
9 * 2023 Martin Owens (New Color classes)
10 *
11 * Copyright (C) 2023 Authors
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
13 */
14
15#include "xyz.h"
16
17#include <cmath>
18
19#include "colors/printer.h"
20
22
30static double dot_product(std::vector<double> const &t1, std::vector<double> const &t2)
31{
32 return (t1[0] * t2[0] + t1[1] * t2[1] + t1[2] * t2[2]);
33}
34
40void XYZ::toLinearRGB(std::vector<double> &in_out)
41{
42 std::vector<double> result = in_out; // copy
43 for (size_t i : {0, 1, 2}) {
44 result[i] = dot_product(d65[i], in_out);
45 }
46 in_out = result;
47}
48
54void XYZ::fromLinearRGB(std::vector<double> &in_out)
55{
56 std::vector<double> result = in_out; // copy
57 for (size_t i : {0, 1, 2}) {
58 result[i] = dot_product(in_out, d65_inv[i]);
59 }
60 in_out = result;
61}
62
69std::string XYZ::toString(std::vector<double> const &values, bool opacity) const
70{
71 auto os = CssColorPrinter(3, "xyz");
72 os << values;
73 if (opacity && values.size() == 4)
74 os << values[3];
75 return os;
76}
77
78}; // namespace Inkscape::Colors::Space
uint32_t Color
static void fromLinearRGB(std::vector< double > &output)
Convert from sRGB icc values to XYZ values.
Definition xyz.cpp:54
std::string toString(std::vector< double > const &values, bool opacity=true) const override
Print the RGB color to a CSS Color module 4 xyz-d65 color.
Definition xyz.cpp:69
static void toLinearRGB(std::vector< double > &output)
Convert a color from the the XYZ colorspace to the RGB colorspace.
Definition xyz.cpp:40
Css & result
std::string original
const std::vector< double > d65_inv[3]
Definition xyz.h:27
static double dot_product(std::vector< double > const &t1, std::vector< double > const &t2)
Calculate the dot product of the given arrays.
Definition xyz.cpp:30
const std::vector< double > d65[3]
Definition xyz.h:23
Helper class to stream background task notifications as a series of messages.