Mercurial > hg > orthanc-wsi
comparison ViewerPlugin/Plugin.cpp @ 153:b798d200ac90
using Semaphore from Orthanc framework
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 27 Jul 2018 14:06:26 +0200 |
parents | 442102e14933 |
children | 32a94bbb7d05 |
comparison
equal
deleted
inserted
replaced
150:442102e14933 | 153:b798d200ac90 |
---|---|
21 | 21 |
22 #include "../Framework/PrecompiledHeadersWSI.h" | 22 #include "../Framework/PrecompiledHeadersWSI.h" |
23 | 23 |
24 #include "DicomPyramidCache.h" | 24 #include "DicomPyramidCache.h" |
25 #include "../Framework/Jpeg2000Reader.h" | 25 #include "../Framework/Jpeg2000Reader.h" |
26 #include "../Framework/Semaphore.h" | |
27 | 26 |
28 #include <Core/Images/ImageProcessing.h> | 27 #include <Core/Images/ImageProcessing.h> |
29 #include <Core/Images/PngWriter.h> | 28 #include <Core/Images/PngWriter.h> |
29 #include <Core/MultiThreading/Semaphore.h> | |
30 #include <Core/OrthancException.h> | 30 #include <Core/OrthancException.h> |
31 #include <Core/SystemToolbox.h> | |
31 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> | 32 #include <Plugins/Samples/Common/OrthancPluginCppWrapper.h> |
32 #include <Plugins/Samples/Common/OrthancPluginConnection.h> | 33 #include <Plugins/Samples/Common/OrthancPluginConnection.h> |
33 | 34 |
34 #include <EmbeddedResources.h> | 35 #include <EmbeddedResources.h> |
35 | 36 |
37 | 38 |
38 OrthancPluginContext* context_ = NULL; | 39 OrthancPluginContext* context_ = NULL; |
39 | 40 |
40 std::auto_ptr<OrthancPlugins::OrthancPluginConnection> orthanc_; | 41 std::auto_ptr<OrthancPlugins::OrthancPluginConnection> orthanc_; |
41 std::auto_ptr<OrthancWSI::DicomPyramidCache> cache_; | 42 std::auto_ptr<OrthancWSI::DicomPyramidCache> cache_; |
42 std::auto_ptr<OrthancWSI::Semaphore> transcoderSemaphore_; | 43 std::auto_ptr<Orthanc::Semaphore> transcoderSemaphore_; |
43 | 44 |
44 | 45 |
45 static void AnswerSparseTile(OrthancPluginRestOutput* output, | 46 static void AnswerSparseTile(OrthancPluginRestOutput* output, |
46 unsigned int tileWidth, | 47 unsigned int tileWidth, |
47 unsigned int tileHeight) | 48 unsigned int tileHeight) |
181 | 182 |
182 // The tile does not come from a DICOM-JPEG instance, we need to | 183 // The tile does not come from a DICOM-JPEG instance, we need to |
183 // decompress the raw tile | 184 // decompress the raw tile |
184 std::auto_ptr<Orthanc::ImageAccessor> decoded; | 185 std::auto_ptr<Orthanc::ImageAccessor> decoded; |
185 | 186 |
186 OrthancWSI::Semaphore::Locker locker(*transcoderSemaphore_); | 187 Orthanc::Semaphore::Locker locker(*transcoderSemaphore_); |
187 | 188 |
188 switch (compression) | 189 switch (compression) |
189 { | 190 { |
190 case OrthancWSI::ImageCompression_Jpeg2000: | 191 case OrthancWSI::ImageCompression_Jpeg2000: |
191 decoded.reset(new OrthancWSI::Jpeg2000Reader); | 192 decoded.reset(new OrthancWSI::Jpeg2000Reader); |
310 } | 311 } |
311 | 312 |
312 // Limit the number of PNG transcoders to the number of available | 313 // Limit the number of PNG transcoders to the number of available |
313 // hardware threads (e.g. number of CPUs or cores or | 314 // hardware threads (e.g. number of CPUs or cores or |
314 // hyperthreading units) | 315 // hyperthreading units) |
315 unsigned int threads = boost::thread::hardware_concurrency(); | 316 unsigned int threads = Orthanc::SystemToolbox::GetHardwareConcurrency(); |
316 | 317 transcoderSemaphore_.reset(new Orthanc::Semaphore(threads)); |
317 if (threads <= 0) | |
318 { | |
319 threads = 1; | |
320 } | |
321 | |
322 transcoderSemaphore_.reset(new OrthancWSI::Semaphore(threads)); | |
323 | 318 |
324 char info[1024]; | 319 char info[1024]; |
325 sprintf(info, "The whole-slide imaging plugin will use at most %u threads to transcode the tiles", threads); | 320 sprintf(info, "The whole-slide imaging plugin will use at most %u threads to transcode the tiles", threads); |
326 OrthancPluginLogWarning(context_, info); | 321 OrthancPluginLogWarning(context_, info); |
327 | 322 |