Mercurial > hg > orthanc
diff OrthancServer/ServerContext.cpp @ 3903:d1273d7cc200 transcoding
avoid unnecessary dicom serialization
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 07 May 2020 16:43:08 +0200 |
parents | 8f7ad4989fec |
children | c62f84c7eda9 |
line wrap: on
line diff
--- 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<DicomTransferSyntax>& allowedSyntaxes, - bool allowNewSopInstanceUid) + bool ServerContext::Transcode(std::string& target, + bool& hasSopInstanceUidChanged, + ParsedDicomFile& dicom, // Possibly modified + const std::set<DicomTransferSyntax>& 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); + } } }