diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-11-06 01:32:06 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-11-06 01:42:52 +0000 |
| commit | 7f23456dce480a813f1d6ebb22cf6aa0d5214c49 (patch) | |
| tree | 1a68823bff672cae8b466c73a8e6576153b3e531 /src/lib | |
| parent | a5c1639bb3c8b880d2742eadf4c2fb3094ad60be (diff) | |
Move deinterleave of OpenJPEGImage to Image into the prepare(), meaning
that it can be multi-threaded. This allows the bit shift for non-12bpp
JPEG2000 sources to be done at the same time as the deinterleave.
Should speed up DCP playback in some cases.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/j2k_image_proxy.cc | 62 | ||||
| -rw-r--r-- | src/lib/j2k_image_proxy.h | 2 |
2 files changed, 26 insertions, 38 deletions
diff --git a/src/lib/j2k_image_proxy.cc b/src/lib/j2k_image_proxy.cc index 1ef00d946..1422b6948 100644 --- a/src/lib/j2k_image_proxy.cc +++ b/src/lib/j2k_image_proxy.cc @@ -118,7 +118,7 @@ J2KImageProxy::prepare (optional<dcp::Size> target_size) const { boost::mutex::scoped_lock lm (_mutex); - if (_decompressed && target_size == _target_size) { + if (_image && target_size == _target_size) { DCPOMATIC_ASSERT (_reduce); return *_reduce; } @@ -136,54 +136,42 @@ J2KImageProxy::prepare (optional<dcp::Size> target_size) const 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; - _reduce = reduce; + shared_ptr<dcp::OpenJPEGImage> decompressed = dcp::decompress_j2k (const_cast<uint8_t*> (_data.data().get()), _data.size (), reduce); - return reduce; -} - -pair<shared_ptr<Image>, int> -J2KImageProxy::image (optional<dcp::NoteHandler>, optional<dcp::Size> target_size) const -{ - int const reduce = prepare (target_size); + _image.reset (new Image (_pixel_format, decompressed->size(), true)); - shared_ptr<Image> image (new Image (_pixel_format, _decompressed->size(), true)); + int const shift = 16 - decompressed->precision (0); /* Copy data in whatever format (sRGB or XYZ) into our Image; I'm assuming the data is 12-bit either way. */ - int const width = _decompressed->size().width; + int const width = decompressed->size().width; int p = 0; - int* decomp_0 = _decompressed->data (0); - int* decomp_1 = _decompressed->data (1); - int* decomp_2 = _decompressed->data (2); - for (int y = 0; y < _decompressed->size().height; ++y) { - uint16_t* q = (uint16_t *) (image->data()[0] + y * image->stride()[0]); + int* decomp_0 = decompressed->data (0); + int* decomp_1 = decompressed->data (1); + int* decomp_2 = decompressed->data (2); + for (int y = 0; y < decompressed->size().height; ++y) { + uint16_t* q = (uint16_t *) (_image->data()[0] + y * _image->stride()[0]); for (int x = 0; x < width; ++x) { - *q++ = decomp_0[p] << 4; - *q++ = decomp_1[p] << 4; - *q++ = decomp_2[p] << 4; + *q++ = decomp_0[p] << shift; + *q++ = decomp_1[p] << shift; + *q++ = decomp_2[p] << shift; ++p; } } - return make_pair (image, reduce); + _target_size = target_size; + _reduce = reduce; + + return reduce; +} + +pair<shared_ptr<Image>, int> +J2KImageProxy::image (optional<dcp::NoteHandler>, optional<dcp::Size> target_size) const +{ + return make_pair (_image, prepare(target_size)); } void @@ -232,9 +220,9 @@ size_t J2KImageProxy::memory_used () const { size_t m = _data.size(); - if (_decompressed) { + if (_image) { /* 3 components, 16-bits per pixel */ - m += 3 * 2 * _decompressed->size().width * _decompressed->size().height; + m += 3 * 2 * _image->size().width * _image->size().height; } return m; } diff --git a/src/lib/j2k_image_proxy.h b/src/lib/j2k_image_proxy.h index a67cc24de..8e9a0fa99 100644 --- a/src/lib/j2k_image_proxy.h +++ b/src/lib/j2k_image_proxy.h @@ -80,7 +80,7 @@ private: dcp::Data _data; dcp::Size _size; boost::optional<dcp::Eye> _eye; - mutable boost::shared_ptr<dcp::OpenJPEGImage> _decompressed; + mutable boost::shared_ptr<Image> _image; mutable boost::optional<dcp::Size> _target_size; mutable boost::optional<int> _reduce; AVPixelFormat _pixel_format; |
