mask: accept any-bit-depth TIFF for user mask upload

PUT /config/user_mask.tiff only accepted 32-bit unsigned TIFF, so masks
exported by tools like PyFAI (8-bit) failed. Route the upload through the
universal ReadTIFF reader and let PixelMask take a CompressedImage directly:
it validates the 2D shape against the detector's converted/raw layouts,
binarizes any 8/16/32-bit integer image (non-zero == masked), and rejects
float/multi-channel images.

Also dedupe the TIFF readers: ReadTIFFFromString16 is now a thin wrapper over
ReadTIFF, and the now-unused ReadTIFFFromString32 is removed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-18 16:05:04 +02:00
co-authored by Claude Opus 4.8
parent 57ae145555
commit 0f5271f14c
10 changed files with 165 additions and 82 deletions
+49
View File
@@ -218,6 +218,55 @@ void PixelMask::LoadUserMask(const DiffractionExperiment& experiment, const std:
"Size of input user mask invalid");
}
void PixelMask::LoadUserMask(const DiffractionExperiment& experiment, const CompressedImage& image) {
const size_t width = image.GetWidth();
const size_t height = image.GetHeight();
// The image has to match one of the two layouts handled by the vector
// overload below: converted geometry, or raw stacked modules.
const bool converted = (width == static_cast<size_t>(experiment.GetXPixelsNumConv()))
&& (height == static_cast<size_t>(experiment.GetYPixelsNumConv()));
const bool raw = (width == static_cast<size_t>(RAW_MODULE_COLS))
&& (height == static_cast<size_t>(RAW_MODULE_LINES * experiment.GetModulesNum()));
if (!converted && !raw)
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
"User mask image size doesn't match the detector");
std::vector<uint8_t> buffer;
const uint8_t *bytes = image.GetUncompressedPtr(buffer);
// A pixel is masked when its value is non-zero. Read each pixel as an
// unsigned integer of the matching width - the sign is irrelevant when
// comparing against zero.
std::vector<uint32_t> mask(width * height);
auto binarize = [&](auto sample) {
using sample_t = decltype(sample);
const auto *typed = reinterpret_cast<const sample_t *>(bytes);
for (size_t i = 0; i < mask.size(); i++)
mask[i] = (typed[i] != 0) ? 1 : 0;
};
switch (image.GetMode()) {
case CompressedImageMode::Uint8:
case CompressedImageMode::Int8:
binarize(uint8_t{});
break;
case CompressedImageMode::Uint16:
case CompressedImageMode::Int16:
binarize(uint16_t{});
break;
case CompressedImageMode::Uint32:
case CompressedImageMode::Int32:
binarize(uint32_t{});
break;
default:
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
"User mask must be an 8-, 16- or 32-bit integer image");
}
LoadUserMask(experiment, mask);
}
void PixelMask::LoadDECTRISBadPixelMask(const std::vector<uint32_t> &input_mask) {
if (input_mask.size() != mask.size())
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,