From 7bb241e6857f5f3614fd3b8722d545e85a6b6316 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 9 Jul 2018 02:30:18 +0100 Subject: [PATCH] Basic reading of Interop/SMPTE image subtitles with a test for Interop. --- src/interop_subtitle_asset.cc | 7 +++++- src/smpte_subtitle_asset.cc | 36 +++++++++++++++++++++--------- src/subtitle_image.h | 4 ++++ test/read_interop_subtitle_test.cc | 7 ++++++ 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index 1cd99563..e2873fb6 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -80,7 +80,12 @@ InteropSubtitleAsset::InteropSubtitleAsset (boost::filesystem::path file) } } - /* XXX: now find SubtitleImages in _subtitles and load their PNG */ + BOOST_FOREACH (shared_ptr i, _subtitles) { + shared_ptr si = dynamic_pointer_cast(i); + if (si) { + si->set_png_image (Data (file.parent_path() / String::compose("%1.png", si->id()))); + } + } } InteropSubtitleAsset::InteropSubtitleAsset () diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index 91afec14..b568139a 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -173,17 +173,19 @@ SMPTESubtitleAsset::read_mxf_descriptor (shared_ptr 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 data (new uint8_t[buffer.Size()]); - memcpy (data.get(), buffer.RoData(), buffer.Size()); + shared_array data (new uint8_t[buffer.Size()]); + memcpy (data.get(), buffer.RoData(), buffer.Size()); + switch (i->Type) { + case ASDCP::TimedText::MT_OPENTYPE: + { list >::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 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 >::const_iterator j = _subtitles.begin (); + while (j != _subtitles.end() && ((!dynamic_pointer_cast(*j)) || dynamic_pointer_cast(*j)->id() != id)) { + ++j; + } - /* XXX: load PNG and attach them to _subtitles */ + if (j != _subtitles.end()) { + dynamic_pointer_cast(*j)->set_png_image (Data(data, buffer.Size())); + } + break; + } + default: + break; + } + } /* Get intrinsic duration */ _intrinsic_duration = descriptor.ContainerDuration; diff --git a/src/subtitle_image.h b/src/subtitle_image.h index c398ef78..062df56b 100644 --- a/src/subtitle_image.h +++ b/src/subtitle_image.h @@ -82,6 +82,10 @@ public: return _png_image; } + void set_png_image (Data d) { + _png_image = d; + } + std::string id () const { return _id; } diff --git a/test/read_interop_subtitle_test.cc b/test/read_interop_subtitle_test.cc index 6997a9a3..79010f7a 100644 --- a/test/read_interop_subtitle_test.cc +++ b/test/read_interop_subtitle_test.cc @@ -20,7 +20,9 @@ #include "interop_subtitle_asset.h" #include "interop_load_font_node.h" #include "subtitle_string.h" +#include "subtitle_image.h" #include +#include 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 si = dynamic_pointer_cast(subs.subtitles().front()); + BOOST_REQUIRE (si); + BOOST_CHECK (si->png_image() == dcp::Data("test/data/822bd341-c751-45b1-94d2-410e4ffcff1b.png")); } -- 2.30.2