From 471901d94aee49928e356bfda1b2d15c1d0742aa Mon Sep 17 00:00:00 2001 From: Filip Leonarski Date: Thu, 16 Apr 2026 09:06:20 +0200 Subject: [PATCH] TIFF: Minor fixes for reading --- broker/JFJochStateMachine.cpp | 2 +- preview/JFJochTIFF.cpp | 17 ++++++++++------- preview/JFJochTIFF.h | 6 ++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/broker/JFJochStateMachine.cpp b/broker/JFJochStateMachine.cpp index d14cfeeb..c3bcce51 100644 --- a/broker/JFJochStateMachine.cpp +++ b/broker/JFJochStateMachine.cpp @@ -28,7 +28,7 @@ JFJochStateMachine::JFJochStateMachine(const DiffractionExperiment& in_experimen #else data_processing_settings.indexing = true; #endif - SupressTIFFErrors(); + SuppressTIFFErrors(); } bool JFJochStateMachine::ImportPedestalG0(const JFJochReceiverOutput &receiver_output) { diff --git a/preview/JFJochTIFF.cpp b/preview/JFJochTIFF.cpp index 991c5f55..25c4f8ed 100644 --- a/preview/JFJochTIFF.cpp +++ b/preview/JFJochTIFF.cpp @@ -121,23 +121,26 @@ CompressedImage ReadTIFF(const std::string &s, std::vector &buffer) { TIFFGetField(tiff, TIFFTAG_ROWSPERSTRIP, &rows_per_string); TIFFGetField(tiff, TIFFTAG_SAMPLEFORMAT, &format); + if (elem_size % 8 != 0) + throw JFJochException(JFJochExceptionCategory::TIFFGeneratorError, "Only byte-aligned TIFF samples are supported"); - if (cols * lines * elem_size <= 0) + const size_t elem_size_bytes = elem_size / 8; + if (cols == 0 || lines == 0 || elem_size_bytes == 0) throw JFJochException(JFJochExceptionCategory::TIFFGeneratorError,"Size wrong"); - if (cols * elem_size != TIFFScanlineSize(tiff)) + if (cols * elem_size_bytes != TIFFScanlineSize(tiff)) throw JFJochException(JFJochExceptionCategory::TIFFGeneratorError, "TIFFScanlineSize mismatch"); - buffer.resize(cols * lines * elem_size); + buffer.resize(static_cast(cols) * static_cast(lines) * elem_size_bytes); - for (int i = 0; i < lines; i++) { - if (TIFFReadScanline(tiff, buffer.data() + i * cols * elem_size, i, 0) < 0) + for (uint32_t i = 0; i < lines; i++) { + if (TIFFReadScanline(tiff, buffer.data() + static_cast(i) * cols * elem_size_bytes, i, 0) < 0) throw JFJochException(JFJochExceptionCategory::TIFFGeneratorError, "TIFFReadScanline error"); } TIFFClose(tiff); - CompressedImageMode mode = CalcImageMode(elem_size / 8, (format == SAMPLEFORMAT_IEEEFP), (format == SAMPLEFORMAT_INT)); + CompressedImageMode mode = CalcImageMode(elem_size_bytes, (format == SAMPLEFORMAT_IEEEFP), (format == SAMPLEFORMAT_INT)); return CompressedImage(buffer, cols, lines, mode); } @@ -216,6 +219,6 @@ std::vector ReadTIFFFromString16(const std::string &s, uint32_t &cols, return ret; } -void SupressTIFFErrors() { +void SuppressTIFFErrors() { TIFFSetErrorHandler(nullptr); } diff --git a/preview/JFJochTIFF.h b/preview/JFJochTIFF.h index 7e3fcebf..ec0dbc10 100644 --- a/preview/JFJochTIFF.h +++ b/preview/JFJochTIFF.h @@ -1,8 +1,7 @@ // SPDX-FileCopyrightText: 2024 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only -#ifndef JUNGFRAUJOCH_WRITETIFF_H -#define JUNGFRAUJOCH_WRITETIFF_H +#pragma once #include #include @@ -16,5 +15,4 @@ CompressedImage ReadTIFF(const std::string &s, std::vector &buffer); std::vector ReadTIFFFromString32(const std::string& s, uint32_t &cols, uint32_t &lines); std::vector ReadTIFFFromString16(const std::string& s, uint32_t &cols, uint32_t &lines); -void SupressTIFFErrors(); -#endif //JUNGFRAUJOCH_WRITETIFF_H +void SuppressTIFFErrors();