comparison Framework/Inputs/OpenSlideLibrary.cpp @ 278:169f168ba07a

retrieval of properties from openslide
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 12 Jul 2023 17:12:10 +0200
parents 20a730889ae2
children 7020852a8fa9
comparison
equal deleted inserted replaced
268:a6e4834ac141 278:169f168ba07a
42 getLevelCount_ = (FunctionGetLevelCount) library_.GetFunction("openslide_get_level_count"); 42 getLevelCount_ = (FunctionGetLevelCount) library_.GetFunction("openslide_get_level_count");
43 getLevelDimensions_ = (FunctionGetLevelDimensions) library_.GetFunction("openslide_get_level_dimensions"); 43 getLevelDimensions_ = (FunctionGetLevelDimensions) library_.GetFunction("openslide_get_level_dimensions");
44 getLevelDownsample_ = (FunctionGetLevelDownsample) library_.GetFunction("openslide_get_level_downsample"); 44 getLevelDownsample_ = (FunctionGetLevelDownsample) library_.GetFunction("openslide_get_level_downsample");
45 open_ = (FunctionOpen) library_.GetFunction("openslide_open"); 45 open_ = (FunctionOpen) library_.GetFunction("openslide_open");
46 readRegion_ = (FunctionReadRegion) library_.GetFunction("openslide_read_region"); 46 readRegion_ = (FunctionReadRegion) library_.GetFunction("openslide_read_region");
47 getPropertyNames_ = (FunctionGetPropertyNames) library_.GetFunction("openslide_get_property_names");
48 getPropertyValue_ = (FunctionGetPropertyValue) library_.GetFunction("openslide_get_property_value");
47 } 49 }
48 50
49 51
50 OpenSlideLibrary::Image::Level::Level() : 52 OpenSlideLibrary::Image::Level::Level() :
51 width_(0), 53 width_(0),
142 OpenSlideLibrary::Image::Image(const std::string& path) : 144 OpenSlideLibrary::Image::Image(const std::string& path) :
143 that_(OpenSlideLibrary::GetInstance()), 145 that_(OpenSlideLibrary::GetInstance()),
144 handle_(NULL) 146 handle_(NULL)
145 { 147 {
146 Initialize(path); 148 Initialize(path);
149
150 const char* const* properties = that_.getPropertyNames_(handle_);
151 if (properties == NULL)
152 {
153 that_.close_(handle_);
154 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
155 }
156
157 for (size_t i = 0; properties[i] != NULL; i++)
158 {
159 const char* value = that_.getPropertyValue_(handle_, properties[i]);
160 if (value == NULL)
161 {
162 that_.close_(handle_);
163 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
164 }
165 else
166 {
167 properties_[properties[i]] = value;
168 }
169 }
147 } 170 }
148 171
149 172
150 void OpenSlideLibrary::Image::Close() 173 void OpenSlideLibrary::Image::Close()
151 { 174 {
235 258
236 void OpenSlideLibrary::Finalize() 259 void OpenSlideLibrary::Finalize()
237 { 260 {
238 globalLibrary_.reset(NULL); 261 globalLibrary_.reset(NULL);
239 } 262 }
263
264
265 bool OpenSlideLibrary::Image::LookupProperty(std::string& value,
266 const std::string& property) const
267 {
268 std::map<std::string, std::string>::const_iterator found = properties_.find(property);
269
270 if (found == properties_.end())
271 {
272 return false;
273 }
274 else
275 {
276 value = found->second;
277 return true;
278 }
279 }
240 } 280 }