# HG changeset patch # User Sebastien Jodogne # Date 1589810390 -7200 # Node ID 54dbebbcc0320de437f6bf54e9ce3328ea39c9fa # Parent 41eec97c23ef49fbc1195f685d4cbd4fc52891c8 fix diff -r 41eec97c23ef -r 54dbebbcc032 Core/DicomParsing/DcmtkTranscoder.cpp --- 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_); diff -r 41eec97c23ef -r 54dbebbcc032 OrthancServer/ServerContext.cpp --- 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; } } diff -r 41eec97c23ef -r 54dbebbcc032 OrthancServer/ServerJobs/ResourceModificationJob.cpp --- 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);