Basic adaptations for changes to libdcp1 colour conversion handling.
[dcpomatic.git] / src / lib / dcp_video.cc
index d849866512d4cdc0e983ca42201631fe3fe88d70..cca199b05f793d56e3ba6001856421e0ddf72995 100644 (file)
  *  of images that require encoding.
  */
 
-#include <stdint.h>
-#include <cstring>
-#include <cstdlib>
-#include <stdexcept>
-#include <cstdio>
-#include <iomanip>
-#include <iostream>
-#include <fstream>
-#include <unistd.h>
-#include <errno.h>
-#include <boost/array.hpp>
-#include <boost/asio.hpp>
-#include <boost/filesystem.hpp>
-#include <boost/lexical_cast.hpp>
-#include <dcp/gamma_lut.h>
-#include <dcp/xyz_frame.h>
-#include <dcp/rgb_xyz.h>
-#include <dcp/colour_matrix.h>
-#include <dcp/raw_convert.h>
-#include <libcxml/cxml.h>
 #include "film.h"
 #include "dcp_video.h"
 #include "config.h"
 #include "cross.h"
 #include "player_video.h"
 #include "encoded_data.h"
+#include <libcxml/cxml.h>
+#include <dcp/xyz_frame.h>
+#include <dcp/rgb_xyz.h>
+#include <dcp/colour_matrix.h>
+#include <dcp/raw_convert.h>
+#include <boost/array.hpp>
+#include <boost/asio.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/lexical_cast.hpp>
+#include <stdint.h>
+#include <cstring>
+#include <cstdlib>
+#include <stdexcept>
+#include <cstdio>
+#include <iomanip>
+#include <iostream>
+#include <fstream>
+#include <unistd.h>
+#include <errno.h>
 
 #define LOG_GENERAL(...) _log->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL);
 
@@ -111,26 +110,17 @@ DCPVideo::DCPVideo (shared_ptr<const PlayerVideo> frame, shared_ptr<const cxml::
 shared_ptr<EncodedData>
 DCPVideo::encode_locally ()
 {
-       shared_ptr<dcp::GammaLUT> in_lut = dcp::GammaLUT::cache.get (
-               12, _frame->colour_conversion().input_gamma, _frame->colour_conversion().input_gamma_linearised
-               );
-       
-       /* XXX: libdcp should probably use boost */
-       
-       double matrix[3][3];
-       for (int i = 0; i < 3; ++i) {
-               for (int j = 0; j < 3; ++j) {
-                       matrix[i][j] = _frame->colour_conversion().matrix (i, j);
-               }
+       shared_ptr<dcp::XYZFrame> xyz;
+
+       if (_frame->colour_conversion()) {
+               xyz = dcp::rgb_to_xyz (
+                       _frame->image (AV_PIX_FMT_RGB48LE, _burn_subtitles),
+                       _frame->colour_conversion().get()
+                       );
+       } else {
+               xyz = dcp::xyz_to_xyz (_frame->image (AV_PIX_FMT_RGB48LE, _burn_subtitles));
        }
 
-       shared_ptr<dcp::XYZFrame> xyz = dcp::rgb_to_xyz (
-               _frame->image (_burn_subtitles),
-               in_lut,
-               dcp::GammaLUT::cache.get (16, 1 / _frame->colour_conversion().output_gamma, false),
-               matrix
-               );
-
        /* Set the max image and component sizes based on frame_rate */
        int max_cs_len = ((float) _j2k_bandwidth) / 8 / _frames_per_second;
        if (_frame->eyes() == EYES_LEFT || _frame->eyes() == EYES_RIGHT) {
@@ -315,3 +305,18 @@ DCPVideo::eyes () const
        return _frame->eyes ();
 }
 
+/** @return true if this DCPVideo is definitely the same as another;
+ *  (apart from the frame index), false if it is probably not.
+ */
+bool
+DCPVideo::same (shared_ptr<const DCPVideo> other) const
+{
+       if (_frames_per_second != other->_frames_per_second ||
+           _j2k_bandwidth != other->_j2k_bandwidth ||
+           _resolution != other->_resolution ||
+           _burn_subtitles != other->_burn_subtitles) {
+               return false;
+       }
+
+       return _frame->same (other->_frame);
+}