Compare two LED buffers and return max/avg error.
| 112 | |
| 113 | // Compare two LED buffers and return max/avg error. |
| 114 | CompareResult compareBuffers(fl::span<const CRGB> a, fl::span<const CRGB> b) { |
| 115 | CompareResult r = {0, 0.0}; |
| 116 | int count = static_cast<int>(a.size()); |
| 117 | int error_pixels = 0; |
| 118 | for (int i = 0; i < count; i++) { |
| 119 | int re = abs(static_cast<int>(a[i].r) - static_cast<int>(b[i].r)); |
| 120 | int ge = abs(static_cast<int>(a[i].g) - static_cast<int>(b[i].g)); |
| 121 | int be = abs(static_cast<int>(a[i].b) - static_cast<int>(b[i].b)); |
| 122 | int mx = re; |
| 123 | if (ge > mx) mx = ge; |
| 124 | if (be > mx) mx = be; |
| 125 | if (mx > r.max_error) r.max_error = mx; |
| 126 | if (mx > 0) { |
| 127 | r.avg_error += mx; |
| 128 | error_pixels++; |
| 129 | } |
| 130 | } |
| 131 | if (error_pixels > 0) r.avg_error /= error_pixels; |
| 132 | return r; |
| 133 | } |
| 134 | |
| 135 | } // namespace |
| 136 |
no test coverage detected