Disable YUV->RGB conversion controls with non-YUV sources (#649).
authorCarl Hetherington <cth@carlh.net>
Fri, 13 Nov 2015 14:12:15 +0000 (14:12 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 13 Nov 2015 14:12:15 +0000 (14:12 +0000)
15 files changed:
ChangeLog
src/lib/dcp_examiner.h
src/lib/ffmpeg_examiner.cc
src/lib/ffmpeg_examiner.h
src/lib/image_examiner.cc
src/lib/image_examiner.h
src/lib/video_content.cc
src/lib/video_content.h
src/lib/video_examiner.h
src/wx/colour_conversion_editor.cc
src/wx/colour_conversion_editor.h
src/wx/content_colour_conversion_dialog.cc
src/wx/content_colour_conversion_dialog.h
src/wx/preset_colour_conversion_dialog.cc
src/wx/video_panel.cc

index a1c4e053ad5cbf98c13ee5160c16e9f913839d71..765b81e4a6eb1179d2277909b52c6b6bd883411e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2015-11-13  c.hetherington  <cth@carlh.net>
 
+       * Disable YUV->RGB conversion controls with non-YUV sources (#649).
+
        * Allow multiple recipients of KDM emails (#745).
 
 2015-11-12  Carl Hetherington  <cth@carlh.net>
index 532bad60c54ba649f91b0958247e8c1474afc4d8..f2609ed3e4b262b72340643c2b23f93455f9d844 100644 (file)
@@ -43,6 +43,10 @@ public:
                return _video_length;
        }
 
+       bool yuv () const {
+               return false;
+       }
+
        std::string name () const {
                return _name;
        }
index 4fd1b6fe8a8495ed9d326036ef07d712fb8efb8a..719e7a2b0863e085fcb6a0308d73e345c8df1bcb 100644 (file)
@@ -332,3 +332,86 @@ FFmpegExaminer::bits_per_pixel () const
 {
        return av_get_bits_per_pixel (av_pix_fmt_desc_get (video_codec_context()->pix_fmt));
 }
+
+bool
+FFmpegExaminer::yuv () const
+{
+       switch (video_codec_context()->pix_fmt) {
+       case AV_PIX_FMT_YUV420P:
+       case AV_PIX_FMT_YUYV422:
+       case AV_PIX_FMT_YUV422P:
+       case AV_PIX_FMT_YUV444P:
+       case AV_PIX_FMT_YUV410P:
+       case AV_PIX_FMT_YUV411P:
+       case AV_PIX_FMT_YUVJ420P:
+       case AV_PIX_FMT_YUVJ422P:
+       case AV_PIX_FMT_YUVJ444P:
+       case AV_PIX_FMT_UYVY422:
+       case AV_PIX_FMT_UYYVYY411:
+       case AV_PIX_FMT_NV12:
+       case AV_PIX_FMT_NV21:
+       case AV_PIX_FMT_YUV440P:
+       case AV_PIX_FMT_YUVJ440P:
+       case AV_PIX_FMT_YUVA420P:
+       case AV_PIX_FMT_YUV420P16LE:
+       case AV_PIX_FMT_YUV420P16BE:
+       case AV_PIX_FMT_YUV422P16LE:
+       case AV_PIX_FMT_YUV422P16BE:
+       case AV_PIX_FMT_YUV444P16LE:
+       case AV_PIX_FMT_YUV444P16BE:
+       case AV_PIX_FMT_YUV420P9BE:
+       case AV_PIX_FMT_YUV420P9LE:
+       case AV_PIX_FMT_YUV420P10BE:
+       case AV_PIX_FMT_YUV420P10LE:
+       case AV_PIX_FMT_YUV422P10BE:
+       case AV_PIX_FMT_YUV422P10LE:
+       case AV_PIX_FMT_YUV444P9BE:
+       case AV_PIX_FMT_YUV444P9LE:
+       case AV_PIX_FMT_YUV444P10BE:
+       case AV_PIX_FMT_YUV444P10LE:
+       case AV_PIX_FMT_YUV422P9BE:
+       case AV_PIX_FMT_YUV422P9LE:
+       case AV_PIX_FMT_YUVA422P_LIBAV:
+       case AV_PIX_FMT_YUVA444P_LIBAV:
+       case AV_PIX_FMT_YUVA420P9BE:
+       case AV_PIX_FMT_YUVA420P9LE:
+       case AV_PIX_FMT_YUVA422P9BE:
+       case AV_PIX_FMT_YUVA422P9LE:
+       case AV_PIX_FMT_YUVA444P9BE:
+       case AV_PIX_FMT_YUVA444P9LE:
+       case AV_PIX_FMT_YUVA420P10BE:
+       case AV_PIX_FMT_YUVA420P10LE:
+       case AV_PIX_FMT_YUVA422P10BE:
+       case AV_PIX_FMT_YUVA422P10LE:
+       case AV_PIX_FMT_YUVA444P10BE:
+       case AV_PIX_FMT_YUVA444P10LE:
+       case AV_PIX_FMT_YUVA420P16BE:
+       case AV_PIX_FMT_YUVA420P16LE:
+       case AV_PIX_FMT_YUVA422P16BE:
+       case AV_PIX_FMT_YUVA422P16LE:
+       case AV_PIX_FMT_YUVA444P16BE:
+       case AV_PIX_FMT_YUVA444P16LE:
+       case AV_PIX_FMT_NV16:
+       case AV_PIX_FMT_NV20LE:
+       case AV_PIX_FMT_NV20BE:
+       case AV_PIX_FMT_YVYU422:
+       case AV_PIX_FMT_YUVA444P:
+       case AV_PIX_FMT_YUVA422P:
+       case AV_PIX_FMT_YUV420P12BE:
+       case AV_PIX_FMT_YUV420P12LE:
+       case AV_PIX_FMT_YUV420P14BE:
+       case AV_PIX_FMT_YUV420P14LE:
+       case AV_PIX_FMT_YUV422P12BE:
+       case AV_PIX_FMT_YUV422P12LE:
+       case AV_PIX_FMT_YUV422P14BE:
+       case AV_PIX_FMT_YUV422P14LE:
+       case AV_PIX_FMT_YUV444P12BE:
+       case AV_PIX_FMT_YUV444P12LE:
+       case AV_PIX_FMT_YUV444P14BE:
+       case AV_PIX_FMT_YUV444P14LE:
+       case AV_PIX_FMT_YUVJ411P:
+               return true;
+       default:
+               return false;
+       }
+}
index 27bff08b47426749eeee7201234a1aed4e955238..6e218512917813a5fe91ddbb7501c1b2ed3345a9 100644 (file)
@@ -35,6 +35,7 @@ public:
        dcp::Size video_size () const;
        Frame video_length () const;
        boost::optional<double> sample_aspect_ratio () const;
+       bool yuv () const;
 
        std::vector<boost::shared_ptr<FFmpegSubtitleStream> > subtitle_streams () const {
                return _subtitle_streams;
index 376491738ef7b004fb2dd5d8dd37ef0c5bf9a96b..73d004d7f9571fafad9f601db9c5f1cb58700a90 100644 (file)
@@ -92,3 +92,13 @@ ImageExaminer::video_frame_rate () const
        /* Don't know */
        return optional<double> ();
 }
+
+bool
+ImageExaminer::yuv () const
+{
+       /* We never convert ImageSource from YUV to RGB (though maybe sometimes we should)
+          so it makes sense to just say they are never YUV so the option of a conversion
+          to RGB is not offered.
+       */
+       return false;
+}
index 792c7b4ebe84a73367f99a60a3f8f884732d34fb..cd8964d0adc7572979b81369b25be41cc1392f46 100644 (file)
@@ -31,10 +31,12 @@ public:
        Frame video_length () const {
                return _video_length;
        }
+       bool yuv () const;
 
 private:
        boost::weak_ptr<const Film> _film;
        boost::shared_ptr<const ImageContent> _image_content;
        boost::optional<dcp::Size> _video_size;
        Frame _video_length;
+       bool _yuv;
 };
index 498d5b9db7f3215dd870bb40db3fc2c4ff29e646..78b3200341e84cc02c0867792b522fec5fd15a8f 100644 (file)
@@ -69,6 +69,7 @@ VideoContent::VideoContent (shared_ptr<const Film> film)
        , _video_length (0)
        , _video_frame_type (VIDEO_FRAME_TYPE_2D)
        , _scale (VideoContentScale (Ratio::from_id ("178")))
+       , _yuv (true)
        , _fade_in (0)
        , _fade_out (0)
 {
@@ -80,6 +81,7 @@ VideoContent::VideoContent (shared_ptr<const Film> film, DCPTime s, Frame len)
        , _video_length (len)
        , _video_frame_type (VIDEO_FRAME_TYPE_2D)
        , _scale (VideoContentScale (Ratio::from_id ("178")))
+       , _yuv (true)
        , _fade_in (0)
        , _fade_out (0)
 {
@@ -91,6 +93,7 @@ VideoContent::VideoContent (shared_ptr<const Film> film, boost::filesystem::path
        , _video_length (0)
        , _video_frame_type (VIDEO_FRAME_TYPE_2D)
        , _scale (VideoContentScale (Ratio::from_id ("178")))
+       , _yuv (true)
        , _fade_in (0)
        , _fade_out (0)
 {
@@ -124,6 +127,9 @@ VideoContent::VideoContent (shared_ptr<const Film> film, cxml::ConstNodePtr node
        if (node->optional_node_child ("ColourConversion")) {
                _colour_conversion = ColourConversion (node->node_child ("ColourConversion"), version);
        }
+
+       _yuv = node->optional_bool_child("YUV").get_value_or (true);
+
        if (version >= 32) {
                _fade_in = node->number_child<Frame> ("FadeIn");
                _fade_out = node->number_child<Frame> ("FadeOut");
@@ -135,6 +141,7 @@ VideoContent::VideoContent (shared_ptr<const Film> film, cxml::ConstNodePtr node
 VideoContent::VideoContent (shared_ptr<const Film> film, vector<shared_ptr<Content> > c)
        : Content (film, c)
        , _video_length (0)
+       , _yuv (false)
 {
        shared_ptr<VideoContent> ref = dynamic_pointer_cast<VideoContent> (c[0]);
        DCPOMATIC_ASSERT (ref);
@@ -171,6 +178,10 @@ VideoContent::VideoContent (shared_ptr<const Film> film, vector<shared_ptr<Conte
                }
 
                _video_length += vc->video_length ();
+
+               if (vc->yuv ()) {
+                       _yuv = true;
+               }
        }
 
        _video_size = ref->video_size ();
@@ -202,6 +213,7 @@ VideoContent::as_xml (xmlpp::Node* node) const
        if (_colour_conversion) {
                _colour_conversion.get().as_xml (node->add_child("ColourConversion"));
        }
+       node->add_child("YUV")->add_child_text (_yuv ? "1" : "0");
        node->add_child("FadeIn")->add_child_text (raw_convert<string> (_fade_in));
        node->add_child("FadeOut")->add_child_text (raw_convert<string> (_fade_out));
 }
@@ -222,6 +234,7 @@ VideoContent::take_from_video_examiner (shared_ptr<VideoExaminer> d)
        optional<double> const vfr = d->video_frame_rate ();
        Frame vl = d->video_length ();
        optional<double> const ar = d->sample_aspect_ratio ();
+       bool const yuv = d->yuv ();
 
        {
                boost::mutex::scoped_lock lm (_mutex);
@@ -229,6 +242,7 @@ VideoContent::take_from_video_examiner (shared_ptr<VideoExaminer> d)
                _video_frame_rate = vfr;
                _video_length = vl;
                _sample_aspect_ratio = ar;
+               _yuv = yuv;
 
                /* Guess correct scale from size and sample aspect ratio */
                _scale = VideoContentScale (
index 309fa067072fcc2ed5eecee98abab55a072d0095..6896551314eaaf9c2a96ae7d5b28af2e1781d044 100644 (file)
@@ -150,6 +150,11 @@ public:
                return _sample_aspect_ratio;
        }
 
+       bool yuv () const {
+               boost::mutex::scoped_lock lm (_mutex);
+               return _yuv;
+       }
+
        Frame fade_in () const {
                boost::mutex::scoped_lock lm (_mutex);
                return _fade_in;
@@ -197,6 +202,7 @@ private:
            if there is one.
        */
        boost::optional<double> _sample_aspect_ratio;
+       bool _yuv;
        Frame _fade_in;
        Frame _fade_out;
 };
index 66d3ae5b57ea2b056a9678ac737b660de38ee0c9..3c8f71757f1cbce6d6a2c226bb023dee28ea5ed7 100644 (file)
@@ -38,4 +38,5 @@ public:
        virtual boost::optional<double> sample_aspect_ratio () const {
                return boost::optional<double> ();
        }
+       virtual bool yuv () const = 0;
 };
index 92dd417a534d51a1c61999bc429d78e41ea5b35f..c24cc689e81d4dfa0549f1a10c889b2cb313954d 100644 (file)
@@ -35,7 +35,7 @@ using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
 using boost::lexical_cast;
 
-ColourConversionEditor::ColourConversionEditor (wxWindow* parent)
+ColourConversionEditor::ColourConversionEditor (wxWindow* parent, bool yuv)
        : wxPanel (parent, wxID_ANY)
 {
        wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
@@ -92,15 +92,21 @@ ColourConversionEditor::ColourConversionEditor (wxWindow* parent)
 
        /* YUV to RGB conversion */
 
-       subhead (table, this, _("YUV to RGB conversion"), r);
+       wxStaticText* yuv_heading = subhead (table, this, _("YUV to RGB conversion"), r);
 
-       add_label_to_sizer (table, this, _("YUV to RGB matrix"), true, wxGBPosition (r, 0));
+       wxStaticText* yuv_label = add_label_to_sizer (table, this, _("YUV to RGB matrix"), true, wxGBPosition (r, 0));
        _yuv_to_rgb = new wxChoice (this, wxID_ANY);
        _yuv_to_rgb->Append (_("Rec. 601"));
        _yuv_to_rgb->Append (_("Rec. 709"));
        table->Add (_yuv_to_rgb, wxGBPosition (r, 1));
        ++r;
 
+       if (!yuv) {
+               yuv_heading->Enable (false);
+               yuv_label->Enable (false);
+               _yuv_to_rgb->Enable (false);
+       }
+
        /* RGB to XYZ conversion */
 
        subhead (table, this, _("RGB to XYZ conversion"), r);
@@ -207,13 +213,14 @@ ColourConversionEditor::ColourConversionEditor (wxWindow* parent)
        _yuv_to_rgb->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&ColourConversionEditor::changed, this));
 }
 
-void
+wxStaticText *
 ColourConversionEditor::subhead (wxGridBagSizer* sizer, wxWindow* parent, wxString text, int& row) const
 {
        wxStaticText* m = new wxStaticText (parent, wxID_ANY, wxT (""));
        m->SetLabelMarkup ("<b>" + text + "</b>");
        sizer->Add (m, wxGBPosition (row, 0), wxGBSpan (1, 3), wxALIGN_CENTER_VERTICAL | wxTOP, 12);
        ++row;
+       return m;
 }
 
 void
index a987cb3a9029ad045e11dd2cb90d529c6a041423..918f2a7d06804d7f500c49ac8ef3c3a3a1707e14 100644 (file)
@@ -29,7 +29,7 @@ class ColourConversion;
 class ColourConversionEditor : public wxPanel
 {
 public:
-       ColourConversionEditor (wxWindow *);
+       ColourConversionEditor (wxWindow *, bool yuv);
 
        void set (ColourConversion);
        ColourConversion get () const;
@@ -43,7 +43,7 @@ private:
        void adjusted_white_changed ();
        void update_rgb_to_xyz ();
        void update_bradford ();
-       void subhead (wxGridBagSizer* sizer, wxWindow* parent, wxString text, int& row) const;
+       wxStaticText* subhead (wxGridBagSizer* sizer, wxWindow* parent, wxString text, int& row) const;
 
        void set_text_ctrl (wxTextCtrl *, double);
        void set_spin_ctrl (wxSpinCtrlDouble *, double);
index e4e16157d3b648b67350a95bbeff0d582d145a05..651e1dc6690c3bd032bbc0be69497cf1a2c653b8 100644 (file)
@@ -32,9 +32,9 @@ using std::vector;
 using std::cout;
 using boost::optional;
 
-ContentColourConversionDialog::ContentColourConversionDialog (wxWindow* parent)
+ContentColourConversionDialog::ContentColourConversionDialog (wxWindow* parent, bool yuv)
        : wxDialog (parent, wxID_ANY, _("Colour conversion"))
-       , _editor (new ColourConversionEditor (this))
+       , _editor (new ColourConversionEditor (this, yuv))
        , _setting (false)
 {
        wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
index f5687a060fccd8196227bcb570655f3170d3bd0b..4207ee08282890f28300722358c24107b211d054 100644 (file)
@@ -25,7 +25,7 @@ class ColourConversionEditor;
 class ContentColourConversionDialog : public wxDialog
 {
 public:
-       ContentColourConversionDialog (wxWindow *);
+       ContentColourConversionDialog (wxWindow *, bool yuv);
 
        void set (ColourConversion);
        ColourConversion get () const;
index 9656ff5dcaefead6ad0398f1f581d61f1bec0ef0..d77cc8ad46698e2ad0ec67b75687aff5e0b08dc0 100644 (file)
@@ -29,7 +29,7 @@ using std::cout;
 
 PresetColourConversionDialog::PresetColourConversionDialog (wxWindow* parent)
        : wxDialog (parent, wxID_ANY, _("Colour conversion"))
-       , _editor (new ColourConversionEditor (this))
+       , _editor (new ColourConversionEditor (this, true))
 {
        wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
        SetSizer (overall_sizer);
index 227f6c6477e8c6e375adb0f88c438b3a44566012..a2c35ec764e0094559da4241ecca952d352416ee 100644 (file)
@@ -402,7 +402,7 @@ VideoPanel::edit_colour_conversion_clicked ()
                return;
        }
 
-       ContentColourConversionDialog* d = new ContentColourConversionDialog (this);
+       ContentColourConversionDialog* d = new ContentColourConversionDialog (this, vc.front()->yuv ());
        d->set (vc.front()->colour_conversion().get_value_or (PresetColourConversion::all().front ().conversion));
        d->ShowModal ();
        vc.front()->set_colour_conversion (d->get ());