digiKam
Loading...
Searching...
No Matches
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 * SPDX-FileCopyrightText: 2005-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
13 * ============================================================ */
14
15#pragma once
16
17// C++ includes
18
19#include <cmath>
20
21// Qt includes
22
23#include <QColor>
24
25// Local includes
26
27#include "digikam_export.h"
28
29namespace Digikam
30{
31
32class DIGIKAM_EXPORT DColor
33{
34public:
35
39 DColor() = default;
40
44 explicit DColor(uchar* data, bool sixteenBit = false)
45 {
46 setColor(data, sixteenBit);
47 }
48
52 DColor(int red, int green, int blue, int alpha, bool sixteenBit)
53 : m_red (red),
54 m_green (green),
55 m_blue (blue),
56 m_alpha (alpha),
57 m_sixteenBit (sixteenBit)
58 {
59 }
60
64 explicit DColor(const QColor& color, bool sixteenBit=false);
65
66 // Use default copy constructor, assignment operator and destructor
67
74 inline void setColor(uchar* const data, bool sixteenBit = false);
75
82 inline void setPixel(uchar* const data) const;
83
84 int red() const
85 {
86 return m_red;
87 }
88
89 int green() const
90 {
91 return m_green;
92 }
93
94 int blue() const
95 {
96 return m_blue;
97 }
98
99 int alpha() const
100 {
101 return m_alpha;
102 }
103
104 bool sixteenBit() const
105 {
106 return m_sixteenBit;
107 }
108
109 void setRed(int red)
110 {
111 m_red = red;
112 }
113
114 void setGreen(int green)
115 {
116 m_green = green;
117 }
118
119 void setBlue (int blue)
120 {
121 m_blue = blue;
122 }
123
124 void setAlpha(int alpha)
125 {
126 m_alpha = alpha;
127 }
128
129 void setSixteenBit(bool sixteenBit)
130 {
131 m_sixteenBit = sixteenBit;
132 }
133
134 QColor getQColor() const;
135
136 inline bool isPureGrayValue(int v)
137 {
138 return ((m_red == v) && (m_green == v) && (m_blue == v));
139 }
140
141 inline bool isPureGray()
142 {
143 return ((m_red == m_green) && (m_red == m_blue));
144 }
145
150 void convertToSixteenBit();
151 void convertToEightBit();
152
158 void premultiply();
159 void demultiply();
160
166 void getHSL(int* const h, int* const s, int* const l) const;
167
175 void setHSL(int h, int s, int l, bool sixteenBit);
176
182 void getYCbCr(double* const y, double* const cb, double* const cr) const;
183
191 void setYCbCr(double y, double cb, double cr, bool sixteenBit);
192
193private:
194
195 int m_red = 0;
196 int m_green = 0;
197 int m_blue = 0;
198 int m_alpha = 0;
199
200 bool m_sixteenBit = false;
201
202public:
203
210 inline void blendZero();
211 inline void blendAlpha8(int alpha);
212 inline void blendInvAlpha8(int alpha);
213 inline void blendAlpha16(int alpha);
214 inline void blendInvAlpha16(int alpha);
215 inline void premultiply16(int alpha);
216 inline void premultiply8(int alpha);
217 inline void demultiply16(int alpha);
218 inline void demultiply8(int alpha);
219 inline void blendAdd(const DColor& src);
220 inline void blendClamp8();
221 inline void blendClamp16();
222 inline void multiply(float factor);
223};
224
225} // namespace Digikam
226
227// Inline methods
228
229#include "dcolorpixelaccess.h"
230#include "dcolorblend.h"
Definition dcolor.h:33
bool isPureGray()
Definition dcolor.h:141
DColor()=default
int green() const
Definition dcolor.h:89
void setGreen(int green)
Definition dcolor.h:114
void setAlpha(int alpha)
Definition dcolor.h:124
void setRed(int red)
Definition dcolor.h:109
DColor(int red, int green, int blue, int alpha, bool sixteenBit)
Definition dcolor.h:52
void setSixteenBit(bool sixteenBit)
Definition dcolor.h:129
bool sixteenBit() const
Definition dcolor.h:104
DColor(uchar *data, bool sixteenBit=false)
Definition dcolor.h:44
void setBlue(int blue)
Definition dcolor.h:119
int alpha() const
Definition dcolor.h:99
int blue() const
Definition dcolor.h:94
bool isPureGrayValue(int v)
Definition dcolor.h:136
int red() const
Definition dcolor.h:84
Definition datefolderview.cpp:34