Skip to content

Instantly share code, notes, and snippets.

Created September 4, 2015 12:56
Show Gist options
  • Save anonymous/ff0776d28ceb89b83ef6 to your computer and use it in GitHub Desktop.
Save anonymous/ff0776d28ceb89b83ef6 to your computer and use it in GitHub Desktop.
stdin
diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h
index 351cada..6b17ba2 100644
--- a/rtengine/improcfun.h
+++ b/rtengine/improcfun.h
@@ -386,6 +386,7 @@ public:
static void getAutoExp (LUTu & histogram, int histcompr, double defgain, double clip, double& expcomp, int& bright, int& contr, int& black, int& hlcompr, int& hlcomprthresh);
static double getAutoDistor (const Glib::ustring& fname, int thumb_size);
double getTransformAutoFill (int oW, int oH, const LCPMapper *pLCPMap = NULL);
+ double getTransformNoCrop (int oW, int oH, const LCPMapper *pLCPMap);
};
}
#endif
diff --git a/rtengine/iptransform.cc b/rtengine/iptransform.cc
index a1078e8..e511c89 100644
--- a/rtengine/iptransform.cc
+++ b/rtengine/iptransform.cc
@@ -78,7 +78,7 @@ bool ImProcFunctions::transCoord (int W, int H, const std::vector<Coord2D> &src,
double hpteta = fabs(hpalpha - RT_PI / 2) < 3e-4 ? 0.0 : acos ((hpdeg > 0 ? 1.0 : -1.0) * sqrt((-oH * oH * tan(hpalpha) * tan(hpalpha) + (hpdeg > 0 ? 1.0 : -1.0) * oH * tan(hpalpha) * sqrt(16 * maxRadius * maxRadius + oH * oH * tan(hpalpha) * tan(hpalpha))) / (maxRadius * maxRadius * 8)));
double hpcospt = (hpdeg >= 0 ? 1.0 : -1.0) * cos (hpteta), hptanpt = tan (hpteta);
- double ascale = ascaleDef > 0 ? ascaleDef : (params->commonTrans.autofill ? getTransformAutoFill (oW, oH, pLCPMap) : 1.0);
+ double ascale = ascaleDef > 0 ? ascaleDef : (params->commonTrans.autofill ? getTransformAutoFill (oW, oH, pLCPMap) : (needsPerspective() ? getTransformNoCrop (oW, oH, pLCPMap) : 1.0));
for (size_t i = 0; i < src.size(); i++) {
double x_d = src[i].x, y_d = src[i].y;
@@ -703,8 +703,7 @@ void ImProcFunctions::transformHighQuality (Imagefloat* original, Imagefloat* tr
oH * tan(hpalpha) * sqrt(SQR(4 * maxRadius) + SQR(oH * tan(hpalpha)))) / (SQR(maxRadius) * 8)));
double hpcospt = (hpdeg >= 0 ? 1.0 : -1.0) * cos (hpteta), hptanpt = tan (hpteta);
- double ascale = params->commonTrans.autofill ? getTransformAutoFill (oW, oH, fullImage ? pLCPMap : NULL) : 1.0;
-
+ double ascale = params->commonTrans.autofill ? getTransformAutoFill (oW, oH, fullImage ? pLCPMap : NULL) : (needsPerspective() ? getTransformNoCrop (oW, oH, fullImage ? pLCPMap : NULL) : 1.0);
// smaller crop images are a problem, so only when processing fully
bool enableLCPCA = pLCPMap && params->lensProf.useCA && fullImage && pLCPMap->enableCA;
bool enableLCPDist = pLCPMap && params->lensProf.useDist && fullImage;
@@ -888,8 +887,7 @@ void ImProcFunctions::transformPreview (Imagefloat* original, Imagefloat* transf
double hpteta = fabs(hpalpha - RT_PI / 2) < 3e-4 ? 0.0 : acos ((hpdeg > 0 ? 1.0 : -1.0) * sqrt((-oH * oH * tan(hpalpha) * tan(hpalpha) + (hpdeg > 0 ? 1.0 : -1.0) * oH * tan(hpalpha) * sqrt(16 * maxRadius * maxRadius + oH * oH * tan(hpalpha) * tan(hpalpha))) / (maxRadius * maxRadius * 8)));
double hpcospt = (hpdeg >= 0 ? 1.0 : -1.0) * cos (hpteta), hptanpt = tan (hpteta);
- double ascale = params->commonTrans.autofill ? getTransformAutoFill (oW, oH, pLCPMap) : 1.0;
-
+ double ascale = params->commonTrans.autofill ? getTransformAutoFill (oW, oH, pLCPMap) : (needsPerspective() ? getTransformNoCrop (oW, oH, pLCPMap) : 1.0);
bool darkening = (params->vignetting.amount <= 0.0);
// main cycle
@@ -1072,6 +1070,29 @@ bool ImProcFunctions::needsTransform ()
return needsCA () || needsDistortion () || needsRotation () || needsPerspective () || needsGradient () || needsPCVignetting () || needsVignetting () || needsLCP();
}
+double ImProcFunctions::getTransformNoCrop (int oW, int oH, const LCPMapper *pLCPMap)
+{
+
+ double base = 0.0;
+ double step = 4.0; // must be larger than theoretical max scale
+ double scale;
+ bool too_small;
+
+ do {
+ scale = base + step;
+ int orx, ory, orw, orh;
+ transCoord (oW, oH, 0, 0, oW, oH, orx, ory, orw, orh, scale, pLCPMap);
+ too_small = (orx > 0 || ory > 0 || orw < oW || orh < oH);
+
+ if (too_small) {
+ base = scale;
+ } else {
+ step /= 2.0;
+ }
+ } while (step > 0.0001 || too_small);
+
+ return scale;
+}
}
@romandocent
Copy link

error: patch failed: rtengine/improcfun.h:386
error: rtengine/improcfun.h: patch does not apply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment