/
qgshuesaturationfilter.h
94 lines (71 loc) · 3.58 KB
/
qgshuesaturationfilter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/***************************************************************************
qgshuesaturationfilter.h
-------------------
begin : February 2013
copyright : (C) 2013 by Alexander Bruy, Nyall Dawson
email : alexander dot bruy at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSHUESATURATIONFILTER_H
#define QGSHUESATURATIONFILTER_H
#include "qgis_core.h"
#include "qgis.h"
#include "qgsrasterinterface.h"
class QDomElement;
/** \ingroup core
* Color and saturation filter pipe for rasters.
*/
class CORE_EXPORT QgsHueSaturationFilter : public QgsRasterInterface
{
public:
// Available modes for converting a raster to grayscale
enum GrayscaleMode
{
GrayscaleOff,
GrayscaleLightness,
GrayscaleLuminosity,
GrayscaleAverage
};
QgsHueSaturationFilter( QgsRasterInterface *input = nullptr );
QgsHueSaturationFilter *clone() const override SIP_FACTORY;
int bandCount() const override;
Qgis::DataType dataType( int bandNo ) const override;
bool setInput( QgsRasterInterface *input ) override;
QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override SIP_FACTORY;
void setSaturation( int saturation );
int saturation() const { return mSaturation; }
void setGrayscaleMode( QgsHueSaturationFilter::GrayscaleMode grayscaleMode ) { mGrayscaleMode = grayscaleMode; }
QgsHueSaturationFilter::GrayscaleMode grayscaleMode() const { return mGrayscaleMode; }
void setColorizeOn( bool colorizeOn ) { mColorizeOn = colorizeOn; }
bool colorizeOn() const { return mColorizeOn; }
void setColorizeColor( const QColor &colorizeColor );
QColor colorizeColor() const { return mColorizeColor; }
void setColorizeStrength( int colorizeStrength ) { mColorizeStrength = colorizeStrength; }
int colorizeStrength() const { return mColorizeStrength; }
void writeXml( QDomDocument &doc, QDomElement &parentElem ) const override;
//! Sets base class members from xml. Usually called from create() methods of subclasses
void readXml( const QDomElement &filterElem ) override;
private:
//! Process a change in saturation and update resultant HSL & RGB values
void processSaturation( int &r, int &g, int &b, int &h, int &s, int &l );
//! Process a colorization and update resultant HSL & RGB values
void processColorization( int &r, int &g, int &b, int &h, int &s, int &l );
//! Current saturation value. Range: -100 (desaturated) ... 0 (no change) ... 100 (increased)
int mSaturation;
double mSaturationScale;
//! Current grayscale mode
QgsHueSaturationFilter::GrayscaleMode mGrayscaleMode;
//! Colorize settings
bool mColorizeOn;
QColor mColorizeColor;
int mColorizeH, mColorizeS;
int mColorizeStrength;
};
#endif // QGSHUESATURATIONFILTER_H