changeset 3910:1f71c2f20e16 transcoding

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 08 May 2020 12:03:26 +0200
parents 6762a97deabc
children 0ef7f4528be2
files Core/DicomParsing/DcmtkTranscoder.cpp Core/DicomParsing/DcmtkTranscoder.h Core/DicomParsing/IDicomTranscoder.h Core/DicomParsing/MemoryBufferTranscoder.cpp Core/DicomParsing/MemoryBufferTranscoder.h OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h UnitTestsSources/FromDcmtkTests.cpp
diffstat 9 files changed, 44 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomParsing/DcmtkTranscoder.cpp	Fri May 08 11:40:12 2020 +0200
+++ b/Core/DicomParsing/DcmtkTranscoder.cpp	Fri May 08 12:03:26 2020 +0200
@@ -326,10 +326,9 @@
   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,
+    DicomTransferSyntax targetSyntax,
     bool allowNewSopInstanceUid)
   {
     if (dicom.getDataset() == NULL)
@@ -343,10 +342,14 @@
       return false;
     }
 
-    if (InplaceTranscode(hasSopInstanceUidChanged, dicom, allowedSyntaxes, allowNewSopInstanceUid))
+    std::set<DicomTransferSyntax> tmp;
+    tmp.insert(targetSyntax);
+
+    if (InplaceTranscode(hasSopInstanceUidChanged, dicom, tmp, allowNewSopInstanceUid))
     {
-      if (FromDcmtkBridge::LookupOrthancTransferSyntax(targetSyntax, dicom) &&
-          allowedSyntaxes.find(targetSyntax) != allowedSyntaxes.end() &&
+      DicomTransferSyntax targetSyntax2;
+      if (FromDcmtkBridge::LookupOrthancTransferSyntax(targetSyntax2, dicom) &&
+          targetSyntax == targetSyntax2 &&
           dicom.getDataset() != NULL)
       {
         FromDcmtkBridge::SaveToMemoryBuffer(target, *dicom.getDataset());
--- a/Core/DicomParsing/DcmtkTranscoder.h	Fri May 08 11:40:12 2020 +0200
+++ b/Core/DicomParsing/DcmtkTranscoder.h	Fri May 08 12:03:26 2020 +0200
@@ -72,10 +72,9 @@
 
     virtual bool TranscodeParsedToBuffer(std::string& target /* out */,
                                          DicomTransferSyntax& sourceSyntax /* out */,
-                                         DicomTransferSyntax& targetSyntax /* out */,
                                          bool& hasSopInstanceUidChanged /* out */,
                                          DcmFileFormat& dicom /* in, possibly modified */,
-                                         const std::set<DicomTransferSyntax>& allowedSyntaxes,
+                                         DicomTransferSyntax targetSyntax,
                                          bool allowNewSopInstanceUid) ORTHANC_OVERRIDE;
 
     virtual TranscodedDicom* TranscodeToParsed(
--- a/Core/DicomParsing/IDicomTranscoder.h	Fri May 08 11:40:12 2020 +0200
+++ b/Core/DicomParsing/IDicomTranscoder.h	Fri May 08 12:03:26 2020 +0200
@@ -57,10 +57,9 @@
 
     virtual bool TranscodeParsedToBuffer(std::string& target /* out */,
                                          DicomTransferSyntax& sourceSyntax /* out */,
-                                         DicomTransferSyntax& targetSyntax /* out */,
                                          bool& hasSopInstanceUidChanged /* out */,
                                          DcmFileFormat& dicom /* in, possibly modified */,
-                                         const std::set<DicomTransferSyntax>& allowedSyntaxes,  // TODO => is a set needed?
+                                         DicomTransferSyntax targetSyntax,
                                          bool allowNewSopInstanceUid) = 0;
 
 
--- a/Core/DicomParsing/MemoryBufferTranscoder.cpp	Fri May 08 11:40:12 2020 +0200
+++ b/Core/DicomParsing/MemoryBufferTranscoder.cpp	Fri May 08 12:03:26 2020 +0200
@@ -66,10 +66,9 @@
   bool MemoryBufferTranscoder::TranscodeParsedToBuffer(
     std::string& target /* out */,
     DicomTransferSyntax& sourceSyntax /* out */,
-    DicomTransferSyntax& targetSyntax /* out */,
     bool& hasSopInstanceUidChanged /* out */,
     DcmFileFormat& dicom /* in, possibly modified */,
-    const std::set<DicomTransferSyntax>& allowedSyntaxes,
+    DicomTransferSyntax targetSyntax,
     bool allowNewSopInstanceUid)
   {
     if (dicom.getDataset() == NULL)
@@ -82,14 +81,25 @@
 
     const void* data = source.empty() ? NULL : source.c_str();
 
-    bool success = Transcode(target, sourceSyntax, targetSyntax, hasSopInstanceUidChanged,
-                             data, source.size(), allowedSyntaxes, allowNewSopInstanceUid);
+    std::set<DicomTransferSyntax> tmp;
+    tmp.insert(targetSyntax);
+
+    DicomTransferSyntax targetSyntax2;
+    bool success = Transcode(target, sourceSyntax, targetSyntax2, hasSopInstanceUidChanged,
+                             data, source.size(), tmp, allowNewSopInstanceUid);
 
+    if (success &&
+        targetSyntax != targetSyntax2)
+    {
+      throw OrthancException(ErrorCode_InternalError);
+    }
+    
 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1
-    if (useDcmtk_ &&
+    if (!success &&
+        useDcmtk_ &&
         dcmtk_.TranscodeParsedToBuffer(
-          target, sourceSyntax, targetSyntax,hasSopInstanceUidChanged,
-          dicom, allowedSyntaxes, allowNewSopInstanceUid))
+          target, sourceSyntax, hasSopInstanceUidChanged,
+          dicom, targetSyntax, allowNewSopInstanceUid))
     {
       success = true;
     }
--- a/Core/DicomParsing/MemoryBufferTranscoder.h	Fri May 08 11:40:12 2020 +0200
+++ b/Core/DicomParsing/MemoryBufferTranscoder.h	Fri May 08 12:03:26 2020 +0200
@@ -79,10 +79,9 @@
     
     virtual bool TranscodeParsedToBuffer(std::string& target /* out */,
                                          DicomTransferSyntax& sourceSyntax /* out */,
-                                         DicomTransferSyntax& targetSyntax /* out */,
                                          bool& hasSopInstanceUidChanged /* out */,
                                          DcmFileFormat& dicom /* in, possibly modified */,
-                                         const std::set<DicomTransferSyntax>& allowedSyntaxes,
+                                         DicomTransferSyntax targetSyntax,
                                          bool allowNewSopInstanceUid) ORTHANC_OVERRIDE;
 
     virtual TranscodedDicom* TranscodeToParsed(
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Fri May 08 11:40:12 2020 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp	Fri May 08 12:03:26 2020 +0200
@@ -130,15 +130,12 @@
 
     if (transcode)
     {
-      std::set<DicomTransferSyntax> ts;
-      ts.insert(targetSyntax);
-
       std::string transcoded;
-      DicomTransferSyntax sourceSyntax, targetSyntax;
+      DicomTransferSyntax sourceSyntax;
       bool hasSopInstanceUidChanged;
 
-      if (context.Transcode(transcoded, sourceSyntax, targetSyntax,
-                            hasSopInstanceUidChanged, *modified, ts, true))
+      if (context.Transcode(transcoded, sourceSyntax, hasSopInstanceUidChanged,
+                            *modified, targetSyntax, true))
       {      
         call.GetOutput().AnswerBuffer(transcoded, MimeType_Dicom);
       }
--- a/OrthancServer/ServerContext.cpp	Fri May 08 11:40:12 2020 +0200
+++ b/OrthancServer/ServerContext.cpp	Fri May 08 12:03:26 2020 +0200
@@ -1157,10 +1157,9 @@
 
   bool ServerContext::Transcode(std::string& target /* out */,
                                 DicomTransferSyntax& sourceSyntax /* out */,
-                                DicomTransferSyntax& targetSyntax /* out */,
                                 bool& hasSopInstanceUidChanged /* out */,
                                 ParsedDicomFile& dicom, // Possibly modified
-                                const std::set<DicomTransferSyntax>& allowedSyntaxes,
+                                DicomTransferSyntax targetSyntax,
                                 bool allowNewSopInstanceUid)
   {
     IDicomTranscoder* transcoder = dcmtkTranscoder_.get();
@@ -1176,9 +1175,11 @@
     {
       throw OrthancException(ErrorCode_InternalError);
     }
-
-    return transcoder->TranscodeParsedToBuffer(
-      target, sourceSyntax, targetSyntax, hasSopInstanceUidChanged,
-      dicom.GetDcmtkObject(), allowedSyntaxes, allowNewSopInstanceUid);
+    else
+    {
+      return transcoder->TranscodeParsedToBuffer(
+        target, sourceSyntax, hasSopInstanceUidChanged,
+        dicom.GetDcmtkObject(), targetSyntax, allowNewSopInstanceUid);
+    }
   }
 }
--- a/OrthancServer/ServerContext.h	Fri May 08 11:40:12 2020 +0200
+++ b/OrthancServer/ServerContext.h	Fri May 08 12:03:26 2020 +0200
@@ -467,10 +467,9 @@
     // "TranscodingEnabled" is set to "false"
     bool Transcode(std::string& target /* out */,
                    DicomTransferSyntax& sourceSyntax /* out */,
-                   DicomTransferSyntax& targetSyntax /* out */,
                    bool& hasSopInstanceUidChanged /* out */,
                    ParsedDicomFile& dicom, // Possibly modified
-                   const std::set<DicomTransferSyntax>& allowedSyntaxes,
+                   DicomTransferSyntax targetSyntax,
                    bool allowNewSopInstanceUid);
   };
 }
--- a/UnitTestsSources/FromDcmtkTests.cpp	Fri May 08 11:40:12 2020 +0200
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Fri May 08 12:03:26 2020 +0200
@@ -1987,22 +1987,23 @@
   for (int i = 0; i <= DicomTransferSyntax_XML; i++)
   {
     DicomTransferSyntax a = (DicomTransferSyntax) i;
-    std::set<DicomTransferSyntax> s;
-    s.insert(a);
 
     std::string t;
 
     bool hasSopInstanceUidChanged;
-    DicomTransferSyntax sourceSyntax2, targetSyntax;
+    DicomTransferSyntax sourceSyntax2;
 
     std::unique_ptr<DcmFileFormat> cloned(dynamic_cast<DcmFileFormat*>(toto->clone()));
-    if (!transcoder.TranscodeParsedToBuffer(t, sourceSyntax2, targetSyntax, hasSopInstanceUidChanged, *cloned, s, true))
+    if (!transcoder.TranscodeParsedToBuffer(t, sourceSyntax2, hasSopInstanceUidChanged, *cloned, a, true))
     {
       printf("**************** CANNOT: [%s] => [%s]\n",
              GetTransferSyntaxUid(sourceSyntax), GetTransferSyntaxUid(a));
     }
     else
     {
+      DicomTransferSyntax targetSyntax;
+      ASSERT_TRUE(FromDcmtkBridge::LookupOrthancTransferSyntax(targetSyntax, *cloned));
+      
       ASSERT_EQ(targetSyntax, a);
       ASSERT_EQ(sourceSyntax, sourceSyntax2);
       bool lossy = (a == DicomTransferSyntax_JPEGProcess1 ||