MCPcopy Create free account
hub / github.com/FastLED/FastLED / ff_analyze_errors

Function ff_analyze_errors

tests/fl/fx/2d/flowfield.hpp:25–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23};
24
25FfErrorStats ff_analyze_errors(const CRGB *float_leds, const CRGB *fp_leds, int count) {
26 FfErrorStats stats = {};
27
28 for (int i = 0; i < count; i++) {
29 int r_err = abs(static_cast<int>(float_leds[i].r) - static_cast<int>(fp_leds[i].r));
30 int g_err = abs(static_cast<int>(float_leds[i].g) - static_cast<int>(fp_leds[i].g));
31 int b_err = abs(static_cast<int>(float_leds[i].b) - static_cast<int>(fp_leds[i].b));
32
33 int pixel_max_err = r_err;
34 if (g_err > pixel_max_err) pixel_max_err = g_err;
35 if (b_err > pixel_max_err) pixel_max_err = b_err;
36
37 if (pixel_max_err > 0) {
38 stats.pixels_with_error++;
39 stats.avg_error += pixel_max_err;
40 }
41
42 if (pixel_max_err > stats.max_error) {
43 stats.max_error = pixel_max_err;
44 }
45
46 if (pixel_max_err > 1) stats.pixels_over_1bit++;
47 if (pixel_max_err > 2) stats.pixels_over_2bit++;
48 if (pixel_max_err > 4) stats.pixels_over_4bit++;
49
50 if (pixel_max_err < 256) stats.histogram[pixel_max_err]++;
51 }
52
53 stats.total_pixels = count;
54 if (stats.pixels_with_error > 0) {
55 stats.avg_error /= stats.pixels_with_error;
56 }
57
58 double variance = 0.0;
59 for (int i = 0; i < count; i++) {
60 int r_err = abs(static_cast<int>(float_leds[i].r) - static_cast<int>(fp_leds[i].r));
61 int g_err = abs(static_cast<int>(float_leds[i].g) - static_cast<int>(fp_leds[i].g));
62 int b_err = abs(static_cast<int>(float_leds[i].b) - static_cast<int>(fp_leds[i].b));
63
64 int pixel_max_err = r_err;
65 if (g_err > pixel_max_err) pixel_max_err = g_err;
66 if (b_err > pixel_max_err) pixel_max_err = b_err;
67
68 double diff = pixel_max_err - stats.avg_error;
69 variance += diff * diff;
70 }
71 stats.std_dev = fl::sqrt(variance / count);
72
73 return stats;
74}
75
76void ff_print_error_stats(const FfErrorStats &stats, const char *test_name) {
77 fl::printf("\n=== %s ===\n", test_name);

Callers 1

flowfield.hppFile · 0.85

Calls 2

sqrtFunction · 0.85
absFunction · 0.50

Tested by

no test coverage detected