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:
@@ -306,6 +306,44 @@ TEST_CASE("PixelMask_LoadUserMaskRaw_UpdatesCachedRawMask", "[PixelMask]") {
|
||||
CHECK((raw_mask_out[0] & (1u << PixelMask::ModuleEdgePixelBit)) != 0);
|
||||
}
|
||||
|
||||
TEST_CASE("PixelMask_LoadUserMask_CompressedImage","[PixelMask]") {
|
||||
DiffractionExperiment experiment(DetJF(4, 1, 8, 36, false));
|
||||
experiment.MaskModuleEdges(false).MaskChipEdges(false);
|
||||
|
||||
const uint32_t cols = experiment.GetXPixelsNumConv();
|
||||
const uint32_t lines = experiment.GetYPixelsNumConv();
|
||||
|
||||
// 8-bit single-channel mask, as e.g. PyFAI produces; non-zero == masked
|
||||
std::vector<uint8_t> values(static_cast<size_t>(cols) * lines, 0);
|
||||
values[1030 * 700 + 300] = 255;
|
||||
CompressedImage image(values, cols, lines, CompressedImageMode::Uint8);
|
||||
|
||||
PixelMask mask(experiment);
|
||||
REQUIRE_NOTHROW(mask.LoadUserMask(experiment, image));
|
||||
|
||||
REQUIRE(mask.GetMask()[1030 * 700 + 300] == (1 << PixelMask::UserMaskedPixelBit));
|
||||
REQUIRE(mask.GetUserMask()[1030 * 700 + 300] == 1);
|
||||
REQUIRE(mask.GetStatistics().user_mask == 1);
|
||||
|
||||
// 32-bit mask goes through the same path
|
||||
std::vector<uint32_t> values32(static_cast<size_t>(cols) * lines, 0);
|
||||
values32[1030 * 700 + 300] = 7;
|
||||
CompressedImage image32(values32, cols, lines);
|
||||
PixelMask mask32(experiment);
|
||||
REQUIRE_NOTHROW(mask32.LoadUserMask(experiment, image32));
|
||||
REQUIRE(mask32.GetUserMask()[1030 * 700 + 300] == 1);
|
||||
|
||||
// Float images are rejected outright
|
||||
std::vector<float> valuesf(static_cast<size_t>(cols) * lines, 0.0f);
|
||||
CompressedImage imagef(valuesf, cols, lines);
|
||||
REQUIRE_THROWS(mask.LoadUserMask(experiment, imagef));
|
||||
|
||||
// Image whose shape doesn't match the detector is rejected
|
||||
std::vector<uint8_t> wrong(static_cast<size_t>(cols) * (lines + 1), 0);
|
||||
CompressedImage bad(wrong, cols, lines + 1, CompressedImageMode::Uint8);
|
||||
REQUIRE_THROWS(mask.LoadUserMask(experiment, bad));
|
||||
}
|
||||
|
||||
TEST_CASE("PixelMask_GetMaskRaw_ThrowsForDECTRIS", "[PixelMask]") {
|
||||
DiffractionExperiment experiment(DetDECTRIS(2068, 2164, "Test", ""));
|
||||
PixelMask mask(experiment);
|
||||
|
||||
Reference in New Issue
Block a user