// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include "ImagePreprocessorBuffer.h" ImagePreprocessorBuffer::ImagePreprocessorBuffer(size_t npixels, bool host_mirror) : npixels(npixels), buffer(host_mirror ? npixels : 0) {} ImagePreprocessorBuffer::ImagePreprocessorBuffer(size_t npixels) : ImagePreprocessorBuffer(npixels, true) {} void ImagePreprocessorBuffer::Gather(const std::vector &npixel, std::vector &values) const { values.resize(npixel.size()); for (size_t i = 0; i < npixel.size(); i++) values[i] = buffer[npixel[i]]; } int32_t *ImagePreprocessorBuffer::getGPUBuffer() { return nullptr; } const int32_t *ImagePreprocessorBuffer::getGPUBuffer() const { return nullptr; } PanelBox ImagePreprocessorBuffer::TileBox(int32_t x, int32_t y, int width) const { for (const auto &p: panels) if (x >= p.x0 && x < p.x1 && y >= p.y0 && y < p.y1) return p; return PanelBox{0, 0, width, static_cast(npixels / width), -1}; } const int32_t *ImagePreprocessorBuffer::GatherTiles(const std::vector &x, const std::vector &y, int width, int half) { const int side = 2 * half + 1; tiles.resize(x.size() * side * side); int32_t *out = tiles.data(); for (size_t i = 0; i < x.size(); i++) { const PanelBox b = TileBox(x[i], y[i], width); for (int py = y[i] - half; py <= y[i] + half; py++) for (int px = x[i] - half; px <= x[i] + half; px++) *out++ = (px < b.x0 || py < b.y0 || px >= b.x1 || py >= b.y1) ? INT32_MIN : buffer[static_cast(py) * width + px]; } return tiles.data(); } const int32_t *ImagePreprocessorBuffer::HostImage() { return buffer.data(); }