From 528de39714effeb8d9d0336a4ebdf08b9a7304b7 Mon Sep 17 00:00:00 2001
From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de>
Date: Tue, 8 Aug 2023 12:04:55 +0200
Subject: [PATCH] refer to webdoc

---
 App/main.cpp                |  2 +-
 Device/IO/ReadWriteTiff.cpp | 28 +++++++++++++++++-----------
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/App/main.cpp b/App/main.cpp
index 9b9c048acc9..92b2ff85e86 100644
--- a/App/main.cpp
+++ b/App/main.cpp
@@ -19,7 +19,6 @@
 #include "GUI/View/Main/MainWindow.h"
 #include "GUI/View/Tool/Globals.h"
 #include "config_build.h"
-#include <iostream>
 #include <QApplication>
 #include <QDir>
 #include <QIcon>
@@ -27,6 +26,7 @@
 #include <QMessageBox>
 #include <QMetaType>
 #include <QtGlobal>
+#include <iostream>
 
 void custom_terminate_handler()
 {
diff --git a/Device/IO/ReadWriteTiff.cpp b/Device/IO/ReadWriteTiff.cpp
index a23a07847a3..44bfb4a4dc9 100644
--- a/Device/IO/ReadWriteTiff.cpp
+++ b/Device/IO/ReadWriteTiff.cpp
@@ -27,13 +27,18 @@
 #include <tiffio.h>
 #include <tiffio.hxx>
 
+namespace {
+const std::string ref_to_doc =
+    "\n\nThe TIFF format requirements can be found in the web documentation.";
+}
+
 Datafield* Util::RW::readTiff(std::istream& input_stream)
 {
     // Update webdoc page about tiff requirements if they are changed.
 
     TIFF* tiffstream = TIFFStreamOpen("MemTIFF", &input_stream);
     if (!tiffstream)
-        throw std::runtime_error("Cannot open the TIFF file");
+        throw std::runtime_error("Cannot open the TIFF file" + ref_to_doc);
 
     //... Read header.
 
@@ -43,7 +48,7 @@ Datafield* Util::RW::readTiff(std::istream& input_stream)
     uint32_t w, h;
     if (!TIFFGetField(tiffstream, TIFFTAG_IMAGEWIDTH, &w)
         || !TIFFGetField(tiffstream, TIFFTAG_IMAGELENGTH, &h)) {
-        message << "missing width/height in header" << std::endl;
+        message << "missing width/height in header" << ref_to_doc << std::endl;
         throw std::runtime_error(message.str());
     }
 
@@ -54,7 +59,7 @@ Datafield* Util::RW::readTiff(std::istream& input_stream)
 
     if (8 != bitsPerSample && 16 != bitsPerSample && 32 != bitsPerSample) {
         message << "    TIFFTAG_BITSPERSAMPLE: " << bitsPerSample << std::endl
-                << "Only 8, 16 or 32 bits per sample are allowed." << std::endl;
+                << "Only 8, 16 or 32 bits per sample are allowed." << ref_to_doc << std::endl;
         throw std::runtime_error(message.str());
     }
 
@@ -66,7 +71,7 @@ Datafield* Util::RW::readTiff(std::istream& input_stream)
 
     if (samplesPerPixel != 1) {
         message << "    TIFFTAG_SAMPLESPERPIXEL: " << samplesPerPixel << std::endl
-                << "Only 1 sample per pixel (channel) is allowed." << std::endl;
+                << "Only 1 sample per pixel (channel) is allowed." << ref_to_doc << std::endl;
         throw std::runtime_error(message.str());
     }
 
@@ -85,13 +90,13 @@ Datafield* Util::RW::readTiff(std::istream& input_stream)
                 << "    TIFFTAG_BITSPERSAMPLE: " << bitsPerSample << std::endl
                 << "    TIFFTAG_SAMPLEFORMAT: " << sampleFormat << std::endl
                 << "Only 32 bits per sample are allowed for IEEE float format (sample format = 3)."
-                << std::endl;
+                << ref_to_doc << std::endl;
             throw std::runtime_error(message.str());
         }
         break;
     default:
         message << "    TIFFTAG_SAMPLEFORMAT: " << sampleFormat << std::endl
-                << "Only value 1, 2 or 3 is allowed." << std::endl;
+                << "Only value 1, 2 or 3 is allowed." << ref_to_doc << std::endl;
         throw std::runtime_error(message.str());
     }
 
@@ -105,11 +110,11 @@ Datafield* Util::RW::readTiff(std::istream& input_stream)
     tmsize_t buf_size = TIFFScanlineSize(tiffstream);
     tmsize_t expected_size = bytesPerSample * width;
     if (buf_size != expected_size)
-        throw std::runtime_error("Cannot read TIFF file: wrong scanline size");
+        throw std::runtime_error("Cannot read TIFF file: wrong scanline size" + ref_to_doc);
 
     tdata_t buf = _TIFFmalloc(buf_size);
     if (!buf)
-        throw std::runtime_error("Cannot read TIFF file: failed allocating buffer");
+        throw std::runtime_error("Cannot read TIFF file: failed allocating buffer" + ref_to_doc);
 
     auto data = std::make_unique<Datafield>(
         std::vector<const Scale*>{newEquiDivision("x", width, 0.0, double(width)),
@@ -122,7 +127,7 @@ Datafield* Util::RW::readTiff(std::istream& input_stream)
 
     for (uint32_t row = 0; row < (uint32_t)height; row++) {
         if (TIFFReadScanline(tiffstream, buf, row) < 0)
-            throw std::runtime_error("Cannot read TIFF file: error in scanline.");
+            throw std::runtime_error("Cannot read TIFF file: error in scanline." + ref_to_doc);
 
         memcpy(&line_buf[0], buf, buf_size);
 
@@ -165,7 +170,8 @@ Datafield* Util::RW::readTiff(std::istream& input_stream)
                 sample = double(*reinterpret_cast<float*>(incoming));
                 break;
             default:
-                throw std::runtime_error("Cannot read TIFF file: unexpected sample format");
+                throw std::runtime_error("Cannot read TIFF file: unexpected sample format"
+                                         + ref_to_doc);
             }
 
             (*data)[global_index] = sample;
@@ -180,7 +186,7 @@ Datafield* Util::RW::readTiff(std::istream& input_stream)
 void Util::RW::writeTiff(const Datafield& data, std::ostream& output_stream)
 {
     if (data.rank() != 2)
-        throw std::runtime_error("Cannot read TIFF file: unsupported data rank");
+        throw std::runtime_error("Cannot write TIFF file: unsupported data rank");
     TIFF* tiffstream = TIFFStreamOpen("MemTIFF", &output_stream);
     ASSERT(tiffstream);
     const size_t m_width = data.axis(0).size();
-- 
GitLab