digiKam
dcolor.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 : 2005-12-02
7  * Description : 8-16 bits color container.
8  *
9  * Copyright (C) 2005-2022 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_DCOLOR_H
25 #define DIGIKAM_DCOLOR_H
26 
27 // C++ includes
28 
29 #include <cmath>
30 
31 // Qt includes
32 
33 #include <QColor>
34 
35 // Local includes
36 
37 #include "digikam_export.h"
38 
39 namespace Digikam
40 {
41 
42 class DIGIKAM_EXPORT DColor
43 {
44 public:
45 
50  : m_red (0),
51  m_green (0),
52  m_blue (0),
53  m_alpha (0),
54  m_sixteenBit(false)
55  {
56  }
57 
61  explicit DColor(uchar* data, bool sixteenBit = false)
62  {
63  setColor(data, sixteenBit);
64  }
65 
69  DColor(int red, int green, int blue, int alpha, bool sixteenBit)
70  : m_red (red),
71  m_green (green),
72  m_blue (blue),
73  m_alpha (alpha),
74  m_sixteenBit (sixteenBit)
75  {
76  }
77 
81  explicit DColor(const QColor& color, bool sixteenBit=false);
82 
83  // Use default copy constructor, assignment operator and destructor
84 
91  inline void setColor(uchar* const data, bool sixteenBit = false);
92 
99  inline void setPixel(uchar* const data) const;
100 
101  int red() const
102  {
103  return m_red;
104  }
105 
106  int green() const
107  {
108  return m_green;
109  }
110 
111  int blue() const
112  {
113  return m_blue;
114  }
115 
116  int alpha() const
117  {
118  return m_alpha;
119  }
120 
121  bool sixteenBit() const
122  {
123  return m_sixteenBit;
124  }
125 
126  void setRed(int red)
127  {
128  m_red = red;
129  }
130 
131  void setGreen(int green)
132  {
133  m_green = green;
134  }
135 
136  void setBlue (int blue)
137  {
138  m_blue = blue;
139  }
140 
141  void setAlpha(int alpha)
142  {
143  m_alpha = alpha;
144  }
145 
146  void setSixteenBit(bool sixteenBit)
147  {
148  m_sixteenBit = sixteenBit;
149  }
150 
151  QColor getQColor() const;
152 
153  inline bool isPureGrayValue(int v)
154  {
155  return ((m_red == v) && (m_green == v) && (m_blue == v));
156  }
157 
158  inline bool isPureGray()
159  {
160  return ((m_red == m_green) && (m_red == m_blue));
161  }
162 
167  void convertToSixteenBit();
168  void convertToEightBit();
169 
175  void premultiply();
176  void demultiply();
177 
183  void getHSL(int* const h, int* const s, int* const l) const;
184 
192  void setHSL(int h, int s, int l, bool sixteenBit);
193 
199  void getYCbCr(double* const y, double* const cb, double* const cr) const;
200 
208  void setYCbCr(double y, double cb, double cr, bool sixteenBit);
209 
210 private:
211 
212  int m_red;
213  int m_green;
214  int m_blue;
215  int m_alpha;
216 
217  bool m_sixteenBit;
218 
219 public:
220 
227  inline void blendZero();
228  inline void blendAlpha8(int alpha);
229  inline void blendInvAlpha8(int alpha);
230  inline void blendAlpha16(int alpha);
231  inline void blendInvAlpha16(int alpha);
232  inline void premultiply16(int alpha);
233  inline void premultiply8(int alpha);
234  inline void demultiply16(int alpha);
235  inline void demultiply8(int alpha);
236  inline void blendAdd(const DColor& src);
237  inline void blendClamp8();
238  inline void blendClamp16();
239  inline void multiply(float factor);
240 };
241 
242 } // namespace Digikam
243 
244 // Inline methods
245 
246 #include "dcolorpixelaccess.h"
247 #include "dcolorblend.h"
248 
249 #endif // DIGIKAM_DCOLOR_H
Definition: dcolor.h:43
bool isPureGray()
Definition: dcolor.h:158
int green() const
Definition: dcolor.h:106
void setGreen(int green)
Definition: dcolor.h:131
void setAlpha(int alpha)
Definition: dcolor.h:141
void setRed(int red)
Definition: dcolor.h:126
DColor(int red, int green, int blue, int alpha, bool sixteenBit)
Definition: dcolor.h:69
void setSixteenBit(bool sixteenBit)
Definition: dcolor.h:146
bool sixteenBit() const
Definition: dcolor.h:121
DColor(uchar *data, bool sixteenBit=false)
Definition: dcolor.h:61
void setBlue(int blue)
Definition: dcolor.h:136
DColor()
Definition: dcolor.h:49
int alpha() const
Definition: dcolor.h:116
int blue() const
Definition: dcolor.h:111
bool isPureGrayValue(int v)
Definition: dcolor.h:153
int red() const
Definition: dcolor.h:101
Definition: datefolderview.cpp:43