Use libxml++ to write CPLs.
[libdcp.git] / src / picture_asset.h
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file  src/picture_asset.h
21  *  @brief An asset made up of JPEG2000 files
22  */
23
24 #include <openjpeg.h>
25 #include "mxf_asset.h"
26
27 namespace libdcp
28 {
29
30 class MonoPictureFrame; 
31 class StereoPictureFrame;       
32
33 /** @brief An asset made up of JPEG2000 files */
34 class PictureAsset : public MXFAsset
35 {
36 public:
37         PictureAsset (
38                 std::string directory, std::string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int entry_point, int length, bool encrypted
39                 );
40         
41         /** Write details of the asset to a CPL AssetList node.
42          *  @param p Parent node.
43          */
44         void write_to_cpl (xmlpp::Element* p) const;
45
46         bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;
47
48         int width () const {
49                 return _width;
50         }
51
52         int height () const {
53                 return _height;
54         }
55
56 protected:      
57
58         bool frame_buffer_equals (
59                 int frame, EqualityOptions opt, std::list<std::string>& notes,
60                 uint8_t const * data_A, unsigned int size_A, uint8_t const * data_B, unsigned int size_B
61                 ) const;
62         
63         /** picture width in pixels */
64         int _width;
65         /** picture height in pixels */
66         int _height;
67 };
68
69 /** A 2D (monoscopic) picture asset */
70 class MonoPictureAsset : public PictureAsset
71 {
72 public:
73         /** Construct a PictureAsset, generating the MXF from the JPEG2000 files.
74          *  This may take some time; progress is indicated by emission of the Progress signal.
75          *  @param files Pathnames of JPEG2000 files, in frame order.
76          *  @param directory Directory in which to create MXF file.
77          *  @param mxf_name Name of MXF file to create.
78          *  @param progress Signal to inform of progress.
79          *  @param fps Frames per second.
80          *  @param length Length in frames.
81          *  @param width Width of images in pixels.
82          *  @param height Height of images in pixels.
83          *  @param encrypted true if asset should be encrypted.
84          */
85         MonoPictureAsset (
86                 std::vector<std::string> const & files,
87                 std::string directory,
88                 std::string mxf_name,
89                 boost::signals2::signal<void (float)>* progress,
90                 int fps,
91                 int length,
92                 int width,
93                 int height,
94                 bool encrypted
95                 );
96
97         /** Construct a PictureAsset, generating the MXF from the JPEG2000 files.
98          *  This may take some time; progress is indicated by emission of the Progress signal.
99          *  @param get_path Functor which returns a JPEG2000 file path for a given frame (frames counted from 0).
100          *  @param directory Directory in which to create MXF file.
101          *  @param mxf_name Name of MXF file to create.
102          *  @param progress Signal to inform of progress.
103          *  @param fps Frames per second.
104          *  @param length Length in frames.
105          *  @param width Width of images in pixels.
106          *  @param height Height of images in pixels.
107          *  @param encrypted true if asset should be encrypted.
108          */
109         MonoPictureAsset (
110                 boost::function<std::string (int)> get_path,
111                 std::string directory,
112                 std::string mxf_name,
113                 boost::signals2::signal<void (float)>* progress,
114                 int fps,
115                 int length,
116                 int width,
117                 int height,
118                 bool encrypted
119                 );
120
121         MonoPictureAsset (std::string directory, std::string mxf_name, int fps, int entry_point, int length);
122         
123         boost::shared_ptr<const MonoPictureFrame> get_frame (int n) const;
124         bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;
125
126 private:
127         std::string path_from_list (int f, std::vector<std::string> const & files) const;
128         void construct (boost::function<std::string (int)>);
129 };
130
131 /** A 3D (stereoscopic) picture asset */        
132 class StereoPictureAsset : public PictureAsset
133 {
134 public:
135         StereoPictureAsset (std::string directory, std::string mxf_name, int fps, int entry_point, int length);
136         
137         boost::shared_ptr<const StereoPictureFrame> get_frame (int n) const;
138         bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;
139 };
140         
141
142 }