Introducing TweakOperator, for better tool's special mode handling

This commit is contained in:
Hombre 2019-08-06 02:04:48 +02:00
parent 7d310e688c
commit 0db64d49a2
14 changed files with 212 additions and 73 deletions

View File

@ -142,6 +142,7 @@ void Crop::update(int todo)
// give possibility to the listener to modify crop window (as the full image dimensions are already known at this point)
int wx, wy, ww, wh, ws;
const bool overrideWindow = cropImageListener;
bool spotsDone = false;
if (overrideWindow) {
cropImageListener->getWindow(wx, wy, ww, wh, ws);
@ -619,6 +620,7 @@ void Crop::update(int todo)
}
if ((todo & M_SPOT) && params.spot.enabled && !params.spot.entries.empty()) {
spotsDone = true;
PreviewProps pp(trafx, trafy, trafw * skip, trafh * skip, skip);
//parent->imgsrc->getImage(parent->currWB, tr, origCrop, pp, params.toneCurve, params.raw);
parent->ipf.removeSpots(origCrop, params.spot.entries, pp);
@ -698,13 +700,8 @@ void Crop::update(int todo)
// has to be called after setCropSizes! Tools prior to this point can't handle the Edit mechanism, but that shouldn't be a problem.
createBuffer(cropw, croph);
if ((todo & M_SPOT_ADJUST) && params.spot.enabled && !params.spot.entries.empty()) {
PreviewProps pp(trafx, trafy, trafw * skip, trafh * skip, skip);
parent->ipf.removeSpots(origCrop, params.spot.entries, pp);
}
// Apply Spot removal
if (todo & (M_SPOT|M_SPOT_ADJUST)) {
if ((todo & M_SPOT) && !spotsDone) {
if (params.spot.enabled && !params.spot.entries.empty()) {
if(!spotCrop) {
spotCrop = new Imagefloat (cropw, croph);

View File

@ -25,6 +25,7 @@
#include "improcfun.h"
#include "iccstore.h"
#include "procparams.h"
#include "tweakoperator.h"
#include <iostream>
#include <fstream>
#include <string>
@ -130,6 +131,7 @@ ImProcCoordinator::ImProcCoordinator() :
hListener(nullptr),
resultValid(false),
params(new procparams::ProcParams),
tweakOperator(nullptr),
lastOutputProfile("BADFOOD"),
lastOutputIntent(RI__COUNT),
lastOutputBPC(false),
@ -200,9 +202,32 @@ void ImProcCoordinator::assign(ImageSource* imgsrc)
this->imgsrc = imgsrc;
}
void ImProcCoordinator::getParams(procparams::ProcParams* dst)
void ImProcCoordinator::getParams(procparams::ProcParams* dst, bool tweaked)
{
*dst = *params;
if (!tweaked && paramsBackup.operator bool()) {
*dst = *paramsBackup;
} else {
*dst = *params;
}
}
void ImProcCoordinator::backupParams()
{
if (!params) {
return;
}
if (!paramsBackup) {
paramsBackup.reset(new ProcParams());
}
*paramsBackup = *params;
}
void ImProcCoordinator::restoreParams()
{
if (!paramsBackup || !params) {
return;
}
*params = *paramsBackup;
}
DetailedCrop* ImProcCoordinator::createCrop(::EditDataProvider *editDataProvider, bool isDetailWindow)
@ -233,41 +258,6 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange)
}
}
if (todo & M_SPOT_ADJUST) {
// TWEAKING THE PROCPARAMS FOR THE SPOT ADJUSTMENT MODE
// -> using fast demozaicing method
highDetailNeeded = false;
//params->raw.bayersensor.method = RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::FAST);
//params->raw.xtranssensor.method = RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::FAST);
// -> disabling all transform
//params->coarse = CoarseTransformParams();
params->lensProf = LensProfParams();
params->cacorrection = CACorrParams();
params->distortion = DistortionParams();
params->rotate = RotateParams();
params->perspective = PerspectiveParams();
params->vignetting = VignettingParams();
// -> disabling standard crop
params->crop.enabled = false;
// -> disabling time consuming and unnecessary tool
params->sh.enabled = false;
params->blackwhite.enabled = false;
params->dehaze.enabled = false;
params->wavelet.enabled = false;
params->filmSimulation.enabled = false;
params->sharpenEdge.enabled = false;
params->sharpenMicro.enabled = false;
params->sharpening.enabled = false;
params->softlight.enabled = false;
params->gradient.enabled = false;
params->pcvignette.enabled = false;
params->colorappearance.enabled = false;
}
if (((todo & ALL) == ALL) || (todo & M_MONITOR) || panningRelatedChange || (highDetailNeeded && options.prevdemo != PD_Sidecar)) {
bwAutoR = bwAutoG = bwAutoB = -9000.f;
@ -545,7 +535,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange)
progress ("Spot Removal...", 100 * readyphase / numofphases);
if (todo & (M_SPOT|M_SPOT_ADJUST)) {
if (todo & M_SPOT) {
if (params->spot.enabled && !params->spot.entries.empty()) {
allocCache(spotprev);
orig_prev->copyData (spotprev);
@ -1089,10 +1079,21 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange)
delete oprevi;
oprevi = nullptr;
}
}
void ImProcCoordinator::setTweakOperator (TweakOperator *tOperator)
{
if (tOperator) {
tweakOperator = tOperator;
}
}
void ImProcCoordinator::unsetTweakOperator (TweakOperator *tOperator)
{
if (tOperator && tOperator == tweakOperator) {
tweakOperator = nullptr;
}
}
void ImProcCoordinator::freeAll()
{
@ -1432,35 +1433,37 @@ void ImProcCoordinator::saveInputICCReference(const Glib::ustring& fname, bool a
MyMutex::MyLock lock(mProcessing);
int fW, fH;
std::unique_ptr<ProcParams> validParams(new ProcParams());
getParams(validParams.get());
int tr = getCoarseBitMask(params->coarse);
int tr = getCoarseBitMask(validParams->coarse);
imgsrc->getFullSize(fW, fH, tr);
PreviewProps pp(0, 0, fW, fH, 1);
ProcParams ppar = *params;
ProcParams ppar = *validParams;
ppar.toneCurve.hrenabled = false;
ppar.icm.inputProfile = "(none)";
Imagefloat* im = new Imagefloat(fW, fH);
imgsrc->preprocess(ppar.raw, ppar.lensProf, ppar.coarse);
double dummy = 0.0;
imgsrc->demosaic(ppar.raw, false, dummy);
ColorTemp currWB = ColorTemp(params->wb.temperature, params->wb.green, params->wb.equal, params->wb.method);
ColorTemp currWB = ColorTemp(validParams->wb.temperature, validParams->wb.green, validParams->wb.equal, validParams->wb.method);
if (params->wb.method == "Camera") {
if (validParams->wb.method == "Camera") {
currWB = imgsrc->getWB();
} else if (params->wb.method == "Auto") {
if (lastAwbEqual != params->wb.equal || lastAwbTempBias != params->wb.tempBias) {
} else if (validParams->wb.method == "Auto") {
if (lastAwbEqual != validParams->wb.equal || lastAwbTempBias != validParams->wb.tempBias) {
double rm, gm, bm;
imgsrc->getAutoWBMultipliers(rm, gm, bm);
if (rm != -1.) {
autoWB.update(rm, gm, bm, params->wb.equal, params->wb.tempBias);
lastAwbEqual = params->wb.equal;
lastAwbTempBias = params->wb.tempBias;
autoWB.update(rm, gm, bm, validParams->wb.equal, validParams->wb.tempBias);
lastAwbEqual = validParams->wb.equal;
lastAwbTempBias = validParams->wb.tempBias;
} else {
lastAwbEqual = -1.;
lastAwbTempBias = 0.0;
autoWB.useDefaults(params->wb.equal);
autoWB.useDefaults(validParams->wb.equal);
}
}
@ -1482,12 +1485,12 @@ void ImProcCoordinator::saveInputICCReference(const Glib::ustring& fname, bool a
im = trImg;
}
if (params->crop.enabled) {
Imagefloat *tmpim = new Imagefloat(params->crop.w, params->crop.h);
int cx = params->crop.x;
int cy = params->crop.y;
int cw = params->crop.w;
int ch = params->crop.h;
if (validParams->crop.enabled) {
Imagefloat *tmpim = new Imagefloat(validParams->crop.w, validParams->crop.h);
int cx = validParams->crop.x;
int cy = validParams->crop.y;
int cw = validParams->crop.w;
int ch = validParams->crop.h;
#ifdef _OPENMP
#pragma omp parallel for
#endif
@ -1518,7 +1521,7 @@ void ImProcCoordinator::saveInputICCReference(const Glib::ustring& fname, bool a
}
int imw, imh;
double tmpScale = ipf.resizeScale(params.get(), fW, fH, imw, imh);
double tmpScale = ipf.resizeScale(validParams.get(), fW, fH, imw, imh);
if (tmpScale != 1.0) {
Imagefloat* tempImage = new Imagefloat(imw, imh);
@ -1628,6 +1631,15 @@ void ImProcCoordinator::process()
*params = *nextParams;
int change = changeSinceLast;
changeSinceLast = 0;
if (tweakOperator) {
// TWEAKING THE PROCPARAMS FOR THE SPOT ADJUSTMENT MODE
backupParams();
tweakOperator->tweakParams(*params);
} else if (paramsBackup) {
paramsBackup.release();
}
paramsUpdateMutex.unlock();
// M_VOID means no update, and is a bit higher that the rest

View File

@ -37,6 +37,7 @@ namespace rtengine
using namespace procparams;
class Crop;
class TweakOperator;
/** @brief Manages the image processing, espc. of the preview windows
*
@ -180,14 +181,20 @@ protected:
MyMutex minit; // to gain mutually exclusive access to ... to what exactly?
void progress (Glib::ustring str, int pr);
void backupParams();
void restoreParams();
void reallocAll ();
void allocCache (Imagefloat* &imgfloat);
void updateLRGBHistograms ();
void setScale (int prevscale);
void updatePreviewImage (int todo, bool panningRelatedChange);
void setTweakOperator (TweakOperator *tOperator);
void unsetTweakOperator (TweakOperator *tOperator);
MyMutex mProcessing;
const std::unique_ptr<ProcParams> params;
const std::unique_ptr<ProcParams> params; // used for the rendering, can be eventually tweaked
std::unique_ptr<ProcParams> paramsBackup; // backup of the untweaked procparams
TweakOperator* tweakOperator;
// for optimization purpose, the output profile, output rendering intent and
// output BPC will trigger a regeneration of the profile on parameter change only
@ -228,7 +235,7 @@ public:
~ImProcCoordinator () override;
void assign (ImageSource* imgsrc);
void getParams (procparams::ProcParams* dst) override;
void getParams (procparams::ProcParams* dst, bool tweaked=false) override;
void startProcessing (int changeCode) override;
ProcParams* beginUpdateParams () override;

View File

@ -22,9 +22,6 @@
#include <unordered_map>
#include "procevents.h"
// Use M_SPOT_ADJUST to update the rendering for On Preview Adjustment of the Spot tool
#define M_SPOT_ADJUST (1<<19)
// Use M_VOID if you wish to update the proc params without updating the preview at all !
#define M_VOID (1<<18)
// Use M_MINUPDATE if you wish to update the preview without modifying the image (think about it like a "refreshPreview")
@ -61,7 +58,7 @@
#define DEMOSAIC (M_RAW|M_INIT|M_SPOT|M_LINDENOISE|M_HDR|M_TRANSFORM|M_BLURMAP|M_AUTOEXP|M_RGBCURVE|M_LUMACURVE|M_LUMINANCE|M_COLOR)
#define ALLNORAW (M_INIT|M_SPOT|M_LINDENOISE|M_HDR|M_TRANSFORM|M_BLURMAP|M_AUTOEXP|M_RGBCURVE|M_LUMACURVE|M_LUMINANCE|M_COLOR)
#define HDR (M_SPOT|M_LINDENOISE|M_HDR|M_TRANSFORM|M_BLURMAP|M_AUTOEXP|M_RGBCURVE|M_LUMACURVE|M_LUMINANCE|M_COLOR)
#define SPOTADJUST (M_SPOT_ADJUST|M_HDR|M_BLURMAP|M_AUTOEXP|M_RGBCURVE|M_LUMACURVE|M_LUMINANCE|M_COLOR)
#define SPOTADJUST (M_SPOT|M_HDR|M_BLURMAP|M_AUTOEXP|M_RGBCURVE|M_LUMACURVE|M_LUMINANCE|M_COLOR)
#define TRANSFORM (M_TRANSFORM|M_BLURMAP|M_AUTOEXP|M_RGBCURVE|M_LUMACURVE|M_LUMINANCE|M_COLOR)
#define AUTOEXP (M_SPOT|M_HDR|M_AUTOEXP|M_RGBCURVE|M_LUMACURVE|M_LUMINANCE|M_COLOR)
#define RGBCURVE (M_RGBCURVE|M_LUMACURVE|M_LUMINANCE|M_COLOR)

View File

@ -70,6 +70,7 @@ class IImage8;
class IImage16;
class IImagefloat;
class ImageSource;
class TweakOperator;
/**
* This class provides functions to obtain exif and IPTC metadata information
@ -454,9 +455,20 @@ public:
/** Returns the initial image corresponding to the image processor.
* @return the initial image corresponding to the image processor */
virtual InitialImage* getInitialImage () = 0;
/** Set the TweakOperator
* @param tOperator is a pointer to the object that will alter the ProcParams for the rendering */
virtual void setTweakOperator (TweakOperator *tOperator) = 0;
/** Unset the TweakOperator
* @param tOperator is a pointer to the object that were altering the ProcParams for the rendering
* It will only unset the tweak operator if tOperator is the same than the currently set operator.
* If it doesn't match, the currently set TweakOperator will remain set. */
virtual void unsetTweakOperator (TweakOperator *tOperator) = 0;
/** Returns the current processing parameters.
* @param dst is the location where the image processing parameters are copied (it is assumed that the memory is allocated by the caller) */
virtual void getParams (procparams::ProcParams* dst) = 0;
* Since the ProcParams can be tweaked by a GUI to operate on the image at a specific stage or with disabled tool,
* you'll have to specify if you want the tweaked version for the current special mode, or the untweaked one.
* @param dst is the location where the image processing parameters are copied (it is assumed that the memory is allocated by the caller)
* @param tweaked is used to chose betwen the tweaked ProcParams (if there is one) or the untweaked one */
virtual void getParams (procparams::ProcParams* dst, bool tweaked=false) = 0;
/** An essential member function. Call this when a setting has been changed. This function returns a pointer to the
* processing parameters, that you have to update to reflect the changed situation. When ready, call the paramsUpdateReady
* function to start the image update.

45
rtengine/tweakoperator.h Normal file
View File

@ -0,0 +1,45 @@
/*
* This file is part of RawTherapee.
*
* Copyright (c) 2019 Jean-Christophe FRISCH <natureh.510@gmail.com>
*
* RawTherapee is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RawTherapee is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
namespace rtengine
{
namespace procparams
{
class ProcParams;
}
/** This class can let objects alter the collected values of the ProcParams for a specific
* purpose, e.g. displaying a preview image at a specific point in the pipeline or with
* disabled tools. Before starting the rendering, the engine will call the TweakOperator
* (if set) to modify the ProcParams. The untweaked one will still exist as a backup, and
* can be sent back if necessary. */
class TweakOperator
{
public:
virtual ~TweakOperator() {}
/** Callback that will alter the ProcParams before hte image is computed. */
virtual void tweakParams(procparams::ProcParams& pparams) = 0;
};
}

View File

@ -558,6 +558,14 @@ void BatchToolPanelCoordinator::panelChanged(const rtengine::ProcEvent& event, c
}
}
void BatchToolPanelCoordinator::setTweakOperator (rtengine::TweakOperator *tOperator)
{
}
void BatchToolPanelCoordinator::unsetTweakOperator (rtengine::TweakOperator *tOperator)
{
}
void BatchToolPanelCoordinator::getAutoWB (double& temp, double& green, double equal, double tempBias)
{

View File

@ -55,6 +55,8 @@ public:
// toolpanellistener interface
void panelChanged(const rtengine::ProcEvent& event, const Glib::ustring& descr) override;
void setTweakOperator (rtengine::TweakOperator *tOperator) override;
void unsetTweakOperator (rtengine::TweakOperator *tOperator) override;
// profilechangelistener interface
void profileChange(

View File

@ -1092,7 +1092,7 @@ void CropWindow::pointerMoved (int bstate, int x, int y)
rtengine::StagedImageProcessor* ipc = iarea->getImProcCoordinator();
if(ipc) {
procparams::ProcParams params;
ipc->getParams(&params);
ipc->getParams(&params, true);
isRaw = params.raw.bayersensor.method == RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::NONE) || params.raw.xtranssensor.method == RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::NONE);
if(isRaw) {
ImageSource *isrc = static_cast<ImageSource*>(ipc->getInitialImage());

View File

@ -197,10 +197,12 @@ void Spot::editToggled ()
{
if (listener) {
if (edit->get_active()) {
listener->setTweakOperator(this);
listener->refreshPreview(EvSpotEnabledOPA); // reprocess the preview w/o creating History entry
subscribe();
} else {
unsubscribe();
listener->unsetTweakOperator(this);
listener->refreshPreview(EvSpotEnabled); // reprocess the preview w/o creating History entry
}
}
@ -701,6 +703,38 @@ void Spot::switchOffEditMode ()
}
EditSubscriber::switchOffEditMode(); // disconnect
listener->unsetTweakOperator(this);
listener->refreshPreview(EvSpotEnabled); // reprocess the preview w/o creating History entry
}
void Spot::tweakParams(procparams::ProcParams& pparams)
{
//params->raw.bayersensor.method = RAWParams::BayerSensor::getMethodString(RAWParams::BayerSensor::Method::FAST);
//params->raw.xtranssensor.method = RAWParams::XTransSensor::getMethodString(RAWParams::XTransSensor::Method::FAST);
// -> disabling all transform
//params->coarse = CoarseTransformParams();
pparams.lensProf = LensProfParams();
pparams.cacorrection = CACorrParams();
pparams.distortion = DistortionParams();
pparams.rotate = RotateParams();
pparams.perspective = PerspectiveParams();
pparams.vignetting = VignettingParams();
// -> disabling standard crop
pparams.crop.enabled = false;
// -> disabling time consuming and unnecessary tool
pparams.sh.enabled = false;
pparams.blackwhite.enabled = false;
pparams.dehaze.enabled = false;
pparams.wavelet.enabled = false;
pparams.filmSimulation.enabled = false;
pparams.sharpenEdge.enabled = false;
pparams.sharpenMicro.enabled = false;
pparams.sharpening.enabled = false;
pparams.softlight.enabled = false;
pparams.gradient.enabled = false;
pparams.pcvignette.enabled = false;
pparams.colorappearance.enabled = false;
}

View File

@ -8,6 +8,7 @@
#include "toolpanel.h"
#include "editwidgets.h"
#include "../rtengine/procparams.h"
#include "../rtengine/tweakoperator.h"
/**
* @brief Let the user create/edit/delete points for Spot Removal tool
@ -36,7 +37,7 @@
* (the point will be deleted on button release).
*/
class Spot : public ToolParamBlock, public FoldableToolPanel, public EditSubscriber
class Spot : public ToolParamBlock, public FoldableToolPanel, public EditSubscriber, public rtengine::TweakOperator
{
private:
@ -99,6 +100,9 @@ public:
bool pick3 (const bool picked);
void switchOffEditMode ();
//TweakOperator interface
void tweakParams(rtengine::procparams::ProcParams& pparams) override;
rtengine::ProcEvent EvSpotEnabled;
rtengine::ProcEvent EvSpotEnabledOPA; // used to toggle-on the Spot 'On Preview Adjustment' mode
rtengine::ProcEvent EvSpotEntry;

View File

@ -40,6 +40,10 @@ public:
virtual void refreshPreview(const rtengine::ProcEvent& event) = 0;
/// @brief Used to notify all listeners that a parameters has been effectively changed
virtual void panelChanged(const rtengine::ProcEvent& event, const Glib::ustring& descr) = 0;
/// @brief Set the TweakOperator to the StagedImageProcessor, to let some tool enter into special modes
virtual void setTweakOperator (rtengine::TweakOperator *tOperator) = 0;
/// @brief Unset the TweakOperator to the StagedImageProcessor
virtual void unsetTweakOperator (rtengine::TweakOperator *tOperator) = 0;
};
/// @brief This class control the space around the group of tools inside a tab, as well as the space separating each tool. */

View File

@ -379,6 +379,20 @@ void ToolPanelCoordinator::imageTypeChanged (bool isRaw, bool isBayer, bool isXt
}
void ToolPanelCoordinator::setTweakOperator (rtengine::TweakOperator *tOperator)
{
if (ipc && tOperator) {
ipc->setTweakOperator(tOperator);
}
}
void ToolPanelCoordinator::unsetTweakOperator (rtengine::TweakOperator *tOperator)
{
if (ipc && tOperator) {
ipc->unsetTweakOperator(tOperator);
}
}
void ToolPanelCoordinator::refreshPreview (const rtengine::ProcEvent& event)
{
if (!ipc) {

View File

@ -239,7 +239,10 @@ public:
// toolpanellistener interface
void refreshPreview(const rtengine::ProcEvent& event) override;
void panelChanged(const rtengine::ProcEvent& event, const Glib::ustring& descr) override;
void setTweakOperator (rtengine::TweakOperator *tOperator) override;
void unsetTweakOperator (rtengine::TweakOperator *tOperator) override;
// FilmNegProvider interface
void imageTypeChanged (bool isRaw, bool isBayer, bool isXtrans, bool isMono = false) override;
// void autoContrastChanged (double autoContrast);