FastLED 3.10.10
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 126 of file options.h.

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

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: