diff Core/DicomParsing/MemoryBufferTranscoder.cpp @ 3946:1f33ed7f82e6 transcoding

automatic test of transcoding
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 19 May 2020 13:44:56 +0200
parents 0b3256c3ee14
children 5fe8c6d3212e
line wrap: on
line diff
--- a/Core/DicomParsing/MemoryBufferTranscoder.cpp	Tue May 19 11:24:00 2020 +0200
+++ b/Core/DicomParsing/MemoryBufferTranscoder.cpp	Tue May 19 13:44:56 2020 +0200
@@ -74,12 +74,32 @@
   {
     target.Clear();
     
+#if !defined(NDEBUG)
+    // Don't run this code in release mode, as it implies parsing the DICOM file
+    DicomTransferSyntax sourceSyntax;
+    if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, source.GetParsed()))
+    {
+      LOG(ERROR) << "Unsupport transfer syntax for transcoding";
+      return false;
+    }
+    
+    const std::string sourceSopInstanceUid = GetSopInstanceUid(source.GetParsed());
+#endif
+
     std::string buffer;
     if (TranscodeBuffer(buffer, hasSopInstanceUidChanged, source.GetBufferData(),
                         source.GetBufferSize(), allowedSyntaxes, allowNewSopInstanceUid))
     {
       CheckTargetSyntax(buffer, allowedSyntaxes);  // For debug only
+
       target.AcquireBuffer(buffer);
+      
+#if !defined(NDEBUG)
+      // Only run the sanity check in debug mode
+      CheckTranscoding(target, hasSopInstanceUidChanged, sourceSyntax, sourceSopInstanceUid,
+                       allowedSyntaxes, allowNewSopInstanceUid);
+#endif
+
       return true;
     }
     else