# HG changeset patch # User Sebastien Jodogne # Date 1588689733 -7200 # Node ID e46b7a997f0a733b0702ffde92430af47c2249be # Parent 25c122277f53a9d7fe820ae8ab58f55bd63c2ad3 IDicomTranscoder::TranscodeToBuffer() diff -r 25c122277f53 -r e46b7a997f0a UnitTestsSources/FromDcmtkTests.cpp --- a/UnitTestsSources/FromDcmtkTests.cpp Tue May 05 16:32:37 2020 +0200 +++ b/UnitTestsSources/FromDcmtkTests.cpp Tue May 05 16:42:13 2020 +0200 @@ -1943,6 +1943,11 @@ namespace Orthanc { + /** + * WARNING: This class might be called from several threads at + * once. Make sure to implement proper locking. + **/ + class IDicomTranscoder : public boost::noncopyable { public: @@ -1950,6 +1955,12 @@ { } + virtual bool TranscodeToBuffer(std::string& target, + const void* buffer, + size_t size, + const std::set& allowedSyntaxes, + bool allowNewSopInstanceUid) = 0; + /** * Transcoding flavor that creates a new parsed DICOM file. A * "std::set<>" is used to give the possible plugin the @@ -2166,7 +2177,7 @@ virtual DcmFileFormat* Transcode(const void* buffer, size_t size, const std::set& allowedSyntaxes, - bool allowNewSopInstanceUid) + bool allowNewSopInstanceUid) ORTHANC_OVERRIDE { std::unique_ptr dicom(FromDcmtkBridge::LoadFromMemoryBuffer(buffer, size)); @@ -2187,7 +2198,7 @@ virtual bool InplaceTranscode(DcmFileFormat& dicom, const std::set& allowedSyntaxes, - bool allowNewSopInstanceUid) + bool allowNewSopInstanceUid) ORTHANC_OVERRIDE { if (dicom.getDataset() == NULL) { @@ -2324,6 +2335,32 @@ return false; } + + + virtual bool TranscodeToBuffer(std::string& target, + const void* buffer, + size_t size, + const std::set& allowedSyntaxes, + bool allowNewSopInstanceUid) ORTHANC_OVERRIDE + { + std::unique_ptr transcoded( + Transcode(buffer, size, allowedSyntaxes, allowNewSopInstanceUid)); + + if (transcoded.get() == NULL) + { + return false; + } + else + { + if (transcoded->getDataset() == NULL) + { + throw OrthancException(ErrorCode_InternalError); + } + + FromDcmtkBridge::SaveToMemoryBuffer(target, *transcoded->getDataset()); + return true; + } + } }; } @@ -2392,24 +2429,17 @@ DicomTransferSyntax a = (DicomTransferSyntax) i; std::set s; s.insert(a); - std::unique_ptr transcoded(transcoder.Transcode(source.c_str(), source.size(), s, true)); - if (transcoded.get() == NULL) + + std::string t; + + if (!transcoder.TranscodeToBuffer(t, source.c_str(), source.size(), s, true)) { printf("**************** CANNOT: [%s] => [%s]\n", GetTransferSyntaxUid(sourceSyntax), GetTransferSyntaxUid(a)); } else { - std::string t; - FromDcmtkBridge::SaveToMemoryBuffer(t, *transcoded->getDataset()); printf("SIZE: %lu\n", t.size()); - - const char* v = NULL; - transcoded->getDataset()->findAndGetString(DCM_SOPInstanceUID, v); - if (std::string(v) != "1.3.12.2.1107.5.12.1.2013021918595000.1.1") - { - printf("CHANGED SOP INSTANCE UID\n"); - } } } }