From dbb4cf6abef3473160f762ddc152f1ea2a0a74ad Mon Sep 17 00:00:00 2001 From: Emil Martinec Date: Fri, 26 Nov 2010 11:56:14 -0600 Subject: [PATCH] Purple fringing tool added. May also be useful for CA desaturation. --- rtengine/CMakeLists.txt | 1 + rtengine/dcrop.cc | 1 + rtengine/improccoordinator.cc | 4 ++++ rtengine/improcfun.cc | 9 ++++++++- rtengine/improcfun.h | 3 +++ rtengine/procevents.h | 5 ++++- rtengine/procparams.cc | 18 ++++++++++++++++++ rtengine/procparams.h | 13 +++++++++++++ rtengine/refreshmap.cc | 3 +++ rtengine/refreshmap.h | 1 + rtengine/simpleprocess.cc | 1 + rtgui/CMakeLists.txt | 2 +- rtgui/paramsedited.cc | 10 ++++++++++ rtgui/paramsedited.h | 11 ++++++++++- rtgui/toolpanelcoord.cc | 2 ++ rtgui/toolpanelcoord.h | 2 ++ 16 files changed, 82 insertions(+), 4 deletions(-) diff --git a/rtengine/CMakeLists.txt b/rtengine/CMakeLists.txt index 181f05037..a41dd4dc2 100644 --- a/rtengine/CMakeLists.txt +++ b/rtengine/CMakeLists.txt @@ -14,6 +14,7 @@ set (RTENGINESOURCEFILES colortemp.cc curves.cc dcraw.cc iccstore.cc dfmanager.c processingjob.cc rtthumbnail.cc utils.cc labimage.cc slicer.cc iplab2rgb.cc ipsharpen.cc iptransform.cc ipresize.cc jpeg_memsrc.c + PF_correct_RT.cc wavelet_dec.cc ipequalizer.cc dirpyrLab_denoise.cc dirpyrLab_equalizer.cc dirpyr_equalizer.cc) add_library (rtengine ${RTENGINESOURCEFILES}) diff --git a/rtengine/dcrop.cc b/rtengine/dcrop.cc index 9776f606c..b8e62a867 100644 --- a/rtengine/dcrop.cc +++ b/rtengine/dcrop.cc @@ -180,6 +180,7 @@ void Crop::update (int todo, bool internal) { if (skip==1) { parent->ipf.impulsedenoise (labnCrop); + parent->ipf.defringe (labnCrop); parent->ipf.lumadenoise (labnCrop, cbuffer); parent->ipf.colordenoise (labnCrop, cbuffer); parent->ipf.dirpyrdenoise (labnCrop); diff --git a/rtengine/improccoordinator.cc b/rtengine/improccoordinator.cc index 9da0605c1..ead9e731a 100644 --- a/rtengine/improccoordinator.cc +++ b/rtengine/improccoordinator.cc @@ -199,6 +199,10 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) { progress ("Denoising luminance impulse...",100*readyphase/numofphases); ipf.impulsedenoise (nprevl); } + if (scale==1) { + progress ("Defringing...",100*readyphase/numofphases); + ipf.defringe (nprevl); + } if (scale==1) { progress ("Denoising luminance...",100*readyphase/numofphases); ipf.lumadenoise (nprevl, buffer); diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index 6eb2a0dea..9de1a368b 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -543,6 +543,13 @@ void ImProcFunctions::colorCurve (LabImage* lold, LabImage* lnew) { impulse_nr (lab->L, lab->L, lab->W, lab->H, (float)params->impulseDenoise.thresh/20.0 ); } + void ImProcFunctions::defringe (LabImage* lab) { + + if (params->defringe.enabled && lab->W>=8 && lab->H>=8) + + PF_correct_RT(lab, lab, params->defringe.radius, params->defringe.threshold, false /*edges only*/ ); + } + void ImProcFunctions::dirpyrdenoise (LabImage* lab) { if (params->dirpyrDenoise.enabled && lab->W>=8 && lab->H>=8) @@ -634,7 +641,7 @@ void ImProcFunctions::getAutoExp (unsigned int* histogram, int histcompr, doubl awg = CurveFactory::igamma2 ((float)(awg/65535.0)) * 65535.0; //need to inverse gamma transform to get correct exposure compensation parameter bl = (int)((65535*bl)/awg); - br = log(65535.0 / (awg)) / log(2.0); + br = log(65535.0 / (awg)) / log(2.0); if (br<0) br = 0; } diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index d9c3730e2..83c389a9d 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -109,6 +109,9 @@ class ImProcFunctions { void dirpyr_channel(unsigned short ** data_fine, unsigned short ** data_coarse, int width, int height, int * rangefn, int level, int scale, const double * mult ); void idirpyr_eq_channel(unsigned short ** data_coarse, unsigned short ** data_fine, int ** buffer, int width, int height, int level, const double * mult ); + void defringe (LabImage* lab); + void PF_correct_RT(LabImage * src, LabImage * dst, double radius, int thresh, bool edges); + Image8* lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile); Image16* lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile); diff --git a/rtengine/procevents.h b/rtengine/procevents.h index 6d0313227..b4d316cf6 100644 --- a/rtengine/procevents.h +++ b/rtengine/procevents.h @@ -126,7 +126,10 @@ enum ProcEvent { EvHSVEqualizerS=101, EvHSVEqualizerV=102, EvHSVEqEnabled=103, - NUMOFEVENTS=104 + EvDefringeEnabled=104, + EvDefringeRadius=105, + EvDefringeThreshold=106, + NUMOFEVENTS=107 }; } #endif diff --git a/rtengine/procparams.cc b/rtengine/procparams.cc index 9f6d27e3e..d89bc48c8 100644 --- a/rtengine/procparams.cc +++ b/rtengine/procparams.cc @@ -103,6 +103,10 @@ void ProcParams::setDefaults () { impulseDenoise.enabled = false; impulseDenoise.thresh = 50; + + defringe.enabled = false; + defringe.radius = 2.0; + defringe.threshold = 25; dirpyrDenoise.enabled = false; dirpyrDenoise.luma = 10; @@ -286,6 +290,10 @@ int ProcParams::save (Glib::ustring fname) const { keyFile.set_boolean ("Impulse Denoising", "Enabled", impulseDenoise.enabled); keyFile.set_integer ("Impulse Denoising", "Threshold", impulseDenoise.thresh); + // save defringe + keyFile.set_boolean ("Defringing", "Enabled", defringe.enabled); + keyFile.set_double ("Defringing", "Radius", defringe.radius); + keyFile.set_integer ("Defringing", "Threshold", defringe.threshold); // save dirpyrDenoise keyFile.set_boolean ("Directional Pyramid Denoising", "Enabled", dirpyrDenoise.enabled); @@ -552,6 +560,13 @@ if (keyFile.has_group ("Color Shift")) { if (keyFile.has_key ("Color Shift", "ChannelB")) colorShift.b = keyFile.get_double ("Color Shift", "ChannelB"); } +// load defringe +if (keyFile.has_group ("Defringing")) { + if (keyFile.has_key ("Defringing", "Enabled")) defringe.enabled = keyFile.get_boolean ("Defringing", "Enabled"); + if (keyFile.has_key ("Defringing", "Radius")) defringe.radius = keyFile.get_double ("Defringing", "Radius"); + if (keyFile.has_key ("Defringing", "Threshold")) defringe.threshold = keyFile.get_integer ("Defringing", "Threshold"); +} + // load impulseDenoise if (keyFile.has_group ("Impulse Denoising")) { if (keyFile.has_key ("Impulse Denoising", "Enabled")) impulseDenoise.enabled = keyFile.get_boolean ("Impulse Denoising", "Enabled"); @@ -853,6 +868,9 @@ bool ProcParams::operator== (const ProcParams& other) { && dirpyrDenoise.luma == other.dirpyrDenoise.luma && dirpyrDenoise.chroma == other.dirpyrDenoise.chroma && dirpyrDenoise.gamma == other.dirpyrDenoise.gamma + && defringe.enabled == other.defringe.enabled + && defringe.radius == other.defringe.radius + && defringe.threshold == other.defringe.threshold && lumaDenoise.enabled == other.lumaDenoise.enabled && lumaDenoise.radius == other.lumaDenoise.radius && lumaDenoise.edgetolerance == other.lumaDenoise.edgetolerance diff --git a/rtengine/procparams.h b/rtengine/procparams.h index 70222141a..5cafcbb7c 100644 --- a/rtengine/procparams.h +++ b/rtengine/procparams.h @@ -137,6 +137,18 @@ class ColorDenoiseParams { int amount; }; + /** + * Parameters of defringing + */ + class DefringeParams { + + public: + bool enabled; + double radius; + int threshold; + }; + + /** * Parameters of impulse denoising */ @@ -403,6 +415,7 @@ class ProcParams { ColorShiftParams colorShift; ///< Color shift parameters LumaDenoiseParams lumaDenoise; ///< Luminance denoising parameters ColorDenoiseParams colorDenoise; ///< Color denoising parameters + DefringeParams defringe; ///< Impulse denoising parameters ImpulseDenoiseParams impulseDenoise; ///< Impulse denoising parameters DirPyrDenoiseParams dirpyrDenoise; ///< Directional Pyramid denoising parameters SHParams sh; ///< Shadow/highlight enhancement parameters diff --git a/rtengine/refreshmap.cc b/rtengine/refreshmap.cc index 0069836f6..c4c7cc862 100644 --- a/rtengine/refreshmap.cc +++ b/rtengine/refreshmap.cc @@ -124,5 +124,8 @@ RGBCURVE, // EvHSVEqualizerH, RGBCURVE, // EvHSVEqualizerS, RGBCURVE, // EvHSVEqualizerV, RGBCURVE, // EvHSVEqEnabled, +DEFRINGE, // EvDefringeEnabled, +DEFRINGE, // EvDefringeRadius, +DEFRINGE, // EvDefringeThreshold, }; diff --git a/rtengine/refreshmap.h b/rtengine/refreshmap.h index d4193f9ef..f8047a473 100644 --- a/rtengine/refreshmap.h +++ b/rtengine/refreshmap.h @@ -31,6 +31,7 @@ #define LUMINANCECURVE 6 #define SHARPENING 2 #define IMPULSEDENOISE 2 +#define DEFRINGE 2 #define LUMADENOISE 2 #define WHITEBALANCE 255 #define DEMOSAIC 511 diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index f17618b59..0227bda0d 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -159,6 +159,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p ipf.chrominanceCurve (labView, labView, 1, curve, 0, fh); ipf.impulsedenoise (labView); + ipf.defringe (labView); ipf.lumadenoise (labView, buffer); ipf.sharpening (labView, (unsigned short**)buffer); diff --git a/rtgui/CMakeLists.txt b/rtgui/CMakeLists.txt index c15cf79e0..719d3921f 100644 --- a/rtgui/CMakeLists.txt +++ b/rtgui/CMakeLists.txt @@ -26,7 +26,7 @@ set (BASESOURCEFILES batchqueue.cc lwbutton.cc lwbuttonset.cc batchqueuebuttonset.cc browserfilter.cc exiffiltersettings.cc profilestore.cc partialpastedlg.cc rawprocess.cc preprocess.cc - equalizer.cc dirpyrequalizer.cc hsvequalizer.cc + equalizer.cc dirpyrequalizer.cc hsvequalizer.cc defringe.cc popupcommon.cc popupbutton.cc popuptogglebutton.cc) if (WIN32) diff --git a/rtgui/paramsedited.cc b/rtgui/paramsedited.cc index 43f2aadae..b0afae6c2 100644 --- a/rtgui/paramsedited.cc +++ b/rtgui/paramsedited.cc @@ -72,6 +72,9 @@ void ParamsEdited::set (bool v) { lumaDenoise.edgetolerance = v; colorDenoise.enabled = v; colorDenoise.amount = v; + defringe.enabled = v; + defringe.radius = v; + defringe.threshold = v; impulseDenoise.enabled = v; impulseDenoise.thresh = v; dirpyrDenoise.enabled = v; @@ -210,6 +213,9 @@ void ParamsEdited::initFrom (const std::vector lumaDenoise.edgetolerance = lumaDenoise.edgetolerance && p.lumaDenoise.edgetolerance == other.lumaDenoise.edgetolerance; colorDenoise.enabled = colorDenoise.enabled && p.colorDenoise.enabled == other.colorDenoise.enabled; colorDenoise.amount = colorDenoise.amount && p.colorDenoise.amount == other.colorDenoise.amount; + defringe.enabled = defringe.enabled && p.defringe.enabled == other.defringe.enabled; + defringe.radius = defringe.radius && p.defringe.radius == other.defringe.radius; + defringe.threshold = defringe.threshold && p.defringe.threshold == other.defringe.threshold; impulseDenoise.enabled = impulseDenoise.enabled && p.impulseDenoise.enabled == other.impulseDenoise.enabled; impulseDenoise.thresh = impulseDenoise.thresh && p.impulseDenoise.thresh == other.impulseDenoise.thresh; @@ -350,6 +356,10 @@ void ParamsEdited::combine (rtengine::procparams::ProcParams& toEdit, const rten if (colorDenoise.enabled) toEdit.colorDenoise.enabled = mods.colorDenoise.enabled; if (colorDenoise.amount) toEdit.colorDenoise.amount = mods.colorDenoise.amount; + if (defringe.enabled) toEdit.defringe.enabled = mods.defringe.enabled; + if (defringe.radius) toEdit.defringe.radius = mods.defringe.radius; + if (defringe.threshold) toEdit.defringe.threshold = mods.defringe.threshold; + if (impulseDenoise.enabled) toEdit.impulseDenoise.enabled = mods.impulseDenoise.enabled; if (impulseDenoise.thresh) toEdit.impulseDenoise.thresh = mods.impulseDenoise.thresh; diff --git a/rtgui/paramsedited.h b/rtgui/paramsedited.h index 6fabc3e46..bad4f2281 100644 --- a/rtgui/paramsedited.h +++ b/rtgui/paramsedited.h @@ -109,6 +109,14 @@ class ColorDenoiseParamsEdited { bool amount; }; +class DefringeParamsEdited { + +public: + bool enabled; + bool radius; + bool threshold; +}; + class ImpulseDenoiseParamsEdited { public: @@ -304,8 +312,9 @@ class ParamsEdited { LumaDenoiseParamsEdited lumaDenoise; ColorDenoiseParamsEdited colorDenoise; + DefringeParamsEdited defringe; DirPyrDenoiseParamsEdited dirpyrDenoise; - ImpulseDenoiseParamsEdited impulseDenoise; + ImpulseDenoiseParamsEdited impulseDenoise; SHParamsEdited sh; CropParamsEdited crop; diff --git a/rtgui/toolpanelcoord.cc b/rtgui/toolpanelcoord.cc index 4b95b93ca..18d8d987b 100644 --- a/rtgui/toolpanelcoord.cc +++ b/rtgui/toolpanelcoord.cc @@ -37,6 +37,7 @@ ToolPanelCoordinator::ToolPanelCoordinator () : ipc(NULL) { lumadenoise = Gtk::manage (new LumaDenoise ()); colordenoise = Gtk::manage (new ColorDenoise ()); impulsedenoise = Gtk::manage (new ImpulseDenoise ()); + defringe = Gtk::manage (new Defringe ()); dirpyrdenoise = Gtk::manage (new DirPyrDenoise ()); sharpening = Gtk::manage (new Sharpening ()); lcurve = Gtk::manage (new LCurve ()); @@ -76,6 +77,7 @@ ToolPanelCoordinator::ToolPanelCoordinator () : ipc(NULL) { addPanel (detailsPanel, lumadenoise, M("TP_LUMADENOISE_LABEL")); toolPanels.push_back (lumadenoise); addPanel (detailsPanel, colordenoise, M("TP_COLORDENOISE_LABEL")); toolPanels.push_back (colordenoise); addPanel (detailsPanel, dirpyrdenoise, M("TP_DIRPYRDENOISE_LABEL")); toolPanels.push_back (dirpyrdenoise); + addPanel (detailsPanel, defringe, M("TP_DEFRINGE_LABEL")); toolPanels.push_back (defringe); addPanel (detailsPanel, dirpyrequalizer, M("TP_DIRPYREQUALIZER_LABEL")); toolPanels.push_back (dirpyrequalizer); addPanel (detailsPanel, equalizer, M("TP_EQUALIZER_LABEL")); toolPanels.push_back (equalizer); addPanel (transformPanel, crop, M("TP_CROP_LABEL")); toolPanels.push_back (crop); diff --git a/rtgui/toolpanelcoord.h b/rtgui/toolpanelcoord.h index 669066afb..5fd2d1b53 100644 --- a/rtgui/toolpanelcoord.h +++ b/rtgui/toolpanelcoord.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -90,6 +91,7 @@ class ToolPanelCoordinator : public ToolPanelListener, ShadowsHighlights* shadowshighlights; LumaDenoise* lumadenoise; ColorDenoise* colordenoise; + Defringe* defringe; ImpulseDenoise* impulsedenoise; DirPyrDenoise* dirpyrdenoise; Sharpening* sharpening;