ACF $AcfVersion:0$
TColorGradient.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// ACF includes
8
9
10namespace icmm
11{
12
13
15{
16public:
17 static double GetValue(double x)
18 {
19 return x;
20 }
21};
22
23
201template <class GradientFunction>
203{
204public:
206
207 TColorGradient(const GradientColor& startColor, const GradientColor& endColor);
208
209 // reimplemented (icmm::IColorTransformation)
210 virtual bool GetValueAt(const ArgumentType& argument, ResultType& result) const override;
211 virtual ResultType GetValueAt(const ArgumentType& argument) const override;
212
213private:
214 GradientColor m_startColor;
215 GradientColor m_endColor;
216};
217
218
219template <class GradientFunction>
221 :m_startColor(startColor),
222 m_endColor(endColor)
223{
224}
225
226
227// reimplemented (icmm::IColorTransformation)
228
229template <class GradientFunction>
230bool TColorGradient<GradientFunction>::GetValueAt(const ArgumentType& argument, ResultType& result) const
231{
232 Q_ASSERT(argument.GetElementsCount() == 1);
233
234 static istd::CRange normRange(0.0, 1.0);
235
236 double argumentValue = normRange.GetClipped(argument[0]);
237
238 for (int componentIndex = 0; componentIndex < result.GetElementsCount(); componentIndex++){
239 double startValue = m_startColor[componentIndex];
240 double endValue = m_endColor[componentIndex];
241
242 double gradientValue = 0.0;
243 if (startValue < endValue){
244 gradientValue = (endValue - startValue) * argumentValue + startValue;
245 }
246 else{
247 gradientValue = (startValue - endValue) * (1.0 - argumentValue) + endValue;
248 }
249
250 result[componentIndex] = GradientFunction::GetValue(gradientValue);
251 }
252
253 return true;
254}
255
256
257template <class GradientFunction>
259{
260 ResultType result(m_startColor.GetElementsCount());
261
262 GetValueAt(argument, result);
263
264 return result;
265}
266
267
269
270
271} // namespace icmm
272
273
Generic color implementation with variable number of color components.
Definition CVarColor.h:176
Basic interface for color transformations between color models.
static double GetValue(double x)
Simple implementation of color gradient based on interpolation between start and end colors.
virtual bool GetValueAt(const ArgumentType &argument, ResultType &result) const override
IColorTransformation::ResultType GradientColor
TColorGradient(const GradientColor &startColor, const GradientColor &endColor)
ValueType GetClipped(ValueType value) const
Get value clipped to the range.
Definition TRange.h:630
Contains color management classes.
TColorGradient< LinearGradientFunction > CLinearColorGradient