changeset 3938:54dbebbcc032 transcoding

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 18 May 2020 15:59:50 +0200
parents 41eec97c23ef
children c205f670098e
files Core/DicomParsing/DcmtkTranscoder.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerJobs/ResourceModificationJob.cpp
diffstat 3 files changed, 33 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomParsing/DcmtkTranscoder.cpp	Mon May 18 11:16:18 2020 +0200
+++ b/Core/DicomParsing/DcmtkTranscoder.cpp	Mon May 18 15:59:50 2020 +0200
@@ -55,18 +55,10 @@
 
 namespace Orthanc
 {
-  static uint16_t GetBitsStored(DcmDataset& dataset)
+  static bool GetBitsStored(uint16_t& bitsStored,
+                            DcmDataset& dataset)
   {
-    uint16_t bitsStored;
-    if (dataset.findAndGetUint16(DCM_BitsStored, bitsStored).good())
-    {
-      return bitsStored;
-    }
-    else
-    {
-      throw OrthancException(ErrorCode_BadFileFormat,
-                             "Missing \"Bits Stored\" tag in DICOM instance");
-    }      
+    return dataset.findAndGetUint16(DCM_BitsStored, bitsStored).good();
   }
 
   
@@ -94,18 +86,26 @@
     {
       throw OrthancException(ErrorCode_InternalError);
     }
-      
+
     bool ok;
       
-    if (mustEqual)
+    if (dicom.getDataset()->tagExists(DCM_PixelData))
     {
-      ok = (GetSopInstanceUid(*dicom.getDataset()) == sopInstanceUid);
+      if (mustEqual)
+      {
+        ok = (GetSopInstanceUid(*dicom.getDataset()) == sopInstanceUid);
+      }
+      else
+      {
+        ok = (GetSopInstanceUid(*dicom.getDataset()) != sopInstanceUid);
+      }
     }
     else
     {
-      ok = (GetSopInstanceUid(*dicom.getDataset()) != sopInstanceUid);
+      // No pixel data: Transcoding must not change the SOP instance UID
+      ok = (GetSopInstanceUid(*dicom.getDataset()) == sopInstanceUid);
     }
-
+    
     if (!ok)
     {
       throw OrthancException(ErrorCode_InternalError,
@@ -148,7 +148,9 @@
                              "Cannot determine the transfer syntax");
     }
 
-    const uint16_t bitsStored = GetBitsStored(*dicom.getDataset());
+    uint16_t bitsStored;
+    bool hasBitsStored = GetBitsStored(bitsStored, *dicom.getDataset());
+    
     std::string sourceSopInstanceUid = GetSopInstanceUid(*dicom.getDataset());
     
     if (allowedSyntaxes.find(syntax) != allowedSyntaxes.end())
@@ -188,7 +190,7 @@
 #if ORTHANC_ENABLE_DCMTK_JPEG == 1
     if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess1) != allowedSyntaxes.end() &&
         allowNewSopInstanceUid &&
-        bitsStored == 8)
+        (!hasBitsStored || bitsStored == 8))
     {
       // Check out "dcmjpeg/apps/dcmcjpeg.cc"
       DJ_RPLossy parameters(lossyQuality_);
@@ -205,7 +207,7 @@
 #if ORTHANC_ENABLE_DCMTK_JPEG == 1
     if (allowedSyntaxes.find(DicomTransferSyntax_JPEGProcess2_4) != allowedSyntaxes.end() &&
         allowNewSopInstanceUid &&
-        bitsStored <= 12)
+        (!hasBitsStored || bitsStored <= 12))
     {
       // Check out "dcmjpeg/apps/dcmcjpeg.cc"
       DJ_RPLossy parameters(lossyQuality_);
--- a/OrthancServer/ServerContext.cpp	Mon May 18 11:16:18 2020 +0200
+++ b/OrthancServer/ServerContext.cpp	Mon May 18 15:59:50 2020 +0200
@@ -508,9 +508,10 @@
                                    DicomInstanceToStore& dicom,
                                    StoreInstanceMode mode)
   {
-    //const DicomTransferSyntax option = DicomTransferSyntax_JPEGProcess1;
-    const DicomTransferSyntax option = DicomTransferSyntax_LittleEndianExplicit;
-    
+    const DicomTransferSyntax option = DicomTransferSyntax_JPEGProcess1;
+    //const DicomTransferSyntax option = DicomTransferSyntax_JPEGProcess14SV1;
+    //const DicomTransferSyntax option = DicomTransferSyntax_LittleEndianExplicit;
+
     if (1)
     {
       return StoreAfterTranscoding(resultPublicId, dicom, mode);
@@ -552,7 +553,8 @@
           toStore.SetOrigin(dicom.GetOrigin());
 
           StoreStatus ok = StoreAfterTranscoding(resultPublicId, toStore, mode);
-          printf(">> %s\n", resultPublicId.c_str());
+          assert(resultPublicId == tmp->GetHasher().HashInstance());
+
           return ok;
         }
       }
--- a/OrthancServer/ServerJobs/ResourceModificationJob.cpp	Mon May 18 11:16:18 2020 +0200
+++ b/OrthancServer/ServerJobs/ResourceModificationJob.cpp	Mon May 18 15:59:50 2020 +0200
@@ -218,7 +218,12 @@
                              "Error while storing a modified instance " + instance);
     }
 
-    assert(modifiedInstance == modifiedHasher.HashInstance());
+    /**
+     * The assertion below will fail if automated transcoding to a
+     * lossy transfer syntax is enabled in the Orthanc core, and if
+     * the source instance is not in this transfer syntax.
+     **/
+    // assert(modifiedInstance == modifiedHasher.HashInstance());
 
     output_->Update(modifiedHasher);