// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once #include #include #include #include "HDF5ImageLocator.h" #include "../common/CompressedImage.h" // Raw-pixel side of the reader. Turns a global image number into a CompressedImage, using // HDF5ImageLocator to find the file (with its open-file cache). This is the part whose "links // to files stay" constant: switching which master the per-image metadata is read from never // touches it. Caller must hold the global hdf5_mutex (HDF5 is not thread-safe). // Bit depth and signedness of /entry/data/data as it is STORED. Deliberately not the same thing as // the experiment's image format: the reader hands every image out in a signed 32-bit container // whatever the file holds (see HDF5MetadataSource), so an output file that links to the original // images rather than writing its own must describe them with this, not with the experiment. struct StoredPixelFormat { int64_t bit_depth = 0; bool is_signed = false; }; class HDF5ImageSource { public: void Configure(HDF5ImageLocator::Layout layout); void Clear(); [[nodiscard]] StoredPixelFormat GetStoredPixelFormat() const; // Where image `global` physically lives. Also used by the metadata source to find the data // file that holds a legacy/VDS image's per-image metadata. HDF5ImageLocator::Location Resolve(int64_t global) const; // Read the pixels at a resolved location into a CompressedImage backed by `buffer`. CompressedImage ReadImageAt(std::vector &buffer, const HDF5ImageLocator::Location &loc) const; std::vector GetSourceMapping(uint64_t first_image, std::optional image_count, uint64_t total_images, uint64_t stride = 1) const; private: HDF5ImageLocator locator_; static CompressedImage LoadImageDataset(std::vector &tmp, HDF5Object &file, hsize_t number); };