// 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; } const int32_t *ImagePreprocessorBuffer::GatherTiles(const std::vector &x, const std::vector &y, int width, int half) { const int side = 2 * half + 1; const int height = static_cast(npixels / width); tiles.resize(x.size() * side * side); int32_t *out = tiles.data(); for (size_t i = 0; i < x.size(); i++) for (int py = y[i] - half; py <= y[i] + half; py++) for (int px = x[i] - half; px <= x[i] + half; px++) *out++ = (px < 0 || py < 0 || px >= width || py >= height) ? INT32_MIN : buffer[static_cast(py) * width + px]; return tiles.data(); } const int32_t *ImagePreprocessorBuffer::HostImage() { return buffer.data(); }