digiKam
localcontrastfilter.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2009-08-09
7  * Description : Enhance image with local contrasts (as human eye does).
8  * LDR ToneMapper zynaddsubfx.sourceforge.net/other/tonemapping
9  *
10  * Copyright (C) 2009 by Julien Pontabry <julien dot pontabry at gmail dot com>
11  * Copyright (C) 2009-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
12  * Copyright (C) 2010 by Martin Klapetek <martin dot klapetek at gmail dot com>
13  *
14  * This program is free software; you can redistribute it
15  * and/or modify it under the terms of the GNU General
16  * Public License as published by the Free Software Foundation;
17  * either version 2, or (at your option)
18  * any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * ============================================================ */
26 
27 #ifndef DIGIKAM_LOCAL_CONTRAST_FILTER_H
28 #define DIGIKAM_LOCAL_CONTRAST_FILTER_H
29 
30 // Qt includes
31 
32 #include <QImage>
33 
34 // Local includes
35 
36 #include "digikam_export.h"
37 #include "dimgthreadedfilter.h"
38 #include "digikam_globals.h"
39 #include "localcontrastcontainer.h"
40 
41 namespace Digikam
42 {
43 
44 class DIGIKAM_EXPORT LocalContrastFilter : public DImgThreadedFilter
45 {
46  Q_OBJECT
47 
48 private:
49 
50  struct Q_DECL_HIDDEN Args
51  {
52  explicit Args()
53  : start (0),
54  stop (0),
55  a (0.0),
56  data (nullptr),
57  sizex (0),
58  sizey (0),
59  blur (0.0),
60  denormal_remove(0.0)
61  {
62  }
63 
64  uint start;
65  uint stop;
66  float a;
67  float* data;
68  int sizex;
69  int sizey;
70  float blur;
71  float denormal_remove;
72  };
73 
74 public:
75 
76  explicit LocalContrastFilter(QObject* const parent = nullptr);
77  explicit LocalContrastFilter(DImg* const image, QObject* const parent = nullptr,
79  ~LocalContrastFilter() override;
80 
81  static QString FilterIdentifier()
82  {
83  return QLatin1String("digikam:LocalContrastFilter");
84  }
85 
86  static QString DisplayableName();
87 
89  {
90  return QList<int>() << 2;
91  }
92 
93  static int CurrentVersion()
94  {
95  return 2;
96  }
97 
98  QString filterIdentifier() const override
99  {
100  return FilterIdentifier();
101  }
102 
103  FilterAction filterAction() override;
104 
105  void readParameters(const FilterAction& action) override;
106 
107 private:
108 
109  void filterImage() override;
110 
111  void processRgbImage(float* const img, int sizex, int sizey);
112  void process8bitRgbImage(unsigned char* const img, int sizex, int sizey);
113  void process16bitRgbImage(unsigned short* const img, int sizex, int sizey);
114 
115  float func(float x1, float x2);
116 
117  void inplaceBlur(float* const data, int sizex, int sizey, float blur);
118  void stretchContrast(float* const data, int datasize);
119 
120  inline void rgb2hsv(const float& r, const float& g, const float& b, float& h, float& s, float& v);
121  inline void hsv2rgb(const float& h, const float& s, const float& v, float& r, float& g, float& b);
122 
123  void blurMultithreaded(uint start, uint stop, float* const img, float* const blurimage);
124  void saturationMultithreaded(uint start, uint stop, float* const img, float* const srcimg);
125 
126  void inplaceBlurYMultithreaded(const Args& prm);
127  void inplaceBlurXMultithreaded(const Args& prm);
128 
129 private:
130 
131  class Private;
132  Private* const d;
133 };
134 
135 } // namespace Digikam
136 
137 #endif // DIGIKAM_LOCAL_CONTRAST_FILTER_H
Definition: dimgthreadedfilter.h:41
Definition: dimg.h:62
Definition: filteraction.h:43
Definition: localcontrastcontainer.h:39
Definition: localcontrastfilter.h:45
QString filterIdentifier() const override
Definition: localcontrastfilter.h:98
static QString FilterIdentifier()
Definition: localcontrastfilter.h:81
static int CurrentVersion()
Definition: localcontrastfilter.h:93
static QList< int > SupportedVersions()
Definition: localcontrastfilter.h:88
Definition: datefolderview.cpp:43