Basic reading of Interop/SMPTE image subtitles with a test for Interop.
authorCarl Hetherington <cth@carlh.net>
Mon, 9 Jul 2018 01:30:18 +0000 (02:30 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 9 Jul 2018 01:30:18 +0000 (02:30 +0100)
src/interop_subtitle_asset.cc
src/smpte_subtitle_asset.cc
src/subtitle_image.h
test/read_interop_subtitle_test.cc

index 1cd995638ac1979ad85b7d31dc683627fd815093..e2873fb656853c7f31e671709f47bfbc0a262318 100644 (file)
@@ -80,7 +80,12 @@ InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file)
                }
        }
 
-       /* XXX: now find SubtitleImages in _subtitles and load their PNG */
+       BOOST_FOREACH (shared_ptr<Subtitle> i, _subtitles) {
+               shared_ptr<SubtitleImage> si = dynamic_pointer_cast<SubtitleImage>(i);
+               if (si) {
+                       si->set_png_image (Data (file.parent_path() / String::compose("%1.png", si->id())));
+               }
+       }
 }
 
 InteropSubtitleAsset::InteropSubtitleAsset ()
index 91afec143840dfd617aef7aa522a67e72ec54aa8..b568139a952d573f0fb38f8622c19d77d48c93d3 100644 (file)
@@ -173,17 +173,19 @@ SMPTESubtitleAsset::read_mxf_descriptor (shared_ptr<ASDCP::TimedText::MXFReader>
                i != descriptor.ResourceList.end();
                ++i) {
 
-               if (i->Type == ASDCP::TimedText::MT_OPENTYPE) {
-                       ASDCP::TimedText::FrameBuffer buffer;
-                       buffer.Capacity (10 * 1024 * 1024);
-                       reader->ReadAncillaryResource (i->ResourceID, buffer, dec->context(), dec->hmac());
+               ASDCP::TimedText::FrameBuffer buffer;
+               buffer.Capacity (10 * 1024 * 1024);
+               reader->ReadAncillaryResource (i->ResourceID, buffer, dec->context(), dec->hmac());
 
-                       char id[64];
-                       Kumu::bin2UUIDhex (i->ResourceID, ASDCP::UUIDlen, id, sizeof (id));
+               char id[64];
+               Kumu::bin2UUIDhex (i->ResourceID, ASDCP::UUIDlen, id, sizeof (id));
 
-                       shared_array<uint8_t> data (new uint8_t[buffer.Size()]);
-                       memcpy (data.get(), buffer.RoData(), buffer.Size());
+               shared_array<uint8_t> data (new uint8_t[buffer.Size()]);
+               memcpy (data.get(), buffer.RoData(), buffer.Size());
 
+               switch (i->Type) {
+               case ASDCP::TimedText::MT_OPENTYPE:
+               {
                        list<shared_ptr<SMPTELoadFontNode> >::const_iterator j = _load_font_nodes.begin ();
                        while (j != _load_font_nodes.end() && (*j)->urn != id) {
                                ++j;
@@ -192,10 +194,24 @@ SMPTESubtitleAsset::read_mxf_descriptor (shared_ptr<ASDCP::TimedText::MXFReader>
                        if (j != _load_font_nodes.end ()) {
                                _fonts.push_back (Font ((*j)->id, (*j)->urn, Data (data, buffer.Size ())));
                        }
+                       break;
                }
-       }
+               case ASDCP::TimedText::MT_PNG:
+               {
+                       list<shared_ptr<Subtitle> >::const_iterator j = _subtitles.begin ();
+                       while (j != _subtitles.end() && ((!dynamic_pointer_cast<SubtitleImage>(*j)) || dynamic_pointer_cast<SubtitleImage>(*j)->id() != id)) {
+                               ++j;
+                       }
 
-       /* XXX: load PNG and attach them to _subtitles */
+                       if (j != _subtitles.end()) {
+                               dynamic_pointer_cast<SubtitleImage>(*j)->set_png_image (Data(data, buffer.Size()));
+                       }
+                       break;
+               }
+               default:
+                       break;
+               }
+       }
 
        /* Get intrinsic duration */
        _intrinsic_duration = descriptor.ContainerDuration;
index c398ef78213f931b321ee307ad3274d9d1725a44..062df56b36aa09b02574cbbfe4347d76e78d687e 100644 (file)
@@ -82,6 +82,10 @@ public:
                return _png_image;
        }
 
+       void set_png_image (Data d) {
+               _png_image = d;
+       }
+
        std::string id () const {
                return _id;
        }
index 6997a9a3cf05e6d90390c77528891052975ec587..79010f7af01f0a65a6404b6b3e7a4eb5072dfcc8 100644 (file)
@@ -20,7 +20,9 @@
 #include "interop_subtitle_asset.h"
 #include "interop_load_font_node.h"
 #include "subtitle_string.h"
+#include "subtitle_image.h"
 #include <boost/test/unit_test.hpp>
+#include <iostream>
 
 using std::list;
 using std::string;
@@ -600,4 +602,9 @@ BOOST_AUTO_TEST_CASE (read_interop_subtitle_test2)
 BOOST_AUTO_TEST_CASE (read_interop_subtitle_test3)
 {
        dcp::InteropSubtitleAsset subs ("test/data/subs3.xml");
+
+       BOOST_REQUIRE_EQUAL (subs.subtitles().size(), 1);
+       shared_ptr<dcp::SubtitleImage> si = dynamic_pointer_cast<dcp::SubtitleImage>(subs.subtitles().front());
+       BOOST_REQUIRE (si);
+       BOOST_CHECK (si->png_image() == dcp::Data("test/data/822bd341-c751-45b1-94d2-410e4ffcff1b.png"));
 }