mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-05 04:20:40 +02:00
bitdepths
This commit is contained in:
parent
da67f58323
commit
d07da42745
@ -66,6 +66,9 @@ class RawSubFile {
|
||||
size_t pixels_per_frame() const { return m_rows * m_cols; }
|
||||
size_t bytes_per_pixel() const { return m_bitdepth / 8; }
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
void read_with_map(std::byte *image_buf);
|
||||
|
||||
};
|
||||
|
||||
|
@ -256,7 +256,7 @@ std::vector<Cluster3x3> ClusterFile::read_cluster_with_cut(size_t n_clusters,
|
||||
}
|
||||
|
||||
NDArray<double, 2> calculate_eta2(ClusterVector<int> &clusters) {
|
||||
NDArray<double, 2> eta2({clusters.size(), 2});
|
||||
NDArray<double, 2> eta2({static_cast<int64_t>(clusters.size()), 2});
|
||||
for (size_t i = 0; i < clusters.size(); i++) {
|
||||
// int32_t t2;
|
||||
// auto* ptr = reinterpret_cast<int32_t*> (clusters.element_ptr(i) + 2 *
|
||||
|
@ -9,11 +9,13 @@ namespace aare {
|
||||
RawSubFile::RawSubFile(const std::filesystem::path &fname,
|
||||
DetectorType detector, size_t rows, size_t cols,
|
||||
size_t bitdepth, uint32_t pos_row, uint32_t pos_col)
|
||||
: m_detector_type(detector), m_bitdepth(bitdepth), m_fname(fname), m_rows(rows), m_cols(cols),
|
||||
m_bytes_per_frame((m_bitdepth / 8) * m_rows * m_cols), m_pos_row(pos_row), m_pos_col(pos_col) {
|
||||
: m_detector_type(detector), m_bitdepth(bitdepth), m_fname(fname),
|
||||
m_rows(rows), m_cols(cols),
|
||||
m_bytes_per_frame((m_bitdepth / 8) * m_rows * m_cols), m_pos_row(pos_row),
|
||||
m_pos_col(pos_col) {
|
||||
if (m_detector_type == DetectorType::Moench03_old) {
|
||||
m_pixel_map = GenerateMoench03PixelMap();
|
||||
}else if(m_detector_type == DetectorType::Eiger && m_pos_row % 2 == 0){
|
||||
} else if (m_detector_type == DetectorType::Eiger && m_pos_row % 2 == 0) {
|
||||
m_pixel_map = GenerateEigerFlipRowsPixelMap();
|
||||
}
|
||||
|
||||
@ -51,37 +53,48 @@ size_t RawSubFile::tell() {
|
||||
return m_file.tellg() / (sizeof(DetectorHeader) + bytes_per_frame());
|
||||
}
|
||||
|
||||
|
||||
void RawSubFile::read_into(std::byte *image_buf, DetectorHeader *header) {
|
||||
if(header){
|
||||
m_file.read(reinterpret_cast<char *>(header), sizeof(DetectorHeader));
|
||||
if (header) {
|
||||
m_file.read(reinterpret_cast<char *>(header), sizeof(DetectorHeader));
|
||||
} else {
|
||||
m_file.seekg(sizeof(DetectorHeader), std::ios::cur);
|
||||
}
|
||||
|
||||
//TODO! expand support for different bitdepths
|
||||
if(m_pixel_map){
|
||||
// TODO! expand support for different bitdepths
|
||||
if (m_pixel_map) {
|
||||
// read into a temporary buffer and then copy the data to the buffer
|
||||
// in the correct order
|
||||
// currently this only supports 16 bit data!
|
||||
auto part_buffer = new std::byte[bytes_per_frame()];
|
||||
m_file.read(reinterpret_cast<char *>(part_buffer), bytes_per_frame());
|
||||
auto *data = reinterpret_cast<uint16_t *>(image_buf);
|
||||
auto *part_data = reinterpret_cast<uint16_t *>(part_buffer);
|
||||
for (size_t i = 0; i < pixels_per_frame(); i++) {
|
||||
data[i] = part_data[(*m_pixel_map)(i)];
|
||||
// TODO! add 4 bit support
|
||||
if(m_bitdepth == 8){
|
||||
read_with_map<uint8_t>(image_buf);
|
||||
}else if (m_bitdepth == 16) {
|
||||
read_with_map<uint16_t>(image_buf);
|
||||
} else if (m_bitdepth == 32) {
|
||||
read_with_map<uint32_t>(image_buf);
|
||||
}else{
|
||||
throw std::runtime_error("Unsupported bitdepth for read with pixel map");
|
||||
}
|
||||
delete[] part_buffer;
|
||||
|
||||
} else {
|
||||
// read directly into the buffer
|
||||
m_file.read(reinterpret_cast<char *>(image_buf), bytes_per_frame());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void RawSubFile::read_with_map(std::byte *image_buf) {
|
||||
auto part_buffer = new std::byte[bytes_per_frame()];
|
||||
m_file.read(reinterpret_cast<char *>(part_buffer), bytes_per_frame());
|
||||
auto *data = reinterpret_cast<T *>(image_buf);
|
||||
auto *part_data = reinterpret_cast<T *>(part_buffer);
|
||||
for (size_t i = 0; i < pixels_per_frame(); i++) {
|
||||
data[i] = part_data[(*m_pixel_map)(i)];
|
||||
}
|
||||
delete[] part_buffer;
|
||||
}
|
||||
size_t RawSubFile::rows() const { return m_rows; }
|
||||
size_t RawSubFile::cols() const { return m_cols; }
|
||||
|
||||
|
||||
void RawSubFile::get_part(std::byte *buffer, size_t frame_index) {
|
||||
seek(frame_index);
|
||||
read_into(buffer, nullptr);
|
||||
@ -94,5 +107,4 @@ size_t RawSubFile::frame_number(size_t frame_index) {
|
||||
return h.frameNumber;
|
||||
}
|
||||
|
||||
|
||||
} // namespace aare
|
Loading…
x
Reference in New Issue
Block a user