From 2ce6e6d1d389bed4dfd82833ddf082920bc9fcd0 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Thu, 2 Jan 2020 14:35:27 +0100 Subject: [PATCH] skip unnecessary transform --- rtengine/dcrop.cc | 75 +++++++++++++++++------------------ rtengine/improccoordinator.cc | 4 +- rtengine/improcfun.h | 2 +- rtengine/iptransform.cc | 9 ++++- rtengine/rtthumbnail.cc | 10 ++--- rtengine/simpleprocess.cc | 2 +- 6 files changed, 52 insertions(+), 50 deletions(-) diff --git a/rtengine/dcrop.cc b/rtengine/dcrop.cc index a6889b954..890003ee0 100644 --- a/rtengine/dcrop.cc +++ b/rtengine/dcrop.cc @@ -173,8 +173,6 @@ void Crop::update(int todo) int widIm = parent->fw;//full image int heiIm = parent->fh; - bool needstransform = parent->ipf.needsTransform(); - if (todo & (M_INIT | M_LINDENOISE | M_HDR)) { MyMutex::MyLock lock(parent->minit); // Also used in improccoord @@ -766,8 +764,9 @@ void Crop::update(int todo) } } + const bool needstransform = parent->ipf.needsTransform(skips(parent->fw, skip), skips(parent->fh, skip), parent->imgsrc->getRotateDegree(), parent->imgsrc->getMetaData()); // transform - if (needstransform || ((todo & (M_TRANSFORM | M_RGBCURVE)) && params.dirpyrequalizer.cbdlMethod == "bef" && params.dirpyrequalizer.enabled && !params.colorappearance.enabled)) { + if (needstransform || ((todo & (M_TRANSFORM | M_RGBCURVE)) && params.dirpyrequalizer.cbdlMethod == "bef" && params.dirpyrequalizer.enabled && !params.colorappearance.enabled)) { if (!transCrop) { transCrop = new Imagefloat(cropw, croph); } @@ -784,10 +783,7 @@ void Crop::update(int todo) baseCrop = transCrop; } } else { - if (transCrop) { - delete transCrop; - } - + delete transCrop; transCrop = nullptr; } @@ -1167,41 +1163,42 @@ bool Crop::setCropSizes(int rcx, int rcy, int rcw, int rch, int skip, bool inter parent->ipf.transCoord(parent->fw, parent->fh, bx1, by1, bw, bh, orx, ory, orw, orh); - if (check_need_larger_crop_for_lcp_distortion(parent->fw, parent->fh, orx, ory, orw, orh, *parent->params)) { - // TODO - this is an estimate of the max distortion relative to the image size. ATM it is hardcoded to be 15%, which seems enough. If not, need to revise - int dW = int (double (parent->fw) * 0.15 / (2 * skip)); - int dH = int (double (parent->fh) * 0.15 / (2 * skip)); - int x1 = orx - dW; - int x2 = orx + orw + dW; - int y1 = ory - dH; - int y2 = ory + orh + dH; + if (parent->ipf.needsTransform(skips(parent->fw, skip), skips(parent->fh, skip), parent->imgsrc->getRotateDegree(), parent->imgsrc->getMetaData())) { + if (check_need_larger_crop_for_lcp_distortion(parent->fw, parent->fh, orx, ory, orw, orh, *parent->params)) { + // TODO - this is an estimate of the max distortion relative to the image size. ATM it is hardcoded to be 15%, which seems enough. If not, need to revise + int dW = int (double (parent->fw) * 0.15 / (2 * skip)); + int dH = int (double (parent->fh) * 0.15 / (2 * skip)); + int x1 = orx - dW; + int x2 = orx + orw + dW; + int y1 = ory - dH; + int y2 = ory + orh + dH; - if (x1 < 0) { - x2 += -x1; - x1 = 0; + if (x1 < 0) { + x2 += -x1; + x1 = 0; + } + + if (x2 > parent->fw) { + x1 -= x2 - parent->fw; + x2 = parent->fw; + } + + if (y1 < 0) { + y2 += -y1; + y1 = 0; + } + + if (y2 > parent->fh) { + y1 -= y2 - parent->fh; + y2 = parent->fh; + } + + orx = max(x1, 0); + ory = max(y1, 0); + orw = min(x2 - x1, parent->fw - orx); + orh = min(y2 - y1, parent->fh - ory); } - - if (x2 > parent->fw) { - x1 -= x2 - parent->fw; - x2 = parent->fw; - } - - if (y1 < 0) { - y2 += -y1; - y1 = 0; - } - - if (y2 > parent->fh) { - y1 -= y2 - parent->fh; - y2 = parent->fh; - } - - orx = max(x1, 0); - ory = max(y1, 0); - orw = min(x2 - x1, parent->fw - orx); - orh = min(y2 - y1, parent->fh - ory); } - leftBorder = skips(rqx1 - bx1, skip); upperBorder = skips(rqy1 - by1, skip); diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index a4ca0ea0b..e915a11b0 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -545,7 +545,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange) oprevi = orig_prev; // Remove transformation if unneeded - bool needstransform = ipf.needsTransform(); + bool needstransform = ipf.needsTransform(fw, fh, imgsrc->getRotateDegree(), imgsrc->getMetaData()); if ((needstransform || ((todo & (M_TRANSFORM | M_RGBCURVE)) && params->dirpyrequalizer.cbdlMethod == "bef" && params->dirpyrequalizer.enabled && !params->colorappearance.enabled))) { assert(oprevi); @@ -1349,7 +1349,7 @@ void ImProcCoordinator::saveInputICCReference(const Glib::ustring& fname, bool a imgsrc->getImage(currWB, tr, im, pp, ppar.toneCurve, ppar.raw); ImProcFunctions ipf(&ppar, true); - if (ipf.needsTransform()) { + if (ipf.needsTransform(fW, fH, imgsrc->getRotateDegree(), imgsrc->getMetaData())) { Imagefloat* trImg = new Imagefloat(fW, fH); ipf.transform(im, trImg, 0, 0, 0, 0, fW, fH, fW, fH, imgsrc->getMetaData(), imgsrc->getRotateDegree(), true); diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index c1a4a5979..8f4ae7771 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -119,7 +119,7 @@ public: } void setScale(double iscale); - bool needsTransform() const; + bool needsTransform(int oW, int oH, int rawRotationDeg, const FramesMetaData *metadata) const; bool needsPCVignetting() const; void firstAnalysis(const Imagefloat* const working, const procparams::ProcParams ¶ms, LUTu & vhist16); diff --git a/rtengine/iptransform.cc b/rtengine/iptransform.cc index fc79dcae4..c9f88caf0 100644 --- a/rtengine/iptransform.cc +++ b/rtengine/iptransform.cc @@ -1358,9 +1358,14 @@ bool ImProcFunctions::needsLensfun() const return params->lensProf.useLensfun(); } -bool ImProcFunctions::needsTransform () const +bool ImProcFunctions::needsTransform (int oW, int oH, int rawRotationDeg, const FramesMetaData *metadata) const { - return needsCA () || needsDistortion () || needsRotation () || needsPerspective () || needsGradient () || needsPCVignetting () || needsVignetting () || needsLCP() || needsLensfun(); + bool needsLf = needsLensfun(); + if (needsLf) { + std::unique_ptr pLCPMap = LFDatabase::getInstance()->findModifier(params->lensProf, metadata, oW, oH, params->coarse, rawRotationDeg); + needsLf = pLCPMap.get(); + } + return needsCA () || needsDistortion () || needsRotation () || needsPerspective () || needsGradient () || needsPCVignetting () || needsVignetting () || needsLCP() || needsLf; } diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index 0cdcbf6ed..9da601e2a 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -1247,12 +1247,12 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, eSensorT ipf.ToneMapFattal02(baseImg); // perform transform - if (ipf.needsTransform()) { + int origFW; + int origFH; + double tscale = 0.0; + getDimensions (origFW, origFH, tscale); + if (ipf.needsTransform(origFW * tscale + 0.5, origFH * tscale + 0.5, 0, metadata)) { Imagefloat* trImg = new Imagefloat (fw, fh); - int origFW; - int origFH; - double tscale = 0.0; - getDimensions (origFW, origFH, tscale); ipf.transform (baseImg, trImg, 0, 0, 0, 0, fw, fh, origFW * tscale + 0.5, origFH * tscale + 0.5, metadata, 0, true); // Raw rotate degree not detectable here delete baseImg; baseImg = trImg; diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index 3811c0c80..1c1e46a65 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -872,7 +872,7 @@ private: ipf.ToneMapFattal02(baseImg); // perform transform (excepted resizing) - if (ipf.needsTransform()) { + if (ipf.needsTransform(fw, fh, imgsrc->getRotateDegree(), imgsrc->getMetaData())) { Imagefloat* trImg = nullptr; if (ipf.needsLuminanceOnly()) { trImg = baseImg;