// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include "MaskDarkAnalysis.h" #include "../../common/JFJochException.h" MaskDarkAnalysis::MaskDarkAnalysis(size_t det_size) : mask(det_size, 0) {} template void MaskDarkAnalysis::check(const T *ptr) { std::unique_lock ul(m); for (int i = 0; i < mask.size(); i++) { auto v64 = static_cast(ptr[i]); if (v64 > max_allowed_value) mask[i]++; } } void MaskDarkAnalysis::AnalyzeImage(const DataMessage &data, std::vector buffer) { if (data.image.GetWidth() * data.image.GetHeight() != mask.size()) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Invalid size of input image"); auto ptr = data.image.GetUncompressedPtr(buffer); switch (data.image.GetMode()) { case CompressedImageMode::Int8: check(reinterpret_cast(ptr)); break; case CompressedImageMode::Uint8: check(reinterpret_cast(ptr)); break; case CompressedImageMode::Int16: check(reinterpret_cast(ptr)); break; case CompressedImageMode::Uint16: check(reinterpret_cast(ptr)); break; case CompressedImageMode::Int32: check(reinterpret_cast(ptr)); break; case CompressedImageMode::Uint32: check(reinterpret_cast(ptr)); break; default: throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "RGB/float image mode not supported"); } } void MaskDarkAnalysis::ApplyMask(PixelMask &in_mask) const { std::unique_lock ul(m); std::vector tmp(mask.size(), 0); for (int i = 0; i < mask.size(); i++) tmp[i] = (mask[i] > max_allowed_freq) ? 1 : 0; in_mask.LoadDarkBadPixelMask(tmp); }