From ca34d35b476868f98d5b7dde00f07831a4302e6b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 10 Jun 2015 14:58:26 +0100 Subject: [PATCH] Shift 8-bit XYZ images up so that they are at least visible (part of #497). --- src/lib/j2k_image_proxy.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lib/j2k_image_proxy.cc b/src/lib/j2k_image_proxy.cc index a5d13b869..28b7299c8 100644 --- a/src/lib/j2k_image_proxy.cc +++ b/src/lib/j2k_image_proxy.cc @@ -22,6 +22,7 @@ #include "image.h" #include "data.h" #include "raw_convert.h" +#include #include #include #include @@ -31,6 +32,7 @@ #include "i18n.h" using std::string; +using std::cout; using boost::shared_ptr; using boost::optional; @@ -80,14 +82,22 @@ J2KImageProxy::image (optional note) const { shared_ptr image (new Image (PIX_FMT_RGB48LE, _size, true)); - dcp::xyz_to_rgb ( - dcp::decompress_j2k (const_cast (_data.data().get()), _data.size (), 0), - dcp::ColourConversion::srgb_to_xyz(), - image->data()[0], - image->stride()[0], - note - ); + shared_ptr xyz = dcp::decompress_j2k (const_cast (_data.data().get()), _data.size (), 0); + + if (xyz->opj_image()->comps[0].prec < 12) { + int const shift = 12 - xyz->opj_image()->comps[0].prec; + for (int c = 0; c < 3; ++c) { + int* p = xyz->data (c); + for (int y = 0; y < xyz->size().height; ++y) { + for (int x = 0; x < xyz->size().width; ++x) { + *p++ <<= shift; + } + } + } + } + dcp::xyz_to_rgb (xyz, dcp::ColourConversion::srgb_to_xyz(), image->data()[0], image->stride()[0], note); + return image; } -- 2.30.2