From b963f368af73a8004b4af9a303150c65120970a2 Mon Sep 17 00:00:00 2001 From: Alberto Griggio Date: Sat, 9 Dec 2017 18:09:13 +0100 Subject: [PATCH] Added On/Off switch for White Balance Candidate fix for #3542 --- rtengine/improccoordinator.cc | 12 ++++++++---- rtengine/procevents.h | 3 +-- rtengine/procparams.cc | 6 +++++- rtengine/procparams.h | 1 + rtengine/refreshmap.cc | 4 ++-- rtengine/rtthumbnail.cc | 23 ++++++++++++++++------- rtengine/simpleprocess.cc | 4 +++- rtgui/paramsedited.cc | 6 ++++++ rtgui/paramsedited.h | 1 + rtgui/whitebalance.cc | 34 ++++++++++++++++++++++++++++------ rtgui/whitebalance.h | 1 + 11 files changed, 72 insertions(+), 23 deletions(-) diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 008344dd7..9c80eed9e 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -296,7 +296,9 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) currWB = ColorTemp (params.wb.temperature, params.wb.green, params.wb.equal, params.wb.method); - if (params.wb.method == "Camera") { + if (!params.wb.enabled) { + currWB = ColorTemp(); + } else if (params.wb.method == "Camera") { currWB = imgsrc->getWB (); } else if (params.wb.method == "Auto") { if (lastAwbEqual != params.wb.equal || lastAwbTempBias != params.wb.tempBias) { @@ -320,10 +322,12 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) currWB = autoWB; } - params.wb.temperature = currWB.getTemp (); - params.wb.green = currWB.getGreen (); + if (params.wb.enabled) { + params.wb.temperature = currWB.getTemp (); + params.wb.green = currWB.getGreen (); + } - if (params.wb.method == "Auto" && awbListener) { + if (params.wb.method == "Auto" && awbListener && params.wb.enabled) { awbListener->WBChanged (params.wb.temperature, params.wb.green); } diff --git a/rtengine/procevents.h b/rtengine/procevents.h index 3aa5505b5..169b22584 100644 --- a/rtengine/procevents.h +++ b/rtengine/procevents.h @@ -511,14 +511,13 @@ enum ProcEvent { EvCATgreensc = 481, EvCATybscen = 482, EvCATAutoyb = 483, - // profiled lens correction new events EvLensCorrMode = 484, EvLensCorrLensfunCamera = 485, EvLensCorrLensfunLens = 486, - // Fattal tone mapping EvTMFattalEnabled = 487, EvTMFattalThreshold = 488, EvTMFattalAmount = 489, + EvWBEnabled = 490, NUMOFEVENTS diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 9f0c13f6d..ff5f0b386 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -1094,6 +1094,7 @@ bool VibranceParams::operator !=(const VibranceParams& other) const } WBParams::WBParams() : + enabled(true), method("Camera"), temperature(6504), green(1.0), @@ -1105,7 +1106,8 @@ WBParams::WBParams() : bool WBParams::operator ==(const WBParams& other) const { return - method == other.method + enabled == other.enabled + && method == other.method && temperature == other.temperature && green == other.green && equal == other.equal @@ -2864,6 +2866,7 @@ int ProcParams::save(const Glib::ustring& fname, const Glib::ustring& fname2, bo saveToKeyfile(!pedited || pedited->sharpenMicro.uniformity, "SharpenMicro", "Uniformity", sharpenMicro.uniformity, keyFile); // WB + saveToKeyfile(!pedited || pedited->wb.enabled, "White Balance", "Enabled", wb.enabled, keyFile); saveToKeyfile(!pedited || pedited->wb.method, "White Balance", "Setting", wb.method, keyFile); saveToKeyfile(!pedited || pedited->wb.temperature, "White Balance", "Temperature", wb.temperature, keyFile); saveToKeyfile(!pedited || pedited->wb.green, "White Balance", "Green", wb.green, keyFile); @@ -3696,6 +3699,7 @@ int ProcParams::load(const Glib::ustring& fname, ParamsEdited* pedited) } if (keyFile.has_group ("White Balance")) { + assignFromKeyfile(keyFile, "White Balance", "Enabled", pedited, wb.enabled, pedited->wb.enabled); assignFromKeyfile(keyFile, "White Balance", "Setting", pedited, wb.method, pedited->wb.method); assignFromKeyfile(keyFile, "White Balance", "Temperature", pedited, wb.temperature, pedited->wb.temperature); assignFromKeyfile(keyFile, "White Balance", "Green", pedited, wb.green, pedited->wb.green); diff --git a/rtengine/procparams.h b/rtengine/procparams.h index 00e6f9389..35f7b79f9 100644 --- a/rtengine/procparams.h +++ b/rtengine/procparams.h @@ -538,6 +538,7 @@ struct WBEntry { }; struct WBParams { + bool enabled; Glib::ustring method; int temperature; double green; diff --git a/rtengine/refreshmap.cc b/rtengine/refreshmap.cc index c95b53c0a..676c1efbf 100644 --- a/rtengine/refreshmap.cc +++ b/rtengine/refreshmap.cc @@ -516,7 +516,7 @@ int refreshmap[rtengine::NUMOFEVENTS] = { DARKFRAME, // EvLensCorrLensfunLens ALLNORAW, // EvTMFattalEnabled HDR, // EvTMFattalThreshold - HDR // EvTMFattalAmount - + HDR, // EvTMFattalAmount + ALLNORAW // EvWBEnabled }; diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index 8adab4ec5..fcc039a81 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -944,7 +944,9 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, eSensorT // compute WB multipliers ColorTemp currWB = ColorTemp (params.wb.temperature, params.wb.green, params.wb.equal, params.wb.method); - if (params.wb.method == "Camera") { + if (!params.wb.enabled) { + currWB = ColorTemp(); + } else if (params.wb.method == "Camera") { //recall colorMatrix is rgb_cam double cam_r = colorMatrix[0][0] * camwbRed + colorMatrix[0][1] * camwbGreen + colorMatrix[0][2] * camwbBlue; double cam_g = colorMatrix[1][0] * camwbRed + colorMatrix[1][1] * camwbGreen + colorMatrix[1][2] * camwbBlue; @@ -954,12 +956,19 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, eSensorT currWB = ColorTemp (autoWBTemp, autoWBGreen, wbEqual, "Custom"); } - double r, g, b; - currWB.getMultipliers (r, g, b); - //iColorMatrix is cam_rgb - double rm = iColorMatrix[0][0] * r + iColorMatrix[0][1] * g + iColorMatrix[0][2] * b; - double gm = iColorMatrix[1][0] * r + iColorMatrix[1][1] * g + iColorMatrix[1][2] * b; - double bm = iColorMatrix[2][0] * r + iColorMatrix[2][1] * g + iColorMatrix[2][2] * b; + double rm, gm, bm; + if (currWB.getTemp() < 0) { + rm = redMultiplier; + gm = greenMultiplier; + bm = blueMultiplier; + } else { + double r, g, b; + currWB.getMultipliers (r, g, b); + //iColorMatrix is cam_rgb + rm = iColorMatrix[0][0] * r + iColorMatrix[0][1] * g + iColorMatrix[0][2] * b; + gm = iColorMatrix[1][0] * r + iColorMatrix[1][1] * g + iColorMatrix[1][2] * b; + bm = iColorMatrix[2][0] * r + iColorMatrix[2][1] * g + iColorMatrix[2][2] * b; + } rm = camwbRed / rm; gm = camwbGreen / gm; bm = camwbBlue / bm; diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index ece818440..5bcaca925 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -223,7 +223,9 @@ private: // set the color temperature currWB = ColorTemp (params.wb.temperature, params.wb.green, params.wb.equal, params.wb.method); - if (params.wb.method == "Camera") { + if (!params.wb.enabled) { + currWB = ColorTemp(); + } else if (params.wb.method == "Camera") { currWB = imgsrc->getWB (); } else if (params.wb.method == "Auto") { double rm, gm, bm; diff --git a/rtgui/paramsedited.cc b/rtgui/paramsedited.cc index 62643221a..b649272db 100644 --- a/rtgui/paramsedited.cc +++ b/rtgui/paramsedited.cc @@ -219,6 +219,7 @@ void ParamsEdited::set (bool v) //colorBoost.avoidclip = v; //colorBoost.enable_saturationlimiter = v; //colorBoost.saturationlimit = v; + wb.enabled = v; wb.method = v; wb.green = v; wb.temperature = v; @@ -758,6 +759,7 @@ void ParamsEdited::initFrom (const std::vector //colorBoost.avoidclip = colorBoost.avoidclip && p.colorBoost.avoidclip == other.colorBoost.avoidclip; //colorBoost.enable_saturationlimiter = colorBoost.enable_saturationlimiter && p.colorBoost.enable_saturationlimiter == other.colorBoost.enable_saturationlimiter; //colorBoost.saturationlimit = colorBoost.saturationlimit && p.colorBoost.saturationlimit == other.colorBoost.saturationlimit; + wb.enabled = wb.enabled && p.wb.enabled == other.wb.enabled; wb.method = wb.method && p.wb.method == other.wb.method; wb.green = wb.green && p.wb.green == other.wb.green; wb.equal = wb.equal && p.wb.equal == other.wb.equal; @@ -1664,6 +1666,10 @@ void ParamsEdited::combine (rtengine::procparams::ProcParams& toEdit, const rten //if (colorBoost.avoidclip) toEdit.colorBoost.avoidclip = mods.colorBoost.avoidclip; //if (colorBoost.enable_saturationlimiter)toEdit.colorBoost.enable_saturationlimiter = mods.colorBoost.enable_saturationlimiter; //if (colorBoost.saturationlimit) toEdit.colorBoost.saturationlimit = mods.colorBoost.saturationlimit; + if (wb.enabled) { + toEdit.wb.enabled = mods.wb.enabled; + } + if (wb.method) { toEdit.wb.method = mods.wb.method; } diff --git a/rtgui/paramsedited.h b/rtgui/paramsedited.h index a571f5484..f8f76f036 100644 --- a/rtgui/paramsedited.h +++ b/rtgui/paramsedited.h @@ -229,6 +229,7 @@ class WBParamsEdited { public: + bool enabled; bool method; bool temperature; bool green; diff --git a/rtgui/whitebalance.cc b/rtgui/whitebalance.cc index 7dbc02b4e..57d73b15f 100644 --- a/rtgui/whitebalance.cc +++ b/rtgui/whitebalance.cc @@ -147,7 +147,7 @@ static double wbTemp2Slider(double temp) return sval; } -WhiteBalance::WhiteBalance () : FoldableToolPanel(this, "whitebalance", M("TP_WBALANCE_LABEL")), wbp(nullptr), wblistener(nullptr) +WhiteBalance::WhiteBalance () : FoldableToolPanel(this, "whitebalance", M("TP_WBALANCE_LABEL"), false, true), wbp(nullptr), wblistener(nullptr) { Gtk::HBox* hbox = Gtk::manage (new Gtk::HBox ()); @@ -349,9 +349,23 @@ WhiteBalance::WhiteBalance () : FoldableToolPanel(this, "whitebalance", M("TP_WB spotsize->signal_changed().connect( sigc::mem_fun(*this, &WhiteBalance::spotSizeChanged) ); } + +void WhiteBalance::enabledChanged() +{ + if (listener) { + if (get_inconsistent()) { + listener->panelChanged(EvWBEnabled, M("GENERAL_UNCHANGED")); + } else if (getEnabled()) { + listener->panelChanged(EvWBEnabled, M("GENERAL_ENABLED")); + } else { + listener->panelChanged(EvWBEnabled, M("GENERAL_DISABLED")); + } + } +} + + void WhiteBalance::adjusterChanged (Adjuster* a, double newval) { - int tVal = (int)temp->getValue(); double gVal = green->getValue(); double eVal = equal->getValue(); @@ -400,7 +414,7 @@ void WhiteBalance::adjusterChanged (Adjuster* a, double newval) // Recomputing AutoWB if it's the current method will happen in improccoordinator.cc - if (listener) { + if (listener && getEnabled()) { if (a == temp) { listener->panelChanged (EvWBTemp, Glib::ustring::format ((int)a->getValue())); } else if (a == green) { @@ -415,7 +429,6 @@ void WhiteBalance::adjusterChanged (Adjuster* a, double newval) void WhiteBalance::optChanged () { - Gtk::TreeModel::Row row = getActiveMethod(); if (row == refTreeModel->children().end()) { @@ -520,7 +533,7 @@ void WhiteBalance::optChanged () } } - if (listener) { + if (listener && getEnabled()) { listener->panelChanged (EvWBMethod, row[methodColumns.colLabel]); } } @@ -528,7 +541,6 @@ void WhiteBalance::optChanged () void WhiteBalance::spotPressed () { - if (wblistener) { wblistener->spotWBRequested (getSize()); } @@ -667,6 +679,11 @@ void WhiteBalance::read (const ProcParams* pp, const ParamsEdited* pedited) tempBias->set_sensitive(wbValues.type == WBEntry::Type::AUTO); } + setEnabled(pp->wb.enabled); + if (pedited) { + set_inconsistent(multiImage && !pedited->wb.enabled); + } + methconn.block (false); enableListener (); } @@ -682,8 +699,11 @@ void WhiteBalance::write (ProcParams* pp, ParamsEdited* pedited) pedited->wb.equal = equal->getEditedState (); pedited->wb.tempBias = tempBias->getEditedState (); pedited->wb.method = row[methodColumns.colLabel] != M("GENERAL_UNCHANGED"); + pedited->wb.enabled = !get_inconsistent(); } + pp->wb.enabled = getEnabled(); + const std::pair ppMethod = findWBEntry (row[methodColumns.colLabel], WBLT_GUI); if (ppMethod.first) { @@ -756,6 +776,7 @@ void WhiteBalance::setWB (int vtemp, double vgreen) methconn.block(true); const std::pair wbValues = findWBEntry("Custom", WBLT_PP); + setEnabled(true); temp->setValue (vtemp); green->setValue (vgreen); opt = setActiveMethod(wbValues.second.GUILabel); @@ -876,6 +897,7 @@ void WhiteBalance::WBChanged(double temperature, double greenVal) { GThreadLock lock; disableListener(); + setEnabled(true); temp->setValue(temperature); green->setValue(greenVal); temp->setDefault(temperature); diff --git a/rtgui/whitebalance.h b/rtgui/whitebalance.h index d1fafcea3..ecf65f476 100644 --- a/rtgui/whitebalance.h +++ b/rtgui/whitebalance.h @@ -119,6 +119,7 @@ public: void setAdjusterBehavior (bool tempadd, bool greenadd, bool equaladd, bool tempbiasadd); void trimValues (rtengine::procparams::ProcParams* pp); + void enabledChanged(); }; #endif