From b4c0bb3acbc6b2acead76b7ea8321d01e60415b6 Mon Sep 17 00:00:00 2001 From: Ingo Weyrich Date: Mon, 10 Feb 2020 20:06:43 +0100 Subject: [PATCH] More double promote fixes --- rtengine/lcp.cc | 132 ++++++++++++++------------------------- rtengine/lcp.h | 2 - rtgui/mycurve.cc | 2 +- rtgui/mydiagonalcurve.cc | 16 ++--- rtgui/myflatcurve.cc | 12 ++-- rtgui/retinex.cc | 2 +- rtgui/rtscalable.cc | 2 +- rtgui/rtwindow.cc | 4 +- 8 files changed, 65 insertions(+), 107 deletions(-) diff --git a/rtengine/lcp.cc b/rtengine/lcp.cc index c80a126f5..1826101e7 100644 --- a/rtengine/lcp.cc +++ b/rtengine/lcp.cc @@ -42,7 +42,6 @@ class rtengine::LCPProfile::LCPPersModel public: LCPPersModel(); bool hasModeData(LCPCorrectionMode mode) const; - void print() const; float focLen; float focDist; @@ -82,27 +81,18 @@ bool rtengine::LCPModelCommon::empty() const && param[2] == 0.0f; } -void rtengine::LCPModelCommon::print() const -{ - std::printf("focLen %g/%g; imgCenter %g/%g; scale %g; err %g\n", foc_len_x, foc_len_y, img_center_x, img_center_y, scale_factor, mean_error); - std::printf("xy0 %g/%g fxy %g/%g\n", x0, y0, fx, fy); - std::printf("param: %g/%g/%g/%g/%g\n", param[0], param[1], param[2], param[3], param[4]); -} - // weighted merge two parameters void rtengine::LCPModelCommon::merge(const LCPModelCommon& a, const LCPModelCommon& b, float facA) { - const float facB = 1.0f - facA; - - foc_len_x = facA * a.foc_len_x + facB * b.foc_len_x; - foc_len_y = facA * a.foc_len_y + facB * b.foc_len_y; - img_center_x = facA * a.img_center_x + facB * b.img_center_x; - img_center_y = facA * a.img_center_y + facB * b.img_center_y; - scale_factor = facA * a.scale_factor + facB * b.scale_factor; - mean_error = facA * a.mean_error + facB * b.mean_error; + foc_len_x = rtengine::intp(facA, a.foc_len_x, b.foc_len_x); + foc_len_y = rtengine::intp(facA, a.foc_len_y, b.foc_len_y); + img_center_x = rtengine::intp(facA, a.img_center_x, b.img_center_x); + img_center_y = rtengine::intp(facA, a.img_center_y, b.img_center_y); + scale_factor = rtengine::intp(facA, a.scale_factor, b.scale_factor); + mean_error = rtengine::intp(facA, a.mean_error, b.mean_error); for (int i = 0; i < 5; ++i) { - param[i] = facA * a.param[i] + facB * b.param[i]; + param[i] = rtengine::intp(facA, a.param[i], b.param[i]); } const float param0Sqr = param[0] * param[0]; @@ -152,7 +142,6 @@ void rtengine::LCPModelCommon::prepareParams( rfx = 1.0f / fx; rfy = 1.0f / fy; - //std::printf("FW %i /X0 %g FH %i /Y0 %g %g\n",fullWidth,x0,fullHeight,y0, imgYCenter); } rtengine::LCPProfile::LCPPersModel::LCPPersModel() : @@ -188,35 +177,6 @@ bool rtengine::LCPProfile::LCPPersModel::hasModeData(LCPCorrectionMode mode) con return false; } -void rtengine::LCPProfile::LCPPersModel::print() const -{ - std::printf("--- PersModel focLen %g; focDist %g; aperture %g\n", focLen, focDist, aperture); - std::printf("Base:\n"); - base.print(); - - if (!chromRG.empty()) { - std::printf("ChromRG:\n"); - chromRG.print(); - } - - if (!chromG.empty()) { - std::printf("ChromG:\n"); - chromG.print(); - } - - if (!chromBG.empty()) { - std::printf("ChromBG:\n"); - chromBG.print(); - } - - if (!vignette.empty()) { - std::printf("Vignette:\n"); - vignette.print(); - } - - std::printf("\n"); -} - rtengine::LCPProfile::LCPProfile(const Glib::ustring& fname) : isFisheye(false), sensorFormatFactor(1.f), @@ -522,7 +482,7 @@ void rtengine::LCPProfile::calcParams( ) { // Mix in aperture const float facAperLow = (pHigh->aperture - aperture) / (pHigh->aperture - pLow->aperture); - facLow = focLenOnSpot ? facAperLow : (0.5 * facLow + 0.5 * facAperLow); + facLow = focLenOnSpot ? facAperLow : (0.5f * (facLow + facAperLow)); } else if ( mode != LCPCorrectionMode::VIGNETTE @@ -532,7 +492,7 @@ void rtengine::LCPProfile::calcParams( ) { // focus distance for all else (if focus distance is given) const float facDistLow = (std::log(pHigh->focDist) + euler - focusDistLog) / (std::log(pHigh->focDist) - std::log(pLow->focDist)); - facLow = focLenOnSpot ? facDistLow : (0.8 * facLow + 0.2 * facDistLow); + facLow = focLenOnSpot ? facDistLow : (0.8f * facLow + 0.2f * facDistLow); } switch (mode) { @@ -555,7 +515,16 @@ void rtengine::LCPProfile::calcParams( } if (settings->verbose) { - std::printf("LCP mode=%i, dist: %g found frames: Fno %g-%g; FocLen %g-%g; Dist %g-%g with weight %g\n", toUnderlying(mode), focusDist, pLow->aperture, pHigh->aperture, pLow->focLen, pHigh->focLen, pLow->focDist, pHigh->focDist, facLow); + std::printf("LCP mode=%i, dist: %g found frames: Fno %g-%g; FocLen %g-%g; Dist %g-%g with weight %g\n", + toUnderlying(mode), + static_cast(focusDist), + static_cast(pLow->aperture), + static_cast(pHigh->aperture), + static_cast(pLow->focLen), + static_cast(pHigh->focLen), + static_cast(pLow->focDist), + static_cast(pHigh->focDist), + static_cast(facLow)); } } else { if (settings->verbose) { @@ -564,15 +533,6 @@ void rtengine::LCPProfile::calcParams( } } -void rtengine::LCPProfile::print() const -{ - std::printf("=== Profile %s\n", profileName.c_str()); - std::printf("Frames: %i, RAW: %i; Fisheye: %i; Sensorformat: %f\n", persModelCount, isRaw, isFisheye, sensorFormatFactor); - - for (int pm = 0; pm < persModelCount; ++pm) { - aPersModel[pm]->print(); - } -} // from all frames not marked as bad already, take average and filter out frames with higher deviation than this if there are enough values int rtengine::LCPProfile::filterBadFrames(LCPCorrectionMode mode, double maxAvgDevFac, int minFramesLeft) @@ -649,7 +609,7 @@ int rtengine::LCPProfile::filterBadFrames(LCPCorrectionMode mode, double maxAvgD } if (settings->verbose && count) { - std::printf("Filtered %.1f%% frames for maxAvgDevFac %g leaving %i\n", filtered * 100.f / count, maxAvgDevFac, count - filtered); + std::printf("Filtered %.1f%% frames for maxAvgDevFac %g leaving %i\n", filtered * 100.0 / count, maxAvgDevFac, count - filtered); } } @@ -1007,7 +967,7 @@ rtengine::LCPMapper::LCPMapper( const bool mirrorX = (rot == 90 || rot == 180); const bool mirrorY = (rot == 180 || rot == 270); if (settings->verbose) { - std::printf("Vign: %i, fullWidth: %i/%i, focLen %g SwapXY: %i / MirX/Y %i / %i on rot:%i from %i\n",vignette, fullWidth, fullHeight, focalLength, swapXY, mirrorX, mirrorY, rot, rawRotationDeg); + std::printf("Vign: %i, fullWidth: %i/%i, focLen %g SwapXY: %i / MirX/Y %i / %i on rot:%i from %i\n",vignette, fullWidth, fullHeight, static_cast(focalLength), swapXY, mirrorX, mirrorY, rot, rawRotationDeg); } pProf->calcParams(vignette ? LCPCorrectionMode::VIGNETTE : LCPCorrectionMode::DISTORTION, focalLength, focusDist, aperture, &mc, nullptr, nullptr); @@ -1038,8 +998,8 @@ void rtengine::LCPMapper::correctDistortion(double &x, double &y, int cx, int cy if (isFisheye) { const double u = x * scale; const double v = y * scale; - const double u0 = mc.x0 * scale; - const double v0 = mc.y0 * scale; + const double u0 = static_cast(mc.x0) * scale; + const double v0 = static_cast(mc.y0) * scale; const double du = (u - u0); const double dv = (v - v0); const double fx = mc.fx; @@ -1059,22 +1019,22 @@ void rtengine::LCPMapper::correctDistortion(double &x, double &y, int cx, int cy } else { x *= scale; y *= scale; - const double x0 = mc.x0 * scale; - const double y0 = mc.y0 * scale; - const double xd = (x - x0) / mc.fx, yd = (y - y0) / mc.fy; + const double x0 = static_cast(mc.x0) * scale; + const double y0 = static_cast(mc.y0) * scale; + const double xd = (x - x0) / static_cast(mc.fx), yd = (y - y0) / static_cast(mc.fy); - const LCPModelCommon::Param aDist = mc.param; + const auto& aDist = mc.param; const double rsqr = xd * xd + yd * yd; - const double xfac = aDist[swapXY ? 3 : 4], yfac = aDist[swapXY ? 4 : 3]; + const double xfac = static_cast(aDist[swapXY ? 3 : 4]), yfac = static_cast(aDist[swapXY ? 4 : 3]); - const double commonFac = (((aDist[2] * rsqr + aDist[1]) * rsqr + aDist[0]) * rsqr + 1.) + const double commonFac = (((static_cast(aDist[2]) * rsqr + static_cast(aDist[1])) * rsqr + static_cast(aDist[0])) * rsqr + 1.) + 2. * (yfac * yd + xfac * xd); const double xnew = xd * commonFac + xfac * rsqr; const double ynew = yd * commonFac + yfac * rsqr; - x = xnew * mc.fx + x0; - y = ynew * mc.fy + y0; + x = xnew * static_cast(mc.fx) + x0; + y = ynew * static_cast(mc.fy) + y0; } x -= cx * scale; @@ -1094,20 +1054,20 @@ void rtengine::LCPMapper::correctCA(double& x, double& y, int cx, int cy, int ch // First calc the green channel like normal distortion // the other are just deviations from it - double xd = (x - chrom[1].x0) / chrom[1].fx; - double yd = (y - chrom[1].y0) / chrom[1].fy; + double xd = (x - static_cast(chrom[1].x0)) / static_cast(chrom[1].fx); + double yd = (y - static_cast(chrom[1].y0)) / static_cast(chrom[1].fy); // Green contains main distortion, just like base if (useCADist) { - const LCPModelCommon::Param aDist = chrom[1].param; - double rsqr = xd * xd + yd * yd; - double xfac = aDist[swapXY ? 3 : 4], yfac = aDist[swapXY ? 4 : 3]; + const auto& aDist = chrom[1].param; + double rsqr = xd * xd + yd * yd; + double xfac = static_cast(aDist[swapXY ? 3 : 4]), yfac = static_cast(aDist[swapXY ? 4 : 3]); - double commonFac = (((aDist[2] * rsqr + aDist[1]) * rsqr + aDist[0]) * rsqr + 1.) + double commonFac = (((static_cast(aDist[2]) * rsqr + static_cast(aDist[1])) * rsqr + static_cast(aDist[0])) * rsqr + 1.) + 2. * (yfac * yd + xfac * xd); - xgreen = xd * commonFac + aDist[4] * rsqr; - ygreen = yd * commonFac + aDist[3] * rsqr; + xgreen = xd * commonFac + static_cast(aDist[4]) * rsqr; + ygreen = yd * commonFac + static_cast(aDist[3]) * rsqr; } else { xgreen = xd; ygreen = yd; @@ -1115,20 +1075,20 @@ void rtengine::LCPMapper::correctCA(double& x, double& y, int cx, int cy, int ch if (channel == 1) { // green goes directly - x = xgreen * chrom[1].fx + chrom[1].x0; - y = ygreen * chrom[1].fy + chrom[1].y0; + x = xgreen * static_cast(chrom[1].fx) + static_cast(chrom[1].x0); + y = ygreen * static_cast(chrom[1].fy) + static_cast(chrom[1].y0); } else { // others are diffs from green xd = xgreen; yd = ygreen; const double rsqr = xd * xd + yd * yd; - const LCPModelCommon::Param aCA = chrom[channel].param; - const double xfac = aCA[swapXY ? 3 : 4], yfac = aCA[swapXY ? 4 : 3]; - const double commonSum = 1. + rsqr * (aCA[0] + rsqr * (aCA[1] + aCA[2] * rsqr)) + 2. * (yfac * yd + xfac * xd); + const auto& aCA = chrom[channel].param; + const double xfac = static_cast(aCA[swapXY ? 3 : 4]), yfac = static_cast(aCA[swapXY ? 4 : 3]); + const double commonSum = 1. + rsqr * (static_cast(aCA[0]) + rsqr * (static_cast(aCA[1]) + static_cast(aCA[2] )* rsqr)) + 2. * (yfac * yd + xfac * xd); - x = (chrom[channel].scale_factor * ( xd * commonSum + xfac * rsqr )) * chrom[channel].fx + chrom[channel].x0; - y = (chrom[channel].scale_factor * ( yd * commonSum + yfac * rsqr )) * chrom[channel].fy + chrom[channel].y0; + x = (static_cast(chrom[channel].scale_factor) * ( xd * commonSum + xfac * rsqr )) * static_cast(chrom[channel].fx) + static_cast(chrom[channel].x0); + y = (static_cast(chrom[channel].scale_factor) * ( yd * commonSum + yfac * rsqr )) * static_cast(chrom[channel].fy) + static_cast(chrom[channel].y0); } x -= cx; diff --git a/rtengine/lcp.h b/rtengine/lcp.h index 2e36fe113..4c1e09865 100644 --- a/rtengine/lcp.h +++ b/rtengine/lcp.h @@ -54,7 +54,6 @@ public: LCPModelCommon(); bool empty() const; // is it empty - void print() const; // printf all values void merge(const LCPModelCommon& a, const LCPModelCommon& b, float facA); void prepareParams( int fullWidth, @@ -106,7 +105,6 @@ public: LCPModelCommon *pCorr3 ) const; // Interpolates between the persModels frames - void print() const; //private: // Common data diff --git a/rtgui/mycurve.cc b/rtgui/mycurve.cc index 7401570c8..d460713fb 100644 --- a/rtgui/mycurve.cc +++ b/rtgui/mycurve.cc @@ -183,7 +183,7 @@ float MyCurve::getVal(LUTf &curve, int x) if (size_t(graphW) == curve.getSize()) { return curve[x]; } else { - return curve.getVal01(float(x) / graphW); + return curve.getVal01(x / graphW); } } diff --git a/rtgui/mydiagonalcurve.cc b/rtgui/mydiagonalcurve.cc index abd339ce0..ac7976b7e 100644 --- a/rtgui/mydiagonalcurve.cc +++ b/rtgui/mydiagonalcurve.cc @@ -358,14 +358,14 @@ void MyDiagonalCurve::draw (int handle) // draw upper and lower bounds if (curve.type == DCT_Parametric && activeParam > 0 && lpoint.getUpperBound() > 1 && upoint.getUpperBound() > 1) { cr->set_source_rgba (1.0, 1.0, 1.0, 0.1); - cr->move_to (graphX, getVal(upoint, 0) * -graphH + graphY); + cr->move_to (graphX, static_cast(getVal(upoint, 0)) * -graphH + graphY); for (int i = 1; i < graphW - 2; ++i) { - cr->line_to ((double)i + graphX, getVal(upoint, i) * -graphH + graphY); + cr->line_to ((double)i + graphX, static_cast(getVal(upoint, i)) * -graphH + graphY); } for (int i = graphW - 3; i >= 0; --i) { - cr->line_to ((double)i + graphX, getVal(lpoint, i) * -graphH + graphY); + cr->line_to ((double)i + graphX, static_cast(getVal(lpoint, i)) * -graphH + graphY); } cr->fill (); @@ -390,21 +390,21 @@ void MyDiagonalCurve::draw (int handle) if (n > 1) { if (pipetteR > -1.f) { cr->set_source_rgba (1., 0., 0., 0.5); // WARNING: assuming that red values are stored in pipetteR, which might not be the case! - cr->move_to (graphX + graphW*pipetteR, graphY + 1. * s); + cr->move_to (graphX + graphW * static_cast(pipetteR), graphY + 1. * s); cr->rel_line_to (0, -graphH - 1. * s); cr->stroke (); } if (pipetteG > -1.f) { cr->set_source_rgba (0., 1., 0., 0.5); // WARNING: assuming that green values are stored in pipetteG, which might not be the case! - cr->move_to (graphX + graphW*pipetteG, graphY + 1. * s); + cr->move_to (graphX + graphW * static_cast(pipetteG), graphY + 1. * s); cr->rel_line_to (0, -graphH - 1. * s); cr->stroke (); } if (pipetteB > -1.f) { cr->set_source_rgba (0., 0., 1., 0.5); // WARNING: assuming that blue values are stored in pipetteB, which might not be the case! - cr->move_to (graphX + graphW*pipetteB, graphY + 1. * s); + cr->move_to (graphX + graphW * static_cast(pipetteB), graphY + 1. * s); cr->rel_line_to (0, -graphH - 1. * s); cr->stroke (); } @@ -414,7 +414,7 @@ void MyDiagonalCurve::draw (int handle) cr->set_line_width (2. * s); c = style->get_color (state); cr->set_source_rgb (c.get_red(), c.get_green(), c.get_blue()); - cr->move_to (graphX + graphW*pipetteVal, graphY + 1. * s); + cr->move_to (graphX + graphW * static_cast(pipetteVal), graphY + 1. * s); cr->rel_line_to (0, -graphH - 1. * s); cr->stroke (); cr->set_line_width (1. * s); @@ -460,7 +460,7 @@ void MyDiagonalCurve::draw (int handle) // draw curve cr->set_source_rgb (c.get_red(), c.get_green(), c.get_blue()); - cr->move_to (graphX, getVal(point, 0) * -graphH + graphY); + cr->move_to (graphX, static_cast(getVal(point, 0)) * -graphH + graphY); for (int i = 1; i < graphW; ++i) { cr->line_to ((double)i + graphX, (double)getVal(point, i) * -graphH + graphY); diff --git a/rtgui/myflatcurve.cc b/rtgui/myflatcurve.cc index 362d34f35..da993987c 100644 --- a/rtgui/myflatcurve.cc +++ b/rtgui/myflatcurve.cc @@ -233,21 +233,21 @@ void MyFlatCurve::draw () if (n > 1) { if (pipetteR > -1.f) { cr->set_source_rgba (1., 0., 0., 0.5); // WARNING: assuming that red values are stored in pipetteR, which might not be the case! - cr->move_to (graphX + graphW*pipetteR, graphY + 1. * s); + cr->move_to (graphX + graphW * static_cast(pipetteR), graphY + 1. * s); cr->rel_line_to (0, -graphH - 1. * s); cr->stroke (); } if (pipetteG > -1.f) { cr->set_source_rgba (0., 1., 0., 0.5); // WARNING: assuming that green values are stored in pipetteG, which might not be the case! - cr->move_to (graphX + graphW*pipetteG, graphY + 1. * s); + cr->move_to (graphX + graphW * static_cast(pipetteG), graphY + 1. * s); cr->rel_line_to (0, -graphH - 1. * s); cr->stroke (); } if (pipetteB > -1.f) { cr->set_source_rgba (0., 0., 1., 0.5); // WARNING: assuming that blue values are stored in pipetteB, which might not be the case! - cr->move_to (graphX + graphW*pipetteB, graphY + 1. * s); + cr->move_to (graphX + graphW * static_cast(pipetteB), graphY + 1. * s); cr->rel_line_to (0, -graphH - 1. * s); cr->stroke (); } @@ -257,7 +257,7 @@ void MyFlatCurve::draw () cr->set_line_width (2. * s); c = style->get_color (state); cr->set_source_rgb (c.get_red(), c.get_green(), c.get_blue()); - cr->move_to (graphX + graphW*pipetteVal, graphY + 1. * s); + cr->move_to (graphX + graphW * static_cast(pipetteVal), graphY + 1. * s); cr->rel_line_to (0, -graphH - 1. * s); cr->stroke (); cr->set_line_width (1. * s); @@ -437,10 +437,10 @@ void MyFlatCurve::draw () // draw curve c = style->get_color(state); cr->set_source_rgb (c.get_red(), c.get_green(), c.get_blue()); - cr->move_to (graphX, getVal(point, 0) * -graphH + graphY); + cr->move_to (graphX, static_cast(getVal(point, 0)) * -graphH + graphY); for (int i = 1; i < graphW; ++i) { - cr->line_to ((double)i + graphX, (double)getVal(point, i) * -graphH + graphY); + cr->line_to ((double)i + graphX, static_cast(getVal(point, i)) * -graphH + graphY); } cr->stroke (); diff --git a/rtgui/retinex.cc b/rtgui/retinex.cc index c78be375f..7fdea0319 100644 --- a/rtgui/retinex.cc +++ b/rtgui/retinex.cc @@ -278,7 +278,7 @@ Retinex::Retinex () : FoldableToolPanel (this, "retinex", M ("TP_RETINEX_LABEL") for (int i = 0; i < 7; i++) { float R, G, B; - float x = float (i) * (1.0f / 6.0); + float x = i / 6.0; Color::hsv2rgb01 (x, 0.5f, 0.5f, R, G, B); milestones.push_back ( GradientMilestone (double (x), double (R), double (G), double (B)) ); } diff --git a/rtgui/rtscalable.cc b/rtgui/rtscalable.cc index a48a95fd2..78202326a 100644 --- a/rtgui/rtscalable.cc +++ b/rtgui/rtscalable.cc @@ -68,7 +68,7 @@ double RTScalable::getDPI () double RTScalable::getTweakedDPI () { - return dpi * fontScale; + return dpi * static_cast(fontScale); } int RTScalable::getScale () diff --git a/rtgui/rtwindow.cc b/rtgui/rtwindow.cc index 514685a16..8cfeb8ec0 100644 --- a/rtgui/rtwindow.cc +++ b/rtgui/rtwindow.cc @@ -179,7 +179,7 @@ RTWindow::RTWindow () fontScale = options.fontSize / (float)RTScalable::baseFontSize; } if (rtengine::settings->verbose) { - printf("\"Non-Default\" font size(%d) * scale(%d) / fontScale(%.3f)\n", options.fontSize, (int)initialGdkScale, fontScale); + printf("\"Non-Default\" font size(%d) * scale(%d) / fontScale(%.3f)\n", options.fontSize, (int)initialGdkScale, static_cast(fontScale)); } } else { Glib::RefPtr style = Gtk::StyleContext::create(); @@ -209,7 +209,7 @@ RTWindow::RTWindow () if ((int)initialGdkScale > 1 || pt != RTScalable::baseFontSize) { css = Glib::ustring::compose ("* { font-size: %1pt}", pt * (int)initialGdkScale); if (rtengine::settings->verbose) { - printf("\"Default\" font size(%d) * scale(%d) / fontScale(%.3f)\n", pt, (int)initialGdkScale, fontScale); + printf("\"Default\" font size(%d) * scale(%d) / fontScale(%.3f)\n", pt, (int)initialGdkScale, static_cast(fontScale)); } } }