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_PyramidDenoise.h"
24 #include "ptCfgItem.h"
25 #include "../ptImage.h"
26 #include <cmath>
27 
28 // TODO: Needed for access to m_ScaleFactor. Find a way to avoid when modernising the processor.
29 #include "../ptProcessor.h"
30 extern ptProcessor* TheProcessor;
31 
32 //------------------------------------------------------------------------------
33 
34 const QString CPyramidDenoiseId = "PyramidDenoise";
35 
36 const QString CLumaStrength   = "LumaStrength";
37 const QString CChromaStrength = "ChromaStrength";
38 const QString CGamma          = "Gamma";
39 const QString CLevels         = "Levels";
40 
41 //------------------------------------------------------------------------------
42 
ptFilter_PyramidDenoise()43 ptFilter_PyramidDenoise::ptFilter_PyramidDenoise():
44   ptFilterBase()
45 {
46   this->internalInit();
47 }
48 
49 //------------------------------------------------------------------------------
50 
createPyramidDenoise()51 ptFilterBase *ptFilter_PyramidDenoise::createPyramidDenoise() {
52   auto hInstance         = new ptFilter_PyramidDenoise;
53   hInstance->FFilterName = CPyramidDenoiseId;
54   hInstance->FCaption    = tr("Pyramid denoising");
55   return hInstance;
56 }
57 
58 //------------------------------------------------------------------------------
59 
doDefineControls()60 void ptFilter_PyramidDenoise::doDefineControls() {
61   FConfig.initStores(TCfgItemList()
62     //            Id                       Type                      Default     Min           Max           Step        Decimals, commonConnect, storeable, caption, tooltip
63     << ptCfgItem({CLumaStrength,           ptCfgItem::Slider,        0,          0,            150,          5,          0,        true, true, tr("Lightness strength"), tr("affects L channel")})
64     << ptCfgItem({CChromaStrength,         ptCfgItem::Slider,        0,          0,            150,          5,          0,        true, true, tr("Color strength"), tr("affects a and b channels")})
65     << ptCfgItem({CGamma,                  ptCfgItem::Slider,        2.0,        1.0,          4.0,          0.1,        1,        true, true, tr("Gamma"), tr("")})
66     << ptCfgItem({CLevels,                 ptCfgItem::SpinEdit,      0,          3,            7,            1,          0,        true, true, tr("Levels"), tr("")})
67   );
68 }
69 
70 //------------------------------------------------------------------------------
71 
doCheckHasActiveCfg()72 bool ptFilter_PyramidDenoise::doCheckHasActiveCfg() {
73   return
74       (FConfig.value(CLumaStrength).toInt() != 0) ||
75       (FConfig.value(CChromaStrength).toInt() != 0);
76 }
77 
78 //------------------------------------------------------------------------------
79 
doRunFilter(ptImage * AImage)80 void ptFilter_PyramidDenoise::doRunFilter(ptImage *AImage) {
81   AImage->toLab();
82   AImage->dirpyrLab_denoise(
83       static_cast<int>(FConfig.value(
84           CLumaStrength).toDouble() /
85           pow(3.0, (log(TheProcessor->m_ScaleFactor) / log(0.5)))),
86       FConfig.value(CChromaStrength).toInt(),
87       FConfig.value(CGamma).toDouble() / 3.0,
88       FConfig.value(CLevels).toInt());
89 }
90 
91 //------------------------------------------------------------------------------
92 
93 RegisterHelper PyramidDenoiseRegister(&ptFilter_PyramidDenoise::createPyramidDenoise, CPyramidDenoiseId);
94 
95 //------------------------------------------------------------------------------
96