FastLED 3.10.8
Loading...
Searching...
No Matches

◆ setColorProfile() [2/3]

bool fl::ChannelOptions::setColorProfile ( const EmitterProfile & profile,
SourceProfile source,
bool global_source,
GamutPolicy gamut = GamutPolicy::ChromaCompress )
inline

Definition at line 124 of file options.h.

125 {
126#if !FL_COLOR_PROFILE_RUNTIME
127 FL_UNUSED(profile); FL_UNUSED(source); FL_UNUSED(global_source); FL_UNUSED(gamut);
128 return false;
129#else
130 // Captured before mStaticProfile is cleared below, so the warning
131 // condition still sees whether a profile was bound on entry.
132 const bool had_profile = hasColorProfile();
133 mColorProfile.mStaticProfile = nullptr;
134 if (profile.native_code_depth == 0 || profile.native_code_depth > 16 ||
135 !validChromaticity(profile.xy_r) || !validChromaticity(profile.xy_g) ||
136 !validChromaticity(profile.xy_b) || !validPrimaries(source.primaries) ||
137 !finitePositive(profile.lum_r) || !finitePositive(profile.lum_g) || !finitePositive(profile.lum_b) ||
138 (profile.topology != colorimetric_response::EmitterTopology::RGB &&
141 (profile.topology != colorimetric_response::EmitterTopology::RGB &&
142 (!validChromaticity(profile.xy_white1) ||
143 !finitePositive(profile.lum_white1) ||
144 (profile.response_lut_size != 0 &&
145 profile.response_lut_white1 == nullptr))) ||
147 (!validChromaticity(profile.xy_white2) ||
148 !finitePositive(profile.lum_white2) ||
149 (profile.response_lut_size != 0 &&
150 profile.response_lut_white2 == nullptr))) ||
151 (profile.response_lut_size != 0 &&
152 (profile.response_lut_r == nullptr || profile.response_lut_g == nullptr || profile.response_lut_b == nullptr))) {
154 return false;
155 }
156 if (!validResponseLut(profile.response_lut_r, profile.response_lut_size) ||
157 !validResponseLut(profile.response_lut_g, profile.response_lut_size) ||
158 !validResponseLut(profile.response_lut_b, profile.response_lut_size)) {
160 return false;
161 }
162 if (profile.topology != colorimetric_response::EmitterTopology::RGB &&
163 !validResponseLut(profile.response_lut_white1,
164 profile.response_lut_size)) {
166 return false;
167 }
168 if (profile.topology == colorimetric_response::EmitterTopology::RGBWW &&
169 !validResponseLut(profile.response_lut_white2,
170 profile.response_lut_size)) {
172 return false;
173 }
174 // Warn only once validation has passed. Warning earlier consumed
175 // mWarnedLegacyCleared on a profile that was then rejected, and
176 // clearColorProfile() leaves mCorrection/mTemperature alone -- so the
177 // next *valid* profile cleared the caller's legacy settings silently.
178 // Every field cleared below whose loss is detectable has to be
179 // represented here, or the caller loses it in silence. This used to
180 // name mCorrection and mTemperature only, while the clear also resets
181 // mGamma -- so a caller who set just a gamma had it discarded with no
182 // warning, which is exactly what the note above is about (#4331).
183 //
184 // mDitherMode is deliberately absent, and cannot be added by
185 // comparison. Its default is BINARY_DITHER and the clear sets
186 // DISABLE_DITHER, so `mDitherMode != BINARY_DITHER` is true precisely
187 // when the caller already chose DISABLE_DITHER and nothing is being
188 // taken away, and false in the case that loses dithering. Detecting
189 // that needs a "the caller set this" flag, which mGamma gets for free
190 // by being an optional. Until then, binding a profile turns dithering
191 // off quietly (#4331).
192 const bool clearing_legacy =
195 mGamma.has_value();
196 if (!had_profile && clearing_legacy && !mWarnedLegacyCleared) {
197 FL_WARN("Color profile clears legacy correction/temperature/gamma");
199 ColorProfileEvent{-1, {}, ColorProfileWarning::LegacyClearedByProfile});
200 mWarnedLegacyCleared = true;
201 }
202 // The one call that makes the colour pipeline reachable. Everything
203 // downstream goes through function pointers these install, so a
204 // program that never gets here never references the pipeline and the
205 // linker drops it -- about 3.5 KB of flash for sketches that do not
206 // ask for colour management.
208 mColorProfile.mStorage = fl::make_shared<ColorProfileStorage>(profile);
209 mColorProfile.mSource = source;
210 mColorProfile.mGamut = gamut;
211 mColorProfile.mRequested = true;
212 mColorProfile.mUseGlobalSourceDefault = global_source;
215 mGamma.reset();
217 return true;
218#endif
219 }
#define FL_UNUSED(x)
#define DISABLE_DITHER
Disable dithering.
Definition dither_mode.h:14
@ UncorrectedTemperature
Uncorrected temperature (0xFFFFFF)
Definition color.h:90
@ UncorrectedColor
Uncorrected color (0xFFFFFF)
Definition color.h:24
#define FL_WARN(...)
Definition log.h:437
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:423
void installColorPipelineHooks() FL_NO_EXCEPT
Point the hooks at the real implementations.
static ChannelEvents & instance() FL_NO_EXCEPT
fl::function_list< void(const ColorProfileEvent &)> onColorProfileWarning
static bool validPrimaries(const RgbPrimaries &primaries) FL_NO_EXCEPT
Definition options.h:299
void clearColorProfile() FL_NO_EXCEPT
Definition options.h:229
fl::optional< float > mGamma
Definition options.h:100
static bool validResponseLut(const u16 *values, u16 size) FL_NO_EXCEPT
Definition options.h:303
bool hasColorProfile() const FL_NO_EXCEPT
Definition options.h:242
fl::u8 mDitherMode
Definition options.h:95
static bool validChromaticity(const float xy[2]) FL_NO_EXCEPT
Definition options.h:291
static bool finitePositive(float value) FL_NO_EXCEPT
Definition options.h:312

References fl::ChromaCompress, clearColorProfile(), DISABLE_DITHER, finitePositive(), fl::FL_NO_EXCEPT, FL_UNUSED, FL_WARN, hasColorProfile(), fl::installColorPipelineHooks(), fl::ChannelEvents::instance(), fl::LegacyClearedByProfile, fl::adl_barrier::make_shared(), mCorrection, mDitherMode, mGamma, fl::ColorProfileBinding::mGamut, fl::ColorProfileBinding::mRequested, fl::ColorProfileBinding::mSource, fl::ColorProfileBinding::mStaticProfile, fl::ColorProfileBinding::mStorage, mTemperature, fl::ColorProfileBinding::mUseGlobalSourceDefault, fl::ChannelEvents::onColorProfileWarning, fl::colorimetric_response::RGB, fl::colorimetric_response::RGBW, fl::colorimetric_response::RGBWW, UncorrectedColor, UncorrectedTemperature, validChromaticity(), validPrimaries(), and validResponseLut().

+ Here is the call graph for this function: