diff Applications/Dicomizer.cpp @ 298:fa734a851551

New option: "tiff-alignment" to control deep zoom of plain TIFF over IIIF
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Jul 2023 08:19:16 +0200
parents 5f783bf882fe
children 7020852a8fa9
line wrap: on
line diff
--- a/Applications/Dicomizer.cpp	Tue Jul 18 07:13:36 2023 +0200
+++ b/Applications/Dicomizer.cpp	Tue Jul 18 08:19:16 2023 +0200
@@ -29,6 +29,7 @@
 #include "../Framework/Inputs/CytomineImage.h"
 #include "../Framework/Inputs/HierarchicalTiff.h"
 #include "../Framework/Inputs/OpenSlidePyramid.h"
+#include "../Framework/Inputs/PlainTiff.h"
 #include "../Framework/Inputs/TiledJpegImage.h"
 #include "../Framework/Inputs/TiledPngImage.h"
 #include "../Framework/Inputs/TiledPyramidStatistics.h"
@@ -91,6 +92,9 @@
 static const char* OPTION_CYTOMINE_PRIVATE_KEY = "cytomine-private-key";
 static const char* OPTION_CYTOMINE_COMPRESSION = "cytomine-compression";
 
+// New in release 2.1
+static const char* OPTION_TIFF_ALIGNMENT = "tiff-alignment";
+
 
 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 9, 0)
 
@@ -592,6 +596,9 @@
      "Whether to repaint the background of the image (Boolean)")
     (OPTION_COLOR, boost::program_options::value<std::string>(),
      "Color of the background (e.g. \"255,0,0\")")
+    (OPTION_TIFF_ALIGNMENT, boost::program_options::value<int>()->default_value(64),
+     "Add padding to plain TIFF images to align the width/height to multiples "
+     "of this value, very useful to enable deep zoom with IIIF (1 means no padding)")
     ;
 
   boost::program_options::options_description cytomine("Options if importing from Cytomine");
@@ -1004,6 +1011,20 @@
     parameters.SetIccProfilePath(options[OPTION_ICC_PROFILE].as<std::string>());
   }
 
+  if (options.count(OPTION_TIFF_ALIGNMENT))
+  {
+    int value = options[OPTION_TIFF_ALIGNMENT].as<int>();
+    if (value <= 0)
+    {
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange,
+                                      "TIFF alignment must be >= 1");
+    }
+    else
+    {
+      parameters.SetTiffAlignment(static_cast<unsigned int>(value));
+    }
+  }
+
   return true;
 }
 
@@ -1061,8 +1082,17 @@
       }
       catch (Orthanc::OrthancException&)
       {
-        LOG(WARNING) << "This is not a standard hierarchical TIFF file";
+        LOG(WARNING) << "This is not a standard hierarchical TIFF file, fallback to plain TIFF";
       }
+
+      sourceCompression = OrthancWSI::ImageCompression_Unknown;
+      return new OrthancWSI::PlainTiff(path,
+                                       parameters.GetTargetTileWidth(512),
+                                       parameters.GetTargetTileHeight(512),
+                                       parameters.GetTiffAlignment(),
+                                       parameters.GetBackgroundColorRed(),
+                                       parameters.GetBackgroundColorGreen(),
+                                       parameters.GetBackgroundColorBlue());
     }
 
     default: