1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2004-07-29
7  * Description : image levels manipulation methods.
8  *
9  * Copyright (C) 2004-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_IMAGE_LEVELS_H
25 #define DIGIKAM_IMAGE_LEVELS_H
26 
27 // Qt includes
28 
29 #include <QUrl>
30 
31 // Local includes
32 
33 #include "dcolor.h"
34 #include "digikam_export.h"
35 
36 namespace Digikam
37 {
38 
39 class ImageHistogram;
40 
41 class DIGIKAM_EXPORT ImageLevels
42 {
43 
44 public:
45 
46     explicit ImageLevels(bool sixteenBit);
47     ~ImageLevels();
48 
49     bool   isDirty();
50     bool   isSixteenBits();
51     void   reset();
52 
53     /**
54      * Methods to manipulate the levels data.
55      */
56     void   levelsChannelReset(int channel);
57     void   levelsAuto(ImageHistogram* const hist);
58     void   levelsChannelAuto(ImageHistogram* const hist, int channel);
59     int    levelsInputFromColor(int channel, const DColor& color);
60     void   levelsBlackToneAdjustByColors(int channel, const DColor& color);
61     void   levelsGrayToneAdjustByColors(int channel, const DColor& color);
62     void   levelsWhiteToneAdjustByColors(int channel, const DColor& color);
63     void   levelsCalculateTransfers();
64     float  levelsLutFunc(int nchannels, int channel, float value);
65     void   levelsLutSetup(int nchannels);
66     void   levelsLutProcess(uchar* const srcPR, uchar* const destPR, int w, int h);
67 
68     /**
69      * Methods to set manually the levels values.
70      */
71     void   setLevelGammaValue(int channel, double val);
72     void   setLevelLowInputValue(int channel, int val);
73     void   setLevelHighInputValue(int channel, int val);
74     void   setLevelLowOutputValue(int channel, int val);
75     void   setLevelHighOutputValue(int channel, int val);
76 
77     double getLevelGammaValue(int channel);
78     int    getLevelLowInputValue(int channel);
79     int    getLevelHighInputValue(int channel);
80     int    getLevelLowOutputValue(int channel);
81     int    getLevelHighOutputValue(int channel);
82 
83     /**
84      * Methods to save/load the levels values to/from a Gimp levels text file.
85      */
86     bool   saveLevelsToGimpLevelsFile(const QUrl& fileUrl);
87     bool   loadLevelsFromGimpLevelsFile(const QUrl& fileUrl);
88 
89 private:
90 
91     // Disable
92     ImageLevels(const ImageLevels&)            = delete;
93     ImageLevels& operator=(const ImageLevels&) = delete;
94 
95 private:
96 
97     class Private;
98     Private* const d;
99 };
100 
101 } // namespace Digikam
102 
103 #endif // DIGIKAM_IMAGE_LEVELS_H
104