diff Core/DicomParsing/DcmtkTranscoder.cpp @ 3906:f0dd5ded8927 transcoding

refactoring using IDicomTranscoder::TranscodedDicom
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 08 May 2020 11:16:16 +0200
parents c62f84c7eda9
children 1555feda39e2
line wrap: on
line diff
--- a/Core/DicomParsing/DcmtkTranscoder.cpp	Fri May 08 08:27:18 2020 +0200
+++ b/Core/DicomParsing/DcmtkTranscoder.cpp	Fri May 08 11:16:16 2020 +0200
@@ -371,4 +371,80 @@
     
     return false;
   }
+
+
+
+  bool DcmtkTranscoder::TranscodeParsedToBuffer(
+    std::string& target /* out */,
+    DicomTransferSyntax& sourceSyntax /* out */,
+    DicomTransferSyntax& targetSyntax /* out */,
+    bool& hasSopInstanceUidChanged /* out */,
+    DcmFileFormat& dicom /* in, possibly modified */,
+    const std::set<DicomTransferSyntax>& allowedSyntaxes,
+    bool allowNewSopInstanceUid)
+  {
+    if (dicom.getDataset() == NULL)
+    {
+      throw OrthancException(ErrorCode_InternalError);
+    }
+
+    if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, dicom))
+    {
+      LOG(ERROR) << "Unsupport transfer syntax for transcoding";
+      return false;
+    }
+
+    if (InplaceTranscode(hasSopInstanceUidChanged, dicom, allowedSyntaxes, allowNewSopInstanceUid))
+    {
+      if (FromDcmtkBridge::LookupOrthancTransferSyntax(targetSyntax, dicom) &&
+          allowedSyntaxes.find(targetSyntax) != allowedSyntaxes.end() &&
+          dicom.getDataset() != NULL)
+      {
+        FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom.getDataset());
+        return true;
+      }
+      else
+      {
+        throw OrthancException(ErrorCode_InternalError);
+      }      
+    }
+    else
+    {
+      return false;
+    }    
+  }
+
+
+  IDicomTranscoder::TranscodedDicom* DcmtkTranscoder::TranscodeToParsed2(
+    DcmFileFormat& dicom /* in, possibly modified */,
+    const void* buffer /* in, same DICOM file as "dicom" */,
+    size_t size,
+    const std::set<DicomTransferSyntax>& allowedSyntaxes,
+    bool allowNewSopInstanceUid)
+  {
+    DicomTransferSyntax sourceSyntax;
+    if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, dicom))
+    {
+      LOG(ERROR) << "Unsupport transfer syntax for transcoding";
+      return NULL;
+    }
+
+    bool hasSopInstanceUidChanged;
+    
+    if (allowedSyntaxes.find(sourceSyntax) != allowedSyntaxes.end())
+    {
+      // No transcoding is needed
+      return TranscodedDicom::CreateFromExternal(dicom, false /* no change in UID */);
+    }
+    else if (InplaceTranscode(hasSopInstanceUidChanged, dicom,
+                              allowedSyntaxes, allowNewSopInstanceUid))
+    {
+      return TranscodedDicom::CreateFromExternal(dicom, hasSopInstanceUidChanged);
+    }
+    else
+    {
+      // Cannot transcode
+      return NULL;
+    }
+  }
 }