X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Frender_subtitles.cc;h=bc89fd3f88dc85977e2d765227401dde059f0275;hb=78dd04db5ee5d1aa5fc915f04dc71cb53d33d059;hp=6306817615b970f90d5cf17d0669e8a766538e57;hpb=b299c1873bf23414061d551843275c77a9256a05;p=dcpomatic.git diff --git a/src/lib/render_subtitles.cc b/src/lib/render_subtitles.cc index 630681761..bc89fd3f8 100644 --- a/src/lib/render_subtitles.cc +++ b/src/lib/render_subtitles.cc @@ -28,36 +28,36 @@ using std::cout; using std::string; using std::min; using std::max; +using std::pair; using boost::shared_ptr; using boost::optional; static int -calculate_position (libdcp::VAlign v_align, double v_position, int target_height, int offset) +calculate_position (dcp::VAlign v_align, double v_position, int target_height, int offset) { switch (v_align) { - case libdcp::TOP: - return (v_position / 100) * target_height - offset; - case libdcp::CENTER: - return (0.5 + v_position / 100) * target_height - offset; - case libdcp::BOTTOM: - return (1.0 - v_position / 100) * target_height - offset; + case dcp::TOP: + return v_position * target_height - offset; + case dcp::CENTER: + return (0.5 + v_position) * target_height - offset; + case dcp::BOTTOM: + return (1.0 - v_position) * target_height - offset; } return 0; } -void -render_subtitles (list subtitles, libdcp::Size target, shared_ptr& image, Position& position) +PositionImage +render_subtitles (list subtitles, dcp::Size target) { if (subtitles.empty ()) { - image.reset (); - return; + return PositionImage (); } /* Estimate height that the subtitle image needs to be */ optional top; optional bottom; - for (list::const_iterator i = subtitles.begin(); i != subtitles.end(); ++i) { + for (list::const_iterator i = subtitles.begin(); i != subtitles.end(); ++i) { int const b = calculate_position (i->v_align(), i->v_position(), target.height, 0); int const t = b - i->size() * target.height / (11 * 72); @@ -68,7 +68,7 @@ render_subtitles (list subtitles, libdcp::Size target, shared_ top = top.get() - 32; bottom = bottom.get() + 32; - image.reset (new Image (PIX_FMT_RGBA, libdcp::Size (target.width, bottom.get() - top.get ()), false)); + shared_ptr image (new Image (PIX_FMT_RGBA, dcp::Size (target.width, bottom.get() - top.get ()), false)); image->make_black (); Cairo::RefPtr surface = Cairo::ImageSurface::create ( @@ -87,12 +87,8 @@ render_subtitles (list subtitles, libdcp::Size target, shared_ context->set_line_width (1); - for (list::const_iterator i = subtitles.begin(); i != subtitles.end(); ++i) { - string f = i->font (); - if (f.empty ()) { - f = "Arial"; - } - Pango::FontDescription font (f); + for (list::const_iterator i = subtitles.begin(); i != subtitles.end(); ++i) { + Pango::FontDescription font (i->font().get_value_or ("Arial")); font.set_absolute_size (i->size_in_pixels (target.height) * PANGO_SCALE); if (i->italic ()) { font.set_style (Pango::STYLE_ITALIC); @@ -103,16 +99,6 @@ render_subtitles (list subtitles, libdcp::Size target, shared_ /* Compute fade factor */ /* XXX */ float fade_factor = 1; -#if 0 - libdcp::Time now (time * 1000 / (4 * TIME_HZ)); - libdcp::Time end_fade_up = i->in() + i->fade_up_time (); - libdcp::Time start_fade_down = i->out() - i->fade_down_time (); - if (now < end_fade_up) { - fade_factor = (now - i->in()) / i->fade_up_time(); - } else if (now > start_fade_down) { - fade_factor = 1.0 - ((now - start_fade_down) / i->fade_down_time ()); - } -#endif layout->update_from_cairo_context (context); @@ -121,9 +107,9 @@ render_subtitles (list subtitles, libdcp::Size target, shared_ int const x = 0; int const y = calculate_position (i->v_align (), i->v_position (), target.height, (layout->get_baseline() / PANGO_SCALE) + top.get ()); - if (i->effect() == libdcp::SHADOW) { + if (i->effect() == dcp::SHADOW) { /* Drop-shadow effect */ - libdcp::Color const ec = i->effect_color (); + dcp::Colour const ec = i->effect_colour (); context->set_source_rgba (float(ec.r) / 255, float(ec.g) / 255, float(ec.b) / 255, fade_factor); context->move_to (x + 4, y + 4); layout->add_to_cairo_context (context); @@ -132,19 +118,21 @@ render_subtitles (list subtitles, libdcp::Size target, shared_ /* The actual subtitle */ context->move_to (x, y); - libdcp::Color const c = i->color (); + dcp::Colour const c = i->colour (); context->set_source_rgba (float(c.r) / 255, float(c.g) / 255, float(c.b) / 255, fade_factor); layout->add_to_cairo_context (context); context->fill (); - if (i->effect() == libdcp::BORDER) { + if (i->effect() == dcp::BORDER) { /* Border effect */ context->move_to (x, y); - libdcp::Color ec = i->effect_color (); + dcp::Colour ec = i->effect_colour (); context->set_source_rgba (float(ec.r) / 255, float(ec.g) / 255, float(ec.b) / 255, fade_factor); layout->add_to_cairo_context (context); context->stroke (); } } + + return PositionImage (image, Position (0, top.get ())); }