Cleanup: move convert_to_xyz().
authorCarl Hetherington <cth@carlh.net>
Thu, 4 Aug 2022 22:28:59 +0000 (00:28 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 11 Aug 2022 20:41:58 +0000 (22:41 +0200)
I don't know what the idea was in putting it in DCPVideo but
it doesn't seem to make any sense.

src/lib/dcp_video.cc
src/lib/dcp_video.h
src/lib/player_video.cc
src/lib/player_video.h
src/wx/video_waveform_plot.cc

index 14f23bd3782e108e8a27c596a926880eccdfbecb..e4977726535b47f6c34d56ad0b253ca79c6f7d66 100644 (file)
@@ -100,26 +100,6 @@ DCPVideo::DCPVideo (shared_ptr<const PlayerVideo> frame, shared_ptr<const cxml::
        _resolution = Resolution (node->optional_number_child<int>("Resolution").get_value_or(static_cast<int>(Resolution::TWO_K)));
 }
 
-shared_ptr<dcp::OpenJPEGImage>
-DCPVideo::convert_to_xyz (shared_ptr<const PlayerVideo> frame, dcp::NoteHandler note)
-{
-       shared_ptr<dcp::OpenJPEGImage> xyz;
-
-       auto image = frame->image (bind(&PlayerVideo::keep_xyz_or_rgb, _1), VideoRange::FULL, false);
-       if (frame->colour_conversion()) {
-               xyz = dcp::rgb_to_xyz (
-                       image->data()[0],
-                       image->size(),
-                       image->stride()[0],
-                       frame->colour_conversion().get(),
-                       note
-                       );
-       } else {
-               xyz = make_shared<dcp::OpenJPEGImage>(image->data()[0], image->size(), image->stride()[0]);
-       }
-
-       return xyz;
-}
 
 /** J2K-encode this frame on the local host.
  *  @return Encoded data.
@@ -134,7 +114,7 @@ DCPVideo::encode_locally () const
        int const minimum_size = 16384;
        LOG_DEBUG_ENCODE("Using minimum frame size %1", minimum_size);
 
-       auto xyz = convert_to_xyz (_frame, boost::bind(&Log::dcp_log, dcpomatic_log.get(), _1, _2));
+       auto xyz = _frame->convert_to_xyz(boost::bind(&Log::dcp_log, dcpomatic_log.get(), _1, _2));
        int noise_amount = 2;
        int pixel_skip = 16;
        while (true) {
@@ -159,7 +139,7 @@ DCPVideo::encode_locally () const
                 * convert_to_xyz() again because compress_j2k() corrupts its xyz parameter.
                 */
 
-               xyz = convert_to_xyz (_frame, boost::bind(&Log::dcp_log, dcpomatic_log.get(), _1, _2));
+               xyz = _frame->convert_to_xyz(boost::bind(&Log::dcp_log, dcpomatic_log.get(), _1, _2));
                auto size = xyz->size ();
                auto pixels = size.width * size.height;
                dcpomatic::RNG rng(42);
index 3bd516ccd4ea676567e80ac70880d39b382568c6..14440deb928e7bf57f1d56b516a0a571e45d754a 100644 (file)
@@ -59,8 +59,6 @@ public:
 
        bool same (std::shared_ptr<const DCPVideo> other) const;
 
-       static std::shared_ptr<dcp::OpenJPEGImage> convert_to_xyz (std::shared_ptr<const PlayerVideo> frame, dcp::NoteHandler note);
-
 private:
 
        void add_metadata (xmlpp::Element *) const;
index d45bf9f432b90c996feb870baf1580fc3a5796a4..04aeffc29535b06833075e77ffedd5163b871907 100644 (file)
@@ -27,7 +27,9 @@
 #include "player.h"
 #include "player_video.h"
 #include "video_content.h"
+#include <dcp/openjpeg_image.h>
 #include <dcp/raw_convert.h>
+#include <dcp/rgb_xyz.h>
 extern "C" {
 #include <libavutil/pixfmt.h>
 }
@@ -43,6 +45,9 @@ using std::shared_ptr;
 using std::string;
 using std::weak_ptr;
 using boost::optional;
+#if BOOST_VERSION >= 106100
+using namespace boost::placeholders;
+#endif
 using dcp::Data;
 using dcp::raw_convert;
 
@@ -374,3 +379,22 @@ PlayerVideo::reset_metadata (shared_ptr<const Film> film, dcp::Size player_video
 
        return true;
 }
+
+
+shared_ptr<dcp::OpenJPEGImage>
+PlayerVideo::convert_to_xyz(dcp::NoteHandler note) const
+{
+       auto frame_image = image(bind(&PlayerVideo::keep_xyz_or_rgb, _1), VideoRange::FULL, false);
+       if (colour_conversion()) {
+               return dcp::rgb_to_xyz (
+                       frame_image->data()[0],
+                       frame_image->size(),
+                       frame_image->stride()[0],
+                       colour_conversion().get(),
+                       note
+                       );
+       } else {
+               return make_shared<dcp::OpenJPEGImage>(frame_image->data()[0], frame_image->size(), frame_image->stride()[0]);
+       }
+}
+
index f2781c1a0c51c3e099dd0009604e04a89ce2c3df..731c1a6958b0d4777fc89b53ecb55cc422a673c6 100644 (file)
@@ -90,6 +90,9 @@ public:
        bool has_j2k () const;
        std::shared_ptr<const dcp::Data> j2k () const;
 
+       std::shared_ptr<dcp::OpenJPEGImage> convert_to_xyz(dcp::NoteHandler note) const;
+
+
        Eyes eyes () const {
                return _eyes;
        }
index 8e3284682485833dc7395c65b75e1c1edeb3be14..c14e5f418a7dcc0de66f9bb9af352597ae4ad61a 100644 (file)
@@ -198,7 +198,7 @@ VideoWaveformPlot::set_image (shared_ptr<PlayerVideo> image)
        /* We must copy the PlayerVideo here as we will call ::image() on it, potentially
           with a different pixel_format than was used when ::prepare() was called.
        */
-       _image = DCPVideo::convert_to_xyz (image->shallow_copy(), [](dcp::NoteType, string) {});
+       _image = image->shallow_copy()->convert_to_xyz([](dcp::NoteType, string) {});
        _dirty = true;
        Refresh ();
 }