FastLED 3.10.6
Loading...
Searching...
No Matches

◆ build_rgb_colorimetric_cache()

bool fl::colorimetric_response::build_rgb_colorimetric_cache ( const EmitterProfile & p,
RgbColorimetricCache * cache )
inline

Definition at line 465 of file colorimetric_response.h.

466 {
467 xyY_to_XYZ(p.xy_r[0], p.xy_r[1], p.lum_r, cache->P_R);
468 xyY_to_XYZ(p.xy_g[0], p.xy_g[1], p.lum_g, cache->P_G);
469 xyY_to_XYZ(p.xy_b[0], p.xy_b[1], p.lum_b, cache->P_B);
470
471 const float P_RGB[3][3] = {
472 { cache->P_R[0], cache->P_G[0], cache->P_B[0] },
473 { cache->P_R[1], cache->P_G[1], cache->P_B[1] },
474 { cache->P_R[2], cache->P_G[2], cache->P_B[2] },
475 };
476 const bool ok_rgb = invert3x3(P_RGB, cache->P_RGB_inv);
477 const bool declares_source_space = (p.input_xy_w[1] > 1e-6f);
478 cache->has_source_space = declares_source_space
481 cache->M_src);
482 if (cache->has_source_space && ok_rgb) {
483 float X_w[3];
484 xyY_to_XYZ(p.input_xy_w[0], p.input_xy_w[1], 1.0f, X_w);
485 float t[3];
486 matvec3(cache->P_RGB_inv, X_w, t);
487 const float mt = fl::max(fl::max(fl::fabs(t[0]), fl::fabs(t[1])),
488 fl::fabs(t[2]));
489 if (mt > 1e-6f) {
490 const float scale_k = 1.0f / mt;
491 for (int i = 0; i < 3; ++i) {
492 for (int j = 0; j < 3; ++j) {
493 cache->M_src[i][j] *= scale_k;
494 }
495 }
496 }
497 }
498 if (!ok_rgb) {
499 for (int i = 0; i < 3; ++i) {
500 for (int j = 0; j < 3; ++j) {
501 cache->P_RGB_inv[i][j] = 0.0f;
502 }
503 }
504 }
505 if (!cache->has_source_space) {
506 for (int i = 0; i < 3; ++i) {
507 for (int j = 0; j < 3; ++j) {
508 cache->M_src[i][j] = 0.0f;
509 }
510 }
511 }
512 if (declares_source_space && !cache->has_source_space) {
513 return false;
514 }
515 return ok_rgb;
516}
void matvec3(const float M[3][3], const float v[3], float out[3]) FL_NO_EXCEPT
bool invert3x3(const float in[3][3], float out[3][3]) FL_NO_EXCEPT
bool build_source_matrix(const float xy_r[2], const float xy_g[2], const float xy_b[2], const float xy_w[2], float M_out[3][3]) FL_NO_EXCEPT
void xyY_to_XYZ(float x, float y, float Y, float out[3]) FL_NO_EXCEPT
constexpr common_type_t< T, U > max(T a, U b) FL_NO_EXCEPT
Definition math.h:75
double fabs(double value) FL_NO_EXCEPT
Definition math.h:509

References build_source_matrix(), fl::fabs(), fl::FL_NO_EXCEPT, invert3x3(), matvec3(), fl::max(), fl::t, and xyY_to_XYZ().

+ Here is the call graph for this function: