changeset 278:169f168ba07a

retrieval of properties from openslide
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2023 17:12:10 +0200
parents a6e4834ac141
children 77afef2cf64b
files Framework/Inputs/OpenSlideLibrary.cpp Framework/Inputs/OpenSlideLibrary.h
diffstat 2 files changed, 54 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Inputs/OpenSlideLibrary.cpp	Mon Jul 10 16:22:14 2023 +0200
+++ b/Framework/Inputs/OpenSlideLibrary.cpp	Wed Jul 12 17:12:10 2023 +0200
@@ -44,6 +44,8 @@
     getLevelDownsample_ = (FunctionGetLevelDownsample) library_.GetFunction("openslide_get_level_downsample");
     open_ = (FunctionOpen) library_.GetFunction("openslide_open");
     readRegion_ = (FunctionReadRegion) library_.GetFunction("openslide_read_region");
+    getPropertyNames_ = (FunctionGetPropertyNames) library_.GetFunction("openslide_get_property_names");
+    getPropertyValue_ = (FunctionGetPropertyValue) library_.GetFunction("openslide_get_property_value");
   }
 
 
@@ -144,6 +146,27 @@
     handle_(NULL)
   {
     Initialize(path);
+
+    const char* const* properties = that_.getPropertyNames_(handle_);
+    if (properties == NULL)
+    {
+      that_.close_(handle_);
+      throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
+    }
+
+    for (size_t i = 0; properties[i] != NULL; i++)
+    {
+      const char* value = that_.getPropertyValue_(handle_, properties[i]);
+      if (value == NULL)
+      {
+        that_.close_(handle_);
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
+      }
+      else
+      {
+        properties_[properties[i]] = value;
+      }
+    }
   }
 
 
@@ -237,4 +260,21 @@
   {
     globalLibrary_.reset(NULL);
   }
+
+
+  bool OpenSlideLibrary::Image::LookupProperty(std::string& value,
+                                               const std::string& property) const
+  {
+    std::map<std::string, std::string>::const_iterator found = properties_.find(property);
+
+    if (found == properties_.end())
+    {
+      return false;
+    }
+    else
+    {
+      value = found->second;
+      return true;
+    }
+  }
 }
--- a/Framework/Inputs/OpenSlideLibrary.h	Mon Jul 10 16:22:14 2023 +0200
+++ b/Framework/Inputs/OpenSlideLibrary.h	Wed Jul 12 17:12:10 2023 +0200
@@ -25,6 +25,7 @@
 #include <Images/ImageAccessor.h>
 #include <SharedLibrary.h>
 
+#include <map>
 #include <vector>
 
 namespace OrthancWSI
@@ -39,6 +40,10 @@
     typedef void*   (*FunctionOpen) (const char*);
     typedef void    (*FunctionReadRegion) (void*, uint32_t*, int64_t, int64_t, int32_t, int64_t, int64_t);
 
+    // New in WSI 2.0
+    typedef const char* const* (*FunctionGetPropertyNames) (void*);
+    typedef const char*        (*FunctionGetPropertyValue) (void*, const char*);
+
     Orthanc::SharedLibrary      library_;
     FunctionClose               close_;
     FunctionGetLevelCount       getLevelCount_;
@@ -46,6 +51,8 @@
     FunctionGetLevelDownsample  getLevelDownsample_;
     FunctionOpen                open_;
     FunctionReadRegion          readRegion_;
+    FunctionGetPropertyNames    getPropertyNames_;
+    FunctionGetPropertyValue    getPropertyValue_;
 
   public:
     explicit OpenSlideLibrary(const std::string& path);
@@ -72,9 +79,10 @@
               double downsample);
       };
 
-      OpenSlideLibrary&   that_;
-      void*               handle_;
-      std::vector<Level>  levels_;
+      OpenSlideLibrary&                   that_;
+      void*                               handle_;
+      std::vector<Level>                  levels_;
+      std::map<std::string, std::string>  properties_;
 
       void Initialize(const std::string& path);
 
@@ -109,6 +117,9 @@
                                          uint64_t y,
                                          unsigned int width,
                                          unsigned int height);
+
+      bool LookupProperty(std::string& value,
+                          const std::string& property) const;
     };
   };
 }