+ try {
+ /* XXX: should check that potentially trashing _data here doesn't matter */
+ auto decompressed = dcp::decompress_j2k (const_cast<uint8_t*>(_data->data()), _data->size(), reduce);
+ _image = make_shared<Image>(_pixel_format, decompressed->size(), aligned);
+
+ 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 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) {
+ auto q = reinterpret_cast<uint16_t *>(_image->data()[0] + y * _image->stride()[0]);
+ for (int x = 0; x < width; ++x) {
+ *q++ = decomp_0[p] << shift;
+ *q++ = decomp_1[p] << shift;
+ *q++ = decomp_2[p] << shift;
+ ++p;
+ }
+ }
+ } catch (dcp::J2KDecompressionError& e) {
+ _image = make_shared<Image>(_pixel_format, _size, aligned);
+ _image->make_black ();
+ _error = true;
+ }
+
+ _target_size = target_size;
+ _reduce = reduce;
+
+ return reduce;