Basic classes for different JPEG2000 encoders; config to choose one.
authorCarl Hetherington <cth@carlh.net>
Sat, 2 May 2015 16:33:07 +0000 (17:33 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 21 Mar 2016 16:41:06 +0000 (16:41 +0000)
15 files changed:
src/lib/config.cc
src/lib/config.h
src/lib/dcp_video.cc
src/lib/exceptions.cc
src/lib/exceptions.h
src/lib/jpeg2000_encoder.cc [new file with mode: 0644]
src/lib/jpeg2000_encoder.h [new file with mode: 0644]
src/lib/openjpeg_encoder.cc [new file with mode: 0644]
src/lib/openjpeg_encoder.h [new file with mode: 0644]
src/lib/poznan_encoder.cc [new file with mode: 0644]
src/lib/poznan_encoder.h [new file with mode: 0644]
src/lib/util.cc
src/lib/wscript
src/wx/config_dialog.cc
wscript

index ba285fd2ce3e9fe1129bd05a667f95396f314587..cdd40ac6f0d3606edb31462f55417cd468e9a63e 100644 (file)
@@ -29,6 +29,7 @@
 #include "util.h"
 #include "cross.h"
 #include "raw_convert.h"
+#include "jpeg2000_encoder.h"
 #include <dcp/colour_matrix.h>
 #include <dcp/certificate_chain.h>
 #include <libcxml/cxml.h>
@@ -104,6 +105,7 @@ Config::set_defaults ()
        _win32_console = false;
 #endif
        _cinemas_file = path ("cinemas.xml");
+       _encoder = optional<string> ();
 
        _allowed_dcp_frame_rates.clear ();
        _allowed_dcp_frame_rates.push_back (24);
@@ -298,6 +300,8 @@ Config::read ()
                f.read_file (_cinemas_file);
                read_cinemas (f);
        }
+
+       _encoder = f.optional_string_child ("Encoder");
 }
 
 /** @return Filename to write configuration to */
@@ -433,6 +437,10 @@ Config::write_config_xml () const
        }
        decryption->add_child("PrivateKey")->add_child_text (_decryption_chain->key().get ());
 
+       if (_encoder) {
+               root->add_child("Encoder")->add_child_text (_encoder.get ());
+       }
+
        for (vector<boost::filesystem::path>::const_iterator i = _history.begin(); i != _history.end(); ++i) {
                root->add_child("History")->add_child_text (i->string ());
        }
index e5795d2c300db8ac02b02cb4c6f97369d713900d..603af8c5e6417608181df69b9e62996a925e6252 100644 (file)
@@ -37,6 +37,7 @@ class CinemaSoundProcessor;
 class DCPContentType;
 class Ratio;
 class Cinema;
+class JPEG2000Encoder;
 
 /** @class Config
  *  @brief A singleton class holding configuration.
@@ -244,6 +245,9 @@ public:
                return _win32_console;
        }
 #endif
+       boost::optional<std::string> encoder () {
+               return _encoder;
+       }
 
        std::vector<boost::filesystem::path> history () const {
                return _history;
@@ -457,6 +461,15 @@ public:
 
        void set_cinemas_file (boost::filesystem::path file);
 
+       void set_encoder (std::string id) {
+               if (_encoder && _encoder.get() == id) {
+                       return;
+               }
+
+               _encoder = id;
+               changed ();
+       }
+
        void clear_history () {
                _history.clear ();
                changed ();
@@ -559,6 +572,7 @@ private:
 #ifdef DCPOMATIC_WINDOWS
        bool _win32_console;
 #endif
+       boost::optional<std::string> _encoder;
        std::vector<boost::filesystem::path> _history;
        std::vector<dcp::EncryptedKDM> _dkdms;
        boost::filesystem::path _cinemas_file;
index cd7d5229e8878cd00f639ad6d611527778faeec8..1933c0e35521b3fd75d4a168564c0792c85920e2 100644 (file)
@@ -1,6 +1,5 @@
 /*
     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
-    Taken from code Copyright (C) 2010-2011 Terrence Meiczinger
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -39,6 +38,7 @@
 #include "player_video.h"
 #include "raw_convert.h"
 #include "compose.hpp"
+#include "jpeg2000_encoder.h"
 #include <libcxml/cxml.h>
 #include <dcp/openjpeg_image.h>
 #include <dcp/rgb_xyz.h>
@@ -121,12 +121,17 @@ DCPVideo::convert_to_xyz (shared_ptr<const PlayerVideo> frame, dcp::NoteHandler
 Data
 DCPVideo::encode_locally (dcp::NoteHandler note)
 {
-       Data enc = compress_j2k (
-               convert_to_xyz (_frame, note),
-               _j2k_bandwidth,
-               _frames_per_second,
-               _frame->eyes() == EYES_LEFT || _frame->eyes() == EYES_RIGHT,
-               _resolution == RESOLUTION_4K
+       shared_ptr<JPEG2000Encoder> encoder;
+       if (Config::instance()->encoder ()) {
+               encoder = JPEG2000Encoder::from_id (Config::instance()->encoder().get ());
+       }
+
+       if (!encoder) {
+               encoder = JPEG2000Encoder::all().front ();
+       }
+
+       shared_ptr<EncodedData> enc = encoder->encode (
+               xyz, note, _j2k_bandwidth, _frames_per_second, _resolution, _frame->eyes() == EYES_LEFT || _frame->eyes() == EYES_RIGHT
                );
 
        switch (_frame->eyes()) {
index 968e81439396881a6152e16951588c79998a7d7b..b5de4168f0491c8cfb310252a15bb2c837c7d5bb 100644 (file)
@@ -80,3 +80,9 @@ ProgrammingError::ProgrammingError (string file, int line)
 {
 
 }
+
+JPEG2000EncoderUnavailableException::JPEG2000EncoderUnavailableException (string encoder_name, string message)
+       : StringError (String::compose (_("Encoder %1 unavailable: %2"), encoder_name, message))
+{
+
+}
index 3e7289a50e13e00c4c04259ff7c63bb65ba5bdce..a7ca01683ebcdce0c749f830c79b4e3bb011b9bc 100644 (file)
@@ -240,6 +240,26 @@ public:
        ProgrammingError (std::string file, int line);
 };
 
+class JPEG2000EncoderUnavailableException : public std::runtime_error
+{
+public:
+       JPEG2000EncoderUnavailableException (std::string encoder_name, std::string message);
+
+       ~JPEG2000EncoderUnavailableException () throw () {}
+
+       std::string encoder_name () const {
+               return _encoder_name;
+       }
+
+       std::string message () const {
+               return _message;
+       }
+
+private:
+       std::string _encoder_name;
+       std::string _message;
+};
+
 class TextEncodingError : public std::runtime_error
 {
 public:
diff --git a/src/lib/jpeg2000_encoder.cc b/src/lib/jpeg2000_encoder.cc
new file mode 100644 (file)
index 0000000..9224f23
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "jpeg2000_encoder.h"
+#include "poznan_encoder.h"
+#include "openjpeg_encoder.h"
+#include "exceptions.h"
+#include <boost/shared_ptr.hpp>
+#include <boost/foreach.hpp>
+#include <vector>
+
+using std::vector;
+using std::string;
+using boost::shared_ptr;
+
+#define LOG_GENERAL(...) log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL);
+
+vector<boost::shared_ptr<JPEG2000Encoder> > JPEG2000Encoder::_encoders;
+
+void
+JPEG2000Encoder::setup_encoders ()
+{
+       try {
+               _encoders.push_back (shared_ptr<JPEG2000Encoder> (new OpenJPEGEncoder ()));
+       } catch (JPEG2000EncoderUnavailableException &) {
+               
+       }
+
+       try {
+               _encoders.push_back (shared_ptr<JPEG2000Encoder> (new PoznanEncoder ()));
+       } catch (JPEG2000EncoderUnavailableException &) {
+
+       }
+}
+
+vector<shared_ptr<JPEG2000Encoder> >
+JPEG2000Encoder::all ()
+{
+       return _encoders;
+}
+
+shared_ptr<JPEG2000Encoder>
+JPEG2000Encoder::from_id (string id)
+{
+       BOOST_FOREACH (shared_ptr<JPEG2000Encoder> i, _encoders) {
+               if (i->id() == id) {
+                       return i;
+               }
+       }
+
+       return shared_ptr<JPEG2000Encoder> ();
+}
+
+shared_ptr<EncodedData>
+JPEG2000Encoder::encode (shared_ptr<const dcp::XYZImage> input,        dcp::NoteHandler note, int bandwidth, int frame_rate, Resolution resolution, bool threed)
+{
+       if (!_last_bandwidth || _last_bandwidth.get() != bandwidth) {
+               _last_bandwidth = bandwidth;
+               set_bandwidth (bandwidth);
+       }
+
+       if (!_last_frame_rate || _last_frame_rate.get() != frame_rate) {
+               _last_frame_rate = frame_rate;
+               set_frame_rate (frame_rate);
+       }
+
+       if (!_last_resolution || _last_resolution.get() != resolution) {
+               _last_resolution = resolution;
+               set_frame_rate (resolution);
+       }
+       
+       if (!_last_threed || _last_threed.get() != threed) {
+               _last_threed = threed;
+               set_frame_rate (threed);
+       }
+
+       return do_encode (input, note);
+}
diff --git a/src/lib/jpeg2000_encoder.h b/src/lib/jpeg2000_encoder.h
new file mode 100644 (file)
index 0000000..f204227
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef DCPOMATIC_JPEG2000_ENCODER_H
+#define DCPOMATIC_JPEG2000_ENCODER_H
+
+#include "types.h"
+#include <dcp/types.h>
+#include <boost/shared_ptr.hpp>
+#include <boost/optional.hpp>
+#include <list>
+
+namespace dcp {
+       class XYZImage;
+}
+
+class EncodedData;
+
+class JPEG2000Encoder
+{
+public:
+       virtual ~JPEG2000Encoder () {}
+       
+       /** @return Internationalised descriptive name for this encoder */
+       virtual std::string name () const = 0;
+       /** @return Non-internationalised ID for this encoder */
+       virtual std::string id () const = 0;
+
+       /** @param input XYZ input frame.
+        *  @param note_handler Handler for notes about the encode.
+        
+        *  @return Encoded JPEG2000 data.
+        */
+       boost::shared_ptr<EncodedData> encode (
+               boost::shared_ptr<const dcp::XYZImage> input,
+               dcp::NoteHandler note_handler,
+               int bandwidth,
+               int frame_rate,
+               Resolution resolution,
+               bool threed
+               );
+
+       static void setup_encoders ();
+       /** @return Return all available JPEG2000 encoders in order of preference (best first) */
+       static std::vector<boost::shared_ptr<JPEG2000Encoder> > all ();
+       static boost::shared_ptr<JPEG2000Encoder> from_id (std::string id);
+
+protected:
+
+       virtual boost::shared_ptr<EncodedData> do_encode (
+               boost::shared_ptr<const dcp::XYZImage> input,
+               dcp::NoteHandler note_handler
+               ) = 0;
+       
+       virtual void set_bandwidth (int bandwidth) = 0;
+       virtual void set_frame_rate (int frame_rate) = 0;
+       virtual void set_resolution (Resolution resolution) = 0;
+       virtual void set_threed (bool threed) = 0;
+
+       boost::optional<int> _last_bandwidth;
+       boost::optional<int> _last_frame_rate;
+       boost::optional<Resolution> _last_resolution;
+       boost::optional<bool> _last_threed;
+
+       static std::vector<boost::shared_ptr<JPEG2000Encoder> > _encoders;
+};
+
+#endif
diff --git a/src/lib/openjpeg_encoder.cc b/src/lib/openjpeg_encoder.cc
new file mode 100644 (file)
index 0000000..545c6ad
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+    Adapted from code Copyright (C) 2010-2011 Terrence Meiczinger
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "openjpeg_encoder.h"
+#include "encoded_data.h"
+#include "exceptions.h"
+#include <dcp/xyz_image.h>
+
+#include "i18n.h"
+
+using std::string;
+using boost::shared_ptr;
+
+string
+OpenJPEGEncoder::name () const
+{
+       return _("OpenJPEG library");
+}
+
+shared_ptr<EncodedData>
+OpenJPEGEncoder::do_encode (shared_ptr<const dcp::XYZImage> input, dcp::NoteHandler note)
+{
+       /* Set the max image and component sizes based on frame_rate */
+       int max_cs_len = ((float) _bandwidth) / 8 / _frame_rate;
+       if (_threed) {
+               /* In 3D we have only half the normal bandwidth per eye */
+               max_cs_len /= 2;
+       }
+       int const max_comp_size = max_cs_len / 1.25;
+
+       /* get a J2K compressor handle */
+       opj_cinfo_t* cinfo = opj_create_compress (CODEC_J2K);
+       if (cinfo == 0) {
+               throw EncodeError (N_("could not create JPEG2000 encoder"));
+       }
+
+       /* Set encoding parameters to default values */
+       opj_cparameters_t parameters;
+       opj_set_default_encoder_parameters (&parameters);
+
+       /* Set default cinema parameters */
+       parameters.tile_size_on = false;
+       parameters.cp_tdx = 1;
+       parameters.cp_tdy = 1;
+       
+       /* Tile part */
+       parameters.tp_flag = 'C';
+       parameters.tp_on = 1;
+       
+       /* Tile and Image shall be at (0,0) */
+       parameters.cp_tx0 = 0;
+       parameters.cp_ty0 = 0;
+       parameters.image_offset_x0 = 0;
+       parameters.image_offset_y0 = 0;
+
+       /* Codeblock size = 32x32 */
+       parameters.cblockw_init = 32;
+       parameters.cblockh_init = 32;
+       parameters.csty |= 0x01;
+       
+       /* The progression order shall be CPRL */
+       parameters.prog_order = CPRL;
+       
+       /* No ROI */
+       parameters.roi_compno = -1;
+       
+       parameters.subsampling_dx = 1;
+       parameters.subsampling_dy = 1;
+       
+       /* 9-7 transform */
+       parameters.irreversible = 1;
+       
+       parameters.tcp_rates[0] = 0;
+       parameters.tcp_numlayers++;
+       parameters.cp_disto_alloc = 1;
+       parameters.cp_rsiz = _resolution == RESOLUTION_2K ? CINEMA2K : CINEMA4K;
+       if (_resolution == RESOLUTION_4K) {
+               parameters.numpocs = 2;
+               parameters.POC[0].tile = 1;
+               parameters.POC[0].resno0 = 0; 
+               parameters.POC[0].compno0 = 0;
+               parameters.POC[0].layno1 = 1;
+               parameters.POC[0].resno1 = parameters.numresolution - 1;
+               parameters.POC[0].compno1 = 3;
+               parameters.POC[0].prg1 = CPRL;
+               parameters.POC[1].tile = 1;
+               parameters.POC[1].resno0 = parameters.numresolution - 1; 
+               parameters.POC[1].compno0 = 0;
+               parameters.POC[1].layno1 = 1;
+               parameters.POC[1].resno1 = parameters.numresolution;
+               parameters.POC[1].compno1 = 3;
+               parameters.POC[1].prg1 = CPRL;
+       }
+       
+       parameters.cp_comment = strdup (N_("DCP-o-matic"));
+       parameters.cp_cinema = _resolution == RESOLUTION_2K ? CINEMA2K_24 : CINEMA4K_24;
+
+       /* 3 components, so use MCT */
+       parameters.tcp_mct = 1;
+       
+       /* set max image */
+       parameters.max_comp_size = max_comp_size;
+       parameters.tcp_rates[0] = ((float) (3 * input->size().width * input->size().height * 12)) / (max_cs_len * 8);
+
+       /* Set event manager to null (openjpeg 1.3 bug) */
+       cinfo->event_mgr = 0;
+
+       /* Setup the encoder parameters using the current image and user parameters */
+       opj_setup_encoder (cinfo, &parameters, input->opj_image ());
+
+       opj_cio_t* cio = opj_cio_open ((opj_common_ptr) cinfo, 0, 0);
+       if (cio == 0) {
+               opj_destroy_compress (cinfo);
+               throw EncodeError (N_("could not open JPEG2000 stream"));
+       }
+
+       int const r = opj_encode (cinfo, cio, input->opj_image(), 0);
+       if (r == 0) {
+               opj_cio_close (cio);
+               opj_destroy_compress (cinfo);
+               throw EncodeError (N_("JPEG2000 encoding failed"));
+       }
+
+       shared_ptr<EncodedData> enc (new LocallyEncodedData (cio->buffer, cio_tell (cio)));
+
+       opj_cio_close (cio);
+       free (parameters.cp_comment);
+       opj_destroy_compress (cinfo);
+
+       return enc;
+}
+
+
+void
+OpenJPEGEncoder::set_bandwidth (int bandwidth)
+{
+       _bandwidth = bandwidth;
+}
+
+void
+OpenJPEGEncoder::set_frame_rate (int frame_rate)
+{
+       _frame_rate = frame_rate;
+}
+
+void
+OpenJPEGEncoder::set_resolution (Resolution resolution)
+{
+       _resolution = resolution;
+}
+
+void
+OpenJPEGEncoder::set_threed (bool threed)
+{
+       _threed = threed;
+}
diff --git a/src/lib/openjpeg_encoder.h b/src/lib/openjpeg_encoder.h
new file mode 100644 (file)
index 0000000..9de65b1
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "jpeg2000_encoder.h"
+#include "types.h"
+
+class OpenJPEGEncoder : public JPEG2000Encoder
+{
+public:
+       std::string name () const;
+
+       std::string id () const {
+               return "openjpeg";
+       }
+
+protected:
+       boost::shared_ptr<EncodedData> do_encode (boost::shared_ptr<const dcp::XYZImage> input, dcp::NoteHandler note_handler);
+
+private:
+       void set_bandwidth (int bandwidth);
+       void set_threed (bool threed);
+       void set_resolution (Resolution resolution);
+       void set_frame_rate (int frame_rate);
+
+       int _bandwidth;
+       bool _threed;
+       Resolution _resolution;
+       int _frame_rate;
+};
diff --git a/src/lib/poznan_encoder.cc b/src/lib/poznan_encoder.cc
new file mode 100644 (file)
index 0000000..2da9770
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "poznan_encoder.h"
+#include "exceptions.h"
+#include "poznan/config/parameters.h"
+#include <dlfcn.h>
+
+#include "i18n.h"
+
+using std::string;
+using boost::shared_ptr;
+
+PoznanEncoder::PoznanEncoder ()
+{
+       /* XXX: need cross-platform implementation of dlopen etc. */
+       
+       void* config = dlopen ("libdcpomatic-config.so", RTLD_LAZY | RTLD_GLOBAL);
+       if (!config) {
+               throw JPEG2000EncoderUnavailableException (name(), "could not find libdcpomatic-config.so");
+       }
+
+       void* misc = dlopen ("libdcpomatic-misc.so", RTLD_LAZY | RTLD_GLOBAL);
+       if (!misc) {
+               throw JPEG2000EncoderUnavailableException (name(), "could not find libdcpomatic-misc.so");
+       }
+       
+       void (*init_device) (type_parameters *);
+       init_device = (void (*)(type_parameters *)) dlsym (config, "init_device");
+       if (!init_device) {
+               throw JPEG2000EncoderUnavailableException (name(), "missing symbol");
+       }
+               
+       type_parameters param;
+
+       /* One tile which covers entire image */
+       param.param_tile_w = -1;
+       param.param_tile_h = -1;
+
+       /* XXX */
+       /*
+       uint8_t param_tile_comp_dlvls;
+       uint8_t param_cblk_exp_w; ///Maximum codeblock size is 2^6 x 2^6 ( 64 x 64 ).
+       uint8_t param_cblk_exp_h; ///Maximum codeblock size is 2^6 x 2^6 ( 64 x 64 ).
+       uint8_t param_wavelet_type; ///Lossy encoding
+       uint8_t param_use_mct;//Multi-component transform
+       */
+       param.param_device = 0;
+       /*
+       uint32_t param_target_size;//Target size of output file
+       float param_bp;//Bits per pixel per component
+       uint8_t param_use_part2_mct; // Multiple component transform as in 15444-2
+       uint8_t param_mct_compression_method; // 0 klt 2 wavelet
+       uint32_t param_mct_klt_iterations; // max number of iterations of Gram-Schmidt algorithm
+       float param_mct_klt_border_eigenvalue; // cut-off for dumping components 
+       float param_mct_klt_err; // error sufficient for Gram-Schmit algorithm to end iteration
+       */
+       
+       init_device (&param);
+}
+
+string
+PoznanEncoder::name () const
+{
+       return _("CUDA (GPU) encoder (Poznan Supercomputing and Networking Center)");
+}
+
+void
+PoznanEncoder::set_bandwidth (int bandwidth)
+{
+       /* XXX */
+}
+
+void
+PoznanEncoder::set_frame_rate (int frame_rate)
+{
+       /* XXX */
+}
+
+void
+PoznanEncoder::set_resolution (Resolution resolution)
+{
+       /* XXX */
+}
+
+void
+PoznanEncoder::set_threed (bool threed)
+{
+       /* XXX */
+}
+
+shared_ptr<EncodedData>
+PoznanEncoder::do_encode (shared_ptr<const dcp::XYZImage> input, dcp::NoteHandler note_handler)
+{
+       return shared_ptr<EncodedData> ();
+}
diff --git a/src/lib/poznan_encoder.h b/src/lib/poznan_encoder.h
new file mode 100644 (file)
index 0000000..3a29c71
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include "jpeg2000_encoder.h"
+#include <string>
+
+class PoznanEncoder : public JPEG2000Encoder
+{
+public:
+       PoznanEncoder ();
+       
+       std::string name () const;
+
+       std::string id () const {
+               return "poznan";
+       }
+
+protected:
+
+       boost::shared_ptr<EncodedData> do_encode (
+               boost::shared_ptr<const dcp::XYZImage> input,
+               dcp::NoteHandler note_handler
+               );
+       
+       void set_bandwidth (int bandwidth);
+       void set_frame_rate (int frame_rate);
+       void set_resolution (Resolution resolution);
+       void set_threed (bool threed);
+};
index a6f38147fc8ae7d72d1d0e0e92a9fea8b751a1f0..02c2848133200c1a5487acb458e3493256b70cd8 100644 (file)
@@ -36,6 +36,7 @@
 #include "audio_processor.h"
 #include "safe_stringstream.h"
 #include "compose.hpp"
+#include "jpeg2000_encoder.h"
 #include <dcp/util.h>
 #include <dcp/picture_asset.h>
 #include <dcp/sound_asset.h>
@@ -335,6 +336,7 @@ dcpomatic_setup ()
        Pango::init ();
        dcp::init ();
 
+       JPEG2000Encoder::setup_encoders ();
        Ratio::setup_ratios ();
        PresetColourConversion::setup_colour_conversion_presets ();
        VideoContentScale::setup_scales ();
index 8dd241a4d92852ee6baab7969bf0d354b1ee2705..7f7d63e5a0261fc8f1e3086271e312e22c3da7ba 100644 (file)
@@ -88,16 +88,19 @@ sources = """
           j2k_image_proxy.cc
           job.cc
           job_manager.cc
+          jpeg2000_encoder.cc
           json_server.cc
           log.cc
           log_entry.cc
           magick_image_proxy.cc
           md5_digester.cc
           mid_side_decoder.cc
+          openjpeg_encoder.cc
           player.cc
           player_subtitles.cc
           player_video.cc
           playlist.cc
+          poznan_encoder.cc
           position_image.cc
           ratio.cc
           raw_image_proxy.cc
index eb3736c6c5de59e3290d2f0bceb43beda10d67d8..77caf11b69b3ee130290917ad9e94e768973df39 100644 (file)
@@ -232,8 +232,15 @@ private:
                table->Add (bottom_table, wxGBPosition (r, 0), wxGBSpan (2, 2), wxEXPAND);
                ++r;
 
-               _set_language->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED,   boost::bind (&GeneralPage::set_language_changed, this));
-               _language->Bind     (wxEVT_COMMAND_CHOICE_SELECTED,    boost::bind (&GeneralPage::language_changed,     this));
+               add_label_to_sizer (table, _panel, _("JPEG2000 encoder"), true);
+               _encoder = new wxChoice (_panel, wxID_ANY);
+               BOOST_FOREACH (shared_ptr<JPEG2000Encoder> i, JPEG2000Encoder::all()) {
+                       _encoder->Append (std_to_wx (i->name ()));
+               }
+               table->Add (_encoder, 1);
+
+               _set_language->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&GeneralPage::set_language_changed, this));
+               _language->Bind     (wxEVT_COMMAND_CHOICE_SELECTED,  boost::bind (&GeneralPage::language_changed,     this));
                _cinemas_file->Bind (wxEVT_COMMAND_FILEPICKER_CHANGED, boost::bind (&GeneralPage::cinemas_file_changed, this));
 
                _num_local_encoding_threads->SetRange (1, 128);
@@ -289,9 +296,23 @@ private:
                checked_set (_check_for_test_updates, config->check_for_test_updates ());
                checked_set (_issuer, config->dcp_issuer ());
                checked_set (_creator, config->dcp_creator ());
+<<<<<<< 0f3c2864599f9e5a5ec001266b4aefb0205d1e1f
                checked_set (_cinemas_file, config->cinemas_file());
 
                setup_sensitivity ();
+=======
+
+               if (!config->encoder ()) {
+                       checked_set (_encoder, 0);
+               } else {
+                       vector<shared_ptr<JPEG2000Encoder> > encoders = JPEG2000Encoder::all ();
+                       for (size_t i = 0; i < encoders.size(); ++i) {
+                               if (encoders[i]->id() == config->encoder().get ()) {
+                                       checked_set (_encoder, i);
+                               }
+                       }
+               }
+>>>>>>> Basic classes for different JPEG2000 encoders; config to choose one.
        }
 
        void setup_sensitivity ()
@@ -374,6 +395,7 @@ private:
        wxCheckBox* _check_for_test_updates;
        wxTextCtrl* _issuer;
        wxTextCtrl* _creator;
+       wxChoice* _encoder;
 };
 
 class DefaultsPage : public StandardPage
diff --git a/wscript b/wscript
index 02429c56c81f852d24d2ce01d70796a108df777c..98b1363684b73230256a2760a44ed44226f7000c 100644 (file)
--- a/wscript
+++ b/wscript
@@ -390,6 +390,9 @@ def configure(conf):
 
     conf.find_program('msgfmt', var='MSGFMT')
 
+    # Check for headers of poznan JPEG2000 encoding library
+    conf.check(header_name="poznan/config/parameters.h")
+
     datadir = conf.env.DATADIR
     if not datadir:
         datadir = os.path.join(conf.env.PREFIX, 'share')