diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-07-09 16:41:53 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-07-09 16:41:53 +0100 |
| commit | 424f9d0c70ff0832da0509776da939b2f855cdc1 (patch) | |
| tree | 619620d613bf1b9d8ade700a01df49469812e72b /src | |
| parent | 58c574239f98b03f253934d061d976bdb3e30899 (diff) | |
Use a new ImageProxy to hold J2K data from DCP content.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/dcp_decoder.cc | 27 | ||||
| -rw-r--r-- | src/lib/image_proxy.cc | 76 | ||||
| -rw-r--r-- | src/lib/image_proxy.h | 23 |
3 files changed, 111 insertions, 15 deletions
diff --git a/src/lib/dcp_decoder.cc b/src/lib/dcp_decoder.cc index 1939fc1c9..e23efba3e 100644 --- a/src/lib/dcp_decoder.cc +++ b/src/lib/dcp_decoder.cc @@ -62,23 +62,20 @@ DCPDecoder::pass () shared_ptr<dcp::PictureMXF> mxf = (*_reel)->main_picture()->mxf (); shared_ptr<dcp::MonoPictureMXF> mono = dynamic_pointer_cast<dcp::MonoPictureMXF> (mxf); shared_ptr<dcp::StereoPictureMXF> stereo = dynamic_pointer_cast<dcp::StereoPictureMXF> (mxf); - int64_t const ep = (*_reel)->main_picture()->entry_point (); + int64_t const entry_point = (*_reel)->main_picture()->entry_point (); + int64_t const frame = _next.frames (vfr); if (mono) { - shared_ptr<Image> image (new Image (PIX_FMT_RGB24, mxf->size(), false)); - mono->get_frame (ep + _next.frames (vfr))->rgb_frame (image->data()[0]); - shared_ptr<Image> aligned (new Image (image, true)); - video (shared_ptr<ImageProxy> (new RawImageProxy (aligned, _log)), _next.frames (vfr)); + video (shared_ptr<ImageProxy> (new J2KImageProxy (mono->get_frame (entry_point + frame), mxf->size(), _log)), frame); } else { - - shared_ptr<Image> left (new Image (PIX_FMT_RGB24, mxf->size(), false)); - stereo->get_frame (ep + _next.frames (vfr))->rgb_frame (dcp::EYE_LEFT, left->data()[0]); - shared_ptr<Image> aligned_left (new Image (left, true)); - video (shared_ptr<ImageProxy> (new RawImageProxy (aligned_left, _log)), _next.frames (vfr)); - - shared_ptr<Image> right (new Image (PIX_FMT_RGB24, mxf->size(), false)); - stereo->get_frame (ep + _next.frames (vfr))->rgb_frame (dcp::EYE_RIGHT, right->data()[0]); - shared_ptr<Image> aligned_right (new Image (right, true)); - video (shared_ptr<ImageProxy> (new RawImageProxy (aligned_right, _log)), _next.frames (vfr)); + video ( + shared_ptr<ImageProxy> (new J2KImageProxy (stereo->get_frame (entry_point + frame), mxf->size(), dcp::EYE_LEFT, _log)), + frame + ); + + video ( + shared_ptr<ImageProxy> (new J2KImageProxy (stereo->get_frame (entry_point + frame), mxf->size(), dcp::EYE_RIGHT, _log)), + frame + ); } } diff --git a/src/lib/image_proxy.cc b/src/lib/image_proxy.cc index 039b11133..6215113aa 100644 --- a/src/lib/image_proxy.cc +++ b/src/lib/image_proxy.cc @@ -20,6 +20,8 @@ #include <Magick++.h> #include <dcp/util.h> #include <dcp/raw_convert.h> +#include <dcp/mono_picture_frame.h> +#include <dcp/stereo_picture_frame.h> #include "image_proxy.h" #include "image.h" #include "exceptions.h" @@ -161,6 +163,80 @@ MagickImageProxy::send_binary (shared_ptr<Socket> socket) const socket->write ((uint8_t *) _blob.data (), _blob.length ()); } +J2KImageProxy::J2KImageProxy (shared_ptr<const dcp::MonoPictureFrame> frame, dcp::Size size, shared_ptr<Log> log) + : ImageProxy (log) + , _mono (frame) + , _size (size) +{ + +} + +J2KImageProxy::J2KImageProxy (shared_ptr<const dcp::StereoPictureFrame> frame, dcp::Size size, dcp::Eye eye, shared_ptr<Log> log) + : ImageProxy (log) + , _stereo (frame) + , _size (size) + , _eye (eye) +{ + +} + +J2KImageProxy::J2KImageProxy (shared_ptr<cxml::Node> xml, shared_ptr<Socket> socket, shared_ptr<Log> log) + : ImageProxy (log) +{ + _size = dcp::Size (xml->number_child<int> ("Width"), xml->number_child<int> ("Height")); + if (xml->optional_number_child<int> ("Eye")) { + _eye = static_cast<dcp::Eye> (xml->number_child<int> ("Eye")); + int const left_size = xml->number_child<int> ("LeftSize"); + int const right_size = xml->number_child<int> ("RightSize"); + _stereo.reset (new dcp::StereoPictureFrame ()); + socket->read (_stereo->left_j2k_data(), left_size); + socket->read (_stereo->right_j2k_data(), right_size); + } else { + int const size = xml->number_child<int> ("Size"); + _mono.reset (new dcp::MonoPictureFrame ()); + socket->read (_mono->j2k_data (), size); + } +} + +shared_ptr<Image> +J2KImageProxy::image () +{ + shared_ptr<Image> image (new Image (PIX_FMT_RGB24, _size, false)); + + if (_mono) { + _mono->rgb_frame (image->data()[0]); + } else { + _stereo->rgb_frame (image->data()[0], _eye); + } + + return shared_ptr<Image> (new Image (image, true)); +} + +void +J2KImageProxy::add_metadata (xmlpp::Node* node) const +{ + node->add_child("Width")->add_child_text (dcp::raw_convert<string> (_size.width)); + node->add_child("Height")->add_child_text (dcp::raw_convert<string> (_size.height)); + if (_stereo) { + node->add_child("Eye")->add_child_text (dcp::raw_convert<string> (_eye)); + node->add_child("LeftSize")->add_child_text (dcp::raw_convert<string> (_stereo->left_j2k_size ())); + node->add_child("RightSize")->add_child_text (dcp::raw_convert<string> (_stereo->right_j2k_size ())); + } else { + node->add_child("Size")->add_child_text (dcp::raw_convert<string> (_mono->j2k_size ())); + } +} + +void +J2KImageProxy::send_binary (shared_ptr<Socket> socket) const +{ + if (_mono) { + socket->write (_mono->j2k_data(), size); + } else { + socket->write (_stereo->left_j2k_data(), _stereo->left_j2k_size ()); + socket->write (_stereo->right_j2k_data(), _stereo->right_j2k_size ()); + } +} + shared_ptr<ImageProxy> image_proxy_factory (shared_ptr<cxml::Node> xml, shared_ptr<Socket> socket, shared_ptr<Log> log) { diff --git a/src/lib/image_proxy.h b/src/lib/image_proxy.h index f6212e54f..9807d027d 100644 --- a/src/lib/image_proxy.h +++ b/src/lib/image_proxy.h @@ -34,6 +34,11 @@ namespace cxml { class Node; } +namespace dcp { + class MonoPictureFrame; + class StereoPictureFrame; +} + /** @class ImageProxy * @brief A class which holds an Image, and can produce it on request. * @@ -88,4 +93,22 @@ private: mutable boost::shared_ptr<Image> _image; }; +class J2KImageProxy : public ImageProxy +{ +public: + J2KImageProxy (boost::shared_ptr<const dcp::MonoPictureFrame> frame, dcp::Size, boost::shared_ptr<Log> log); + J2KImageProxy (boost::shared_ptr<const dcp::StereoPictureFrame> frame, dcp::Size, dcp::Eye, boost::shared_ptr<Log> log); + J2KImageProxy (boost::shared_ptr<cxml::Node> xml, boost::shared_ptr<Socket> socket, boost::shared_ptr<Log> log); + + boost::shared_ptr<Image> image () const; + void add_metadata (xmlpp::Node *) const; + void send_binary (boost::shared_ptr<Socket>) const; + +private: + boost::shared_ptr<const dcp::MonoPictureFrame> _mono; + boost::shared_ptr<const dcp::StereoPictureFrame> _stereo; + dcp::Size _size; + dcp::Eye _eye; +}; + boost::shared_ptr<ImageProxy> image_proxy_factory (boost::shared_ptr<cxml::Node> xml, boost::shared_ptr<Socket> socket, boost::shared_ptr<Log> log); |
