Mercurial > hg > orthanc
changeset 3951:5fe8c6d3212e transcoding
removed useless information "hasSopInstanceUidChanged"
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 19 May 2020 21:06:53 +0200 |
parents | 5797ca4f3b8d |
children | 6e14f2da7c7e acf628e61671 |
files | Core/DicomNetworking/DicomStoreUserConnection.cpp Core/DicomParsing/DcmtkTranscoder.cpp Core/DicomParsing/DcmtkTranscoder.h Core/DicomParsing/IDicomTranscoder.cpp Core/DicomParsing/IDicomTranscoder.h Core/DicomParsing/MemoryBufferTranscoder.cpp Core/DicomParsing/MemoryBufferTranscoder.h OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h OrthancServer/ServerJobs/ArchiveJob.cpp OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp OrthancServer/ServerJobs/ResourceModificationJob.cpp Plugins/Engine/OrthancPlugins.cpp Plugins/Engine/OrthancPlugins.h Plugins/Include/orthanc/OrthancCPlugin.h UnitTestsSources/FromDcmtkTests.cpp |
diffstat | 17 files changed, 32 insertions(+), 79 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/DicomNetworking/DicomStoreUserConnection.cpp Tue May 19 20:37:00 2020 +0200 +++ b/Core/DicomNetworking/DicomStoreUserConnection.cpp Tue May 19 21:06:53 2020 +0200 @@ -494,12 +494,13 @@ IDicomTranscoder::DicomImage source; source.AcquireParsed(dicom.release()); source.SetExternalBuffer(buffer, size); + + const std::string sourceUid = IDicomTranscoder::GetSopInstanceUid(source.GetParsed()); IDicomTranscoder::DicomImage transcoded; - bool hasSopInstanceUidChanged; - if (transcoder.Transcode(transcoded, hasSopInstanceUidChanged, source, uncompressedSyntaxes, false)) + if (transcoder.Transcode(transcoded, source, uncompressedSyntaxes, false)) { - if (hasSopInstanceUidChanged) + if (sourceUid != IDicomTranscoder::GetSopInstanceUid(transcoded.GetParsed())) { throw OrthancException(ErrorCode_Plugin, "The transcoder has changed the SOP " "instance UID while transcoding to an uncompressed transfer syntax");
--- a/Core/DicomParsing/DcmtkTranscoder.cpp Tue May 19 20:37:00 2020 +0200 +++ b/Core/DicomParsing/DcmtkTranscoder.cpp Tue May 19 21:06:53 2020 +0200 @@ -80,8 +80,7 @@ } - bool DcmtkTranscoder::InplaceTranscode(bool& hasSopInstanceUidChanged /* out */, - DicomTransferSyntax& selectedSyntax /* out */, + bool DcmtkTranscoder::InplaceTranscode(DicomTransferSyntax& selectedSyntax /* out */, DcmFileFormat& dicom, const std::set<DicomTransferSyntax>& allowedSyntaxes, bool allowNewSopInstanceUid) @@ -91,8 +90,6 @@ throw OrthancException(ErrorCode_InternalError); } - hasSopInstanceUidChanged = false; - DicomTransferSyntax syntax; if (!FromDcmtkBridge::LookupOrthancTransferSyntax(syntax, dicom)) { @@ -150,7 +147,6 @@ if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess1, ¶meters)) { selectedSyntax = DicomTransferSyntax_JPEGProcess1; - hasSopInstanceUidChanged = true; return true; } } @@ -166,7 +162,6 @@ if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGProcess2_4, ¶meters)) { selectedSyntax = DicomTransferSyntax_JPEGProcess2_4; - hasSopInstanceUidChanged = true; return true; } } @@ -234,7 +229,6 @@ if (FromDcmtkBridge::Transcode(dicom, DicomTransferSyntax_JPEGLSLossy, ¶meters)) { selectedSyntax = DicomTransferSyntax_JPEGLSLossy; - hasSopInstanceUidChanged = true; return true; } } @@ -277,7 +271,6 @@ bool DcmtkTranscoder::Transcode(DicomImage& target, - bool& hasSopInstanceUidChanged /* out */, DicomImage& source /* in, "GetParsed()" possibly modified */, const std::set<DicomTransferSyntax>& allowedSyntaxes, bool allowNewSopInstanceUid) @@ -303,7 +296,7 @@ target.AcquireBuffer(source); return true; } - else if (InplaceTranscode(hasSopInstanceUidChanged, targetSyntax, source.GetParsed(), + else if (InplaceTranscode(targetSyntax, source.GetParsed(), allowedSyntaxes, allowNewSopInstanceUid)) { // Sanity check @@ -317,7 +310,7 @@ #if !defined(NDEBUG) // Only run the sanity check in debug mode - CheckTranscoding(target, hasSopInstanceUidChanged, sourceSyntax, sourceSopInstanceUid, + CheckTranscoding(target, sourceSyntax, sourceSopInstanceUid, allowedSyntaxes, allowNewSopInstanceUid); #endif
--- a/Core/DicomParsing/DcmtkTranscoder.h Tue May 19 20:37:00 2020 +0200 +++ b/Core/DicomParsing/DcmtkTranscoder.h Tue May 19 21:06:53 2020 +0200 @@ -50,8 +50,7 @@ private: unsigned int lossyQuality_; - bool InplaceTranscode(bool& hasSopInstanceUidChanged /* out */, - DicomTransferSyntax& selectedSyntax /* out */, + bool InplaceTranscode(DicomTransferSyntax& selectedSyntax /* out */, DcmFileFormat& dicom, const std::set<DicomTransferSyntax>& allowedSyntaxes, bool allowNewSopInstanceUid); @@ -72,7 +71,6 @@ static bool IsSupported(DicomTransferSyntax syntax); virtual bool Transcode(DicomImage& target, - bool& hasSopInstanceUidChanged /* out */, DicomImage& source /* in, "GetParsed()" possibly modified */, const std::set<DicomTransferSyntax>& allowedSyntaxes, bool allowNewSopInstanceUid) ORTHANC_OVERRIDE;
--- a/Core/DicomParsing/IDicomTranscoder.cpp Tue May 19 20:37:00 2020 +0200 +++ b/Core/DicomParsing/IDicomTranscoder.cpp Tue May 19 21:06:53 2020 +0200 @@ -101,7 +101,6 @@ void IDicomTranscoder::CheckTranscoding(IDicomTranscoder::DicomImage& transcoded, - bool hasSopInstanceUidChanged, DicomTransferSyntax sourceSyntax, const std::string& sourceSopInstanceUid, const std::set<DicomTransferSyntax>& allowedSyntaxes, @@ -116,16 +115,6 @@ std::string targetSopInstanceUid = GetSopInstanceUid(parsed); - if (hasSopInstanceUidChanged && (targetSopInstanceUid == sourceSopInstanceUid)) - { - throw OrthancException(ErrorCode_InternalError); - } - - if (!hasSopInstanceUidChanged && (targetSopInstanceUid != sourceSopInstanceUid)) - { - throw OrthancException(ErrorCode_InternalError); - } - if (parsed.getDataset()->tagExists(DCM_PixelData)) { if (!allowNewSopInstanceUid && (targetSopInstanceUid != sourceSopInstanceUid)) @@ -135,8 +124,7 @@ } else { - if (hasSopInstanceUidChanged || - targetSopInstanceUid != sourceSopInstanceUid) + if (targetSopInstanceUid != sourceSopInstanceUid) { throw OrthancException(ErrorCode_InternalError, "No pixel data: Transcoding must not change the SOP instance UID"); @@ -152,8 +140,7 @@ if (allowedSyntaxes.find(sourceSyntax) != allowedSyntaxes.end()) { // No transcoding should have happened - if (targetSopInstanceUid != sourceSopInstanceUid || - hasSopInstanceUidChanged) + if (targetSopInstanceUid != sourceSopInstanceUid) { throw OrthancException(ErrorCode_InternalError); }
--- a/Core/DicomParsing/IDicomTranscoder.h Tue May 19 20:37:00 2020 +0200 +++ b/Core/DicomParsing/IDicomTranscoder.h Tue May 19 21:06:53 2020 +0200 @@ -111,7 +111,6 @@ DicomTransferSyntax source); static void CheckTranscoding(DicomImage& transcoded, - bool hasSopInstanceUidChanged, DicomTransferSyntax sourceSyntax, const std::string& sourceSopInstanceUid, const std::set<DicomTransferSyntax>& allowedSyntaxes, @@ -123,7 +122,6 @@ } virtual bool Transcode(DicomImage& target, - bool& hasSopInstanceUidChanged /* out */, DicomImage& source /* in, "GetParsed()" possibly modified */, const std::set<DicomTransferSyntax>& allowedSyntaxes, bool allowNewSopInstanceUid) = 0;
--- a/Core/DicomParsing/MemoryBufferTranscoder.cpp Tue May 19 20:37:00 2020 +0200 +++ b/Core/DicomParsing/MemoryBufferTranscoder.cpp Tue May 19 21:06:53 2020 +0200 @@ -67,7 +67,6 @@ bool MemoryBufferTranscoder::Transcode(DicomImage& target, - bool& hasSopInstanceUidChanged /* out */, DicomImage& source, const std::set<DicomTransferSyntax>& allowedSyntaxes, bool allowNewSopInstanceUid) @@ -87,8 +86,8 @@ #endif std::string buffer; - if (TranscodeBuffer(buffer, hasSopInstanceUidChanged, source.GetBufferData(), - source.GetBufferSize(), allowedSyntaxes, allowNewSopInstanceUid)) + if (TranscodeBuffer(buffer, source.GetBufferData(), source.GetBufferSize(), + allowedSyntaxes, allowNewSopInstanceUid)) { CheckTargetSyntax(buffer, allowedSyntaxes); // For debug only @@ -96,7 +95,7 @@ #if !defined(NDEBUG) // Only run the sanity check in debug mode - CheckTranscoding(target, hasSopInstanceUidChanged, sourceSyntax, sourceSopInstanceUid, + CheckTranscoding(target, sourceSyntax, sourceSopInstanceUid, allowedSyntaxes, allowNewSopInstanceUid); #endif
--- a/Core/DicomParsing/MemoryBufferTranscoder.h Tue May 19 20:37:00 2020 +0200 +++ b/Core/DicomParsing/MemoryBufferTranscoder.h Tue May 19 21:06:53 2020 +0200 @@ -42,7 +42,6 @@ { protected: virtual bool TranscodeBuffer(std::string& target, - bool& hasSopInstanceUidChanged /* out */, const void* buffer, size_t size, const std::set<DicomTransferSyntax>& allowedSyntaxes, @@ -50,7 +49,6 @@ public: virtual bool Transcode(DicomImage& target /* out */, - bool& hasSopInstanceUidChanged /* out */, DicomImage& source, const std::set<DicomTransferSyntax>& allowedSyntaxes, bool allowNewSopInstanceUid) ORTHANC_OVERRIDE;
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Tue May 19 20:37:00 2020 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Tue May 19 21:06:53 2020 +0200 @@ -134,12 +134,11 @@ source.AcquireParsed(*modified); // "modified" is invalid below this point IDicomTranscoder::DicomImage transcoded; - bool hasSopInstanceUidChanged; std::set<DicomTransferSyntax> s; s.insert(targetSyntax); - if (context.Transcode(transcoded, hasSopInstanceUidChanged, source, s, true)) + if (context.Transcode(transcoded, source, s, true)) { call.GetOutput().AnswerBuffer(transcoded.GetBufferData(), transcoded.GetBufferSize(), MimeType_Dicom);
--- a/OrthancServer/ServerContext.cpp Tue May 19 20:37:00 2020 +0200 +++ b/OrthancServer/ServerContext.cpp Tue May 19 21:06:53 2020 +0200 @@ -569,9 +569,7 @@ source.SetExternalBuffer(dicom.GetBufferData(), dicom.GetBufferSize()); IDicomTranscoder::DicomImage transcoded; - bool hasSopInstanceUidChanged; - if (Transcode(transcoded, hasSopInstanceUidChanged, - source, syntaxes, true /* allow new SOP instance UID */)) + if (Transcode(transcoded, source, syntaxes, true /* allow new SOP instance UID */)) { std::unique_ptr<ParsedDicomFile> tmp(transcoded.ReleaseAsParsedDicomFile()); @@ -1323,15 +1321,13 @@ bool ServerContext::Transcode(DicomImage& target, - bool& hasSopInstanceUidChanged /* out */, DicomImage& source /* in, "GetParsed()" possibly modified */, const std::set<DicomTransferSyntax>& allowedSyntaxes, bool allowNewSopInstanceUid) { if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_Before) { - if (dcmtkTranscoder_->Transcode(target, hasSopInstanceUidChanged, source, - allowedSyntaxes, allowNewSopInstanceUid)) + if (dcmtkTranscoder_->Transcode(target, source, allowedSyntaxes, allowNewSopInstanceUid)) { return true; } @@ -1341,8 +1337,7 @@ if (HasPlugins() && GetPlugins().HasCustomTranscoder()) { - if (GetPlugins().Transcode(target, hasSopInstanceUidChanged, source, - allowedSyntaxes, allowNewSopInstanceUid)) + if (GetPlugins().Transcode(target, source, allowedSyntaxes, allowNewSopInstanceUid)) { return true; } @@ -1356,8 +1351,7 @@ if (builtinDecoderTranscoderOrder_ == BuiltinDecoderTranscoderOrder_After) { - return dcmtkTranscoder_->Transcode(target, hasSopInstanceUidChanged, source, - allowedSyntaxes, allowNewSopInstanceUid); + return dcmtkTranscoder_->Transcode(target, source, allowedSyntaxes, allowNewSopInstanceUid); } else {
--- a/OrthancServer/ServerContext.h Tue May 19 20:37:00 2020 +0200 +++ b/OrthancServer/ServerContext.h Tue May 19 21:06:53 2020 +0200 @@ -480,7 +480,6 @@ // This method can be used even if the global option // "TranscodeDicomProtocol" is set to "false" virtual bool Transcode(DicomImage& target, - bool& hasSopInstanceUidChanged /* out */, DicomImage& source /* in, "GetParsed()" possibly modified */, const std::set<DicomTransferSyntax>& allowedSyntaxes, bool allowNewSopInstanceUid) ORTHANC_OVERRIDE;
--- a/OrthancServer/ServerJobs/ArchiveJob.cpp Tue May 19 20:37:00 2020 +0200 +++ b/OrthancServer/ServerJobs/ArchiveJob.cpp Tue May 19 21:06:53 2020 +0200 @@ -446,9 +446,7 @@ IDicomTranscoder::DicomImage source, transcoded; source.SetExternalBuffer(content); - bool hasSopInstanceChanged; - if (context.Transcode(transcoded, hasSopInstanceChanged, source, - syntaxes, true /* allow new SOP instance UID */)) + if (context.Transcode(transcoded, source, syntaxes, true /* allow new SOP instance UID */)) { writer.Write(transcoded.GetBufferData(), transcoded.GetBufferSize());
--- a/OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp Tue May 19 20:37:00 2020 +0200 +++ b/OrthancServer/ServerJobs/OrthancPeerStoreJob.cpp Tue May 19 21:06:53 2020 +0200 @@ -69,8 +69,7 @@ IDicomTranscoder::DicomImage source, transcoded; source.SetExternalBuffer(dicom); - bool hasSopInstanceUidChanged; - if (context_.Transcode(transcoded, hasSopInstanceUidChanged, source, syntaxes, true)) + if (context_.Transcode(transcoded, source, syntaxes, true)) { client_->GetBody().assign(reinterpret_cast<const char*>(transcoded.GetBufferData()), transcoded.GetBufferSize());
--- a/OrthancServer/ServerJobs/ResourceModificationJob.cpp Tue May 19 20:37:00 2020 +0200 +++ b/OrthancServer/ServerJobs/ResourceModificationJob.cpp Tue May 19 21:06:53 2020 +0200 @@ -186,8 +186,7 @@ source.AcquireParsed(*modified); // "modified" is invalid below this point IDicomTranscoder::DicomImage transcoded; - bool hasSopInstanceUidChanged; - if (GetContext().Transcode(transcoded, hasSopInstanceUidChanged, source, syntaxes, true)) + if (GetContext().Transcode(transcoded, source, syntaxes, true)) { modified.reset(transcoded.ReleaseAsParsedDicomFile());
--- a/Plugins/Engine/OrthancPlugins.cpp Tue May 19 20:37:00 2020 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Tue May 19 21:06:53 2020 +0200 @@ -4376,12 +4376,12 @@ source.SetExternalBuffer(p.buffer, p.size); IDicomTranscoder::DicomImage transcoded; - bool success, hasSopInstanceChanged; + bool success; { PImpl::ServerContextLock lock(*pimpl_); - success = lock.GetContext().Transcode(transcoded, hasSopInstanceChanged, source, - syntaxes, true /* allow new sop */); + success = lock.GetContext().Transcode( + transcoded, source, syntaxes, true /* allow new sop */); } if (success) @@ -5214,7 +5214,6 @@ bool OrthancPlugins::TranscodeBuffer(std::string& target, - bool& hasSopInstanceUidChanged /* out */, const void* buffer, size_t size, const std::set<DicomTransferSyntax>& allowedSyntaxes, @@ -5240,14 +5239,12 @@ transcoder != pimpl_->transcoderCallbacks_.end(); ++transcoder) { MemoryBufferRaii a; - uint8_t b; - - if ((*transcoder) (a.GetObject(), &b, buffer, size, uids.empty() ? NULL : &uids[0], + + if ((*transcoder) (a.GetObject(), buffer, size, uids.empty() ? NULL : &uids[0], static_cast<uint32_t>(uids.size()), allowNewSopInstanceUid) == OrthancPluginErrorCode_Success) { a.ToString(target); - hasSopInstanceUidChanged = b; return true; } }
--- a/Plugins/Engine/OrthancPlugins.h Tue May 19 20:37:00 2020 +0200 +++ b/Plugins/Engine/OrthancPlugins.h Tue May 19 21:06:53 2020 +0200 @@ -240,7 +240,6 @@ protected: // From "MemoryBufferTranscoder" virtual bool TranscodeBuffer(std::string& target, - bool& hasSopInstanceUidChanged /* out */, const void* buffer, size_t size, const std::set<DicomTransferSyntax>& allowedSyntaxes,
--- a/Plugins/Include/orthanc/OrthancCPlugin.h Tue May 19 20:37:00 2020 +0200 +++ b/Plugins/Include/orthanc/OrthancCPlugin.h Tue May 19 21:06:53 2020 +0200 @@ -8091,10 +8091,6 @@ * @brief Signature of a callback function to transcode a DICOM instance. * @param transcoded Target memory buffer. It must be allocated by the * plugin using OrthancPluginCreateMemoryBuffer(). - * @param hasSopInstanceUidChanged Whether the SOP Instance UID of the - * DICOM instance has changed because of the transcoding. This value - * should be "true" if and only if the selected transfer syntax is - * affected by lossy compression. * @param buffer Memory buffer containing the source DICOM instance. * @param size Size of the source memory buffer. * @param allowedSyntaxes A C array of possible transfer syntaxes UIDs for the @@ -8111,7 +8107,6 @@ **/ typedef OrthancPluginErrorCode (*OrthancPluginTranscoderCallback) ( OrthancPluginMemoryBuffer* transcoded /* out */, - uint8_t* hasSopInstanceUidChanged /* out */, const void* buffer, uint64_t size, const char* const* allowedSyntaxes,
--- a/UnitTestsSources/FromDcmtkTests.cpp Tue May 19 20:37:00 2020 +0200 +++ b/UnitTestsSources/FromDcmtkTests.cpp Tue May 19 21:06:53 2020 +0200 @@ -1980,6 +1980,8 @@ Orthanc::SystemToolbox::ReadFile(source, "/home/jodogne/Subversion/orthanc-tests/Database/KarstenHilbertRF.dcm"); std::unique_ptr<DcmFileFormat> toto(FromDcmtkBridge::LoadFromMemoryBuffer(source.c_str(), source.size())); + const std::string sourceUid = IDicomTranscoder::GetSopInstanceUid(*toto); + DicomTransferSyntax sourceSyntax; ASSERT_TRUE(FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, *toto)); @@ -1994,12 +1996,10 @@ std::string t; - bool hasSopInstanceUidChanged; - IDicomTranscoder::DicomImage source, target; source.AcquireParsed(dynamic_cast<DcmFileFormat*>(toto->clone())); - if (!transcoder.Transcode(target, hasSopInstanceUidChanged, source, s, true)) + if (!transcoder.Transcode(target, source, s, true)) { printf("**************** CANNOT: [%s] => [%s]\n", GetTransferSyntaxUid(sourceSyntax), GetTransferSyntaxUid(a)); @@ -2015,13 +2015,13 @@ a == DicomTransferSyntax_JPEGLSLossy); printf("SIZE: %lu\n", t.size()); - if (hasSopInstanceUidChanged) + if (sourceUid == IDicomTranscoder::GetSopInstanceUid(target.GetParsed())) { - ASSERT_TRUE(lossy); + ASSERT_FALSE(lossy); } else { - ASSERT_FALSE(lossy); + ASSERT_TRUE(lossy); } } }