Mercurial > hg > orthanc
changeset 3929:7dc5e7e0045d transcoding
simplifying MemoryBufferTranscoder::Transcode() interface
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 14 May 2020 14:40:13 +0200 |
parents | 4cdc875510d1 |
children | b99acc213937 |
files | Core/DicomParsing/DcmtkTranscoder.cpp Core/DicomParsing/DcmtkTranscoder.h Core/DicomParsing/IDicomTranscoder.h Core/DicomParsing/MemoryBufferTranscoder.cpp Core/DicomParsing/MemoryBufferTranscoder.h OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Plugins/Engine/OrthancPlugins.cpp Plugins/Engine/OrthancPlugins.h UnitTestsSources/FromDcmtkTests.cpp |
diffstat | 9 files changed, 39 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/Core/DicomParsing/DcmtkTranscoder.cpp Thu May 14 13:31:05 2020 +0200 +++ b/Core/DicomParsing/DcmtkTranscoder.cpp Thu May 14 14:40:13 2020 +0200 @@ -325,7 +325,6 @@ bool DcmtkTranscoder::TranscodeParsedToBuffer( std::string& target /* out */, - DicomTransferSyntax& sourceSyntax /* out */, bool& hasSopInstanceUidChanged /* out */, DcmFileFormat& dicom /* in, possibly modified */, DicomTransferSyntax targetSyntax, @@ -336,12 +335,6 @@ throw OrthancException(ErrorCode_InternalError); } - if (!FromDcmtkBridge::LookupOrthancTransferSyntax(sourceSyntax, dicom)) - { - LOG(ERROR) << "Unsupport transfer syntax for transcoding"; - return false; - } - std::set<DicomTransferSyntax> tmp; tmp.insert(targetSyntax);
--- a/Core/DicomParsing/DcmtkTranscoder.h Thu May 14 13:31:05 2020 +0200 +++ b/Core/DicomParsing/DcmtkTranscoder.h Thu May 14 14:40:13 2020 +0200 @@ -71,7 +71,6 @@ static bool IsSupported(DicomTransferSyntax syntax); virtual bool TranscodeParsedToBuffer(std::string& target /* out */, - DicomTransferSyntax& sourceSyntax /* out */, bool& hasSopInstanceUidChanged /* out */, DcmFileFormat& dicom /* in, possibly modified */, DicomTransferSyntax targetSyntax,
--- a/Core/DicomParsing/IDicomTranscoder.h Thu May 14 13:31:05 2020 +0200 +++ b/Core/DicomParsing/IDicomTranscoder.h Thu May 14 14:40:13 2020 +0200 @@ -56,7 +56,6 @@ } virtual bool TranscodeParsedToBuffer(std::string& target /* out */, - DicomTransferSyntax& sourceSyntax /* out */, bool& hasSopInstanceUidChanged /* out */, DcmFileFormat& dicom /* in, possibly modified */, DicomTransferSyntax targetSyntax,
--- a/Core/DicomParsing/MemoryBufferTranscoder.cpp Thu May 14 13:31:05 2020 +0200 +++ b/Core/DicomParsing/MemoryBufferTranscoder.cpp Thu May 14 14:40:13 2020 +0200 @@ -37,6 +37,10 @@ #include "../OrthancException.h" #include "FromDcmtkBridge.h" +#if !defined(NDEBUG) // For debugging +# include "ParsedDicomFile.h" +#endif + namespace Orthanc { MemoryBufferTranscoder::MemoryBufferTranscoder() @@ -63,9 +67,31 @@ } + static void CheckTargetSyntax(const std::string& transcoded, + const std::set<DicomTransferSyntax>& allowedSyntaxes) + { +#if !defined(NDEBUG) + // Debug mode + ParsedDicomFile parsed(transcoded); + + std::string s; + DicomTransferSyntax a, b; + if (!parsed.LookupTransferSyntax(s) || + !FromDcmtkBridge::LookupOrthancTransferSyntax(a, parsed.GetDcmtkObject()) || + !LookupTransferSyntax(b, s) || + a != b || + allowedSyntaxes.find(a) == allowedSyntaxes.end()) + { + throw OrthancException( + ErrorCode_Plugin, + "DEBUG - The transcoding plugin has not written to one of the allowed transfer syntaxes"); + } +#endif + } + + bool MemoryBufferTranscoder::TranscodeParsedToBuffer( std::string& target /* out */, - DicomTransferSyntax& sourceSyntax /* out */, bool& hasSopInstanceUidChanged /* out */, DcmFileFormat& dicom /* in, possibly modified */, DicomTransferSyntax targetSyntax, @@ -81,30 +107,23 @@ const void* data = source.empty() ? NULL : source.c_str(); - std::set<DicomTransferSyntax> tmp; - tmp.insert(targetSyntax); - - DicomTransferSyntax targetSyntax2; - bool success = Transcode(target, sourceSyntax, targetSyntax2, hasSopInstanceUidChanged, - data, source.size(), tmp, allowNewSopInstanceUid); + std::set<DicomTransferSyntax> allowedSyntaxes; + allowedSyntaxes.insert(targetSyntax); - if (success && - targetSyntax != targetSyntax2) - { - throw OrthancException(ErrorCode_InternalError); - } - + bool success = Transcode(target, hasSopInstanceUidChanged, + data, source.size(), allowedSyntaxes, allowNewSopInstanceUid); + #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1 if (!success && useDcmtk_ && dcmtk_.TranscodeParsedToBuffer( - target, sourceSyntax, hasSopInstanceUidChanged, - dicom, targetSyntax, allowNewSopInstanceUid)) + target, hasSopInstanceUidChanged, dicom, targetSyntax, allowNewSopInstanceUid)) { success = true; } #endif + CheckTargetSyntax(target, allowedSyntaxes); return success; } @@ -116,13 +135,14 @@ const std::set<DicomTransferSyntax>& allowedSyntaxes, bool allowNewSopInstanceUid) { - DicomTransferSyntax sourceSyntax, targetSyntax; bool hasSopInstanceUidChanged; std::string target; - if (Transcode(target, sourceSyntax, targetSyntax, hasSopInstanceUidChanged, + if (Transcode(target, hasSopInstanceUidChanged, buffer, size, allowedSyntaxes, allowNewSopInstanceUid)) { + CheckTargetSyntax(target, allowedSyntaxes); + const void* data = target.empty() ? NULL : target.c_str(); return IDicomTranscoder::TranscodedDicom::CreateFromInternal( FromDcmtkBridge::LoadFromMemoryBuffer(data, target.size()), hasSopInstanceUidChanged);
--- a/Core/DicomParsing/MemoryBufferTranscoder.h Thu May 14 13:31:05 2020 +0200 +++ b/Core/DicomParsing/MemoryBufferTranscoder.h Thu May 14 14:40:13 2020 +0200 @@ -55,8 +55,6 @@ protected: virtual bool Transcode(std::string& target, - DicomTransferSyntax& sourceSyntax /* out */, - DicomTransferSyntax& targetSyntax /* out */, bool& hasSopInstanceUidChanged /* out */, const void* buffer, size_t size, @@ -78,7 +76,6 @@ } virtual bool TranscodeParsedToBuffer(std::string& target /* out */, - DicomTransferSyntax& sourceSyntax /* out */, bool& hasSopInstanceUidChanged /* out */, DcmFileFormat& dicom /* in, possibly modified */, DicomTransferSyntax targetSyntax,
--- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Thu May 14 13:31:05 2020 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Thu May 14 14:40:13 2020 +0200 @@ -131,11 +131,10 @@ if (transcode) { std::string transcoded; - DicomTransferSyntax sourceSyntax; bool hasSopInstanceUidChanged; if (context.GetTranscoder().TranscodeParsedToBuffer( - transcoded, sourceSyntax, hasSopInstanceUidChanged, + transcoded, hasSopInstanceUidChanged, modified->GetDcmtkObject(), targetSyntax, true)) { call.GetOutput().AnswerBuffer(transcoded, MimeType_Dicom);
--- a/Plugins/Engine/OrthancPlugins.cpp Thu May 14 13:31:05 2020 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Thu May 14 14:40:13 2020 +0200 @@ -5131,8 +5131,6 @@ bool OrthancPlugins::Transcode(std::string& target, - DicomTransferSyntax& sourceSyntax /* out */, - DicomTransferSyntax& targetSyntax /* out */, bool& hasSopInstanceUidChanged /* out */, const void* buffer, size_t size,
--- a/Plugins/Engine/OrthancPlugins.h Thu May 14 13:31:05 2020 +0200 +++ b/Plugins/Engine/OrthancPlugins.h Thu May 14 14:40:13 2020 +0200 @@ -238,8 +238,6 @@ protected: // From "MemoryBufferTranscoder" virtual bool Transcode(std::string& target, - DicomTransferSyntax& sourceSyntax /* out */, - DicomTransferSyntax& targetSyntax /* out */, bool& hasSopInstanceUidChanged /* out */, const void* buffer, size_t size,
--- a/UnitTestsSources/FromDcmtkTests.cpp Thu May 14 13:31:05 2020 +0200 +++ b/UnitTestsSources/FromDcmtkTests.cpp Thu May 14 14:40:13 2020 +0200 @@ -1991,10 +1991,9 @@ std::string t; bool hasSopInstanceUidChanged; - DicomTransferSyntax sourceSyntax2; std::unique_ptr<DcmFileFormat> cloned(dynamic_cast<DcmFileFormat*>(toto->clone())); - if (!transcoder.TranscodeParsedToBuffer(t, sourceSyntax2, hasSopInstanceUidChanged, *cloned, a, true)) + if (!transcoder.TranscodeParsedToBuffer(t, hasSopInstanceUidChanged, *cloned, a, true)) { printf("**************** CANNOT: [%s] => [%s]\n", GetTransferSyntaxUid(sourceSyntax), GetTransferSyntaxUid(a)); @@ -2005,7 +2004,6 @@ ASSERT_TRUE(FromDcmtkBridge::LookupOrthancTransferSyntax(targetSyntax, *cloned)); ASSERT_EQ(targetSyntax, a); - ASSERT_EQ(sourceSyntax, sourceSyntax2); bool lossy = (a == DicomTransferSyntax_JPEGProcess1 || a == DicomTransferSyntax_JPEGProcess2_4 || a == DicomTransferSyntax_JPEGLSLossy);