Use new Size struct.
[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 #include "util.h"
27
28 namespace libdcp
29 {
30
31 class MonoPictureFrame; 
32 class StereoPictureFrame;       
33
34 /** @brief An asset made up of JPEG2000 files */
35 class PictureAsset : public MXFAsset
36 {
37 public:
38         PictureAsset (std::string directory, std::string mxf_name, boost::signals2::signal<void (float)>* progress, int fps, int entry_point, int length);
39         
40         /** Write details of this asset to a CPL stream.
41          *  @param s Stream.
42          */
43         void write_to_cpl (std::ostream& s) const;
44
45         bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;
46
47         Size size () const {
48                 return _size;
49         }
50
51 protected:      
52
53         bool frame_buffer_equals (
54                 int frame, EqualityOptions opt, std::list<std::string>& notes,
55                 uint8_t const * data_A, unsigned int size_A, uint8_t const * data_B, unsigned int size_B
56                 ) const;
57
58         /** picture size in pixels */
59         Size _size;
60 };
61
62 /** A 2D (monoscopic) picture asset */
63 class MonoPictureAsset : public PictureAsset
64 {
65 public:
66         /** Construct a PictureAsset, generating the MXF from the JPEG2000 files.
67          *  This may take some time; progress is indicated by emission of the Progress signal.
68          *  @param files Pathnames of JPEG2000 files, in frame order.
69          *  @param directory Directory in which to create MXF file.
70          *  @param mxf_name Name of MXF file to create.
71          *  @param progress Signal to inform of progress.
72          *  @param fps Frames per second.
73          *  @param length Length in frames.
74          *  @param size Size of images in pixels.
75          */
76         MonoPictureAsset (
77                 std::vector<std::string> const & files,
78                 std::string directory,
79                 std::string mxf_name,
80                 boost::signals2::signal<void (float)>* progress,
81                 int fps,
82                 int length,
83                 Size size
84                 );
85
86         /** Construct a PictureAsset, generating the MXF from the JPEG2000 files.
87          *  This may take some time; progress is indicated by emission of the Progress signal.
88          *  @param get_path Functor which returns a JPEG2000 file path for a given frame (frames counted from 0).
89          *  @param directory Directory in which to create MXF file.
90          *  @param mxf_name Name of MXF file to create.
91          *  @param progress Signal to inform of progress.
92          *  @param fps Frames per second.
93          *  @param length Length in frames.
94          *  @param size Size of images in pixels.
95          */
96         MonoPictureAsset (
97                 boost::function<std::string (int)> get_path,
98                 std::string directory,
99                 std::string mxf_name,
100                 boost::signals2::signal<void (float)>* progress,
101                 int fps,
102                 int length,
103                 Size size
104                 );
105
106         MonoPictureAsset (std::string directory, std::string mxf_name, int fps, int entry_point, int length);
107         
108         boost::shared_ptr<const MonoPictureFrame> get_frame (int n) const;
109         bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;
110
111 private:
112         std::string path_from_list (int f, std::vector<std::string> const & files) const;
113         void construct (boost::function<std::string (int)>);
114 };
115
116 /** A 3D (stereoscopic) picture asset */        
117 class StereoPictureAsset : public PictureAsset
118 {
119 public:
120         StereoPictureAsset (std::string directory, std::string mxf_name, int fps, int entry_point, int length);
121         
122         boost::shared_ptr<const StereoPictureFrame> get_frame (int n) const;
123         bool equals (boost::shared_ptr<const Asset> other, EqualityOptions opt, std::list<std::string>& notes) const;
124 };
125         
126
127 }