diff Core/DicomParsing/FromDcmtkBridge.cpp @ 3872:b40dfa6dc8da transcoding

working on a simpler abstraction for transcoding
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 Apr 2020 14:39:28 +0200
parents 890af7156f19
children f23ab7829a8d
line wrap: on
line diff
--- a/Core/DicomParsing/FromDcmtkBridge.cpp	Wed Apr 29 14:38:20 2020 +0200
+++ b/Core/DicomParsing/FromDcmtkBridge.cpp	Thu Apr 30 14:39:28 2020 +0200
@@ -1206,7 +1206,7 @@
   }
 
 
-
+  
   static bool SaveToMemoryBufferInternal(std::string& buffer,
                                          DcmFileFormat& dicom,
                                          E_TransferSyntax xfer)
@@ -1254,6 +1254,27 @@
   
 
   bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer,
+                                           DcmFileFormat& dicom,
+                                           DicomTransferSyntax syntax)
+  {
+    E_TransferSyntax xfer;
+    if (!LookupDcmtkTransferSyntax(xfer, syntax))
+    {
+      return false;
+    }
+    else if (!dicom.validateMetaInfo(xfer).good())
+    {
+      throw OrthancException(ErrorCode_InternalError,
+                             "Cannot setup the transfer syntax to write a DICOM instance");
+    }
+    else
+    {
+      return SaveToMemoryBufferInternal(buffer, dicom, xfer);
+    }
+  }
+
+
+  bool FromDcmtkBridge::SaveToMemoryBuffer(std::string& buffer,
                                            DcmDataset& dataSet)
   {
     // Determine the transfer syntax which shall be used to write the
@@ -1307,8 +1328,7 @@
   }
 
 
-  bool FromDcmtkBridge::Transcode(std::string& buffer,
-                                  DcmFileFormat& dicom,
+  bool FromDcmtkBridge::Transcode(DcmFileFormat& dicom,
                                   DicomTransferSyntax syntax,
                                   const DcmRepresentationParameter* representation)
   {
@@ -1325,10 +1345,11 @@
       {
         return false;
       }
-
-      dicom.removeInvalidGroups();
-      
-      return SaveToMemoryBufferInternal(buffer, dicom, xfer);
+      else
+      {
+        dicom.removeInvalidGroups();
+        return true;
+      }
     }
   }