# HG changeset patch # User Sebastien Jodogne # Date 1588862588 -7200 # Node ID d1273d7cc20099d025403b51330847bf2c9114e0 # Parent 7459fcb1bdf7126a60ff3210def460d8d40b5a80 avoid unnecessary dicom serialization diff -r 7459fcb1bdf7 -r d1273d7cc200 OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp --- a/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Thu May 07 15:29:39 2020 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp Thu May 07 16:43:08 2020 +0200 @@ -130,14 +130,13 @@ if (transcode) { - std::string saved; - modified->SaveToMemoryBuffer(saved); + std::set ts; + ts.insert(targetSyntax); std::string transcoded; bool hasSopInstanceUidChanged; - std::set ts; - ts.insert(targetSyntax); - if (context.TranscodeMemoryBuffer(transcoded, hasSopInstanceUidChanged, saved, ts, true)) + + if (context.Transcode(transcoded, hasSopInstanceUidChanged, *modified, ts, true)) { call.GetOutput().AnswerBuffer(transcoded, MimeType_Dicom); } diff -r 7459fcb1bdf7 -r d1273d7cc200 OrthancServer/ServerContext.cpp --- a/OrthancServer/ServerContext.cpp Thu May 07 15:29:39 2020 +0200 +++ b/OrthancServer/ServerContext.cpp Thu May 07 16:43:08 2020 +0200 @@ -1155,24 +1155,48 @@ } - bool ServerContext::TranscodeMemoryBuffer(std::string& target, - bool& hasSopInstanceUidChanged, - const std::string& source, - const std::set& allowedSyntaxes, - bool allowNewSopInstanceUid) + bool ServerContext::Transcode(std::string& target, + bool& hasSopInstanceUidChanged, + ParsedDicomFile& dicom, // Possibly modified + const std::set& allowedSyntaxes, + bool allowNewSopInstanceUid) { - const char* data = source.empty() ? NULL : source.c_str(); + IDicomTranscoder* transcoder = dcmtkTranscoder_.get(); #if ORTHANC_ENABLE_PLUGINS == 1 if (HasPlugins()) { - return GetPlugins().TranscodeToBuffer( - target, hasSopInstanceUidChanged, data, source.size(), allowedSyntaxes, allowNewSopInstanceUid); + transcoder = &GetPlugins(); } #endif - assert(dcmtkTranscoder_.get() != NULL); - return dcmtkTranscoder_->TranscodeToBuffer( - target, hasSopInstanceUidChanged, data, source.size(), allowedSyntaxes, allowNewSopInstanceUid); + if (transcoder == NULL) + { + throw OrthancException(ErrorCode_InternalError); + } + else if (transcoder->HasInplaceTranscode()) + { + if (transcoder->InplaceTranscode(hasSopInstanceUidChanged, dicom.GetDcmtkObject(), + allowedSyntaxes, allowNewSopInstanceUid)) + { + // In-place transcoding is supported and has succeeded + dicom.SaveToMemoryBuffer(target); + return true; + } + else + { + return false; + } + } + else + { + std::string source; + dicom.SaveToMemoryBuffer(source); + + const char* data = source.empty() ? NULL : source.c_str(); + + return transcoder->TranscodeToBuffer( + target, hasSopInstanceUidChanged, data, source.size(), allowedSyntaxes, allowNewSopInstanceUid); + } } } diff -r 7459fcb1bdf7 -r d1273d7cc200 OrthancServer/ServerContext.h --- a/OrthancServer/ServerContext.h Thu May 07 15:29:39 2020 +0200 +++ b/OrthancServer/ServerContext.h Thu May 07 16:43:08 2020 +0200 @@ -464,10 +464,10 @@ uint16_t moveOriginatorId); // This method can be used even if "TranscodingEnabled" is set to "false" - bool TranscodeMemoryBuffer(std::string& target, - bool& hasSopInstanceUidChanged, - const std::string& source, - const std::set& allowedSyntaxes, - bool allowNewSopInstanceUid); + bool Transcode(std::string& target, + bool& hasSopInstanceUidChanged, + ParsedDicomFile& dicom, // Possibly modified + const std::set& allowedSyntaxes, + bool allowNewSopInstanceUid); }; }