diff --git a/image_analysis/spot_finding/ImageSpotFinderCPU.cpp b/image_analysis/spot_finding/ImageSpotFinderCPU.cpp index 1cb6773f9..4062f5b10 100644 --- a/image_analysis/spot_finding/ImageSpotFinderCPU.cpp +++ b/image_analysis/spot_finding/ImageSpotFinderCPU.cpp @@ -45,14 +45,15 @@ bool StrongInWindow(int64_t pxl_val, int64_t sum, int64_t sum2, int64_t valid, // pixel is above SNR threshold } -// Adds row `in` to the vertical sums and takes row `out` out of them; nullptr is no row. A bad or -// saturated pixel adds 0. Written without branches, and as a function of its own so that the loop -// vectorises whatever it is inlined into; integer sums, so the same totals as pixel by pixel. +// Adds row `in` to the vertical sums and takes row `out` out of them; a row of INT32_MIN is no row. A +// bad or saturated pixel adds 0. Written without branches - both rows are always read, so no load is +// conditional - and as a function of its own, so that the loop vectorises whatever it is inlined into; +// integer sums, so the same totals as pixel by pixel. void SlideVertical(const int32_t *in, const int32_t *out, int32_t width, int64_t *sum, int64_t *sum2, uint16_t *valid) { for (int32_t col = 0; col < width; col++) { - const int64_t a = in ? in[col] : INT32_MIN; - const int64_t r = out ? out[col] : INT32_MIN; + const int64_t a = in[col]; + const int64_t r = out[col]; const bool a_ok = a != INT32_MAX && a != INT32_MIN; const bool r_ok = r != INT32_MAX && r != INT32_MIN; const int64_t a_v = a_ok ? a : 0; @@ -190,9 +191,10 @@ void ImageSpotFinderCPU::DetectPass(const ImagePreprocessorBuffer &image, int64_t *sv = sum_vert.data(); int64_t *sv2 = sum2_vert.data(); uint16_t *vv = valid_vert.data(); + const std::vector no_row(width, INT32_MIN); auto slide_vert = [&](int line_in, int line_out) { - SlideVertical(line_in >= 0 ? img + static_cast(line_in) * w : nullptr, - line_out >= 0 ? img + static_cast(line_out) * w : nullptr, w, sv, sv2, vv); + SlideVertical(line_in >= 0 ? img + static_cast(line_in) * w : no_row.data(), + line_out >= 0 ? img + static_cast(line_out) * w : no_row.data(), w, sv, sv2, vv); if (!prev_strong) return; // sign = +1 takes out what line_in added, -1 puts back what line_out took out.