summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-01-24 00:41:33 +0000
committerCarl Hetherington <cth@carlh.net>2018-01-24 00:41:33 +0000
commitd2593fb73b15c66dd2c9b28dad53a98186c2a70a (patch)
treedfefe2af5d6142f0c13d038d9ff83118de78e887
parent0a47e4c639c5dbdbec5172ef0366e6f02428f74f (diff)
Throw exceptions in openjpeg's error handler during decode as well as encode.
-rw-r--r--src/j2k.cc16
1 files 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<ReadBuffer*>(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::OpenJPEGImage>
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<WriteBuffer*>(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.
*/