changeset 3888:e46b7a997f0a transcoding

IDicomTranscoder::TranscodeToBuffer()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 05 May 2020 16:42:13 +0200
parents 25c122277f53
children 56ce23ba93b7
files UnitTestsSources/FromDcmtkTests.cpp
diffstat 1 files changed, 43 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/UnitTestsSources/FromDcmtkTests.cpp	Tue May 05 16:32:37 2020 +0200
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Tue May 05 16:42:13 2020 +0200
@@ -1943,6 +1943,11 @@
 
 namespace Orthanc
 {
+  /**
+   * WARNING: This class might be called from several threads at
+   * once. Make sure to implement proper locking.
+   **/
+  
   class IDicomTranscoder : public boost::noncopyable
   {
   public:
@@ -1950,6 +1955,12 @@
     {
     }
 
+    virtual bool TranscodeToBuffer(std::string& target,
+                                   const void* buffer,
+                                   size_t size,
+                                   const std::set<DicomTransferSyntax>& allowedSyntaxes,
+                                   bool allowNewSopInstanceUid) = 0;
+
     /**
      * Transcoding flavor that creates a new parsed DICOM file. A
      * "std::set<>" is used to give the possible plugin the
@@ -2166,7 +2177,7 @@
     virtual DcmFileFormat* Transcode(const void* buffer,
                                      size_t size,
                                      const std::set<DicomTransferSyntax>& allowedSyntaxes,
-                                     bool allowNewSopInstanceUid)
+                                     bool allowNewSopInstanceUid) ORTHANC_OVERRIDE
     {
       std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(buffer, size));
 
@@ -2187,7 +2198,7 @@
 
     virtual bool InplaceTranscode(DcmFileFormat& dicom,
                                   const std::set<DicomTransferSyntax>& allowedSyntaxes,
-                                  bool allowNewSopInstanceUid)
+                                  bool allowNewSopInstanceUid) ORTHANC_OVERRIDE
     {
       if (dicom.getDataset() == NULL)
       {
@@ -2324,6 +2335,32 @@
 
       return false;
     }
+
+    
+    virtual bool TranscodeToBuffer(std::string& target,
+                                   const void* buffer,
+                                   size_t size,
+                                   const std::set<DicomTransferSyntax>& allowedSyntaxes,
+                                   bool allowNewSopInstanceUid) ORTHANC_OVERRIDE
+    {
+      std::unique_ptr<DcmFileFormat> transcoded(
+        Transcode(buffer, size, allowedSyntaxes, allowNewSopInstanceUid));
+
+      if (transcoded.get() == NULL)
+      {
+        return false;
+      }
+      else
+      {
+        if (transcoded->getDataset() == NULL)
+        {
+          throw OrthancException(ErrorCode_InternalError);
+        }          
+        
+        FromDcmtkBridge::SaveToMemoryBuffer(target, *transcoded->getDataset());
+        return true;
+      }
+    }
   };
 }
 
@@ -2392,24 +2429,17 @@
     DicomTransferSyntax a = (DicomTransferSyntax) i;
     std::set<DicomTransferSyntax> s;
     s.insert(a);
-    std::unique_ptr<DcmFileFormat> transcoded(transcoder.Transcode(source.c_str(), source.size(), s, true));
-    if (transcoded.get() == NULL)
+
+    std::string t;
+    
+    if (!transcoder.TranscodeToBuffer(t, source.c_str(), source.size(), s, true))
     {
       printf("**************** CANNOT: [%s] => [%s]\n",
              GetTransferSyntaxUid(sourceSyntax), GetTransferSyntaxUid(a));
     }
     else
     {
-      std::string t;
-      FromDcmtkBridge::SaveToMemoryBuffer(t, *transcoded->getDataset());
       printf("SIZE: %lu\n", t.size());
-      
-      const char* v = NULL;
-      transcoded->getDataset()->findAndGetString(DCM_SOPInstanceUID, v);
-      if (std::string(v) != "1.3.12.2.1107.5.12.1.2013021918595000.1.1")
-      {
-        printf("CHANGED SOP INSTANCE UID\n");
-      }
     }
   }
 }