Plasma Engine  2.0
Loading...
Searching...
No Matches
ColorGradient.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Containers/HybridArray.h>
5#include <Foundation/Math/Declarations.h>
6
9
14class PL_FOUNDATION_DLL plColorGradient
15{
16public:
18 struct ColorCP
19 {
20 PL_DECLARE_POD_TYPE();
21
22 double m_PosX;
23 plUInt8 m_GammaRed;
24 plUInt8 m_GammaGreen;
25 plUInt8 m_GammaBlue;
26 float m_fInvDistToNextCp;
27
28 PL_ALWAYS_INLINE bool operator<(const ColorCP& rhs) const { return m_PosX < rhs.m_PosX; }
29 };
30
32 struct AlphaCP
33 {
34 PL_DECLARE_POD_TYPE();
35
36 double m_PosX;
37 plUInt8 m_Alpha;
38 float m_fInvDistToNextCp;
39
40 PL_ALWAYS_INLINE bool operator<(const AlphaCP& rhs) const { return m_PosX < rhs.m_PosX; }
41 };
42
45 {
46 PL_DECLARE_POD_TYPE();
47
48 double m_PosX;
49 float m_Intensity;
50 float m_fInvDistToNextCp;
51
52 PL_ALWAYS_INLINE bool operator<(const IntensityCP& rhs) const { return m_PosX < rhs.m_PosX; }
53 };
54
55public:
57
59 void Clear();
60
62 bool IsEmpty() const;
63
65 void AddColorControlPoint(double x, const plColorGammaUB& rgb);
66
68 void AddAlphaControlPoint(double x, plUInt8 uiAlpha);
69
71 void AddIntensityControlPoint(double x, float fIntensity);
72
74 bool GetExtents(double& ref_fMinx, double& ref_fMaxx) const;
75
77 void GetNumControlPoints(plUInt32& ref_uiRgb, plUInt32& ref_uiAlpha, plUInt32& ref_uiIntensity) const;
78
80 const ColorCP& GetColorControlPoint(plUInt32 uiIdx) const { return m_ColorCPs[uiIdx]; }
82 const AlphaCP& GetAlphaControlPoint(plUInt32 uiIdx) const { return m_AlphaCPs[uiIdx]; }
84 const IntensityCP& GetIntensityControlPoint(plUInt32 uiIdx) const { return m_IntensityCPs[uiIdx]; }
85
88 ColorCP& ModifyColorControlPoint(plUInt32 uiIdx) { return m_ColorCPs[uiIdx]; }
91 AlphaCP& ModifyAlphaControlPoint(plUInt32 uiIdx) { return m_AlphaCPs[uiIdx]; }
94 IntensityCP& ModifyIntensityControlPoint(plUInt32 uiIdx) { return m_IntensityCPs[uiIdx]; }
95
98 void SortControlPoints();
99
103 void Evaluate(double x, plColorGammaUB& ref_rgba, float& ref_fIntensity) const;
104
106 void Evaluate(double x, plColor& ref_hdr) const;
107
109 void EvaluateColor(double x, plColorGammaUB& ref_rgb) const;
111 void EvaluateColor(double x, plColor& ref_rgb) const;
113 void EvaluateAlpha(double x, plUInt8& ref_uiAlpha) const;
115 void EvaluateIntensity(double x, float& ref_fIntensity) const;
116
118 plUInt64 GetHeapMemoryUsage() const;
119
121 void Save(plStreamWriter& inout_stream) const;
122
124 void Load(plStreamReader& inout_stream);
125
126private:
127 void PrecomputeLerpNormalizer();
128
129 plHybridArray<ColorCP, 8> m_ColorCPs;
130 plHybridArray<AlphaCP, 8> m_AlphaCPs;
131 plHybridArray<IntensityCP, 8> m_IntensityCPs;
132};
A 8bit per channel unsigned normalized (values interpreted as 0-1) color storage format that represen...
Definition Color8UNorm.h:99
A color curve for animating colors.
Definition ColorGradient.h:15
const AlphaCP & GetAlphaControlPoint(plUInt32 uiIdx) const
Const access to a control point.
Definition ColorGradient.h:82
ColorCP & ModifyColorControlPoint(plUInt32 uiIdx)
Non-const access to a control point. If you modify the x coordinate, SortControlPoints() has to be ca...
Definition ColorGradient.h:88
AlphaCP & ModifyAlphaControlPoint(plUInt32 uiIdx)
Non-const access to a control point. If you modify the x coordinate, SortControlPoints() has to be ca...
Definition ColorGradient.h:91
const ColorCP & GetColorControlPoint(plUInt32 uiIdx) const
Const access to a control point.
Definition ColorGradient.h:80
const IntensityCP & GetIntensityControlPoint(plUInt32 uiIdx) const
Const access to a control point.
Definition ColorGradient.h:84
IntensityCP & ModifyIntensityControlPoint(plUInt32 uiIdx)
Non-const access to a control point. If you modify the x coordinate, SortControlPoints() has to be ca...
Definition ColorGradient.h:94
plColor represents an RGBA color in linear color space. Values are stored as float,...
Definition Color.h:44
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
Alpha control point.
Definition ColorGradient.h:33
PL_ALWAYS_INLINE bool operator<(const AlphaCP &rhs) const
Internal: Optimization for Evaluate to not recalculate 1/distance to the next control point.
Definition ColorGradient.h:40
Color control point. Stores red, green and blue in gamma space.
Definition ColorGradient.h:19
PL_ALWAYS_INLINE bool operator<(const ColorCP &rhs) const
Internal: Optimization for Evaluate to not recalculate 1/distance to the next control point.
Definition ColorGradient.h:28
Intensity control point. Used to scale rgb for high-dynamic range values.
Definition ColorGradient.h:45
PL_ALWAYS_INLINE bool operator<(const IntensityCP &rhs) const
Internal: Optimization for Evaluate to not recalculate 1/distance to the next control point.
Definition ColorGradient.h:52