| 29 | }; |
| 30 | |
| 31 | ErrorStats analyze_errors(const CRGB *float_leds, const CRGB *q31_leds, int count) { |
| 32 | ErrorStats stats = {}; |
| 33 | |
| 34 | for (int i = 0; i < count; i++) { |
| 35 | int r_err = abs(static_cast<int>(float_leds[i].r) - static_cast<int>(q31_leds[i].r)); |
| 36 | int g_err = abs(static_cast<int>(float_leds[i].g) - static_cast<int>(q31_leds[i].g)); |
| 37 | int b_err = abs(static_cast<int>(float_leds[i].b) - static_cast<int>(q31_leds[i].b)); |
| 38 | |
| 39 | int pixel_max_err = r_err; |
| 40 | if (g_err > pixel_max_err) pixel_max_err = g_err; |
| 41 | if (b_err > pixel_max_err) pixel_max_err = b_err; |
| 42 | |
| 43 | if (pixel_max_err > 0) { |
| 44 | stats.pixels_with_error++; |
| 45 | stats.avg_error += pixel_max_err; |
| 46 | } |
| 47 | |
| 48 | if (pixel_max_err > stats.max_error) { |
| 49 | stats.max_error = pixel_max_err; |
| 50 | } |
| 51 | |
| 52 | if (pixel_max_err > 1) stats.pixels_over_1bit++; |
| 53 | if (pixel_max_err > 2) stats.pixels_over_2bit++; |
| 54 | if (pixel_max_err > 4) stats.pixels_over_4bit++; |
| 55 | |
| 56 | stats.histogram[pixel_max_err]++; |
| 57 | } |
| 58 | |
| 59 | stats.total_pixels = count; |
| 60 | if (stats.pixels_with_error > 0) { |
| 61 | stats.avg_error /= stats.pixels_with_error; |
| 62 | } |
| 63 | |
| 64 | // Calculate standard deviation |
| 65 | double variance = 0.0; |
| 66 | for (int i = 0; i < count; i++) { |
| 67 | int r_err = abs(static_cast<int>(float_leds[i].r) - static_cast<int>(q31_leds[i].r)); |
| 68 | int g_err = abs(static_cast<int>(float_leds[i].g) - static_cast<int>(q31_leds[i].g)); |
| 69 | int b_err = abs(static_cast<int>(float_leds[i].b) - static_cast<int>(q31_leds[i].b)); |
| 70 | |
| 71 | int pixel_max_err = r_err; |
| 72 | if (g_err > pixel_max_err) pixel_max_err = g_err; |
| 73 | if (b_err > pixel_max_err) pixel_max_err = b_err; |
| 74 | |
| 75 | double diff = pixel_max_err - stats.avg_error; |
| 76 | variance += diff * diff; |
| 77 | } |
| 78 | stats.std_dev = fl::sqrt(variance / count); |
| 79 | |
| 80 | return stats; |
| 81 | } |
| 82 | |
| 83 | void print_error_stats(const ErrorStats &stats, const char *test_name) { |
| 84 | fl::printf("\n=== %s ===\n", test_name); |
no test coverage detected