From a3adf8fb07fdd2dd46f5e1b4ea65427f9c968a46 Mon Sep 17 00:00:00 2001 From: Alberto Griggio Date: Tue, 14 Mar 2017 11:48:51 +0100 Subject: [PATCH] code cleanup after feedback by @Floessie --- rtengine/rtengine.h | 1 + rtengine/simpleprocess.cc | 71 +++++++++++++--------------- rtgui/filecatalog.cc | 97 +++++++++++++++++++-------------------- 3 files changed, 81 insertions(+), 88 deletions(-) diff --git a/rtengine/rtengine.h b/rtengine/rtengine.h index 7449dbd0d..4a87414b8 100644 --- a/rtengine/rtengine.h +++ b/rtengine/rtengine.h @@ -461,6 +461,7 @@ class ProcessingJob { public: + virtual ~ProcessingJob() {} /** Creates a processing job from a file name. This function always succeeds. It only stores the data into the ProcessingJob class, it does not load * the image thus it returns immediately. diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index fd06df66b..4a6c7a695 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -37,6 +37,14 @@ extern const Settings* settings; namespace { +template +void adjust_radius(const T &default_param, double scale_factor, T ¶m) +{ + const double delta = (param - default_param) * scale_factor; + param = default_param + delta; +} + + class ImageProcessor { public: ImageProcessor(ProcessingJob* pjob, int& errorCode, @@ -1338,20 +1346,18 @@ private: ImProcFunctions ipf (¶ms, true); int imw, imh; - double tmpScale = ipf.resizeScale(¶ms, fw, fh, imw, imh); + double scale_factor = ipf.resizeScale(¶ms, fw, fh, imw, imh); - LabImage *tmplab = new LabImage(fw, fh); + std::unique_ptr tmplab(new LabImage(fw, fh)); ipf.rgb2lab(*baseImg, *tmplab, params.icm.working); - int cx = 0, cy = 0, cw = fw, ch = fh; - if (params.crop.enabled) { - cx = params.crop.x; - cy = params.crop.y; - cw = params.crop.w; - ch = params.crop.h; + int cx = params.crop.x; + int cy = params.crop.y; + int cw = params.crop.w; + int ch = params.crop.h; - LabImage *cropped = new LabImage(cw, ch); + std::unique_ptr cropped(new LabImage(cw, ch)); for(int row = 0; row < ch; row++) { for(int col = 0; col < cw; col++) { @@ -1361,23 +1367,20 @@ private: } } - delete tmplab; - tmplab = cropped; - cx = 0; - cy = 0; - + tmplab.swap(cropped); params.crop.enabled = false; } assert(params.resize.enabled); // resize image - LabImage *resized = new LabImage(imw, imh); - ipf.Lanczos(tmplab, resized, tmpScale); - delete tmplab; - tmplab = resized; + { + std::unique_ptr resized(new LabImage(imw, imh)); + ipf.Lanczos(tmplab.get(), resized.get(), scale_factor); + tmplab.swap(resized); + } - adjust_procparams(tmpScale); + adjust_procparams(scale_factor); fw = imw; fh = imh; @@ -1385,34 +1388,26 @@ private: delete baseImg; baseImg = new Imagefloat(fw, fh); ipf.lab2rgb(*tmplab, *baseImg, params.icm.working); - delete tmplab; } void adjust_procparams(double scale_factor) { - procparams::ProcParams& params = job->pparams; + procparams::ProcParams ¶ms = job->pparams; procparams::ProcParams defaultparams; -#define ADJUST_RADIUS_(n, f) \ - do { \ - auto delta = (params. n - defaultparams. n) * f; \ - params. n = defaultparams. n + delta; \ - } while (false) - params.resize.enabled = false; if (params.prsharpening.enabled) { params.sharpening = params.prsharpening; } else { - ADJUST_RADIUS_(sharpening.radius, scale_factor); + adjust_radius(defaultparams.sharpening.radius, scale_factor, + params.sharpening.radius); } - params.impulseDenoise.thresh = - int(float(params.impulseDenoise.thresh) * scale_factor); + params.impulseDenoise.thresh *= scale_factor; if (scale_factor < 0.5) { params.impulseDenoise.enabled = false; } - params.wavelet.strength = - int(float(params.wavelet.strength) * scale_factor); + params.wavelet.strength *= scale_factor; params.dirpyrDenoise.luma *= scale_factor; //params.dirpyrDenoise.smethod = "shal"; for (auto &p : params.dirpyrDenoise.lcurve) { @@ -1427,13 +1422,13 @@ private: const double dirpyreq_scale = min(scale_factor * 1.5, 1.0); for (int i = 0; i < 6; ++i) { - ADJUST_RADIUS_(dirpyrequalizer.mult[i], dirpyreq_scale); - // auto &n = params.dirpyrequalizer.mult[i]; - // n = 1.0 + (n - 1.0) * dirpyreq_scale; + adjust_radius(defaultparams.dirpyrequalizer.mult[i], dirpyreq_scale, + params.dirpyrequalizer.mult[i]); } - ADJUST_RADIUS_(defringe.radius, scale_factor); - ADJUST_RADIUS_(sh.radius, scale_factor); + adjust_radius(defaultparams.defringe.radius, scale_factor, + params.defringe.radius); + adjust_radius(defaultparams.sh.radius, scale_factor, params.sh.radius); if (params.raw.xtranssensor.method == procparams::RAWParams::XTransSensor::methodstring[ @@ -1442,8 +1437,6 @@ private: procparams::RAWParams::XTransSensor::methodstring[ procparams::RAWParams::XTransSensor::onePass]; } - -#undef ADJUST_RADIUS_ } private: diff --git a/rtgui/filecatalog.cc b/rtgui/filecatalog.cc index cdba10316..96a04ba0b 100644 --- a/rtgui/filecatalog.cc +++ b/rtgui/filecatalog.cc @@ -1096,105 +1096,104 @@ void FileCatalog::developRequested (std::vector tbe, bool fas // TODO!!! could expose selections below via preferences if (fastmode) { if (!options.fastexport_use_fast_pipeline) { - if (options.fastexport_bypass_sharpening ) { - params.sharpening.enabled = false; + if (options.fastexport_bypass_sharpening) { + params.sharpening.enabled = false; } - if (options.fastexport_bypass_sharpenEdge ) { - params.sharpenEdge.enabled = false; + if (options.fastexport_bypass_sharpenEdge) { + params.sharpenEdge.enabled = false; } - if (options.fastexport_bypass_sharpenMicro ) { - params.sharpenMicro.enabled = false; + if (options.fastexport_bypass_sharpenMicro) { + params.sharpenMicro.enabled = false; } - //if (options.fastexport_bypass_lumaDenoise ) params.lumaDenoise.enabled = false; - //if (options.fastexport_bypass_colorDenoise ) params.colorDenoise.enabled = false; - if (options.fastexport_bypass_defringe ) { - params.defringe.enabled = false; + //if (options.fastexport_bypass_lumaDenoise) params.lumaDenoise.enabled = false; + //if (options.fastexport_bypass_colorDenoise) params.colorDenoise.enabled = false; + if (options.fastexport_bypass_defringe) { + params.defringe.enabled = false; } - if (options.fastexport_bypass_dirpyrDenoise ) { - params.dirpyrDenoise.enabled = false; + if (options.fastexport_bypass_dirpyrDenoise) { + params.dirpyrDenoise.enabled = false; } - if (options.fastexport_bypass_sh_hq ) { - params.sh.hq = false; + if (options.fastexport_bypass_sh_hq) { + params.sh.hq = false; } - if (options.fastexport_bypass_dirpyrequalizer ) { - params.dirpyrequalizer.enabled = false; + if (options.fastexport_bypass_dirpyrequalizer) { + params.dirpyrequalizer.enabled = false; } - if (options.fastexport_bypass_wavelet ) { - params.wavelet.enabled = false; + if (options.fastexport_bypass_wavelet) { + params.wavelet.enabled = false; } - //if (options.fastexport_bypass_raw_bayer_all_enhance ) params.raw.bayersensor.all_enhance = false; - if (options.fastexport_bypass_raw_bayer_dcb_iterations ) { - params.raw.bayersensor.dcb_iterations = 0; + //if (options.fastexport_bypass_raw_bayer_all_enhance) params.raw.bayersensor.all_enhance = false; + if (options.fastexport_bypass_raw_bayer_dcb_iterations) { + params.raw.bayersensor.dcb_iterations = 0; } - if (options.fastexport_bypass_raw_bayer_dcb_enhance ) { - params.raw.bayersensor.dcb_enhance = false; + if (options.fastexport_bypass_raw_bayer_dcb_enhance) { + params.raw.bayersensor.dcb_enhance = false; } if (options.fastexport_bypass_raw_bayer_lmmse_iterations) { - params.raw.bayersensor.lmmse_iterations = 0; + params.raw.bayersensor.lmmse_iterations = 0; } - if (options.fastexport_bypass_raw_bayer_linenoise ) { - params.raw.bayersensor.linenoise = 0; + if (options.fastexport_bypass_raw_bayer_linenoise) { + params.raw.bayersensor.linenoise = 0; } - if (options.fastexport_bypass_raw_bayer_greenthresh ) { - params.raw.bayersensor.greenthresh = 0; + if (options.fastexport_bypass_raw_bayer_greenthresh) { + params.raw.bayersensor.greenthresh = 0; } - if (options.fastexport_bypass_raw_ccSteps ) { + if (options.fastexport_bypass_raw_ccSteps) { params.raw.bayersensor.ccSteps = params.raw.xtranssensor.ccSteps = 0; } - if (options.fastexport_bypass_raw_ca ) { + if (options.fastexport_bypass_raw_ca) { params.raw.ca_autocorrect = false; params.raw.cared = 0; params.raw.cablue = 0; } - if (options.fastexport_bypass_raw_df ) { - params.raw.df_autoselect = false; + if (options.fastexport_bypass_raw_df) { + params.raw.df_autoselect = false; params.raw.dark_frame = ""; } - if (options.fastexport_bypass_raw_ff ) { - params.raw.ff_AutoSelect = false; + if (options.fastexport_bypass_raw_ff) { + params.raw.ff_AutoSelect = false; params.raw.ff_file = ""; } - - params.raw.bayersensor.method = options.fastexport_raw_bayer_method ; + params.raw.bayersensor.method = options.fastexport_raw_bayer_method; params.raw.xtranssensor.method = options.fastexport_raw_xtrans_method; - params.icm.input = options.fastexport_icm_input ; - params.icm.working = options.fastexport_icm_working ; - params.icm.output = options.fastexport_icm_output ; - params.icm.outputIntent = options.fastexport_icm_outputIntent ; - params.icm.outputBPC = options.fastexport_icm_outputBPC ; - params.icm.gamma = options.fastexport_icm_gamma ; + params.icm.input = options.fastexport_icm_input; + params.icm.working = options.fastexport_icm_working; + params.icm.output = options.fastexport_icm_output; + params.icm.outputIntent = options.fastexport_icm_outputIntent; + params.icm.outputBPC = options.fastexport_icm_outputBPC; + params.icm.gamma = options.fastexport_icm_gamma; } if (params.resize.enabled) { - params.resize.width = rtengine::min(params.resize.width, options.fastexport_resize_width) ; - params.resize.height = rtengine::min(params.resize.height, options.fastexport_resize_height) ; + params.resize.width = rtengine::min(params.resize.width, options.fastexport_resize_width); + params.resize.height = rtengine::min(params.resize.height, options.fastexport_resize_height); } else { params.resize.width = options.fastexport_resize_width; params.resize.height = options.fastexport_resize_height; } - params.resize.enabled = options.fastexport_resize_enabled ; - params.resize.scale = options.fastexport_resize_scale ; - params.resize.appliesTo = options.fastexport_resize_appliesTo ; - params.resize.method = options.fastexport_resize_method ; - params.resize.dataspec = options.fastexport_resize_dataspec ; + params.resize.enabled = options.fastexport_resize_enabled; + params.resize.scale = options.fastexport_resize_scale; + params.resize.appliesTo = options.fastexport_resize_appliesTo; + params.resize.method = options.fastexport_resize_method; + params.resize.dataspec = options.fastexport_resize_dataspec; } rtengine::ProcessingJob* pjob = rtengine::ProcessingJob::create (fbe->filename, th->getType() == FT_Raw, params, fastmode && options.fastexport_use_fast_pipeline);