2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <boost/lexical_cast.hpp>
21 #include <libxml++/libxml++.h>
22 #include <libdcp/colour_matrix.h>
23 #include <libcxml/cxml.h>
24 #include "colour_conversion.h"
30 using boost::shared_ptr;
31 using boost::lexical_cast;
33 ColourConversion::ColourConversion ()
34 : name (_("Untitled"))
36 , input_gamma_linearised (true)
40 for (int i = 0; i < 3; ++i) {
41 for (int j = 0; j < 3; ++j) {
42 matrix (i, j) = libdcp::colour_matrix::xyz_to_rgb[i][j];
47 ColourConversion::ColourConversion (string n, float i, bool il, float const m[3][3], float o)
50 , input_gamma_linearised (il)
54 for (int i = 0; i < 3; ++i) {
55 for (int j = 0; j < 3; ++j) {
56 matrix (i, j) = m[i][j];
61 ColourConversion::ColourConversion (shared_ptr<cxml::Node> node)
64 name = node->string_child ("Name");
65 input_gamma = node->number_child<float> ("InputGamma");
66 input_gamma_linearised = node->bool_child ("InputGammaLinearised");
68 for (int i = 0; i < 3; ++i) {
69 for (int j = 0; j < 3; ++j) {
74 list<shared_ptr<cxml::Node> > m = node->node_children ("Matrix");
75 for (list<shared_ptr<cxml::Node> >::iterator i = m.begin(); i != m.end(); ++i) {
76 int const ti = (*i)->number_attribute<int> ("i");
77 int const tj = (*i)->number_attribute<int> ("j");
78 matrix(ti, tj) = lexical_cast<float> ((*i)->content ());
81 output_gamma = node->number_child<float> ("OutputGamma");
85 ColourConversion::as_xml (xmlpp::Node* node) const
87 node->add_child("Name")->add_child_text (name);
88 node->add_child("InputGamma")->add_child_text (lexical_cast<string> (input_gamma));
89 node->add_child("InputGammaLinearised")->add_child_text (input_gamma_linearised ? "1" : "0");
91 for (int i = 0; i < 3; ++i) {
92 for (int j = 0; j < 3; ++j) {
93 xmlpp::Element* m = node->add_child("Matrix");
94 m->set_attribute ("i", lexical_cast<string> (i));
95 m->set_attribute ("j", lexical_cast<string> (j));
96 m->add_child_text (lexical_cast<string> (matrix (i, j)));
100 node->add_child("OutputGamma")->add_child_text (lexical_cast<string> (output_gamma));