Put Image in dcpomatic:: to avoid Fastvideo name clash.
[dcpomatic.git] / src / lib / raw_image_proxy.cc
1 /*
2     Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "raw_image_proxy.h"
22 #include "image.h"
23 #include "warnings.h"
24 #include <dcp/raw_convert.h>
25 #include <dcp/util.h>
26 #include <libcxml/cxml.h>
27 extern "C" {
28 #include <libavutil/pixfmt.h>
29 }
30 DCPOMATIC_DISABLE_WARNINGS
31 #include <libxml++/libxml++.h>
32 DCPOMATIC_ENABLE_WARNINGS
33
34 #include "i18n.h"
35
36 using std::string;
37 using std::pair;
38 using std::make_pair;
39 using boost::shared_ptr;
40 using boost::dynamic_pointer_cast;
41 using boost::optional;
42 using dcp::raw_convert;
43 using namespace dcpomatic;
44
45 RawImageProxy::RawImageProxy (shared_ptr<Image> image)
46         : _image (image)
47 {
48
49 }
50
51 RawImageProxy::RawImageProxy (shared_ptr<cxml::Node> xml, shared_ptr<Socket> socket)
52 {
53         dcp::Size size (
54                 xml->number_child<int> ("Width"), xml->number_child<int> ("Height")
55                 );
56
57         _image.reset (new Image (static_cast<AVPixelFormat> (xml->number_child<int> ("PixelFormat")), size, true));
58         _image->read_from_socket (socket);
59 }
60
61 ImageProxy::Result
62 RawImageProxy::image (optional<dcp::Size>) const
63 {
64         return Result (_image, 0);
65 }
66
67 void
68 RawImageProxy::add_metadata (xmlpp::Node* node) const
69 {
70         node->add_child("Type")->add_child_text (N_("Raw"));
71         node->add_child("Width")->add_child_text (raw_convert<string> (_image->size().width));
72         node->add_child("Height")->add_child_text (raw_convert<string> (_image->size().height));
73         node->add_child("PixelFormat")->add_child_text (raw_convert<string> (static_cast<int> (_image->pixel_format ())));
74 }
75
76 void
77 RawImageProxy::write_to_socket (shared_ptr<Socket> socket) const
78 {
79         _image->write_to_socket (socket);
80 }
81
82 bool
83 RawImageProxy::same (shared_ptr<const ImageProxy> other) const
84 {
85         shared_ptr<const RawImageProxy> rp = dynamic_pointer_cast<const RawImageProxy> (other);
86         if (!rp) {
87                 return false;
88         }
89
90         return (*_image.get()) == (*rp->image().image.get());
91 }
92
93 size_t
94 RawImageProxy::memory_used () const
95 {
96         return _image->memory_used ();
97 }