--- /dev/null
+#!/bin/bash
+
+# Private test data; this is stuff that is non-distributable
+private=../libdcp1-test-private
+
+export LD_LIBRARY_PATH=build/src:build/asdcplib/src:$LD_LIBRARY_PATH
+build/test/bench $private
throw FileError ("could not read file", file, -1);
}
}
+
+Data::Data (uint8_t const * data_, boost::uintmax_t size_)
+ : data (new uint8_t[size])
+ , size (size_)
+{
+ memcpy (data.get(), data_, size);
+}
*/
+#ifndef LIBDCP_DATA_H
+#define LIBDCP_DATA_H
+
/** @file src/data.h
* @brief Data class.
*/
, size (size_)
{}
+ Data (uint8_t const * data, boost::uintmax_t size_);
+
Data (boost::filesystem::path file);
boost::shared_array<uint8_t> data;
};
}
+
+#endif
return shared_ptr<OpenJPEGImage> (new OpenJPEGImage (image));
}
+Data
+dcp::compress_j2k (shared_ptr<OpenJPEGImage> xyz, int bandwidth, int frames_per_second, bool threed, bool fourk)
+{
+ /* Set the max image and component sizes based on frame_rate */
+ int max_cs_len = ((float) bandwidth) / 8 / frames_per_second;
+ 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 MiscError ("could not create JPEG2000 encoder");
+ }
+
+ /* Set encoding parameters to default values */
+ opj_cparameters_t parameters;
+ opj_set_default_encoder_parameters (¶meters);
+
+ /* 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 = fourk ? CINEMA4K : CINEMA2K;
+ if (fourk) {
+ 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 ("libdcp");
+ parameters.cp_cinema = fourk ? CINEMA4K_24 : CINEMA2K_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 * xyz->size().width * xyz->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, ¶meters, xyz->opj_image ());
+
+ opj_cio_t* cio = opj_cio_open ((opj_common_ptr) cinfo, 0, 0);
+ if (cio == 0) {
+ opj_destroy_compress (cinfo);
+ throw MiscError ("could not open JPEG2000 stream");
+ }
+
+ int const r = opj_encode (cinfo, cio, xyz->opj_image(), 0);
+ if (r == 0) {
+ opj_cio_close (cio);
+ opj_destroy_compress (cinfo);
+ throw MiscError ("JPEG2000 encoding failed");
+ }
+
+ Data enc (cio->buffer, cio_tell (cio));
+
+ opj_cio_close (cio);
+ free (parameters.cp_comment);
+ opj_destroy_compress (cinfo);
+
+ return enc;
+}
+
/** @param s A string.
* @return true if the string contains only space, newline or tab characters, or is empty.
*/
*/
#include "types.h"
+#include "data.h"
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <boost/filesystem.hpp>
extern ContentKind content_kind_from_string (std::string kind);
extern bool empty_or_white_space (std::string s);
extern boost::shared_ptr<OpenJPEGImage> decompress_j2k (uint8_t* data, int64_t size, int reduce);
+extern Data compress_j2k (boost::shared_ptr<OpenJPEGImage>, int bandwith, int frames_per_second, bool threed, bool fourk);
extern bool ids_equal (std::string a, std::string b);
extern void init ();
extern char const * version;
extern char const * git_commit;
-extern bool built_with_debug;
+extern bool const built_with_debug;
}
--- /dev/null
+/*
+ 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 "data.h"
+#include "test.h"
+#include "util.h"
+#include "version.h"
+#include <sys/time.h>
+#include <iostream>
+
+using std::cout;
+using std::cerr;
+using boost::shared_ptr;
+
+/** Run some basic benchmarks of JPEG2000 encoding / decoding */
+int
+main (int argc, char* argv[])
+{
+ if (argc < 2) {
+ cerr << "Syntax: " << argv[0] << " private-test-path\n";
+ exit (EXIT_FAILURE);
+ }
+
+ int const decompress_count = 100;
+ int const compress_count = 100;
+ int const j2k_bandwidth = 100000000;
+
+ struct timeval start;
+ dcp::Data j2k (boost::filesystem::path (argv[1]) / "thx.j2c");
+
+ gettimeofday (&start, 0);
+
+ shared_ptr<dcp::OpenJPEGImage> xyz;
+ for (int i = 0; i < decompress_count; ++i) {
+ xyz = dcp::decompress_j2k (j2k.data.get(), j2k.size, 0);
+ }
+
+ struct timeval stop;
+ gettimeofday (&stop, 0);
+
+ double start_seconds = start.tv_sec + double(start.tv_usec) / 1000000;
+ double stop_seconds = stop.tv_sec + double(start.tv_usec) / 1000000;
+ if (dcp::built_with_debug) {
+ cout << "Decompress (debug build): ";
+ } else {
+ cout << "Decompress: ";
+ }
+ cout << decompress_count / (stop_seconds - start_seconds) << " fps.\n";
+
+ gettimeofday (&start, 0);
+
+ for (int i = 0; i < compress_count; ++i) {
+ dcp::compress_j2k (xyz, j2k_bandwidth, 24, false, false);
+ }
+
+ gettimeofday (&stop, 0);
+
+ start_seconds = start.tv_sec + double(start.tv_usec) / 1000000;
+ stop_seconds = stop.tv_sec + double(start.tv_usec) / 1000000;
+ if (dcp::built_with_debug) {
+ cout << "Compress (debug build) ";
+ } else {
+ cout << "Compress ";
+ }
+
+ cout << (j2k_bandwidth / 1000000) << "Mbps: "
+ << compress_count / (stop_seconds - start_seconds) << " fps.";
+}
obj.source = 'rewrite_subs.cc'
obj.target = 'rewrite_subs'
obj.install_path = ''
+
+ obj = bld(features='cxx cxxprogram')
+ obj.name = 'bench'
+ obj.uselib = 'BOOST_FILESYSTEM OPENJPEG CXML'
+ obj.use = 'libdcp%s' % bld.env.API_VERSION
+ obj.source = 'bench.cc'
+ obj.target = 'bench'
+ obj.install_path = ''
debug_string = 'true'
else:
debug_string = 'false'
- text += 'bool const built_with_debug = %s;\n' % debug_string
+ text += 'bool const dcp::built_with_debug = %s;\n' % debug_string
print('Writing version information to src/version.cc')
o = open('src/version.cc', 'w')
o.write(text)