From 3e230d3785f19bc707fd7ea2b1f55321b93f536f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 26 Jul 2017 15:47:52 +0100 Subject: Multi-threaded decode of DCP when previewing. --- src/lib/j2k_image_proxy.cc | 50 +++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'src/lib/j2k_image_proxy.cc') diff --git a/src/lib/j2k_image_proxy.cc b/src/lib/j2k_image_proxy.cc index f7e6dd5f4..9e68951e9 100644 --- a/src/lib/j2k_image_proxy.cc +++ b/src/lib/j2k_image_proxy.cc @@ -93,35 +93,45 @@ J2KImageProxy::J2KImageProxy (shared_ptr xml, shared_ptr soc socket->read (_data.data().get (), _data.size ()); } -shared_ptr -J2KImageProxy::image (optional, optional target_size) const +void +J2KImageProxy::prepare (optional target_size) const { - if (!_decompressed || target_size != _target_size) { - int reduce = 0; + boost::mutex::scoped_lock lm (_mutex); - while (target_size && (_size.width / pow(2, reduce)) > target_size->width && (_size.height / pow(2, reduce)) > target_size->height) { - ++reduce; - } + if (_decompressed && target_size == _target_size) { + return; + } - --reduce; - reduce = max (0, reduce); - _decompressed = dcp::decompress_j2k (const_cast (_data.data().get()), _data.size (), reduce); + int reduce = 0; - if (_decompressed->precision(0) < 12) { - int const shift = 12 - _decompressed->precision (0); - for (int c = 0; c < 3; ++c) { - int* p = _decompressed->data (c); - for (int y = 0; y < _decompressed->size().height; ++y) { - for (int x = 0; x < _decompressed->size().width; ++x) { - *p++ <<= shift; - } + while (target_size && (_size.width / pow(2, reduce)) > target_size->width && (_size.height / pow(2, reduce)) > target_size->height) { + ++reduce; + } + + --reduce; + reduce = max (0, reduce); + _decompressed = dcp::decompress_j2k (const_cast (_data.data().get()), _data.size (), reduce); + + if (_decompressed->precision(0) < 12) { + int const shift = 12 - _decompressed->precision (0); + for (int c = 0; c < 3; ++c) { + int* p = _decompressed->data (c); + for (int y = 0; y < _decompressed->size().height; ++y) { + for (int x = 0; x < _decompressed->size().width; ++x) { + *p++ <<= shift; } } } - - _target_size = target_size; } + _target_size = target_size; +} + +shared_ptr +J2KImageProxy::image (optional, optional target_size) const +{ + prepare (target_size); + shared_ptr image (new Image (_pixel_format, _decompressed->size(), true)); /* Copy data in whatever format (sRGB or XYZ) into our Image; I'm assuming -- cgit v1.2.3