From a1d11f2e9cc3678bd68b95c0e444c8245ef776b5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 28 Apr 2022 13:47:57 +0200 Subject: [PATCH] Allow ContentBitmapText to contain multiple BitmapText objects. --- src/lib/content_text.h | 6 +++--- src/lib/player.cc | 43 ++++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/lib/content_text.h b/src/lib/content_text.h index 5edb9af20..fb86bc786 100644 --- a/src/lib/content_text.h +++ b/src/lib/content_text.h @@ -50,11 +50,11 @@ class ContentBitmapText : public ContentText public: ContentBitmapText (dcpomatic::ContentTime f, std::shared_ptr im, dcpomatic::Rect r) : ContentText (f) - , sub (im, r) + , subs{ {im, r} } {} - /* Our text, with its rectangle unmodified by any offsets or scales that the content specifies */ - BitmapText sub; + /* Our texts, with their rectangles unmodified by any offsets or scales that the content specifies */ + std::vector subs; }; /** A text caption. We store the time period separately (as well as in the dcp::SubtitleStrings) diff --git a/src/lib/player.cc b/src/lib/player.cc index 981078636..619a3583c 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -1104,32 +1104,35 @@ Player::bitmap_text_start (weak_ptr weak_piece, weak_ptrx_offset (); - subtitle.sub.rectangle.y += content->y_offset (); + PlayerText ps; + for (auto& sub: subtitle.subs) + { + /* Apply content's subtitle offsets */ + sub.rectangle.x += content->x_offset (); + sub.rectangle.y += content->y_offset (); - /* Apply a corrective translation to keep the subtitle centred after the scale that is coming up */ - subtitle.sub.rectangle.x -= subtitle.sub.rectangle.width * ((content->x_scale() - 1) / 2); - subtitle.sub.rectangle.y -= subtitle.sub.rectangle.height * ((content->y_scale() - 1) / 2); + /* Apply a corrective translation to keep the subtitle centred after the scale that is coming up */ + sub.rectangle.x -= sub.rectangle.width * ((content->x_scale() - 1) / 2); + sub.rectangle.y -= sub.rectangle.height * ((content->y_scale() - 1) / 2); - /* Apply content's subtitle scale */ - subtitle.sub.rectangle.width *= content->x_scale (); - subtitle.sub.rectangle.height *= content->y_scale (); + /* Apply content's subtitle scale */ + sub.rectangle.width *= content->x_scale (); + sub.rectangle.height *= content->y_scale (); - PlayerText ps; - auto image = subtitle.sub.image; + auto image = sub.image; - /* We will scale the subtitle up to fit _video_container_size */ - int const width = subtitle.sub.rectangle.width * _video_container_size.width; - int const height = subtitle.sub.rectangle.height * _video_container_size.height; - if (width == 0 || height == 0) { - return; - } + /* We will scale the subtitle up to fit _video_container_size */ + int const width = sub.rectangle.width * _video_container_size.width; + int const height = sub.rectangle.height * _video_container_size.height; + if (width == 0 || height == 0) { + return; + } - dcp::Size scaled_size (width, height); - ps.bitmap.push_back (BitmapText(image->scale(scaled_size, dcp::YUVToRGB::REC601, image->pixel_format(), Image::Alignment::PADDED, _fast), subtitle.sub.rectangle)); - DCPTime from (content_time_to_dcp (piece, subtitle.from())); + dcp::Size scaled_size (width, height); + ps.bitmap.push_back (BitmapText(image->scale(scaled_size, dcp::YUVToRGB::REC601, image->pixel_format(), Image::Alignment::PADDED, _fast), sub.rectangle)); + } + DCPTime from(content_time_to_dcp(piece, subtitle.from())); _active_texts[static_cast(content->type())].add_from(weak_content, ps, from); } -- 2.30.2