changeset 3907:1555feda39e2 transcoding

substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 08 May 2020 11:24:34 +0200
parents f0dd5ded8927
children 89ebb37cee6a
files Core/DicomNetworking/DicomStoreUserConnection.cpp Core/DicomParsing/DcmtkTranscoder.cpp Core/DicomParsing/DcmtkTranscoder.h Core/DicomParsing/IDicomTranscoder.h Core/DicomParsing/MemoryBufferTranscoder.cpp Core/DicomParsing/MemoryBufferTranscoder.h
diffstat 6 files changed, 21 insertions(+), 94 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomNetworking/DicomStoreUserConnection.cpp	Fri May 08 11:16:16 2020 +0200
+++ b/Core/DicomNetworking/DicomStoreUserConnection.cpp	Fri May 08 11:24:34 2020 +0200
@@ -492,7 +492,7 @@
       }
 
       std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded(
-        transcoder.TranscodeToParsed2(*dicom, buffer, size, uncompressedSyntaxes, false));
+        transcoder.TranscodeToParsed(*dicom, buffer, size, uncompressedSyntaxes, false));
 
       // WARNING: Below this point, "transcoded->GetDicom()" is possibly
       // a reference to "*dicom", if the DCMTK transcoder was used
--- a/Core/DicomParsing/DcmtkTranscoder.cpp	Fri May 08 11:16:16 2020 +0200
+++ b/Core/DicomParsing/DcmtkTranscoder.cpp	Fri May 08 11:24:34 2020 +0200
@@ -129,30 +129,6 @@
   }
 
     
-  DcmFileFormat* DcmtkTranscoder::TranscodeToParsed(bool& hasSopInstanceUidChanged /* out */,
-                                                    const void* buffer,
-                                                    size_t size,
-                                                    const std::set<DicomTransferSyntax>& allowedSyntaxes,
-                                                    bool allowNewSopInstanceUid) 
-  {
-    std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(buffer, size));
-
-    if (dicom.get() == NULL)
-    {
-      throw OrthancException(ErrorCode_InternalError);
-    }
-
-    if (InplaceTranscode(hasSopInstanceUidChanged, *dicom, allowedSyntaxes, allowNewSopInstanceUid))
-    {
-      return dicom.release();
-    }
-    else
-    {
-      return NULL;
-    }
-  }
-
-
   bool DcmtkTranscoder::InplaceTranscode(bool& hasSopInstanceUidChanged /* out */,
                                          DcmFileFormat& dicom,
                                          const std::set<DicomTransferSyntax>& allowedSyntaxes,
@@ -321,8 +297,14 @@
                                           const std::set<DicomTransferSyntax>& allowedSyntaxes,
                                           bool allowNewSopInstanceUid) 
   {
-    std::unique_ptr<DcmFileFormat> transcoded(
-      TranscodeToParsed(hasSopInstanceUidChanged, buffer, size, allowedSyntaxes, allowNewSopInstanceUid));
+    std::unique_ptr<DcmFileFormat> dicom(FromDcmtkBridge::LoadFromMemoryBuffer(buffer, size));
+    if (dicom.get() == NULL)
+    {
+      throw OrthancException(ErrorCode_BadFileFormat);
+    }
+    
+    std::unique_ptr<TranscodedDicom> transcoded(
+      TranscodeToParsed(*dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid));
 
     if (transcoded.get() == NULL)
     {
@@ -330,12 +312,12 @@
     }
     else
     {
-      if (transcoded->getDataset() == NULL)
+      if (transcoded->GetDicom().getDataset() == NULL)
       {
         throw OrthancException(ErrorCode_InternalError);
       }          
         
-      FromDcmtkBridge::SaveToMemoryBuffer(target, *transcoded->getDataset());
+      FromDcmtkBridge::SaveToMemoryBuffer(target, *transcoded->GetDicom().getDataset());
       return true;
     }
   }
@@ -415,7 +397,7 @@
   }
 
 
-  IDicomTranscoder::TranscodedDicom* DcmtkTranscoder::TranscodeToParsed2(
+  IDicomTranscoder::TranscodedDicom* DcmtkTranscoder::TranscodeToParsed(
     DcmFileFormat& dicom /* in, possibly modified */,
     const void* buffer /* in, same DICOM file as "dicom" */,
     size_t size,
--- a/Core/DicomParsing/DcmtkTranscoder.h	Fri May 08 11:16:16 2020 +0200
+++ b/Core/DicomParsing/DcmtkTranscoder.h	Fri May 08 11:24:34 2020 +0200
@@ -63,12 +63,6 @@
       return lossyQuality_;
     }
     
-    virtual DcmFileFormat* TranscodeToParsed(bool& hasSopInstanceUidChanged /* out */,
-                                             const void* buffer,
-                                             size_t size,
-                                             const std::set<DicomTransferSyntax>& allowedSyntaxes,
-                                             bool allowNewSopInstanceUid) ORTHANC_OVERRIDE;
-
     virtual bool HasInplaceTranscode(DicomTransferSyntax inputSyntax,
                                      const std::set<DicomTransferSyntax>& outputSyntaxes) const
     {
@@ -98,7 +92,7 @@
                                          const std::set<DicomTransferSyntax>& allowedSyntaxes,
                                          bool allowNewSopInstanceUid) ORTHANC_OVERRIDE;
 
-    virtual TranscodedDicom* TranscodeToParsed2(
+    virtual TranscodedDicom* TranscodeToParsed(
       DcmFileFormat& dicom /* in, possibly modified */,
       const void* buffer /* in, same DICOM file as "dicom" */,
       size_t size,
--- a/Core/DicomParsing/IDicomTranscoder.h	Fri May 08 11:16:16 2020 +0200
+++ b/Core/DicomParsing/IDicomTranscoder.h	Fri May 08 11:24:34 2020 +0200
@@ -62,18 +62,6 @@
                                    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
-     * possibility to do a single parsing for all the possible
-     * transfer syntaxes.
-     **/
-    virtual DcmFileFormat* TranscodeToParsed(bool& hasSopInstanceUidChanged /* out */,
-                                             const void* buffer,
-                                             size_t size,
-                                             const std::set<DicomTransferSyntax>& allowedSyntaxes,
-                                             bool allowNewSopInstanceUid) = 0;
-    
     virtual bool HasInplaceTranscode(DicomTransferSyntax inputSyntax,
                                      const std::set<DicomTransferSyntax>& outputSyntaxes) const = 0;
 
@@ -122,9 +110,12 @@
     };
     
     /**
-     * This flavor is used by C-STORE.
+     * Transcoding flavor that creates a new parsed DICOM file. A
+     * "std::set<>" is used to give the possible plugin the
+     * possibility to do a single parsing for all the possible
+     * transfer syntaxes. This flavor is used by C-STORE.
      **/
-    virtual TranscodedDicom* TranscodeToParsed2(
+    virtual TranscodedDicom* TranscodeToParsed(
       DcmFileFormat& dicom /* in, possibly modified */,
       const void* buffer /* in, same DICOM file as "dicom" */,
       size_t size,
--- a/Core/DicomParsing/MemoryBufferTranscoder.cpp	Fri May 08 11:16:16 2020 +0200
+++ b/Core/DicomParsing/MemoryBufferTranscoder.cpp	Fri May 08 11:24:34 2020 +0200
@@ -87,40 +87,6 @@
   }
 
   
-  DcmFileFormat* MemoryBufferTranscoder::TranscodeToParsed(bool& hasSopInstanceUidChanged,
-                                                           const void* buffer,
-                                                           size_t size,
-                                                           const std::set<DicomTransferSyntax>& allowedSyntaxes,
-                                                           bool allowNewSopInstanceUid)
-  {
-#if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1
-    if (useDcmtk_)
-    {
-      std::unique_ptr<DcmFileFormat> transcoded(
-        dcmtk_.TranscodeToParsed(hasSopInstanceUidChanged, buffer, size,
-                                 allowedSyntaxes, allowNewSopInstanceUid));
-      if (transcoded.get() != NULL)
-      {
-        return transcoded.release();
-      }
-    }
-#endif
-
-    std::string transcoded;
-    DicomTransferSyntax sourceSyntax, targetSyntax;
-    if (Transcode(transcoded, sourceSyntax, targetSyntax, hasSopInstanceUidChanged,
-                  buffer, size, allowedSyntaxes, allowNewSopInstanceUid))
-    {
-      return FromDcmtkBridge::LoadFromMemoryBuffer(
-        transcoded.empty() ? NULL : transcoded.c_str(), transcoded.size());
-    }
-    else
-    {
-      return NULL;
-    }
-  }
-
-
   bool MemoryBufferTranscoder::HasInplaceTranscode(
     DicomTransferSyntax inputSyntax,
     const std::set<DicomTransferSyntax>& outputSyntaxes) const
@@ -219,7 +185,7 @@
   }
   
 
-  IDicomTranscoder::TranscodedDicom* MemoryBufferTranscoder::TranscodeToParsed2(
+  IDicomTranscoder::TranscodedDicom* MemoryBufferTranscoder::TranscodeToParsed(
     DcmFileFormat& dicom /* in, possibly modified */,
     const void* buffer /* in, same DICOM file as "dicom" */,
     size_t size,
@@ -240,7 +206,7 @@
 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1
     else if (useDcmtk_)
     {
-      return dcmtk_.TranscodeToParsed2(dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid);
+      return dcmtk_.TranscodeToParsed(dicom, buffer, size, allowedSyntaxes, allowNewSopInstanceUid);
     }
 #endif
     else
--- a/Core/DicomParsing/MemoryBufferTranscoder.h	Fri May 08 11:16:16 2020 +0200
+++ b/Core/DicomParsing/MemoryBufferTranscoder.h	Fri May 08 11:24:34 2020 +0200
@@ -84,12 +84,6 @@
                                    const std::set<DicomTransferSyntax>& allowedSyntaxes,
                                    bool allowNewSopInstanceUid) ORTHANC_OVERRIDE;
     
-    virtual DcmFileFormat* TranscodeToParsed(bool& hasSopInstanceUidChanged /* out */,
-                                             const void* buffer,
-                                             size_t size,
-                                             const std::set<DicomTransferSyntax>& allowedSyntaxes,
-                                             bool allowNewSopInstanceUid) ORTHANC_OVERRIDE;
-
     virtual bool HasInplaceTranscode(
       DicomTransferSyntax inputSyntax,
       const std::set<DicomTransferSyntax>& outputSyntaxes) const ORTHANC_OVERRIDE;
@@ -109,7 +103,7 @@
                                          const std::set<DicomTransferSyntax>& allowedSyntaxes,
                                          bool allowNewSopInstanceUid) ORTHANC_OVERRIDE;
 
-    virtual TranscodedDicom* TranscodeToParsed2(
+    virtual TranscodedDicom* TranscodeToParsed(
       DcmFileFormat& dicom /* in, possibly modified */,
       const void* buffer /* in, same DICOM file as "dicom" */,
       size_t size,