f20422770eb827bc64a4dc38a47c95fabd5bd25e
[dcpomatic.git] / src / lib / jpeg2000_encoder.h
1 /*
2     Copyright (C) 2015 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 #ifndef DCPOMATIC_JPEG2000_ENCODER_H
21 #define DCPOMATIC_JPEG2000_ENCODER_H
22
23 #include "types.h"
24 #include <dcp/types.h>
25 #include <boost/shared_ptr.hpp>
26 #include <boost/optional.hpp>
27 #include <list>
28
29 namespace dcp {
30         class XYZImage;
31 }
32
33 class EncodedData;
34
35 class JPEG2000Encoder
36 {
37 public:
38         virtual ~JPEG2000Encoder () {}
39         
40         /** @return Internationalised descriptive name for this encoder */
41         virtual std::string name () const = 0;
42         /** @return Non-internationalised ID for this encoder */
43         virtual std::string id () const = 0;
44
45         /** @param input XYZ input frame.
46          *  @param note_handler Handler for notes about the encode.
47          
48          *  @return Encoded JPEG2000 data.
49          */
50         boost::shared_ptr<EncodedData> encode (
51                 boost::shared_ptr<const dcp::XYZImage> input,
52                 dcp::NoteHandler note_handler,
53                 int bandwidth,
54                 int frame_rate,
55                 Resolution resolution,
56                 bool threed
57                 );
58
59         static void setup_encoders ();
60         /** @return Return all available JPEG2000 encoders in order of preference (best first) */
61         static std::vector<boost::shared_ptr<JPEG2000Encoder> > all ();
62         static boost::shared_ptr<JPEG2000Encoder> from_id (std::string id);
63
64 protected:
65
66         virtual boost::shared_ptr<EncodedData> do_encode (
67                 boost::shared_ptr<const dcp::XYZImage> input,
68                 dcp::NoteHandler note_handler
69                 ) = 0;
70         
71         virtual void set_bandwidth (int bandwidth) = 0;
72         virtual void set_frame_rate (int frame_rate) = 0;
73         virtual void set_resolution (Resolution resolution) = 0;
74         virtual void set_threed (bool threed) = 0;
75
76         boost::optional<int> _last_bandwidth;
77         boost::optional<int> _last_frame_rate;
78         boost::optional<Resolution> _last_resolution;
79         boost::optional<bool> _last_threed;
80
81         static std::vector<boost::shared_ptr<JPEG2000Encoder> > _encoders;
82 };
83
84 #endif