From d2593fb73b15c66dd2c9b28dad53a98186c2a70a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 24 Jan 2018 00:41:33 +0000 Subject: Throw exceptions in openjpeg's error handler during decode as well as encode. --- src/j2k.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/j2k.cc b/src/j2k.cc index b3192025..f1e4c3f5 100644 --- a/src/j2k.cc +++ b/src/j2k.cc @@ -90,6 +90,12 @@ read_free_function (void* data) delete reinterpret_cast(data); } +static void +error_callback (char const * msg, void *) +{ + throw MiscError (msg); +} + /** Decompress a JPEG2000 image to a bitmap. * @param data JPEG2000 data. * @param size Size of data in bytes. @@ -102,6 +108,8 @@ read_free_function (void* data) shared_ptr dcp::decompress_j2k (uint8_t* data, int64_t size, int reduce) { + DCP_ASSERT (reduce >= 0); + uint8_t const jp2_magic[] = { 0x00, 0x00, @@ -132,6 +140,8 @@ dcp::decompress_j2k (uint8_t* data, int64_t size, int reduce) throw MiscError ("could not create JPEG2000 stream"); } + opj_set_error_handler(decoder, error_callback, 00); + opj_stream_set_read_function (stream, read_function); ReadBuffer* buffer = new ReadBuffer (data, size); opj_stream_set_user_data (stream, buffer, read_free_function); @@ -251,12 +261,6 @@ seek_function (OPJ_OFF_T nb_bytes, void* data) return reinterpret_cast(data)->seek (nb_bytes); } -static void -error_callback (char const * msg, void *) -{ - throw MiscError (msg); -} - /** @xyz Picture to compress. Parts of xyz's data WILL BE OVERWRITTEN by libopenjpeg so xyz cannot be re-used * after this call; see opj_j2k_encode where if l_reuse_data is false it will set l_tilec->data = l_img_comp->data. */ -- cgit v1.2.3