# HG changeset patch # User Sebastien Jodogne # Date 1687699165 -7200 # Node ID e95caa87fed80c4724b5e43ea68fd4780fb35898 # Parent 138e9d0c08c13739bf0281f4e002608fb47d52c4 only store PixelDataVR metadata if needed diff -r 138e9d0c08c1 -r e95caa87fed8 OrthancFramework/Sources/DicomFormat/DicomStreamReader.cpp --- 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 diff -r 138e9d0c08c1 -r e95caa87fed8 OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp --- 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(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; diff -r 138e9d0c08c1 -r e95caa87fed8 OrthancServer/Sources/ServerContext.cpp --- 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(pixelDataOffset)); - index_.OverwriteMetadata(instancePublicId, MetadataType_Instance_PixelDataVR, - EnumerationToString(pixelDataVR)); if (!area_.HasReadRange() || compressionEnabled_)