56 lines
2.0 KiB
C++
56 lines
2.0 KiB
C++
// SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// 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<class T>
|
|
void MaskDarkAnalysis::check(const T *ptr) {
|
|
std::unique_lock ul(m);
|
|
for (int i = 0; i < mask.size(); i++) {
|
|
auto v64 = static_cast<int64_t>(ptr[i]);
|
|
if (v64 > max_allowed_value)
|
|
mask[i]++;
|
|
}
|
|
}
|
|
|
|
void MaskDarkAnalysis::AnalyzeImage(const DataMessage &data, std::vector<uint8_t> 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<const int8_t *>(ptr));
|
|
break;
|
|
case CompressedImageMode::Uint8:
|
|
check(reinterpret_cast<const uint8_t *>(ptr));
|
|
break;
|
|
case CompressedImageMode::Int16:
|
|
check(reinterpret_cast<const int16_t *>(ptr));
|
|
break;
|
|
case CompressedImageMode::Uint16:
|
|
check(reinterpret_cast<const uint16_t *>(ptr));
|
|
break;
|
|
case CompressedImageMode::Int32:
|
|
check(reinterpret_cast<const int32_t *>(ptr));
|
|
break;
|
|
case CompressedImageMode::Uint32:
|
|
check(reinterpret_cast<const uint32_t *>(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<uint32_t> 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);
|
|
}
|