1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 
8 #ifndef CXFCOLOR_H
9 #define CXFCOLOR_H
10 
11 #include <QDomDocument>
12 #include <QSharedPointer>
13 #include <QVector>
14 
15 #include "cxftypes.h"
16 
17 class  CxfColorSpecification;
18 class  CxfDocument;
19 struct ScLab;
20 
21 class CxfColor
22 {
23 public:
24 	CxfColor(CxfDocument* cxfDoc);
~CxfColor()25 	virtual ~CxfColor() {}
26 
27 	virtual bool isValid() const;
type()28 	virtual CxfColorType type() const { return cxfColorUnknown; }
29 
colorSpecification()30 	const CxfColorSpecification* colorSpecification() const { return m_colorSpec; }
document()31 	const CxfDocument* document() const { return m_cxfDoc; }
32 
33 	virtual bool parse(QDomElement& colorElem) = 0;
34 	virtual void reset();
35 
36 protected:
37 	CxfDocument* m_cxfDoc;
38 	const CxfColorSpecification* m_colorSpec;
39 };
40 
41 typedef QSharedPointer<CxfColor> CxfColorShPtr;
42 
43 class CxfColorRGB : public CxfColor
44 {
45 public:
46 	CxfColorRGB(CxfDocument* cxfDoc);
47 
maxRange()48 	double  maxRange() const { return m_maxRange; }
49 
red()50 	double  red() const   { return m_values[0]; }
green()51 	double  green() const { return m_values[1]; }
blue()52 	double  blue() const  { return m_values[2]; }
53 
type()54 	virtual CxfColorType type() const { return cxfColorRGB; }
55 
56 	virtual bool parse(QDomElement& colorElem);
57 	virtual void reset();
58 
59 protected:
60 	double m_maxRange;
61 	double m_values[3];
62 };
63 
64 class CxfColorSRGB : public CxfColorRGB
65 {
66 public:
67 	CxfColorSRGB(CxfDocument* cxfDoc);
68 
type()69 	virtual CxfColorType type() const { return cxfColorSRGB; }
70 };
71 
72 class CxfColorAdobeRGB : public CxfColorRGB
73 {
74 public:
75 	CxfColorAdobeRGB(CxfDocument* cxfDoc);
76 
type()77 	virtual CxfColorType type() const { return cxfColorAdobeRGB; }
78 };
79 
80 class CxfColorHTML : public CxfColorRGB
81 {
82 public:
83 	CxfColorHTML(CxfDocument* cxfDoc);
84 
type()85 	virtual CxfColorType type() const { return cxfColorHTML; }
86 	virtual bool parse(QDomElement& colorElem);
87 };
88 
89 class CxfColorCMYK : public CxfColor
90 {
91 public:
92 	CxfColorCMYK(CxfDocument* cxfDoc);
93 
cyan()94 	double  cyan() const    { return m_values[0]; }
magenta()95 	double  magenta() const { return m_values[1]; }
yellow()96 	double  yellow() const  { return m_values[2]; }
black()97 	double  black() const   { return m_values[3]; }
98 
type()99 	virtual CxfColorType type() const { return cxfColorCMYK; }
100 
101 	virtual bool parse(QDomElement& colorElem);
102 	virtual void reset();
103 
104 protected:
105 	double m_values[4];
106 };
107 
108 class CxfColorCIELab : public CxfColor
109 {
110 public:
111 	CxfColorCIELab(CxfDocument* cxfDoc);
112 
L()113 	double  L() const { return m_values[0]; }
a()114 	double  a() const { return m_values[1]; }
b()115 	double  b() const { return m_values[2]; }
116 
type()117 	virtual CxfColorType type() const { return cxfColorCIELab; }
118 
119 	virtual bool parse(QDomElement& colorElem);
120 	virtual void reset();
121 
122 protected:
123 	double m_values[3];
124 };
125 
126 class CxfColorCIELCh : public CxfColor
127 {
128 public:
129 	CxfColorCIELCh(CxfDocument* cxfDoc);
130 
L()131 	double  L() const { return m_values[0]; }
C()132 	double  C() const { return m_values[1]; }
h()133 	double  h() const { return m_values[2]; }
134 
135 	ScLab lab() const;
136 
type()137 	virtual CxfColorType type() const { return cxfColorCIELCh; }
138 
139 	virtual bool parse(QDomElement& colorElem);
140 	virtual void reset();
141 
142 protected:
143 	double m_values[3];
144 };
145 
146 class CxfColorCIEXYZ : public CxfColor
147 {
148 public:
149 	CxfColorCIEXYZ(CxfDocument* cxfDoc);
150 
X()151 	double  X() const { return m_values[0]; }
Y()152 	double  Y() const { return m_values[1]; }
Z()153 	double  Z() const { return m_values[2]; }
154 
155 	ScLab lab() const;
156 
type()157 	virtual CxfColorType type() const { return cxfColorCIELCh; }
158 
159 	virtual bool parse(QDomElement& colorElem);
160 	virtual void reset();
161 
162 protected:
163 	double m_values[3];
164 };
165 
166 class CxfReflectanceSpectrum : public CxfColor
167 {
168 public:
169 	CxfReflectanceSpectrum(CxfDocument* cxfDoc);
170 
values()171 	const QVector<double>& values() const { return m_values; }
type()172 	virtual CxfColorType type() const { return cxfReflectanceSpectrum; }
173 
174 	virtual bool parse(QDomElement& colorElem);
175 	virtual void reset();
176 
177 	int wavelengthStart() const;
178 	int wavelengthIncrement() const;
179 	QVector<int> wavelengths() const;
180 
181 protected:
182 	QVector<double> m_values;
183 	int m_wavelengthStart;
184 };
185 
186 #endif
187