summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-12-04 23:32:09 +0100
committerCarl Hetherington <cth@carlh.net>2022-12-04 23:32:11 +0100
commit2c6d80c295dd3d10c1c9c08dd31758dd1abdf5da (patch)
tree2f6b676c56d1693e339fc61f318a450bcb78495a
parentb995947a86a583a44bbe667e9bbd031296bf7e88 (diff)
Support building either with our patched OpenJPEG, or 2.5.0.
Either has a way to specify the number of guard bits.
-rw-r--r--src/j2k_transcode.cc8
-rw-r--r--wscript21
2 files changed, 27 insertions, 2 deletions
diff --git a/src/j2k_transcode.cc b/src/j2k_transcode.cc
index 2cc903c7..596d92c1 100644
--- a/src/j2k_transcode.cc
+++ b/src/j2k_transcode.cc
@@ -281,11 +281,19 @@ dcp::compress_j2k (shared_ptr<const OpenJPEGImage> xyz, int bandwidth, int frame
parameters.max_comp_size = parameters.max_cs_size / 1.25;
parameters.tcp_numlayers = 1;
parameters.tcp_mct = 1;
+#ifdef LIBDCP_HAVE_NUMGBITS
parameters.numgbits = fourk ? 2 : 1;
+#endif
/* Setup the encoder parameters using the current image and user parameters */
opj_setup_encoder (encoder, &parameters, xyz->opj_image());
+#ifndef LIBDCP_HAVE_NUMGBITS
+ string numgbits = String::compose("GUARD_BITS=%1", fourk ? 2 : 1);
+ char const* extra_options[] = { numgbits.c_str(), nullptr };
+ opj_encoder_set_extra_options(encoder, extra_options);
+#endif
+
auto stream = opj_stream_default_create (OPJ_FALSE);
if (!stream) {
opj_destroy_codec (encoder);
diff --git a/wscript b/wscript
index 4c2d20c1..9113ee27 100644
--- a/wscript
+++ b/wscript
@@ -129,8 +129,26 @@ def configure(conf):
conf.check_cfg(package='sndfile', args='--cflags --libs', uselib_store='SNDFILE', mandatory=False)
+ # Find openjpeg so that we can test to see if it's the right version
+ if conf.options.static:
+ conf.check_cfg(package='libopenjp2', args='--cflags', uselib_store='OPENJPEG', mandatory=True, msg='Checking for any version of libopenjp2')
+ else:
+ conf.check_cfg(package='libopenjp2', args='--cflags --libs', uselib_store='OPENJPEG', mandatory=True, msg='Checking for any version of libopenjp2')
+
+ patched_openjpeg = conf.check_cxx(fragment="""
+ #include <openjpeg.h>
+ int main() { opj_cparameters_t p; p.numgbits = 2; }\n
+ """,
+ msg='Checking for numgbits in opj_cparameters_t',
+ use='OPENJPEG',
+ mandatory=False,
+ define_name='LIBDCP_HAVE_NUMGBITS')
+
+ if not patched_openjpeg:
+ # We don't have our patched version so we need 2.5.0 to get the GUARD_BITS option
+ conf.check_cfg(package='libopenjp2', args='libopenjp2 >= 2.5.0', uselib_store='OPENJPEG', mandatory=True, msg='Checking for libopenjp2 >= 2.5.0')
+
if conf.options.static:
- conf.check_cfg(package='libopenjp2', args='--cflags', atleast_version='2.1.0', uselib_store='OPENJPEG', mandatory=True)
conf.env.STLIB_OPENJPEG = ['openjp2']
conf.check_cfg(package='libasdcp-carl', atleast_version='0.1.3', args='--cflags', uselib_store='ASDCPLIB_CTH', mandatory=True)
conf.env.HAVE_ASDCPLIB_CTH = 1
@@ -141,7 +159,6 @@ def configure(conf):
conf.check_cfg(package='xerces-c', args='--cflags', uselib_store='XERCES', mandatory=True)
conf.env.LIB_XERCES = ['xerces-c', 'icuuc', 'curl']
else:
- conf.check_cfg(package='libopenjp2', args='--cflags --libs', atleast_version='2.1.0', uselib_store='OPENJPEG', mandatory=True)
conf.check_cfg(package='libasdcp-carl', atleast_version='0.1.3', args='--cflags --libs', uselib_store='ASDCPLIB_CTH', mandatory=True)
conf.check_cfg(package='libcxml', atleast_version='0.17.0', args='--cflags --libs', uselib_store='CXML', mandatory=True)
conf.check_cfg(package='xerces-c', args='--cflags --libs', uselib_store='XERCES', mandatory=True)