diff Plugins/Engine/OrthancPlugins.cpp @ 3928:4cdc875510d1 transcoding

ServerContext::DecodeDicomFrame()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 14 May 2020 13:31:05 +0200
parents 2910b0d30fe0
children 7dc5e7e0045d
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp	Thu May 14 07:37:44 2020 +0200
+++ b/Plugins/Engine/OrthancPlugins.cpp	Thu May 14 13:31:05 2020 +0200
@@ -62,7 +62,6 @@
 #include "../../Core/OrthancException.h"
 #include "../../Core/SerializationToolbox.h"
 #include "../../Core/Toolbox.h"
-#include "../../OrthancServer/DefaultDicomImageDecoder.h"
 #include "../../OrthancServer/OrthancConfiguration.h"
 #include "../../OrthancServer/OrthancFindRequestHandler.h"
 #include "../../OrthancServer/Search/HierarchicalMatcher.h"
@@ -2757,6 +2756,11 @@
     // Images returned to plugins are assumed to be writeable. If the
     // input image is read-only, we return a copy so that it can be modified.
 
+    if (image.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_NullPointer);
+    }
+    
     if (image->IsReadOnly())
     {
       std::unique_ptr<Image> copy(new Image(image->GetFormat(), image->GetWidth(), image->GetHeight(), false));
@@ -2810,22 +2814,17 @@
         
       case _OrthancPluginService_GetInstanceDecodedFrame:
       {
-        std::unique_ptr<ImageAccessor> decoded;
         if (p.targetImage == NULL)
         {
           throw OrthancException(ErrorCode_NullPointer);
         }
-        else if (HasCustomImageDecoder())
+
+        std::unique_ptr<ImageAccessor> decoded;
         {
-          // TODO - This call could be speeded up the future, if a
-          // "decoding context" gets introduced in the decoder plugins          
-          decoded.reset(Decode(instance.GetBufferData(), instance.GetBufferSize(), p.frameIndex));
+          PImpl::ServerContextLock lock(*pimpl_);
+          decoded.reset(lock.GetContext().DecodeDicomFrame(instance, p.frameIndex));
         }
-        else
-        {
-          decoded.reset(DicomImageDecoder::Decode(instance.GetParsedDicomFile(), p.frameIndex));
-        }
-
+        
         *(p.targetImage) = ReturnImage(decoded);
         return;
       }
@@ -2859,8 +2858,7 @@
           static_cast<DicomToJsonFlags>(p.flags), p.maxStringLength);
 
         Json::FastWriter writer;
-        *p.targetStringToFree = CopyString(writer.write(json));
-        
+        *p.targetStringToFree = CopyString(writer.write(json));        
         return;
       }
       
@@ -4825,9 +4823,9 @@
   }
 
 
-  ImageAccessor*  OrthancPlugins::DecodeUnsafe(const void* dicom,
-                                               size_t size,
-                                               unsigned int frame)
+  ImageAccessor* OrthancPlugins::Decode(const void* dicom,
+                                        size_t size,
+                                        unsigned int frame)
   {
     boost::shared_lock<boost::shared_mutex> lock(pimpl_->decodeImageCallbackMutex_);
 
@@ -4846,25 +4844,6 @@
     return NULL;
   }
 
-
-  ImageAccessor* OrthancPlugins::Decode(const void* dicom,
-                                        size_t size,
-                                        unsigned int frame)
-  {
-    ImageAccessor* result = DecodeUnsafe(dicom, size, frame);
-
-    if (result != NULL)
-    {
-      return result;
-    }
-    else
-    {
-      LOG(INFO) << "The installed image decoding plugins cannot handle an image, fallback to the built-in decoder";
-      DefaultDicomImageDecoder defaultDecoder;
-      return defaultDecoder.Decode(dicom, size, frame); 
-    }
-  }
-
   
   bool OrthancPlugins::IsAllowed(HttpMethod method,
                                  const char* uri,