2 Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <libdcp/raw_convert.h>
21 #include "player_video_frame.h"
27 using boost::shared_ptr;
28 using libdcp::raw_convert;
30 PlayerVideoFrame::PlayerVideoFrame (
31 shared_ptr<const Image> in,
33 libdcp::Size inter_size,
34 libdcp::Size out_size,
35 Scaler const * scaler,
37 ColourConversion colour_conversion
41 , _inter_size (inter_size)
42 , _out_size (out_size)
45 , _colour_conversion (colour_conversion)
50 PlayerVideoFrame::PlayerVideoFrame (shared_ptr<cxml::Node> node, shared_ptr<Socket> socket)
54 _inter_size = libdcp::Size (node->number_child<int> ("InterWidth"), node->number_child<int> ("InterHeight"));
55 _out_size = libdcp::Size (node->number_child<int> ("OutWidth"), node->number_child<int> ("OutHeight"));
56 _scaler = Scaler::from_id (node->string_child ("Scaler"));
57 _eyes = (Eyes) node->number_child<int> ("Eyes");
58 _colour_conversion = ColourConversion (node);
60 shared_ptr<Image> image (new Image (PIX_FMT_RGB24, libdcp::Size (node->number_child<int> ("InWidth"), node->number_child<int> ("InHeight")), true));
61 image->read_from_socket (socket);
64 if (node->optional_number_child<int> ("SubtitleX")) {
66 _subtitle_position = Position<int> (node->number_child<int> ("SubtitleX"), node->number_child<int> ("SubtitleY"));
68 shared_ptr<Image> image (
69 new Image (PIX_FMT_RGBA, libdcp::Size (node->number_child<int> ("SubtitleWidth"), node->number_child<int> ("SubtitleHeight")), true)
72 image->read_from_socket (socket);
73 _subtitle_image = image;
78 PlayerVideoFrame::set_subtitle (shared_ptr<const Image> image, Position<int> pos)
80 _subtitle_image = image;
81 _subtitle_position = pos;
85 PlayerVideoFrame::image () const
87 shared_ptr<Image> out = _in->crop_scale_window (_crop, _inter_size, _out_size, _scaler, PIX_FMT_RGB24, false);
89 Position<int> const container_offset ((_out_size.width - _inter_size.width) / 2, (_out_size.height - _inter_size.width) / 2);
91 if (_subtitle_image) {
92 out->alpha_blend (_subtitle_image, _subtitle_position);
99 PlayerVideoFrame::add_metadata (xmlpp::Element* node) const
102 node->add_child("InWidth")->add_child_text (raw_convert<string> (_in->size().width));
103 node->add_child("InHeight")->add_child_text (raw_convert<string> (_in->size().height));
104 node->add_child("InterWidth")->add_child_text (raw_convert<string> (_inter_size.width));
105 node->add_child("InterHeight")->add_child_text (raw_convert<string> (_inter_size.height));
106 node->add_child("OutWidth")->add_child_text (raw_convert<string> (_out_size.width));
107 node->add_child("OutHeight")->add_child_text (raw_convert<string> (_out_size.height));
108 node->add_child("Scaler")->add_child_text (_scaler->id ());
109 node->add_child("Eyes")->add_child_text (raw_convert<string> (_eyes));
110 _colour_conversion.as_xml (node);
111 if (_subtitle_image) {
112 node->add_child ("SubtitleWidth")->add_child_text (raw_convert<string> (_subtitle_image->size().width));
113 node->add_child ("SubtitleHeight")->add_child_text (raw_convert<string> (_subtitle_image->size().height));
114 node->add_child ("SubtitleX")->add_child_text (raw_convert<string> (_subtitle_position.x));
115 node->add_child ("SubtitleY")->add_child_text (raw_convert<string> (_subtitle_position.y));
120 PlayerVideoFrame::send_binary (shared_ptr<Socket> socket) const
122 _in->write_to_socket (socket);
123 if (_subtitle_image) {
124 _subtitle_image->write_to_socket (socket);