Mercurial > hg > orthanc
changeset 1935:e251606c1433
FromDcmtkBridge::LoadFromMemoryBuffer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 24 Mar 2016 11:46:41 +0100 |
parents | 72a2fd7fed8b |
children | dba0db0a94b4 |
files | OrthancServer/FromDcmtkBridge.cpp OrthancServer/FromDcmtkBridge.h OrthancServer/ParsedDicomFile.cpp OrthancServer/ParsedDicomFile.h |
diffstat | 4 files changed, 33 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/FromDcmtkBridge.cpp Tue Mar 22 15:11:53 2016 +0100 +++ b/OrthancServer/FromDcmtkBridge.cpp Thu Mar 24 11:46:41 2016 +0100 @@ -56,6 +56,7 @@ #include <dcmtk/dcmdata/dcostrmb.h> #include <dcmtk/dcmdata/dcpixel.h> #include <dcmtk/dcmdata/dcuid.h> +#include <dcmtk/dcmdata/dcistrmb.h> #include <dcmtk/dcmdata/dcvrae.h> #include <dcmtk/dcmdata/dcvras.h> @@ -1705,4 +1706,29 @@ return result.release(); } + + + DcmFileFormat* FromDcmtkBridge::LoadFromMemoryBuffer(const void* buffer, + size_t size) + { + DcmInputBufferStream is; + if (size > 0) + { + is.setBuffer(buffer, size); + } + is.setEos(); + + std::auto_ptr<DcmFileFormat> result(new DcmFileFormat); + + result->transferInit(); + if (!result->read(is).good()) + { + throw OrthancException(ErrorCode_BadFileFormat); + } + + result->loadAllDataIntoMemory(); + result->transferEnd(); + + return result.release(); + } }
--- a/OrthancServer/FromDcmtkBridge.h Tue Mar 22 15:11:53 2016 +0100 +++ b/OrthancServer/FromDcmtkBridge.h Thu Mar 24 11:46:41 2016 +0100 @@ -39,6 +39,7 @@ #include <dcmtk/dcmdata/dcdatset.h> #include <dcmtk/dcmdata/dcmetinf.h> #include <dcmtk/dcmdata/dcpixseq.h> +#include <dcmtk/dcmdata/dcfilefo.h> #include <json/json.h> namespace Orthanc @@ -156,5 +157,8 @@ bool generateIdentifiers, bool decodeDataUriScheme, Encoding defaultEncoding); + + static DcmFileFormat* LoadFromMemoryBuffer(const void* buffer, + size_t size); }; }
--- a/OrthancServer/ParsedDicomFile.cpp Tue Mar 22 15:11:53 2016 +0100 +++ b/OrthancServer/ParsedDicomFile.cpp Thu Mar 24 11:46:41 2016 +0100 @@ -101,7 +101,6 @@ #include <dcmtk/dcmdata/dcdicent.h> #include <dcmtk/dcmdata/dcdict.h> #include <dcmtk/dcmdata/dcfilefo.h> -#include <dcmtk/dcmdata/dcistrmb.h> #include <dcmtk/dcmdata/dcuid.h> #include <dcmtk/dcmdata/dcmetinf.h> #include <dcmtk/dcmdata/dcdeftag.h> @@ -150,31 +149,6 @@ }; - // This method can only be called from the constructors! - void ParsedDicomFile::Setup(const void* buffer, - size_t size) - { - DcmInputBufferStream is; - if (size > 0) - { - is.setBuffer(buffer, size); - } - is.setEos(); - - pimpl_->file_.reset(new DcmFileFormat); - pimpl_->file_->transferInit(); - if (!pimpl_->file_->read(is).good()) - { - delete pimpl_; // Avoid a memory leak due to exception - // throwing, as we are in the constructor - - throw OrthancException(ErrorCode_BadFileFormat); - } - pimpl_->file_->loadAllDataIntoMemory(); - pimpl_->file_->transferEnd(); - } - - static void SendPathValueForDictionary(RestApiOutput& output, DcmItem& dicom) { @@ -852,18 +826,18 @@ ParsedDicomFile::ParsedDicomFile(const void* content, size_t size) : pimpl_(new PImpl) { - Setup(content, size); + pimpl_->file_.reset(FromDcmtkBridge::LoadFromMemoryBuffer(content, size)); } ParsedDicomFile::ParsedDicomFile(const std::string& content) : pimpl_(new PImpl) { if (content.size() == 0) { - Setup(NULL, 0); + pimpl_->file_.reset(FromDcmtkBridge::LoadFromMemoryBuffer(NULL, 0)); } else { - Setup(&content[0], content.size()); + pimpl_->file_.reset(FromDcmtkBridge::LoadFromMemoryBuffer(&content[0], content.size())); } }
--- a/OrthancServer/ParsedDicomFile.h Tue Mar 22 15:11:53 2016 +0100 +++ b/OrthancServer/ParsedDicomFile.h Thu Mar 24 11:46:41 2016 +0100 @@ -51,9 +51,6 @@ ParsedDicomFile(ParsedDicomFile& other); - void Setup(const void* content, - size_t size); - void RemovePrivateTagsInternal(const std::set<DicomTag>* toKeep); void UpdateStorageUid(const DicomTag& tag,