1 /*******************************************************************************
2 **
3 ** Photivo
4 **
5 ** Copyright (C) 2015 Bernd Schoeler <brjohn@brother-john.net>
6 **
7 ** This file is part of Photivo.
8 **
9 ** Photivo is free software: you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License version 3
11 ** as published by the Free Software Foundation.
12 **
13 ** Photivo is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with Photivo. If not, see <http://www.gnu.org/licenses/>.
20 **
21 *******************************************************************************/
22
23 #include "ptFilter_LumaDenoise.h"
24 #include "ptCfgItem.h"
25 #include "../ptImage.h"
26
27 // TODO: Needed for access to m_ScaleFactor. Find a way to avoid when modernising the processor.
28 #include "../ptProcessor.h"
29 extern ptProcessor* TheProcessor;
30
31 //------------------------------------------------------------------------------
32
33 const QString CLumaDenoiseId = "LumaDenoise";
34
35 const QString COpacity = "Opacity";
36 const QString CEdgeThreshold = "EdgeThreshold";
37 const QString CLScale = "LScale";
38 const QString CLStrength = "LStrength";
39
40 //------------------------------------------------------------------------------
41
ptFilter_LumaDenoise()42 ptFilter_LumaDenoise::ptFilter_LumaDenoise():
43 ptFilterBase()
44 {
45 FIsSlow = true;
46 this->internalInit();
47 }
48
49 //------------------------------------------------------------------------------
50
createLumaDenoise()51 ptFilterBase *ptFilter_LumaDenoise::createLumaDenoise() {
52 auto hInstance = new ptFilter_LumaDenoise;
53 hInstance->FFilterName = CLumaDenoiseId;
54 hInstance->FCaption = tr("Luminance denoising");
55 return hInstance;
56 }
57
58 //------------------------------------------------------------------------------
59
doDefineControls()60 void ptFilter_LumaDenoise::doDefineControls() {
61 FConfig.initStores(TCfgItemList()
62 // Id Type Default Min Max Step Decimals, commonConnect, storeable, caption, tooltip
63 << ptCfgItem({COpacity, ptCfgItem::Slider, 0.0, 0.0, 1.0, 0.1, 2, true, true, tr("Opacity"), tr("")})
64 << ptCfgItem({CEdgeThreshold, ptCfgItem::Slider, 50, 0, 50, 10, 0, true, true, tr("Edge Threshold"), tr("")})
65 << ptCfgItem({CLScale, ptCfgItem::Slider, 8.0, 4.0, 50.0, 4.0, 1, true, true, tr("L scale"), tr("")})
66 << ptCfgItem({CLStrength, ptCfgItem::Slider, 0.3, 0.0, 3.0, 0.02, 2, true, true, tr("L strength"), tr("")})
67 );
68 }
69
70 //------------------------------------------------------------------------------
71
doCheckHasActiveCfg()72 bool ptFilter_LumaDenoise::doCheckHasActiveCfg() {
73 return !qFuzzyIsNull(FConfig.value(COpacity).toDouble());
74 }
75
76 //------------------------------------------------------------------------------
77
doRunFilter(ptImage * AImage)78 void ptFilter_LumaDenoise::doRunFilter(ptImage *AImage) {
79 AImage->toLab();
80 AImage->BilateralDenoise(
81 FConfig.value(CLScale).toDouble() * TheProcessor->m_ScaleFactor,
82 FConfig.value(CLStrength).toDouble() / 10.0,
83 FConfig.value(COpacity).toDouble(),
84 FConfig.value(CEdgeThreshold).toDouble() * TheProcessor->m_ScaleFactor);
85 }
86
87 //------------------------------------------------------------------------------
88
89 RegisterHelper LumaDenoiseRegister(&ptFilter_LumaDenoise::createLumaDenoise, CLumaDenoiseId);
90
91 //------------------------------------------------------------------------------
92