From 0253b4e45c71a1c2e2a8bffaf1c3cb84a0a3e41a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 3 Aug 2017 17:54:06 +0100 Subject: Basics of forced reduction of JPEG2000 decode resolution. --- src/lib/j2k_image_proxy.cc | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src/lib/j2k_image_proxy.cc') diff --git a/src/lib/j2k_image_proxy.cc b/src/lib/j2k_image_proxy.cc index 9e68951e9..a60af1eb2 100644 --- a/src/lib/j2k_image_proxy.cc +++ b/src/lib/j2k_image_proxy.cc @@ -53,18 +53,31 @@ J2KImageProxy::J2KImageProxy (boost::filesystem::path path, dcp::Size size, AVPi } -J2KImageProxy::J2KImageProxy (shared_ptr frame, dcp::Size size, AVPixelFormat pixel_format) +J2KImageProxy::J2KImageProxy ( + shared_ptr frame, + dcp::Size size, + AVPixelFormat pixel_format, + optional forced_reduction + ) : _data (frame->j2k_size ()) , _size (size) , _pixel_format (pixel_format) + , _forced_reduction (forced_reduction) { memcpy (_data.data().get(), frame->j2k_data(), _data.size ()); } -J2KImageProxy::J2KImageProxy (shared_ptr frame, dcp::Size size, dcp::Eye eye, AVPixelFormat pixel_format) +J2KImageProxy::J2KImageProxy ( + shared_ptr frame, + dcp::Size size, + dcp::Eye eye, + AVPixelFormat pixel_format, + optional forced_reduction + ) : _size (size) , _eye (eye) , _pixel_format (pixel_format) + , _forced_reduction (forced_reduction) { switch (eye) { case dcp::EYE_LEFT: @@ -104,12 +117,17 @@ J2KImageProxy::prepare (optional target_size) const int reduce = 0; - while (target_size && (_size.width / pow(2, reduce)) > target_size->width && (_size.height / pow(2, reduce)) > target_size->height) { - ++reduce; + 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; + } + + --reduce; + reduce = max (0, reduce); } - --reduce; - reduce = max (0, reduce); _decompressed = dcp::decompress_j2k (const_cast (_data.data().get()), _data.size (), reduce); if (_decompressed->precision(0) < 12) { -- cgit v1.2.3