diff OrthancServer/ServerContext.cpp @ 3945:0b3256c3ee14 transcoding

simplified IDicomTranscoder
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 19 May 2020 11:24:00 +0200
parents aae045f802f4
children cf6eb4fc6841
line wrap: on
line diff
--- a/OrthancServer/ServerContext.cpp	Tue May 19 10:17:06 2020 +0200
+++ b/OrthancServer/ServerContext.cpp	Tue May 19 11:24:00 2020 +0200
@@ -551,7 +551,7 @@
     else
     {
       // Automated transcoding of incoming DICOM files
-      
+
       DicomTransferSyntax sourceSyntax;
       if (!FromDcmtkBridge::LookupOrthancTransferSyntax(
             sourceSyntax, dicom.GetParsedDicomFile().GetDcmtkObject()) ||
@@ -565,21 +565,16 @@
         std::set<DicomTransferSyntax> syntaxes;
         syntaxes.insert(ingestTransferSyntax_);
 
-        std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded(
-          TranscodeToParsed(dicom.GetParsedDicomFile().GetDcmtkObject(),
-                            dicom.GetBufferData(), dicom.GetBufferSize(),
-                            syntaxes, true /* allow new SOP instance UID */));
-        
-        if (transcoded.get() == NULL)
+        IDicomTranscoder::DicomImage source;
+        source.SetExternalBuffer(dicom.GetBufferData(), dicom.GetBufferSize());
+
+        IDicomTranscoder::DicomImage transcoded;
+        bool hasSopInstanceUidChanged;
+        if (Transcode(transcoded, hasSopInstanceUidChanged,
+                      source, syntaxes, true /* allow new SOP instance UID */))
         {
-          // Cannot transcode => store the original file
-          return StoreAfterTranscoding(resultPublicId, dicom, mode);
-        }
-        else
-        {
-          std::unique_ptr<ParsedDicomFile> tmp(
-            ParsedDicomFile::AcquireDcmtkObject(transcoded->ReleaseDicom()));
-      
+          std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile());
+
           DicomInstanceToStore toStore;
           toStore.SetParsedDicomFile(*tmp);
           toStore.SetOrigin(dicom.GetOrigin());
@@ -589,6 +584,11 @@
 
           return ok;
         }
+        else
+        {
+          // Cannot transcode => store the original file
+          return StoreAfterTranscoding(resultPublicId, dicom, mode);
+        }
       }
     }
   }
@@ -1322,99 +1322,6 @@
   }
 
 
-  bool ServerContext::TranscodeParsedToBuffer(std::string& target /* out */,
-                                              bool& hasSopInstanceUidChanged /* out */,
-                                              DcmFileFormat& dicom /* in, possibly modified */,
-                                              DicomTransferSyntax targetSyntax,
-                                              bool allowNewSopInstanceUid)
-  {
-    if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_Before)
-    {
-      if (dcmtkTranscoder_->TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom,
-                                                    targetSyntax, allowNewSopInstanceUid))
-      {
-        return true;
-      }
-    }
-    
-#if ORTHANC_ENABLE_PLUGINS == 1
-    if (HasPlugins() &&
-        GetPlugins().HasCustomTranscoder())
-    {
-      if (GetPlugins().TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom,
-                                               targetSyntax, allowNewSopInstanceUid))
-      {
-        return true;
-      }
-      else if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
-      {
-        LOG(INFO) << "The installed transcoding plugins cannot handle an image, "
-                  << "fallback to the built-in DCMTK transcoder";
-      }
-    }
-#endif
-    
-    if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
-    {
-      return dcmtkTranscoder_->TranscodeParsedToBuffer(target, hasSopInstanceUidChanged, dicom,
-                                                       targetSyntax, allowNewSopInstanceUid);
-    }
-    else
-    {
-      return false;
-    }
-  }
-      
-
-  IDicomTranscoder::TranscodedDicom*
-  ServerContext::TranscodeToParsed(DcmFileFormat& dicom,
-                                   const void* buffer,
-                                   size_t size,
-                                   const std::set<DicomTransferSyntax>& allowedSyntaxes,
-                                   bool allowNewSopInstanceUid)
-  {
-    if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_Before)
-    {
-      std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded(
-        dcmtkTranscoder_->TranscodeToParsed(dicom, buffer, size, allowedSyntaxes,
-                                            allowNewSopInstanceUid));
-      if (transcoded.get() != NULL)
-      {
-        return transcoded.release();
-      }
-    }
-
-#if ORTHANC_ENABLE_PLUGINS == 1
-    if (HasPlugins() &&
-        GetPlugins().HasCustomTranscoder())
-    {
-      std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded(
-        GetPlugins().TranscodeToParsed(dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid));
-
-      if (transcoded.get() != NULL)
-      {
-        return transcoded.release();
-      }
-      else if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
-      {
-        LOG(INFO) << "The installed transcoding plugins cannot handle an image, "
-                  << "fallback to the built-in DCMTK transcoder";
-      }
-    }
-#endif
-
-    if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After)
-    {
-      return dcmtkTranscoder_->TranscodeToParsed(
-        dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid);
-    }
-    else
-    {
-      return NULL;
-    }
-  }
-
-
   bool ServerContext::Transcode(DicomImage& target,
                                 bool& hasSopInstanceUidChanged /* out */,
                                 DicomImage& source /* in, "GetParsed()" possibly modified */,