diff --git a/rtengine/iptransform.cc b/rtengine/iptransform.cc index 0c900c998..577f02970 100644 --- a/rtengine/iptransform.cc +++ b/rtengine/iptransform.cc @@ -467,9 +467,10 @@ bool ImProcFunctions::transCoord (int W, int H, const std::vector &src, double hpteta = fabs (hpalpha - rtengine::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); // Camera-based. - const double f = params->perspective.camera_focal_length * - params->perspective.camera_crop_factor * (maxRadius / sqrt(18.0*18.0 + - 12.0*12.0)); + const double f = + ((params->perspective.camera_focal_length > 0) ? params->perspective.camera_focal_length : 24.0) + * ((params->perspective.camera_crop_factor > 0) ? params->perspective.camera_crop_factor : 1.0) + * (maxRadius / sqrt(18.0*18.0 + 12.0*12.0)); const double p_camera_yaw = params->perspective.camera_yaw / 180.0 * rtengine::RT_PI; const double p_camera_pitch = params->perspective.camera_pitch / 180.0 * rtengine::RT_PI; const double p_camera_roll = params->perspective.camera_roll * rtengine::RT_PI_180; @@ -1165,9 +1166,10 @@ void ImProcFunctions::transformGeneral(bool highQuality, Imagefloat *original, I const double hpcospt = (hpdeg >= 0 ? 1.0 : -1.0) * cos(hpteta); const double hptanpt = tan(hpteta); // Camera-based. - const double f = params->perspective.camera_focal_length * - params->perspective.camera_crop_factor * (maxRadius / sqrt(18.0*18.0 + - 12.0*12.0)); + const double f = + ((params->perspective.camera_focal_length > 0) ? params->perspective.camera_focal_length : 24.0) + * ((params->perspective.camera_crop_factor > 0) ? params->perspective.camera_crop_factor : 1.0) + * (maxRadius / sqrt(18.0*18.0 + 12.0*12.0)); const double p_camera_yaw = params->perspective.camera_yaw / 180.0 * rtengine::RT_PI; const double p_camera_pitch = params->perspective.camera_pitch / 180.0 * rtengine::RT_PI; const double p_camera_roll = params->perspective.camera_roll * rtengine::RT_PI_180; diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 686577d98..0f39a9a16 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -1854,8 +1854,8 @@ PerspectiveParams::PerspectiveParams() : method("simple"), horizontal(0.0), vertical(0.0), - camera_crop_factor(1.0), - camera_focal_length(24.0), + camera_crop_factor(0.0), + camera_focal_length(0.0), camera_pitch(0.0), camera_roll(0.0), camera_shift_horiz(0.0), diff --git a/rtgui/perspective.cc b/rtgui/perspective.cc index f3b6eea2c..7736f72ec 100644 --- a/rtgui/perspective.cc +++ b/rtgui/perspective.cc @@ -213,8 +213,7 @@ void PerspCorrection::read (const ProcParams* pp, const ParamsEdited* pedited) horiz->setValue (pp->perspective.horizontal); vert->setValue (pp->perspective.vertical); - camera_crop_factor->setValue (pp->perspective.camera_crop_factor); - camera_focal_length->setValue (pp->perspective.camera_focal_length); + setFocalLengthValue (pp, metadata); camera_pitch->setValue (pp->perspective.camera_pitch); camera_roll->setValue (pp->perspective.camera_roll); camera_shift_horiz->setValue (pp->perspective.camera_shift_horiz); @@ -461,6 +460,11 @@ void PerspCorrection::setAdjusterBehavior (bool badd, bool camera_focal_length_a projection_yaw->setAddMode(projection_angle_add); } +void PerspCorrection::setMetadata (const rtengine::FramesMetaData* metadata) +{ + this->metadata = metadata; +} + void PerspCorrection::trimValues (rtengine::procparams::ProcParams* pp) { @@ -507,3 +511,49 @@ void PerspCorrection::setBatchMode (bool batchMode) method->append (M("GENERAL_UNCHANGED")); } + +void PerspCorrection::setFocalLengthValue (const ProcParams* pparams, const FramesMetaData* metadata) +{ + const double pp_crop_factor = pparams->perspective.camera_crop_factor; + const double pp_focal_length = pparams->perspective.camera_focal_length; + double default_crop_factor = 1.0; + double default_focal_length = 24.0; + + // Defaults from metadata. + if (metadata && (pp_crop_factor <= 0 || pp_focal_length <= 0)) { + const double fl = metadata->getFocalLen(); + const double fl35 = metadata->getFocalLen35mm(); + + if (fl <= 0) { + if (fl35 <= 0) { + // No focal length data. + } else { + // 35mm focal length available. + default_focal_length = fl35; + } + } else { + if (fl35 <= 0) { + // Focal length available. + default_focal_length = fl; + } else { + // Focal length and 35mm equivalent available. + default_focal_length = fl; + default_crop_factor = fl35 / fl; + } + } + } + + // Change value if those from the ProcParams are invalid. + if (pp_crop_factor > 0) { + camera_crop_factor->setValue(pparams->perspective.camera_crop_factor); + } else { + camera_crop_factor->setDefault(default_crop_factor); + camera_crop_factor->setValue(default_crop_factor); + } + if (pp_focal_length > 0) { + camera_focal_length->setValue(pparams->perspective.camera_focal_length); + } else { + camera_focal_length->setDefault(default_focal_length); + camera_focal_length->setValue(default_focal_length); + } +} diff --git a/rtgui/perspective.h b/rtgui/perspective.h index a7a2da7ed..c1dd20ee4 100644 --- a/rtgui/perspective.h +++ b/rtgui/perspective.h @@ -53,6 +53,9 @@ protected: Adjuster* projection_shift_vert; Adjuster* projection_yaw; LensGeomListener* lens_geom_listener; + const rtengine::FramesMetaData* metadata; + + void setFocalLengthValue (const rtengine::procparams::ProcParams* pparams, const rtengine::FramesMetaData* metadata); public: @@ -71,5 +74,6 @@ public: { lens_geom_listener = listener; } + void setMetadata (const rtengine::FramesMetaData* metadata); void trimValues (rtengine::procparams::ProcParams* pp) override; }; diff --git a/rtgui/toolpanelcoord.cc b/rtgui/toolpanelcoord.cc index a62bc5610..77cb5643b 100644 --- a/rtgui/toolpanelcoord.cc +++ b/rtgui/toolpanelcoord.cc @@ -615,6 +615,7 @@ void ToolPanelCoordinator::initImage (rtengine::StagedImageProcessor* ipc_, bool icm->setRawMeta (raw, (const rtengine::FramesData*)pMetaData); lensProf->setRawMeta (raw, pMetaData); + perspective->setMetadata (pMetaData); }