Very basics of colour conversion configuration.
[dcpomatic.git] / src / lib / config.cc
index c9ec730f20aa94c03357b56cbd9398e21698eb46..8f4e5aed02763a204593f22cab98ca4ead60ef11 100644 (file)
@@ -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"
 
@@ -38,6 +40,7 @@ using std::ifstream;
 using std::string;
 using std::ofstream;
 using std::list;
+using std::max;
 using boost::shared_ptr;
 using boost::lexical_cast;
 using boost::optional;
@@ -46,13 +49,14 @@ Config* Config::_instance = 0;
 
 /** Construct default configuration */
 Config::Config ()
-       : _num_local_encoding_threads (2)
+       : _num_local_encoding_threads (max (2U, boost::thread::hardware_concurrency()))
        , _server_port (6192)
        , _tms_path (N_("."))
        , _sound_processor (SoundProcessor::from_id (N_("dolby_cp750")))
        , _default_still_length (10)
        , _default_container (Ratio::from_id ("185"))
-       , _default_dcp_content_type (0)
+       , _default_dcp_content_type (DCPContentType::from_dci_name ("TST"))
+       , _default_j2k_bandwidth (200000000)
 {
        _allowed_dcp_frame_rates.push_back (24);
        _allowed_dcp_frame_rates.push_back (25);
@@ -60,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
@@ -79,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");
@@ -109,6 +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);
+
+       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
@@ -214,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"));
        }
 
@@ -240,6 +257,11 @@ Config::write () const
        _default_dci_metadata.as_xml (root->add_child ("DCIMetadata"));
 
        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));
 }