# HG changeset patch # User Sebastien Jodogne # Date 1689174730 -7200 # Node ID 169f168ba07a6372c11e84ce609a01fc00c00d5c # Parent a6e4834ac1414a7e0c086ef210c6b67bc5e8d13a retrieval of properties from openslide diff -r a6e4834ac141 -r 169f168ba07a Framework/Inputs/OpenSlideLibrary.cpp --- 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::const_iterator found = properties_.find(property); + + if (found == properties_.end()) + { + return false; + } + else + { + value = found->second; + return true; + } + } } diff -r a6e4834ac141 -r 169f168ba07a Framework/Inputs/OpenSlideLibrary.h --- 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 #include +#include #include 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 levels_; + OpenSlideLibrary& that_; + void* handle_; + std::vector levels_; + std::map 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; }; }; }