diff options
| author | Carl Hetherington <cth@carlh.net> | 2015-06-10 10:55:22 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2015-06-10 10:55:22 +0100 |
| commit | 8771c1f7b00ab0fb5c252adaa437d753155b7c18 (patch) | |
| tree | f1f4c6109c1b64c795a05ff2a6188f246028e767 | |
| parent | 91e1e17b4c9771e00b48d9fcc0dcbe2bdfa94c17 (diff) | |
Rename Font -> FontAsset; add dcpdumpsub tool.
| -rw-r--r-- | run/tools/dcpdumpsub | 12 | ||||
| -rw-r--r-- | src/data.h | 38 | ||||
| -rw-r--r-- | src/dcp.cc | 4 | ||||
| -rw-r--r-- | src/font_asset.cc (renamed from src/font.cc) | 10 | ||||
| -rw-r--r-- | src/font_asset.h (renamed from src/font.h) | 10 | ||||
| -rw-r--r-- | src/interop_subtitle_asset.cc | 10 | ||||
| -rw-r--r-- | src/smpte_subtitle_asset.cc | 6 | ||||
| -rw-r--r-- | src/subtitle_asset.cc | 13 | ||||
| -rw-r--r-- | src/subtitle_asset.h | 15 | ||||
| -rw-r--r-- | src/wscript | 5 | ||||
| -rw-r--r-- | tools/dcpdumpsub.cc | 90 | ||||
| -rw-r--r-- | tools/wscript | 6 |
12 files changed, 188 insertions, 31 deletions
diff --git a/run/tools/dcpdumpsub b/run/tools/dcpdumpsub new file mode 100644 index 00000000..adb3c6fc --- /dev/null +++ b/run/tools/dcpdumpsub @@ -0,0 +1,12 @@ +#!/bin/bash + +export LD_LIBRARY_PATH=build/src:build/asdcplib/src:$LD_LIBRARY_PATH +if [ "$1" == "--debug" ]; then + shift + gdb --args build/tools/dcpdumpsub "$@" +elif [ "$1" == "--valgrind" ]; then + shift + valgrind --tool="memcheck" --leak-check=full --show-reachable=yes build/tools/dcpdumpsub "$@" +else + build/tools/dcpdumpsub "$@" +fi diff --git a/src/data.h b/src/data.h new file mode 100644 index 00000000..d1f52b3b --- /dev/null +++ b/src/data.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include <boost/shared_array.hpp> + +namespace dcp { + +class Data +{ +public: + Data () {} + + Data (boost::shared_array<uint8_t> data_, boost::uintmax_t size_) + : data (data_) + , size (size_) + {} + + boost::shared_array<uint8_t> data; + boost::uintmax_t size; +}; + +} @@ -41,7 +41,7 @@ #include "decrypted_kdm_key.h" #include "dcp_assert.h" #include "reel_asset.h" -#include "font.h" +#include "font_asset.h" #include <xmlsec/xmldsig.h> #include <xmlsec/app.h> #include <libxml++/libxml++.h> @@ -176,7 +176,7 @@ DCP::read (bool keep_going, ReadErrors* errors) throw DCPReadError ("Unknown MXF essence type"); } } else if (boost::filesystem::extension (path) == ".ttf") { - other_assets.push_back (shared_ptr<Font> (new Font (path))); + other_assets.push_back (shared_ptr<FontAsset> (new FontAsset (path))); } } diff --git a/src/font.cc b/src/font_asset.cc index cbfb999a..8f8e4ff3 100644 --- a/src/font.cc +++ b/src/font_asset.cc @@ -17,24 +17,24 @@ */ -/** @file src/font.cc - * @brief Font class. +/** @file src/font_asset.cc + * @brief FontAsset class. */ -#include "font.h" +#include "font_asset.h" using std::string; using namespace dcp; -Font::Font (boost::filesystem::path file) +FontAsset::FontAsset (boost::filesystem::path file) : Asset (file) { } string -Font::pkl_type (Standard) const +FontAsset::pkl_type (Standard) const { return "application/ttf"; } diff --git a/src/font.h b/src/font_asset.h index e87419c0..13333777 100644 --- a/src/font.h +++ b/src/font_asset.h @@ -17,21 +17,21 @@ */ -/** @file src/font.h - * @brief Font class. +/** @file src/font_asset.h + * @brief FontAsset class. */ #include "asset.h" namespace dcp { -/** @class Font +/** @class FontAsset * @brief A (truetype) font asset for subtitles in an Interop DCP. */ -class Font : public Asset +class FontAsset : public Asset { public: - Font (boost::filesystem::path file); + FontAsset (boost::filesystem::path file); private: std::string pkl_type (Standard standard) const; diff --git a/src/interop_subtitle_asset.cc b/src/interop_subtitle_asset.cc index 5be4c53c..e329158e 100644 --- a/src/interop_subtitle_asset.cc +++ b/src/interop_subtitle_asset.cc @@ -23,7 +23,7 @@ #include "raw_convert.h" #include "font_node.h" #include "util.h" -#include "font.h" +#include "font_asset.h" #include "dcp_assert.h" #include <libxml++/libxml++.h> #include <boost/foreach.hpp> @@ -163,7 +163,7 @@ InteropSubtitleAsset::write (boost::filesystem::path p) const if (!f) { throw FileError ("could not open font file for writing", file, errno); } - map<string, FontData>::const_iterator j = _fonts.find (i->id); + map<string, FileData>::const_iterator j = _fonts.find (i->id); if (j != _fonts.end ()) { fwrite (j->second.data.get(), 1, j->second.size, f); j->second.file = file; @@ -176,7 +176,7 @@ void InteropSubtitleAsset::resolve_fonts (list<shared_ptr<Object> > objects) { BOOST_FOREACH (shared_ptr<Object> i, objects) { - shared_ptr<Font> font = dynamic_pointer_cast<Font> (i); + shared_ptr<FontAsset> font = dynamic_pointer_cast<FontAsset> (i); if (!font) { continue; } @@ -192,8 +192,8 @@ InteropSubtitleAsset::resolve_fonts (list<shared_ptr<Object> > objects) void InteropSubtitleAsset::add_font_assets (list<shared_ptr<Asset> >& assets) { - for (map<string, FontData>::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { + for (map<string, FileData>::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { DCP_ASSERT (i->second.file); - assets.push_back (shared_ptr<Font> (new Font (i->second.file.get ()))); + assets.push_back (shared_ptr<FontAsset> (new FontAsset (i->second.file.get ()))); } } diff --git a/src/smpte_subtitle_asset.cc b/src/smpte_subtitle_asset.cc index 362211cf..e426ae22 100644 --- a/src/smpte_subtitle_asset.cc +++ b/src/smpte_subtitle_asset.cc @@ -144,7 +144,7 @@ SMPTESubtitleAsset::SMPTESubtitleAsset (boost::filesystem::path file) } if (j != _load_font_nodes.end ()) { - _fonts[(*j)->id] = FontData (data, buffer.Size ()); + _fonts[(*j)->id] = FileData (data, buffer.Size ()); } } } @@ -217,7 +217,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const descriptor.EncodingName = "UTF-8"; BOOST_FOREACH (shared_ptr<dcp::SMPTELoadFontNode> i, _load_font_nodes) { - map<string, FontData>::const_iterator j = _fonts.find (i->id); + map<string, FileData>::const_iterator j = _fonts.find (i->id); if (j != _fonts.end ()) { ASDCP::TimedText::TimedTextResourceDescriptor res; unsigned int c; @@ -245,7 +245,7 @@ SMPTESubtitleAsset::write (boost::filesystem::path p) const } BOOST_FOREACH (shared_ptr<dcp::SMPTELoadFontNode> i, _load_font_nodes) { - map<string, FontData>::const_iterator j = _fonts.find (i->id); + map<string, FileData>::const_iterator j = _fonts.find (i->id); if (j != _fonts.end ()) { ASDCP::TimedText::FrameBuffer buffer; buffer.SetData (j->second.data.get(), j->second.size); diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index 085e5959..d9a87263 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -39,6 +39,7 @@ using std::ofstream; using std::stringstream; using std::cout; using std::cerr; +using std::map; using boost::shared_ptr; using boost::shared_array; using boost::optional; @@ -324,5 +325,15 @@ SubtitleAsset::add_font_data (string id, boost::filesystem::path file) throw FileError ("could not read font file", file, -1); } - _fonts[id] = FontData (data, size); + _fonts[id] = FileData (data, size); +} + +map<string, Data> +SubtitleAsset::fonts () const +{ + map<string, Data> out; + for (map<string, FileData>::const_iterator i = _fonts.begin(); i != _fonts.end(); ++i) { + out[i->first] = i->second; + } + return out; } diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 4cbbff0d..c28f6446 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -23,6 +23,7 @@ #include "asset.h" #include "dcp_time.h" #include "subtitle_string.h" +#include "data.h" #include <libcxml/cxml.h> #include <boost/shared_array.hpp> @@ -69,6 +70,7 @@ public: void add (SubtitleString); virtual void add_font (std::string id, boost::filesystem::path file) = 0; + std::map<std::string, Data> fonts () const; virtual void write (boost::filesystem::path) const = 0; virtual Glib::ustring xml_as_string () const = 0; @@ -88,17 +90,14 @@ protected: /** All our subtitles, in no particular order */ std::list<SubtitleString> _subtitles; - class FontData { + class FileData : public Data { public: - FontData () {} + FileData () {} - FontData (boost::shared_array<uint8_t> data_, boost::uintmax_t size_) - : data (data_) - , size (size_) + FileData (boost::shared_array<uint8_t> data_, boost::uintmax_t size_) + : Data (data_, size_) {} - boost::shared_array<uint8_t> data; - boost::uintmax_t size; /** .ttf file that this data was last written to */ mutable boost::optional<boost::filesystem::path> file; }; @@ -107,7 +106,7 @@ protected: * For Interop, the string is the font ID from the subtitle file. * For SMPTE, the string is the font's URN from the subtitle file. */ - std::map<std::string, FontData> _fonts; + std::map<std::string, FileData> _fonts; private: /** @struct ParseState diff --git a/src/wscript b/src/wscript index f54aaa8f..ede704bb 100644 --- a/src/wscript +++ b/src/wscript @@ -15,7 +15,7 @@ def build(bld): encrypted_kdm.cc exceptions.cc file.cc - font.cc + font_asset.cc font_node.cc gamma_transfer_function.cc interop_load_font_node.cc @@ -71,11 +71,12 @@ def build(bld): cpl.h dcp.h dcp_time.h + data.h decrypted_kdm.h decrypted_kdm_key.h encrypted_kdm.h exceptions.h - font.h + font_asset.h gamma_transfer_function.h interop_load_font_node.h interop_subtitle_asset.h diff --git a/tools/dcpdumpsub.cc b/tools/dcpdumpsub.cc new file mode 100644 index 00000000..06802320 --- /dev/null +++ b/tools/dcpdumpsub.cc @@ -0,0 +1,90 @@ +/* + Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "smpte_subtitle_asset.h" +#include "util.h" +#include <getopt.h> +#include <cstdlib> +#include <string> +#include <iostream> + +using std::string; +using std::cout; +using std::cerr; +using std::map; + +static void +help (string n) +{ + cerr << "Syntax: " << n << " [OPTION] <MXF>\n" + << " -h, --help show this help\n" + << " -n, --no-fonts don't extract fonts\n"; +} + +int +main (int argc, char* argv[]) +{ + bool extract_fonts = true; + + int option_index = 0; + while (1) { + static struct option long_options[] = { + { "help", no_argument, 0, 'h'}, + { "no-fonts", no_argument, 0, 'n'}, + { 0, 0, 0, 0 } + }; + + int c = getopt_long (argc, argv, "hn", long_options, &option_index); + + if (c == -1) { + break; + } + + switch (c) { + case 'h': + help (argv[0]); + exit (EXIT_SUCCESS); + case 'n': + extract_fonts = false; + break; + } + } + + if (argc <= optind || argc > (optind + 2)) { + help (argv[0]); + exit (EXIT_FAILURE); + } + + dcp::SMPTESubtitleAsset sub (argv[optind]); + + cout << sub.xml_as_string() << "\n"; + + if (extract_fonts) { + map<string, dcp::Data> fonts = sub.fonts (); + for (map<string, dcp::Data>::const_iterator i = fonts.begin(); i != fonts.end(); ++i) { + FILE* f = dcp::fopen_boost (i->first + ".ttf", "wb"); + if (!f) { + cerr << "Could not open font file " << i->first << ".ttf for writing"; + exit (EXIT_FAILURE); + } + fwrite (i->second.data.get(), 1, i->second.size, f); + fclose (f); + } + } +} diff --git a/tools/wscript b/tools/wscript index 10389eac..26474fc8 100644 --- a/tools/wscript +++ b/tools/wscript @@ -11,3 +11,9 @@ def build(bld): obj.source = 'dcpinfo.cc common.cc' obj.target = 'dcpinfo' + obj = bld(features = 'cxx cxxprogram') + obj.use = ['libdcp%s' % bld.env.API_VERSION] + obj.uselib = 'OPENJPEG CXML' + obj.source = 'dcpdumpsub.cc' + obj.target = 'dcpdumpsub' + |
