Various probably quite untidy progress on KDMs.
[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 private:
69         std::string key_type () const;
70 };
71
72 /** A 2D (monoscopic) picture asset */
73 class MonoPictureAsset : public PictureAsset
74 {
75 public:
76         /** Construct a PictureAsset, generating the MXF from the JPEG2000 files.
77          *  This may take some time; progress is indicated by emission of the Progress signal.
78          *  @param files Pathnames of JPEG2000 files, in frame order.
79          *  @param directory Directory in which to create MXF file.
80          *  @param mxf_name Name of MXF file to create.
81          *  @param progress Signal to inform of progress.
82          *  @param fps Frames per second.
83          *  @param length Length in frames.
84          *  @param width Width of images in pixels.
85          *  @param height Height of images in pixels.
86          *  @param encrypted true if asset should be encrypted.
87          */
88         MonoPictureAsset (
89                 std::vector<std::string> const & files,
90                 std::string directory,
91                 std::string mxf_name,
92                 boost::signals2::signal<void (float)>* progress,
93                 int fps,
94                 int length,
95                 int width,
96                 int height,
97                 bool encrypted
98                 );
99
100         /** Construct a PictureAsset, generating the MXF from the JPEG2000 files.
101          *  This may take some time; progress is indicated by emission of the Progress signal.
102          *  @param get_path Functor which returns a JPEG2000 file path for a given frame (frames counted from 0).
103          *  @param directory Directory in which to create MXF file.
104          *  @param mxf_name Name of MXF file to create.
105          *  @param progress Signal to inform of progress.
106          *  @param fps Frames per second.
107          *  @param length Length in frames.
108          *  @param width Width of images in pixels.
109          *  @param height Height of images in pixels.
110          *  @param encrypted true if asset should be encrypted.
111          */
112         MonoPictureAsset (
113                 boost::function<std::string (int)> get_path,
114                 std::string directory,
115                 std::string mxf_name,
116                 boost::signals2::signal<void (float)>* progress,
117                 int fps,
118                 int length,
119                 int width,
120                 int height,
121                 bool encrypted
122                 );
123
124         MonoPictureAsset (std::string directory, std::string mxf_name, int fps, int entry_point, int length);
125         
126         boost::shared_ptr<const MonoPictureFrame> get_frame (int n) const;
127         bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;
128
129 private:
130         std::string path_from_list (int f, std::vector<std::string> const & files) const;
131         void construct (boost::function<std::string (int)>);
132 };
133
134 /** A 3D (stereoscopic) picture asset */        
135 class StereoPictureAsset : public PictureAsset
136 {
137 public:
138         StereoPictureAsset (std::string directory, std::string mxf_name, int fps, int entry_point, int length);
139         
140         boost::shared_ptr<const StereoPictureFrame> get_frame (int n) const;
141         bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;
142 };
143         
144
145 }