changeset 5324:e95caa87fed8

only store PixelDataVR metadata if needed
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sun, 25 Jun 2023 15:19:25 +0200
parents 138e9d0c08c1
children 9c00e832985f
files OrthancFramework/Sources/DicomFormat/DicomStreamReader.cpp OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp OrthancServer/Sources/ServerContext.cpp
diffstat 3 files changed, 28 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomFormat/DicomStreamReader.cpp	Sun Jun 25 12:29:39 2023 +0200
+++ b/OrthancFramework/Sources/DicomFormat/DicomStreamReader.cpp	Sun Jun 25 15:19:25 2023 +0200
@@ -582,12 +582,14 @@
     bool                 hasPixelData_;
     uint64_t             pixelDataOffset_;
     ValueRepresentation  pixelDataVR_;
+    DicomTransferSyntax  transferSyntax_;
     
   public:
     PixelDataVisitor() :
       hasPixelData_(false),
       pixelDataOffset_(0),
-      pixelDataVR_(ValueRepresentation_Unknown)
+      pixelDataVR_(ValueRepresentation_Unknown),
+      transferSyntax_(DicomTransferSyntax_LittleEndianImplicit) // Default DICOM transfer syntax
     {
     }
     
@@ -599,6 +601,7 @@
 
     virtual void VisitTransferSyntax(DicomTransferSyntax transferSyntax) ORTHANC_OVERRIDE
     {
+      transferSyntax_ = transferSyntax;
     }
     
     virtual bool VisitDatasetTag(const DicomTag& tag,
@@ -611,7 +614,23 @@
       {
         hasPixelData_ = true;
         pixelDataOffset_ = fileOffset;
-        pixelDataVR_ = vr;
+
+        if (transferSyntax_ == DicomTransferSyntax_LittleEndianImplicit)
+        {
+          // Implicit Little Endian has always "OW" VR for pixel data
+          // https://dicom.nema.org/medical/dicom/current/output/chtml/part05/chapter_A.html
+          pixelDataVR_ = ValueRepresentation_OtherWord;
+        }
+        else if (transferSyntax_ == DicomTransferSyntax_LittleEndianExplicit ||
+                 transferSyntax_ == DicomTransferSyntax_BigEndianExplicit)
+        {
+          pixelDataVR_ = vr;
+        }
+        else
+        {
+          // Compressed transfer syntaxes must always be OB
+          pixelDataVR_ = ValueRepresentation_OtherByte;
+        }
       }
 
       // Stop processing once pixel data has been passed
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Sun Jun 25 12:29:39 2023 +0200
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Sun Jun 25 15:19:25 2023 +0200
@@ -3361,9 +3361,13 @@
                                 boost::lexical_cast<std::string>(pixelDataOffset_));
 
             // New in Orthanc 1.12.1
-            SetInstanceMetadata(content, instanceMetadata_, instanceId,
-                                MetadataType_Instance_PixelDataVR,
-                                EnumerationToString(pixelDataVR_));
+            if (dicomSummary_.GuessPixelDataValueRepresentation(transferSyntax_) != pixelDataVR_)
+            {
+              // Store the VR of pixel data if it doesn't comply with the standard
+              SetInstanceMetadata(content, instanceMetadata_, instanceId,
+                                  MetadataType_Instance_PixelDataVR,
+                                  EnumerationToString(pixelDataVR_));
+            }
           }
       
           const DicomValue* value;
--- a/OrthancServer/Sources/ServerContext.cpp	Sun Jun 25 12:29:39 2023 +0200
+++ b/OrthancServer/Sources/ServerContext.cpp	Sun Jun 25 15:19:25 2023 +0200
@@ -1101,8 +1101,6 @@
           {
             index_.OverwriteMetadata(instancePublicId, MetadataType_Instance_PixelDataOffset,
                                      boost::lexical_cast<std::string>(pixelDataOffset));
-            index_.OverwriteMetadata(instancePublicId, MetadataType_Instance_PixelDataVR,
-                                     EnumerationToString(pixelDataVR));
 
             if (!area_.HasReadRange() ||
                 compressionEnabled_)