skip unnecessary transform

This commit is contained in:
Ingo Weyrich
2020-01-02 14:35:27 +01:00
parent 085c68fc29
commit 2ce6e6d1d3
6 changed files with 52 additions and 50 deletions

View File

@@ -173,8 +173,6 @@ void Crop::update(int todo)
int widIm = parent->fw;//full image int widIm = parent->fw;//full image
int heiIm = parent->fh; int heiIm = parent->fh;
bool needstransform = parent->ipf.needsTransform();
if (todo & (M_INIT | M_LINDENOISE | M_HDR)) { if (todo & (M_INIT | M_LINDENOISE | M_HDR)) {
MyMutex::MyLock lock(parent->minit); // Also used in improccoord MyMutex::MyLock lock(parent->minit); // Also used in improccoord
@@ -766,6 +764,7 @@ 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 // 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) { if (!transCrop) {
@@ -784,10 +783,7 @@ void Crop::update(int todo)
baseCrop = transCrop; baseCrop = transCrop;
} }
} else { } else {
if (transCrop) {
delete transCrop; delete transCrop;
}
transCrop = nullptr; transCrop = nullptr;
} }
@@ -1167,6 +1163,7 @@ 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); parent->ipf.transCoord(parent->fw, parent->fh, bx1, by1, bw, bh, orx, ory, orw, orh);
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)) { 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 // 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 dW = int (double (parent->fw) * 0.15 / (2 * skip));
@@ -1201,7 +1198,7 @@ bool Crop::setCropSizes(int rcx, int rcy, int rcw, int rch, int skip, bool inter
orw = min(x2 - x1, parent->fw - orx); orw = min(x2 - x1, parent->fw - orx);
orh = min(y2 - y1, parent->fh - ory); orh = min(y2 - y1, parent->fh - ory);
} }
}
leftBorder = skips(rqx1 - bx1, skip); leftBorder = skips(rqx1 - bx1, skip);
upperBorder = skips(rqy1 - by1, skip); upperBorder = skips(rqy1 - by1, skip);

View File

@@ -545,7 +545,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange)
oprevi = orig_prev; oprevi = orig_prev;
// Remove transformation if unneeded // 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))) { if ((needstransform || ((todo & (M_TRANSFORM | M_RGBCURVE)) && params->dirpyrequalizer.cbdlMethod == "bef" && params->dirpyrequalizer.enabled && !params->colorappearance.enabled))) {
assert(oprevi); 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); imgsrc->getImage(currWB, tr, im, pp, ppar.toneCurve, ppar.raw);
ImProcFunctions ipf(&ppar, true); ImProcFunctions ipf(&ppar, true);
if (ipf.needsTransform()) { if (ipf.needsTransform(fW, fH, imgsrc->getRotateDegree(), imgsrc->getMetaData())) {
Imagefloat* trImg = new Imagefloat(fW, fH); Imagefloat* trImg = new Imagefloat(fW, fH);
ipf.transform(im, trImg, 0, 0, 0, 0, fW, fH, fW, fH, ipf.transform(im, trImg, 0, 0, 0, 0, fW, fH, fW, fH,
imgsrc->getMetaData(), imgsrc->getRotateDegree(), true); imgsrc->getMetaData(), imgsrc->getRotateDegree(), true);

View File

@@ -119,7 +119,7 @@ public:
} }
void setScale(double iscale); void setScale(double iscale);
bool needsTransform() const; bool needsTransform(int oW, int oH, int rawRotationDeg, const FramesMetaData *metadata) const;
bool needsPCVignetting() const; bool needsPCVignetting() const;
void firstAnalysis(const Imagefloat* const working, const procparams::ProcParams &params, LUTu & vhist16); void firstAnalysis(const Imagefloat* const working, const procparams::ProcParams &params, LUTu & vhist16);

View File

@@ -1358,9 +1358,14 @@ bool ImProcFunctions::needsLensfun() const
return params->lensProf.useLensfun(); 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<const LensCorrection> 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;
} }

View File

@@ -1247,12 +1247,12 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, eSensorT
ipf.ToneMapFattal02(baseImg); ipf.ToneMapFattal02(baseImg);
// perform transform // perform transform
if (ipf.needsTransform()) {
Imagefloat* trImg = new Imagefloat (fw, fh);
int origFW; int origFW;
int origFH; int origFH;
double tscale = 0.0; double tscale = 0.0;
getDimensions (origFW, origFH, tscale); getDimensions (origFW, origFH, tscale);
if (ipf.needsTransform(origFW * tscale + 0.5, origFH * tscale + 0.5, 0, metadata)) {
Imagefloat* trImg = new Imagefloat (fw, fh);
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 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; delete baseImg;
baseImg = trImg; baseImg = trImg;

View File

@@ -872,7 +872,7 @@ private:
ipf.ToneMapFattal02(baseImg); ipf.ToneMapFattal02(baseImg);
// perform transform (excepted resizing) // perform transform (excepted resizing)
if (ipf.needsTransform()) { if (ipf.needsTransform(fw, fh, imgsrc->getRotateDegree(), imgsrc->getMetaData())) {
Imagefloat* trImg = nullptr; Imagefloat* trImg = nullptr;
if (ipf.needsLuminanceOnly()) { if (ipf.needsLuminanceOnly()) {
trImg = baseImg; trImg = baseImg;