summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-08-16 20:14:33 +0100
committerCarl Hetherington <cth@carlh.net>2013-08-16 21:51:15 +0100
commit74a8d26a8907c6e00e29f054178a3425f44e38ed (patch)
treefd700ba8471edcbd6e9e6481a3ca1397397a2d5d /src/lib
parentc2909b61d360510241ef37abd255269bd8aa9526 (diff)
Very basics of colour conversion configuration.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/colour_conversion.cc101
-rw-r--r--src/lib/colour_conversion.h45
-rw-r--r--src/lib/config.cc24
-rw-r--r--src/lib/config.h16
-rw-r--r--src/lib/dcp_video_frame.cc2
-rw-r--r--src/lib/dcp_video_frame.h2
-rw-r--r--src/lib/encoder.cc8
-rw-r--r--src/lib/encoder.h2
-rw-r--r--src/lib/server.cc6
-rw-r--r--src/lib/server.h7
-rw-r--r--src/lib/wscript1
11 files changed, 197 insertions, 17 deletions
diff --git a/src/lib/colour_conversion.cc b/src/lib/colour_conversion.cc
new file mode 100644
index 000000000..96dc0e2c9
--- /dev/null
+++ b/src/lib/colour_conversion.cc
@@ -0,0 +1,101 @@
+/*
+ Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/lexical_cast.hpp>
+#include <libxml++/libxml++.h>
+#include <libdcp/colour_matrix.h>
+#include <libcxml/cxml.h>
+#include "colour_conversion.h"
+
+#include "i18n.h"
+
+using std::list;
+using std::string;
+using boost::shared_ptr;
+using boost::lexical_cast;
+
+ColourConversion::ColourConversion ()
+ : name (_("Untitled"))
+ , input_gamma (2.4)
+ , input_gamma_linearised (true)
+ , matrix (3, 3)
+ , output_gamma (2.6)
+{
+ for (int i = 0; i < 3; ++i) {
+ for (int j = 0; j < 3; ++j) {
+ matrix (i, j) = libdcp::colour_matrix::xyz_to_rgb[i][j];
+ }
+ }
+}
+
+ColourConversion::ColourConversion (string n, float i, bool il, float const m[3][3], float o)
+ : name (n)
+ , input_gamma (i)
+ , input_gamma_linearised (il)
+ , matrix (3, 3)
+ , output_gamma (o)
+{
+ for (int i = 0; i < 3; ++i) {
+ for (int j = 0; j < 3; ++j) {
+ matrix (i, j) = m[i][j];
+ }
+ }
+}
+
+ColourConversion::ColourConversion (shared_ptr<cxml::Node> node)
+ : matrix (3, 3)
+{
+ name = node->string_child ("Name");
+ input_gamma = node->number_child<float> ("InputGamma");
+ input_gamma_linearised = node->bool_child ("InputGammaLinearised");
+
+ for (int i = 0; i < 3; ++i) {
+ for (int j = 0; j < 3; ++j) {
+ matrix (i, j) = 0;
+ }
+ }
+
+ list<shared_ptr<cxml::Node> > m = node->node_children ("Matrix");
+ for (list<shared_ptr<cxml::Node> >::iterator i = m.begin(); i != m.end(); ++i) {
+ int const ti = (*i)->number_attribute<int> ("i");
+ int const tj = (*i)->number_attribute<int> ("j");
+ matrix(ti, tj) = lexical_cast<float> ((*i)->content ());
+ }
+
+ output_gamma = node->number_child<float> ("OutputGamma");
+}
+
+void
+ColourConversion::as_xml (xmlpp::Node* node) const
+{
+ node->add_child("Name")->add_child_text (name);
+ node->add_child("InputGamma")->add_child_text (lexical_cast<string> (input_gamma));
+ node->add_child("InputGammaLinearised")->add_child_text (input_gamma_linearised ? "1" : "0");
+
+ for (int i = 0; i < 3; ++i) {
+ for (int j = 0; j < 3; ++j) {
+ xmlpp::Element* m = node->add_child("Matrix");
+ m->set_attribute ("i", lexical_cast<string> (i));
+ m->set_attribute ("j", lexical_cast<string> (j));
+ m->add_child_text (lexical_cast<string> (matrix (i, j)));
+ }
+ }
+
+ node->add_child("OutputGamma")->add_child_text (lexical_cast<string> (output_gamma));
+}
diff --git a/src/lib/colour_conversion.h b/src/lib/colour_conversion.h
new file mode 100644
index 000000000..ed89f8c63
--- /dev/null
+++ b/src/lib/colour_conversion.h
@@ -0,0 +1,45 @@
+/*
+ Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <boost/utility.hpp>
+#include <boost/numeric/ublas/matrix.hpp>
+
+namespace cxml {
+ class Node;
+}
+
+namespace xmlpp {
+ class Node;
+}
+
+class ColourConversion : public boost::noncopyable
+{
+public:
+ ColourConversion ();
+ ColourConversion (std::string, float, bool, float const matrix[3][3], float);
+ ColourConversion (boost::shared_ptr<cxml::Node>);
+
+ void as_xml (xmlpp::Node *) const;
+
+ std::string name;
+ float input_gamma;
+ bool input_gamma_linearised;
+ boost::numeric::ublas::matrix<float> matrix;
+ float output_gamma;
+};
diff --git a/src/lib/config.cc b/src/lib/config.cc
index 29b63b5c8..8f4e5aed0 100644
--- a/src/lib/config.cc
+++ b/src/lib/config.cc
@@ -22,6 +22,7 @@
#include <fstream>
#include <glib.h>
#include <boost/filesystem.hpp>
+#include <libdcp/colour_matrix.h>
#include <libcxml/cxml.h>
#include "config.h"
#include "server.h"
@@ -30,6 +31,7 @@
#include "ratio.h"
#include "dcp_content_type.h"
#include "sound_processor.h"
+#include "colour_conversion.h"
#include "i18n.h"
@@ -62,6 +64,8 @@ Config::Config ()
_allowed_dcp_frame_rates.push_back (48);
_allowed_dcp_frame_rates.push_back (50);
_allowed_dcp_frame_rates.push_back (60);
+
+ _colour_conversions.push_back (shared_ptr<ColourConversion> (new ColourConversion (_("sRGB"), 2.4, true, libdcp::colour_matrix::xyz_to_rgb, 2.6)));
}
void
@@ -81,7 +85,7 @@ Config::read ()
list<shared_ptr<cxml::Node> > servers = f.node_children ("Server");
for (list<shared_ptr<cxml::Node> >::iterator i = servers.begin(); i != servers.end(); ++i) {
- _servers.push_back (new ServerDescription (*i));
+ _servers.push_back (shared_ptr<ServerDescription> (new ServerDescription (*i)));
}
_tms_ip = f.string_child ("TMSIP");
@@ -111,7 +115,17 @@ Config::read ()
_default_dci_metadata = DCIMetadata (f.node_child ("DCIMetadata"));
_default_still_length = f.optional_number_child<int>("DefaultStillLength").get_value_or (10);
- _default_j2k_bandwidth = f.optional_number_child<int>("DefaultJ2KBandwidth").get_value_or (200000000);
+ _default_j2k_bandwidth = f.optional_number_child<int>("DefaultJ2KBandwidth").get_value_or (200000000);
+
+ list<shared_ptr<cxml::Node> > cc = f.node_children ("ColourConversion");
+
+ if (!cc.empty ()) {
+ _colour_conversions.clear ();
+ }
+
+ for (list<shared_ptr<cxml::Node> >::iterator i = cc.begin(); i != cc.end(); ++i) {
+ _colour_conversions.push_back (shared_ptr<ColourConversion> (new ColourConversion (*i)));
+ }
}
void
@@ -217,7 +231,7 @@ Config::write () const
root->add_child("DefaultDirectory")->add_child_text (_default_directory);
root->add_child("ServerPort")->add_child_text (lexical_cast<string> (_server_port));
- for (vector<ServerDescription*>::const_iterator i = _servers.begin(); i != _servers.end(); ++i) {
+ for (vector<shared_ptr<ServerDescription> >::const_iterator i = _servers.begin(); i != _servers.end(); ++i) {
(*i)->as_xml (root->add_child ("Server"));
}
@@ -245,6 +259,10 @@ Config::write () const
root->add_child("DefaultStillLength")->add_child_text (lexical_cast<string> (_default_still_length));
root->add_child("DefaultJ2KBandwidth")->add_child_text (lexical_cast<string> (_default_j2k_bandwidth));
+ for (vector<shared_ptr<ColourConversion> >::const_iterator i = _colour_conversions.begin(); i != _colour_conversions.end(); ++i) {
+ (*i)->as_xml (root->add_child ("ColourConversion"));
+ }
+
doc.write_to_file_formatted (file (false));
}
diff --git a/src/lib/config.h b/src/lib/config.h
index 77287e686..40d06a172 100644
--- a/src/lib/config.h
+++ b/src/lib/config.h
@@ -36,6 +36,7 @@ class Filter;
class SoundProcessor;
class DCPContentType;
class Ratio;
+class ColourConversion;
/** @class Config
* @brief A singleton class holding configuration.
@@ -61,7 +62,7 @@ public:
}
/** @return J2K encoding servers to use */
- std::vector<ServerDescription*> servers () const {
+ std::vector<boost::shared_ptr<ServerDescription> > servers () const {
return _servers;
}
@@ -122,6 +123,10 @@ public:
return _default_j2k_bandwidth;
}
+ std::vector<boost::shared_ptr<ColourConversion> > colour_conversions () const {
+ return _colour_conversions;
+ }
+
/** @param n New number of local encoding threads */
void set_num_local_encoding_threads (int n) {
_num_local_encoding_threads = n;
@@ -137,7 +142,7 @@ public:
}
/** @param s New list of servers */
- void set_servers (std::vector<ServerDescription*> s) {
+ void set_servers (std::vector<boost::shared_ptr<ServerDescription> > s) {
_servers = s;
}
@@ -204,6 +209,10 @@ public:
void set_default_j2k_bandwidth (int b) {
_default_j2k_bandwidth = b;
}
+
+ void set_colour_conversions (std::vector<boost::shared_ptr<ColourConversion> > const & c) {
+ _colour_conversions = c;
+ }
void write () const;
@@ -224,7 +233,7 @@ private:
int _server_port;
/** J2K encoding servers to use */
- std::vector<ServerDescription *> _servers;
+ std::vector<boost::shared_ptr<ServerDescription> > _servers;
/** Scaler to use for the "A" part of A/B comparisons */
Scaler const * _reference_scaler;
/** Filters to use for the "A" part of A/B comparisons */
@@ -248,6 +257,7 @@ private:
DCPContentType const * _default_dcp_content_type;
libdcp::XMLMetadata _dcp_metadata;
int _default_j2k_bandwidth;
+ std::vector<boost::shared_ptr<ColourConversion> > _colour_conversions;
/** Singleton instance, or 0 */
static Config* _instance;
diff --git a/src/lib/dcp_video_frame.cc b/src/lib/dcp_video_frame.cc
index 4f6ff9987..53cf1753a 100644
--- a/src/lib/dcp_video_frame.cc
+++ b/src/lib/dcp_video_frame.cc
@@ -213,7 +213,7 @@ DCPVideoFrame::encode_locally ()
* @return Encoded data.
*/
shared_ptr<EncodedData>
-DCPVideoFrame::encode_remotely (ServerDescription const * serv)
+DCPVideoFrame::encode_remotely (boost::shared_ptr<const ServerDescription> serv)
{
boost::asio::io_service io_service;
boost::asio::ip::tcp::resolver resolver (io_service);
diff --git a/src/lib/dcp_video_frame.h b/src/lib/dcp_video_frame.h
index 96a773a6f..18c8fe628 100644
--- a/src/lib/dcp_video_frame.h
+++ b/src/lib/dcp_video_frame.h
@@ -105,7 +105,7 @@ public:
DCPVideoFrame (boost::shared_ptr<const Image>, int, Eyes, int, int, boost::shared_ptr<Log>);
boost::shared_ptr<EncodedData> encode_locally ();
- boost::shared_ptr<EncodedData> encode_remotely (ServerDescription const *);
+ boost::shared_ptr<EncodedData> encode_remotely (boost::shared_ptr<const ServerDescription>);
Eyes eyes () const {
return _eyes;
diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc
index 0c7434220..a1c024799 100644
--- a/src/lib/encoder.cc
+++ b/src/lib/encoder.cc
@@ -71,12 +71,12 @@ void
Encoder::process_begin ()
{
for (int i = 0; i < Config::instance()->num_local_encoding_threads (); ++i) {
- _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, (ServerDescription *) 0)));
+ _threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, shared_ptr<ServerDescription> ())));
}
- vector<ServerDescription*> servers = Config::instance()->servers ();
+ vector<shared_ptr<ServerDescription> > servers = Config::instance()->servers ();
- for (vector<ServerDescription*>::iterator i = servers.begin(); i != servers.end(); ++i) {
+ for (vector<shared_ptr<ServerDescription> >::iterator i = servers.begin(); i != servers.end(); ++i) {
for (int j = 0; j < (*i)->threads (); ++j) {
_threads.push_back (new boost::thread (boost::bind (&Encoder::encoder_thread, this, *i)));
}
@@ -244,7 +244,7 @@ Encoder::terminate_threads ()
}
void
-Encoder::encoder_thread (ServerDescription* server)
+Encoder::encoder_thread (shared_ptr<ServerDescription> server)
{
/* Number of seconds that we currently wait between attempts
to connect to the server; not relevant for localhost
diff --git a/src/lib/encoder.h b/src/lib/encoder.h
index a866a77f1..a4df202a2 100644
--- a/src/lib/encoder.h
+++ b/src/lib/encoder.h
@@ -81,7 +81,7 @@ private:
void frame_done ();
- void encoder_thread (ServerDescription *);
+ void encoder_thread (boost::shared_ptr<ServerDescription>);
void terminate_threads ();
/** Film that we are encoding */
diff --git a/src/lib/server.cc b/src/lib/server.cc
index 37a076a54..54cffc077 100644
--- a/src/lib/server.cc
+++ b/src/lib/server.cc
@@ -68,17 +68,17 @@ ServerDescription::as_xml (xmlpp::Node* root) const
* @param v Metadata.
* @return ServerDescription, or 0.
*/
-ServerDescription *
+shared_ptr<ServerDescription>
ServerDescription::create_from_metadata (string v)
{
vector<string> b;
split (b, v, is_any_of (N_(" ")));
if (b.size() != 2) {
- return 0;
+ return shared_ptr<ServerDescription> ();
}
- return new ServerDescription (b[0], atoi (b[1].c_str ()));
+ return shared_ptr<ServerDescription> (new ServerDescription (b[0], atoi (b[1].c_str ())));
}
Server::Server (shared_ptr<Log> log)
diff --git a/src/lib/server.h b/src/lib/server.h
index e6d374369..6307c1867 100644
--- a/src/lib/server.h
+++ b/src/lib/server.h
@@ -41,6 +41,11 @@ namespace cxml {
class ServerDescription
{
public:
+ ServerDescription ()
+ : _host_name ("")
+ , _threads (1)
+ {}
+
/** @param h Server host name or IP address in string form.
* @param t Number of threads to use on the server.
*/
@@ -73,7 +78,7 @@ public:
void as_xml (xmlpp::Node *) const;
- static ServerDescription * create_from_metadata (std::string v);
+ static boost::shared_ptr<ServerDescription> create_from_metadata (std::string v);
private:
/** server's host name */
diff --git a/src/lib/wscript b/src/lib/wscript
index 04dae7587..6c45d8b1e 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -8,6 +8,7 @@ sources = """
audio_content.cc
audio_decoder.cc
audio_mapping.cc
+ colour_conversion.cc
config.cc
content.cc
content_factory.cc