summaryrefslogtreecommitdiff
path: root/src/lib/j2k_image_proxy.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2017-07-26 15:47:52 +0100
committerCarl Hetherington <cth@carlh.net>2017-07-26 15:47:52 +0100
commit3e230d3785f19bc707fd7ea2b1f55321b93f536f (patch)
tree2773a105d2cf218d9c038418e388ff50f9b46236 /src/lib/j2k_image_proxy.cc
parentb395478cbb0706de2b6afa9a34fb33e49c61ee67 (diff)
Multi-threaded decode of DCP when previewing.
Diffstat (limited to 'src/lib/j2k_image_proxy.cc')
-rw-r--r--src/lib/j2k_image_proxy.cc50
1 files changed, 30 insertions, 20 deletions
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<cxml::Node> xml, shared_ptr<Socket> soc
socket->read (_data.data().get (), _data.size ());
}
-shared_ptr<Image>
-J2KImageProxy::image (optional<dcp::NoteHandler>, optional<dcp::Size> target_size) const
+void
+J2KImageProxy::prepare (optional<dcp::Size> 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<uint8_t*> (_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<uint8_t*> (_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<Image>
+J2KImageProxy::image (optional<dcp::NoteHandler>, optional<dcp::Size> target_size) const
+{
+ prepare (target_size);
+
shared_ptr<Image> image (new Image (_pixel_format, _decompressed->size(), true));
/* Copy data in whatever format (sRGB or XYZ) into our Image; I'm assuming