Change MagickImageProxy to FFmpegImageProxy and make it use FFmpeg
[dcpomatic.git] / src / lib / j2k_image_proxy.cc
index 2489a949925f12ffd535779c0efc2507257d0135..52b6f34f0c351de8acd5c42a70fff7b02ace8023 100644 (file)
@@ -21,6 +21,7 @@
 #include "j2k_image_proxy.h"
 #include "dcpomatic_socket.h"
 #include "image.h"
+#include "dcpomatic_assert.h"
 #include <dcp/raw_convert.h>
 #include <dcp/openjpeg_image.h>
 #include <dcp/mono_picture_frame.h>
@@ -30,7 +31,6 @@
 #include <dcp/j2k.h>
 #include <libcxml/cxml.h>
 #include <libxml++/libxml++.h>
-#include <Magick++.h>
 #include <iostream>
 
 #include "i18n.h"
@@ -38,6 +38,8 @@
 using std::string;
 using std::cout;
 using std::max;
+using std::pair;
+using std::make_pair;
 using boost::shared_ptr;
 using boost::optional;
 using boost::dynamic_pointer_cast;
@@ -50,7 +52,8 @@ J2KImageProxy::J2KImageProxy (boost::filesystem::path path, dcp::Size size, AVPi
        , _size (size)
        , _pixel_format (pixel_format)
 {
-
+       /* ::image assumes 16bpp */
+       DCPOMATIC_ASSERT (_pixel_format == AV_PIX_FMT_RGB48 || _pixel_format == AV_PIX_FMT_XYZ12LE);
 }
 
 J2KImageProxy::J2KImageProxy (
@@ -64,6 +67,8 @@ J2KImageProxy::J2KImageProxy (
        , _pixel_format (pixel_format)
        , _forced_reduction (forced_reduction)
 {
+       /* ::image assumes 16bpp */
+       DCPOMATIC_ASSERT (_pixel_format == AV_PIX_FMT_RGB48 || _pixel_format == AV_PIX_FMT_XYZ12LE);
        memcpy (_data.data().get(), frame->j2k_data(), _data.size ());
 }
 
@@ -79,6 +84,8 @@ J2KImageProxy::J2KImageProxy (
        , _pixel_format (pixel_format)
        , _forced_reduction (forced_reduction)
 {
+       /* ::image assumes 16bpp */
+       DCPOMATIC_ASSERT (_pixel_format == AV_PIX_FMT_RGB48 || _pixel_format == AV_PIX_FMT_XYZ12LE);
        switch (eye) {
        case dcp::EYE_LEFT:
                _data = Data (frame->left_j2k_size ());
@@ -106,13 +113,14 @@ J2KImageProxy::J2KImageProxy (shared_ptr<cxml::Node> xml, shared_ptr<Socket> soc
        socket->read (_data.data().get (), _data.size ());
 }
 
-void
+int
 J2KImageProxy::prepare (optional<dcp::Size> target_size) const
 {
        boost::mutex::scoped_lock lm (_mutex);
 
        if (_decompressed && target_size == _target_size) {
-               return;
+               DCPOMATIC_ASSERT (_reduce);
+               return *_reduce;
        }
 
        int reduce = 0;
@@ -143,12 +151,15 @@ J2KImageProxy::prepare (optional<dcp::Size> target_size) const
        }
 
        _target_size = target_size;
+       _reduce = reduce;
+
+       return reduce;
 }
 
-shared_ptr<Image>
+pair<shared_ptr<Image>, int>
 J2KImageProxy::image (optional<dcp::NoteHandler>, optional<dcp::Size> target_size) const
 {
-       prepare (target_size);
+       int const reduce = prepare (target_size);
 
        shared_ptr<Image> image (new Image (_pixel_format, _decompressed->size(), true));
 
@@ -169,7 +180,7 @@ J2KImageProxy::image (optional<dcp::NoteHandler>, optional<dcp::Size> target_siz
                }
        }
 
-       return image;
+       return make_pair (image, reduce);
 }
 
 void
@@ -210,7 +221,8 @@ J2KImageProxy::J2KImageProxy (Data data, dcp::Size size, AVPixelFormat pixel_for
        , _size (size)
        , _pixel_format (pixel_format)
 {
-
+       /* ::image assumes 16bpp */
+       DCPOMATIC_ASSERT (_pixel_format == AV_PIX_FMT_RGB48 || _pixel_format == AV_PIX_FMT_XYZ12LE);
 }
 
 size_t