- shared_ptr<Image> image (new Image (PIX_FMT_RGB48LE, _size, true));
-
- shared_ptr<dcp::OpenJPEGImage> oj = dcp::decompress_j2k (const_cast<uint8_t*> (_data.data().get()), _data.size (), 0);
-
- if (oj->opj_image()->comps[0].prec < 12) {
- int const shift = 12 - oj->opj_image()->comps[0].prec;
- for (int c = 0; c < 3; ++c) {
- int* p = oj->data (c);
- for (int y = 0; y < oj->size().height; ++y) {
- for (int x = 0; x < oj->size().width; ++x) {
- *p++ <<= shift;
- }
- }
+ boost::mutex::scoped_lock lm (_mutex);
+
+ if (_image && target_size == _target_size) {
+ DCPOMATIC_ASSERT (_reduce);
+ return *_reduce;
+ }
+
+ int reduce = 0;
+
+ if (_forced_reduction) {
+ reduce = *_forced_reduction;
+ } else {
+ while (target_size && (_size.width / pow(2, reduce)) > target_size->width && (_size.height / pow(2, reduce)) > target_size->height) {
+ ++reduce;