From 23cfe2a3639bb4119c20cd1456f59e3744f489a7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 4 Dec 2015 11:51:01 +0000 Subject: Add missing seek code; fix memory leak. --- src/j2k.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/j2k.cc b/src/j2k.cc index c5502ec3..79b7ca89 100644 --- a/src/j2k.cc +++ b/src/j2k.cc @@ -158,6 +158,12 @@ public: return nb_bytes; } + OPJ_BOOL seek (OPJ_SIZE_T nb_bytes) + { + _offset = nb_bytes; + return OPJ_TRUE; + } + Data data () const { return _data; } @@ -179,6 +185,13 @@ write_free_function (void* data) delete reinterpret_cast(data); } +static OPJ_BOOL +seek_function (OPJ_OFF_T nb_bytes, void* data) +{ + return reinterpret_cast(data)->seek (nb_bytes); +} + + Data dcp::compress_j2k (shared_ptr xyz, int bandwidth, int frames_per_second, bool threed, bool fourk) { @@ -275,6 +288,7 @@ dcp::compress_j2k (shared_ptr xyz, int bandwidth, int frame } opj_stream_set_write_function (stream, write_function); + opj_stream_set_seek_function (stream, seek_function); WriteBuffer* buffer = new WriteBuffer (); opj_stream_set_user_data (stream, buffer, write_free_function); @@ -289,6 +303,8 @@ dcp::compress_j2k (shared_ptr xyz, int bandwidth, int frame } if (!opj_end_compress (encoder, stream)) { + opj_destroy_codec (encoder); + opj_stream_destroy (stream); throw MiscError ("could not end JPEG2000 encoding"); } -- cgit v1.2.3