8#include <Common/assertion.h>
15template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
19 for(std::size_t i = 0; i < N; ++i)
21 m[i] =
static_cast<T
>(values[i]);
25template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
31template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
35 return this->minIndex();
38template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
42 return this->maxIndex();
45template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
50 return this->set(values);
53template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
58 return this->set(rawColorValues);
61template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
68template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
69template<EColorSpace SRC_COLOR_SPACE>
74 srcColorValues, usage);
75 setColorValues(transformedColorValues);
77 return static_cast<Derived&
>(*this);
80template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
81template<CColorValuesInterface ImplType>
85 return setTransformed<ImplType::getColorSpace()>(
86 srcColorValues.getColorValues(), usage);
89template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
90template<EColorSpace SPECTRAL_COLOR_SPACE>
96 return setTransformed<SPECTRAL_COLOR_SPACE>(sampleValues, usage);
99template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
100template<CColorValuesInterface ImplType>
104 return setSpectral<ImplType::getColorSpace()>(
105 sampleValues.getColorValues(), usage);
108template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
109template<EColorSpace DST_COLOR_SPACE>
113 getColorValues(), usage);
116template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
117template<EColorSpace DST_COLOR_SPACE>
120 return toTransformed<DST_COLOR_SPACE>(usage);
123template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
129template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
130template<EColorSpace SRC_COLOR_SPACE>
132 const auto& srcColorValues,
const EColorUsage usage)
134 if constexpr(
is_compatible<
decltype(srcColorValues), SRC_COLOR_SPACE>)
136 setTransformed<SRC_COLOR_SPACE>(srcColorValues, usage);
141 "Using incompatible type for color transformation (`srcColorValues` is incompatible "
142 "with its color space).");
146template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
147template<EColorSpace DST_COLOR_SPACE>
148inline void TSpectrumBase<Derived, COLOR_SPACE, T, N>::toTransformedIfCompatible(
149 auto*
const out_dstColorValues,
const EColorUsage usage)
const
151 PH_ASSERT(out_dstColorValues);
155 *out_dstColorValues = toTransformed<DST_COLOR_SPACE>(usage);
160 "Using incompatible type for color transformation (`out_dstColorValues` is incompatible "
161 "with its color space).");
165template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
169 switch(srcColorSpace)
172 return setTransformedIfCompatible<EColorSpace::CIE_XYZ>(srcColorValues, usage);
175 return setTransformedIfCompatible<EColorSpace::CIE_xyY>(srcColorValues, usage);
178 return setTransformedIfCompatible<EColorSpace::Linear_sRGB>(srcColorValues, usage);
181 return setTransformedIfCompatible<EColorSpace::sRGB>(srcColorValues, usage);
184 return setTransformedIfCompatible<EColorSpace::ACEScg>(srcColorValues, usage);
187 return setTransformedIfCompatible<EColorSpace::Spectral_Smits>(srcColorValues, usage);
191 PH_ASSERT_UNREACHABLE_SECTION();
197template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
201 PH_ASSERT(out_dstColorValues);
203 switch(dstColorSpace)
206 return toTransformedIfCompatible<EColorSpace::CIE_XYZ>(out_dstColorValues, usage);
209 return toTransformedIfCompatible<EColorSpace::CIE_xyY>(out_dstColorValues, usage);
212 return toTransformedIfCompatible<EColorSpace::Linear_sRGB>(out_dstColorValues, usage);
215 return toTransformedIfCompatible<EColorSpace::sRGB>(out_dstColorValues, usage);
218 return toTransformedIfCompatible<EColorSpace::ACEScg>(out_dstColorValues, usage);
221 return toTransformedIfCompatible<EColorSpace::Spectral_Smits>(out_dstColorValues, usage);
225 PH_ASSERT_UNREACHABLE_SECTION();
226 out_dstColorValues->fill(0);
231template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
239 setColorValues(transformedColorValues);
241 return static_cast<Derived&
>(*this);
244template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
251 getColorValues(), usage);
254template<
typename Derived, EColorSpace COLOR_SPACE,
typename T, std::
size_t N>
263 return setColorValues(
269 return setColorValues(
Error on the color-related functionalities.
Definition math_exceptions.h:24
static consteval bool isTristimulus() noexcept
Definition color_spaces.h:81
Base for spectrum implementations.
Definition TSpectrumBase.h:28
TRawColorValues< T, 3 > toLinearSRGB(EColorUsage usage) const
Helper for converting this spectrum to linear-sRGB color.
Definition TSpectrumBase.ipp:245
Derived & setTransformed(const auto &srcColorValues, EColorUsage usage)
TSpectrumBase(const TRawColorValues< U, N > &values)
Set color values directly. Calling setColorValues() has the same effect. This is the most general for...
Definition TSpectrumBase.ipp:17
void transformTo(auto *out_dstColorValues, EColorSpace dstColorSpace, EColorUsage usage) const
Definition TSpectrumBase.ipp:198
T relativeLuminance(EColorUsage usage=EColorUsage::EMR) const
Definition TSpectrumBase.ipp:124
const TRawColorValues< T, N > & getColorValues() const
Definition TSpectrumBase.ipp:62
void transformFrom(const auto &srcColorValues, EColorSpace srcColorSpace, EColorUsage usage)
Definition TSpectrumBase.ipp:166
static consteval EColorSpace getColorSpace() noexcept
Definition TSpectrumBase.ipp:26
std::size_t maxComponent() const
Definition TSpectrumBase.ipp:39
Derived & putEnergy(T energyLevel)
Definition TSpectrumBase.ipp:255
auto toTransformed(EColorUsage usage) const
Definition TSpectrumBase.ipp:110
TSpectralSampleValues< T > toSpectral(EColorUsage usage) const
Helper for getting spectral values from this spectrum.
Definition TSpectrumBase.ipp:118
Derived & setLinearSRGB(const TRawColorValues< T, 3 > &linearSRGB, EColorUsage usage)
Helper for setting linear-sRGB color to this spectrum.
Definition TSpectrumBase.ipp:232
Derived & setSpectral(const TSpectralSampleValues< T > &sampleValues, EColorUsage usage)
Helper for setting spectral values to this spectrum.
std::size_t minComponent() const
Definition TSpectrumBase.ipp:32
Derived & setColorValues(const TRawColorValues< T, N > &values)
Set and get raw color values directly.
Definition TSpectrumBase.ipp:46
Satisfying this concept makes ImplType usable as color values.
Definition color_basics.h:75
Miscellaneous math utilities.
Math functions and utilities.
Definition TransformInfo.h:10
auto put_color_energy(const auto &srcColorValues, T energyLevel)
Definition color_spaces.ipp:783
std::array< T, N > TRawColorValues
Definition color_basics.h:45
TRawColorValues< T, SampleProps::NUM_SAMPLES > TSpectralSampleValues
Definition color_basics.h:54
T relative_luminance(const auto &srcColorValues, EColorUsage usage=EColorUsage::EMR)
Definition color_spaces.ipp:701
constexpr bool is_compatible()
Check whether InColorValuesType is suitable to represent values in COLOR_SPACE.
Definition color_spaces.ipp:563
auto transform_color(const auto &srcColorValues, EColorUsage usage)
Definition color_spaces.ipp:589
EColorUsage
Definition color_enums.h:140
EColorSpace
Definition color_enums.h:7
TTristimulusValues< T > transform_to_linear_sRGB(const auto &srcColorValues, EColorUsage usage)
Helper for converting any color space to linear-sRGB.
Definition color_spaces.ipp:828
auto transform_from_linear_sRGB(const TTristimulusValues< T > &linearSRGB, EColorUsage usage)
Helper for converting from linear-sRGB to any color space.
Definition color_spaces.ipp:814