11b5bf6229b8713dffde89a777cd5181335136f6 from master; default colour conversions...
authorCarl Hetherington <cth@carlh.net>
Mon, 25 May 2015 01:48:32 +0000 (02:48 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 25 May 2015 01:48:32 +0000 (02:48 +0100)
ChangeLog
TO_PORT
src/lib/colour_conversion.cc
src/lib/colour_conversion.h
src/lib/ffmpeg_content.cc
src/lib/ffmpeg_content.h
src/lib/image_content.cc
src/lib/image_content.h
src/lib/video_content.cc
src/lib/video_content.h

index 3067283d2fb64a384d46be9e609772094c539e0f..307068e5b1df2514c549dfbe1d1839324b1b2f2d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-05-25  Carl Hetherington  <cth@carlh.net>
+
+       * Try to set up useful default colour conversions
+       depending on the type and resolution of content (#565).
+
 2015-05-23  Carl Hetherington  <cth@carlh.net>
 
        * Fix failure to import some video MXFs (#566).
diff --git a/TO_PORT b/TO_PORT
index e567a83225b912ad318dfa750bcdf71c28460fe9..ec27f6ec653b134a543553949b2042a2b029e72e 100644 (file)
--- a/TO_PORT
+++ b/TO_PORT
@@ -1,4 +1,3 @@
-823dc6064795fd128bcb2f0229202d507e289324
 994df155c9d1f6256cdcf51c355a74ebad24288b
 ccb883a479cb341c686fc4237763f483d15e1ec5
 8e5f3e2d989a119f41ba4c69434545c0929e92e0
index cb3a92c1a428ffa4988356b7eb06c1bfb4551a4e..bc11071eeb8586cead428a8f7a04baaa96bbe391 100644 (file)
@@ -222,9 +222,10 @@ PresetColourConversion::PresetColourConversion ()
 
 }
 
-PresetColourConversion::PresetColourConversion (string n, dcp::ColourConversion conversion_)
+PresetColourConversion::PresetColourConversion (string n, string i, dcp::ColourConversion conversion_)
        : conversion (conversion_)
        , name (n)
+       , id (i)
 {
 
 }
@@ -257,8 +258,21 @@ operator== (PresetColourConversion const & a, PresetColourConversion const & b)
 void
 PresetColourConversion::setup_colour_conversion_presets ()
 {
-       _presets.push_back (PresetColourConversion (_("sRGB"), dcp::ColourConversion::srgb_to_xyz ()));
-       _presets.push_back (PresetColourConversion (_("Rec. 601"), dcp::ColourConversion::rec601_to_xyz ()));
-       _presets.push_back (PresetColourConversion (_("Rec. 709"), dcp::ColourConversion::rec709_to_xyz ()));
-       _presets.push_back (PresetColourConversion (_("P3"), dcp::ColourConversion::p3_to_xyz ()));
+       _presets.push_back (PresetColourConversion (_("sRGB"), "rgb", dcp::ColourConversion::srgb_to_xyz ()));
+       _presets.push_back (PresetColourConversion (_("Rec. 601"), "rec601", dcp::ColourConversion::rec601_to_xyz ()));
+       _presets.push_back (PresetColourConversion (_("Rec. 709"), "rec709", dcp::ColourConversion::rec709_to_xyz ()));
+       _presets.push_back (PresetColourConversion (_("P3"), "p3", dcp::ColourConversion::p3_to_xyz ()));
 }
+
+PresetColourConversion
+PresetColourConversion::from_id (string s)
+{
+       BOOST_FOREACH (PresetColourConversion const& i, _presets) {
+               if (i.id == s) {
+                       return i;
+               }
+       }
+
+       DCPOMATIC_ASSERT (false);
+}
+
index 1b42dffb7829c43f98baab2ae8fb54baca17f7f2..06a9cf6c3c3d4f1413a82f578101911d43b3d4e0 100644 (file)
@@ -52,16 +52,20 @@ class PresetColourConversion
 {
 public:
        PresetColourConversion ();
-       PresetColourConversion (std::string, dcp::ColourConversion);
+       PresetColourConversion (std::string n, std::string i, dcp::ColourConversion);
        PresetColourConversion (cxml::NodePtr node, int version);
 
        ColourConversion conversion;
        std::string name;
-
+       /** an internal short (non-internationalised) name for this preset */
+       std::string id;
+       
        static std::vector<PresetColourConversion> all () {
                return _presets;
        }
 
+       static PresetColourConversion from_id (std::string id);
+
        static void setup_colour_conversion_presets ();
        
 private:
index a52b53b04099251b8f84a7d1e9446f869c7ffc31..187d61953d34f1e5c1472a8d468f29206187d87f 100644 (file)
@@ -388,3 +388,19 @@ FFmpegContent::has_subtitles () const
 {
        return !subtitle_streams().empty ();
 }
+
+void
+FFmpegContent::set_default_colour_conversion ()
+{
+       dcp::Size const s = video_size ();
+
+       boost::mutex::scoped_lock lm (_mutex);
+
+       if (s.width < 1080) {
+               _colour_conversion = PresetColourConversion::from_id ("rec601").conversion;
+       } else {
+               _colour_conversion = PresetColourConversion::from_id ("rec709").conversion;
+       }
+}
+
+
index d6edb2bdbd10978688c8c9c88bd614b52507baa6..bc1872ac160b380dc20c1509571da635fb5308a7 100644 (file)
@@ -63,6 +63,9 @@ public:
        DCPTime full_length () const;
 
        std::string identifier () const;
+
+       /* VideoContent */
+       void set_default_colour_conversion ();
        
        /* AudioContent */
        int audio_channels () const;
index f9a772e00126c5d49162442ff68c5559820764bb..54ac56eaef17112276554b6ce22a7c1efe35171d 100644 (file)
@@ -174,3 +174,16 @@ ImageContent::set_video_frame_rate (float r)
        signal_changed (VideoContentProperty::VIDEO_FRAME_RATE);
 }
 
+void
+ImageContent::set_default_colour_conversion ()
+{
+       bool const s = still ();
+
+       boost::mutex::scoped_lock lm (_mutex);
+
+       if (s) {
+               _colour_conversion = PresetColourConversion::from_id ("srgb").conversion;
+       } else {
+               _colour_conversion = PresetColourConversion::from_id ("rec709").conversion;
+       }
+}
index 38aa77bf52eddf7ea889b436483c3f585b628292..83a02a166ecd621f7a09bb1560b8f4394cae6fe4 100644 (file)
@@ -44,6 +44,9 @@ public:
        DCPTime full_length () const;
 
        std::string identifier () const;
+
+       /* VideoContent */
+       void set_default_colour_conversion ();
        
        void set_video_length (ContentTime);
        bool still () const;
index 442ee703c01204d8e805fef786bde33dfee4ae3e..891ccecd859e9811c8c8df1295b59a75443d8c1e 100644 (file)
@@ -205,8 +205,9 @@ VideoContent::as_xml (xmlpp::Node* node) const
 void
 VideoContent::set_default_colour_conversion ()
 {
+       /* If there's no better offer we'll use Rec. 709 */
        boost::mutex::scoped_lock lm (_mutex);
-       _colour_conversion = ColourConversion (dcp::ColourConversion::srgb_to_xyz ());
+       _colour_conversion = PresetColourConversion::from_id ("rec709").conversion;
 }
 
 void
@@ -235,6 +236,8 @@ VideoContent::take_from_video_examiner (shared_ptr<VideoExaminer> d)
        shared_ptr<const Film> film = _film.lock ();
        DCPOMATIC_ASSERT (film);
        LOG_GENERAL ("Video length obtained from header as %1 frames", _video_length.frames (_video_frame_rate));
+
+       set_default_colour_conversion ();
        
        signal_changed (VideoContentProperty::VIDEO_SIZE);
        signal_changed (VideoContentProperty::VIDEO_FRAME_RATE);
@@ -562,4 +565,3 @@ VideoContent::processing_description () const
 
        return d.str ();
 }
-
index 0e9f20348635589210ae5204b1076c7a3b791420..ccc61b1f9eba3f15b7cc4521609642545874be45 100644 (file)
@@ -53,6 +53,8 @@ public:
        std::string technical_summary () const;
        virtual std::string identifier () const;
 
+       virtual void set_default_colour_conversion ();
+       
        ContentTime video_length () const {
                boost::mutex::scoped_lock lm (_mutex);
                return _video_length;
@@ -88,7 +90,6 @@ public:
        void set_scale (VideoContentScale);
        void unset_colour_conversion (bool signal = true);
        void set_colour_conversion (ColourConversion);
-       void set_default_colour_conversion ();
 
        void set_fade_in (ContentTime);
        void set_fade_out (ContentTime);
@@ -166,6 +167,7 @@ protected:
 
        ContentTime _video_length;
        float _video_frame_rate;
+       boost::optional<ColourConversion> _colour_conversion;
 
 private:
        friend struct ffmpeg_pts_offset_test;
@@ -179,7 +181,6 @@ private:
        VideoFrameType _video_frame_type;
        Crop _crop;
        VideoContentScale _scale;
-       boost::optional<ColourConversion> _colour_conversion;
        /** Sample aspect ratio obtained from the content file's header,
            if there is one.
        */