digiKam
contentawarefilter.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-02-01
7  * Description : Content aware resizer class.
8  *
9  * Copyright (C) 2009 by Julien Pontabry <julien dot pontabry at ulp dot u-strasbg dot fr>
10  * Copyright (C) 2009-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  * Copyright (C) 2010 by Martin Klapetek <martin dot klapetek at gmail dot com>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_CONTENT_AWARE_FILTER_H
27 #define DIGIKAM_CONTENT_AWARE_FILTER_H
28 
29 // Qt includes
30 
31 #include <QImage>
32 
33 // Local includes
34 
35 #include "digikam_config.h"
36 #include "dcolor.h"
37 #include "digikam_export.h"
38 #include "dimgthreadedfilter.h"
39 
40 namespace Digikam
41 {
42 
43 class DIGIKAM_EXPORT ContentAwareContainer
44 {
45 
46 public:
47 
49  {
50  GradientNorm = 0,
55  LumaXAbsoluteValue
56  };
57 
58 public:
59 
61  : preserve_skin_tones(false),
62  width(0),
63  height(0),
64  step(1),
65  side_switch_freq(4),
66  rigidity(0.0),
67  func(GradientNorm),
68  resize_order(Qt::Horizontal)
69  {
70  };
71 
73  {
74  };
75 
76 public:
77 
79 
80  uint width;
81  uint height;
82 
83  int step;
85 
86  double rigidity;
87 
88  QImage mask;
89 
92 };
93 
94 // -----------------------------------------------------------------------------------------
95 
96 class DIGIKAM_EXPORT ContentAwareFilter : public DImgThreadedFilter
97 {
98  Q_OBJECT
99 
100 public:
101 
102  explicit ContentAwareFilter(QObject* const parent = nullptr);
103  explicit ContentAwareFilter(DImg* const orgImage,
104  QObject* const parent = nullptr,
105  const ContentAwareContainer& settings = ContentAwareContainer());
106  ~ContentAwareFilter() override;
107 
108  void progressCallback(int progress);
109 
110  static QString FilterIdentifier()
111  {
112  return QLatin1String("digikam:ContentAwareFilter");
113  }
114 
115  static QString DisplayableName();
116 
118  {
119  return QList<int>() << 1;
120  }
121 
122  static int CurrentVersion()
123  {
124  return 1;
125  }
126 
127  QString filterIdentifier() const override
128  {
129  return FilterIdentifier();
130  }
131 
132  FilterAction filterAction() override;
133  void readParameters(const FilterAction& action) override;
134 
135 private:
136 
137  void cancelFilter() override;
138  void filterImage() override;
139 
140  void buildBias(const QImage& mask);
141  void buildSkinToneBias();
142  inline bool isSkinTone(const DColor& c);
143  void getEnergyImage();
144 
145 private:
146 
147  class Private;
148  Private* const d;
149 };
150 
151 } // namespace Digikam
152 
153 #endif // DIGIKAM_CONTENT_AWARE_FILTER_H
Definition: contentawarefilter.h:44
EnergyFunction
Definition: contentawarefilter.h:49
@ SumOfAbsoluteValues
Definition: contentawarefilter.h:51
@ LumaGradientNorm
Definition: contentawarefilter.h:53
@ LumaSumOfAbsoluteValues
Definition: contentawarefilter.h:54
@ XAbsoluteValue
Definition: contentawarefilter.h:52
Qt::Orientation resize_order
Definition: contentawarefilter.h:91
double rigidity
Definition: contentawarefilter.h:86
QImage mask
Definition: contentawarefilter.h:88
int step
Definition: contentawarefilter.h:83
EnergyFunction func
Definition: contentawarefilter.h:90
uint height
Definition: contentawarefilter.h:81
bool preserve_skin_tones
Definition: contentawarefilter.h:74
int side_switch_freq
Definition: contentawarefilter.h:84
uint width
Definition: contentawarefilter.h:80
~ContentAwareContainer()
Definition: contentawarefilter.h:72
ContentAwareContainer()
Definition: contentawarefilter.h:60
Definition: contentawarefilter.h:97
QString filterIdentifier() const override
Definition: contentawarefilter.h:127
static QString FilterIdentifier()
Definition: contentawarefilter.h:110
static int CurrentVersion()
Definition: contentawarefilter.h:122
static QList< int > SupportedVersions()
Definition: contentawarefilter.h:117
Definition: dcolor.h:43
Definition: dimgthreadedfilter.h:41
Definition: dimg.h:62
Definition: filteraction.h:43
@ Orientation
Definition: coredbfields.h:86
Definition: datefolderview.cpp:43