Mercurial > hg > orthanc
diff Plugins/Engine/OrthancPlugins.cpp @ 3924:395c59208f10 transcoding
new functions in SDK: OrthancPluginEncodeDicomWebJson2() and OrthancPluginEncodeDicomWebXml2()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 13 May 2020 16:43:09 +0200 |
parents | 6f11b3233a06 |
children | dd112d2b83f0 |
line wrap: on
line diff
--- a/Plugins/Engine/OrthancPlugins.cpp Tue May 12 21:05:15 2020 +0200 +++ b/Plugins/Engine/OrthancPlugins.cpp Wed May 13 16:43:09 2020 +0200 @@ -330,9 +330,11 @@ class DicomWebBinaryFormatter : public DicomWebJsonVisitor::IBinaryFormatter { private: - OrthancPluginDicomWebBinaryCallback callback_; - DicomWebJsonVisitor::BinaryMode currentMode_; - std::string currentBulkDataUri_; + OrthancPluginDicomWebBinaryCallback oldCallback_; + OrthancPluginDicomWebBinaryCallback2 newCallback_; // New in Orthanc 1.7.0 + void* newPayload_; // New in Orthanc 1.7.0 + DicomWebJsonVisitor::BinaryMode currentMode_; + std::string currentBulkDataUri_; static void Setter(OrthancPluginDicomWebNode* node, OrthancPluginDicomWebBinaryMode mode, @@ -367,7 +369,16 @@ public: DicomWebBinaryFormatter(const _OrthancPluginEncodeDicomWeb& parameters) : - callback_(parameters.callback) + oldCallback_(parameters.callback), + newCallback_(NULL), + newPayload_(NULL) + { + } + + DicomWebBinaryFormatter(const _OrthancPluginEncodeDicomWeb2& parameters) : + oldCallback_(NULL), + newCallback_(parameters.callback), + newPayload_(parameters.payload) { } @@ -377,7 +388,8 @@ const DicomTag& tag, ValueRepresentation vr) { - if (callback_ == NULL) + if (oldCallback_ == NULL && + newCallback_ == NULL) { return DicomWebJsonVisitor::BinaryMode_InlineBinary; } @@ -398,15 +410,32 @@ currentMode_ = DicomWebJsonVisitor::BinaryMode_Ignore; - callback_(reinterpret_cast<OrthancPluginDicomWebNode*>(this), - DicomWebBinaryFormatter::Setter, - static_cast<uint32_t>(parentTags.size()), - (empty ? NULL : &groups[0]), - (empty ? NULL : &elements[0]), - (empty ? NULL : &indexes[0]), - tag.GetGroup(), - tag.GetElement(), - Plugins::Convert(vr)); + if (oldCallback_ != NULL) + { + oldCallback_(reinterpret_cast<OrthancPluginDicomWebNode*>(this), + DicomWebBinaryFormatter::Setter, + static_cast<uint32_t>(parentTags.size()), + (empty ? NULL : &groups[0]), + (empty ? NULL : &elements[0]), + (empty ? NULL : &indexes[0]), + tag.GetGroup(), + tag.GetElement(), + Plugins::Convert(vr)); + } + else + { + assert(newCallback_ != NULL); + newCallback_(reinterpret_cast<OrthancPluginDicomWebNode*>(this), + DicomWebBinaryFormatter::Setter, + static_cast<uint32_t>(parentTags.size()), + (empty ? NULL : &groups[0]), + (empty ? NULL : &elements[0]), + (empty ? NULL : &indexes[0]), + tag.GetGroup(), + tag.GetElement(), + Plugins::Convert(vr), + newPayload_); + } bulkDataUri = currentBulkDataUri_; return currentMode_; @@ -3514,6 +3543,35 @@ } + static void FormatDicomWeb(char** target, + bool isJson, + DicomWebBinaryFormatter& formatter, + const void* dicom, + size_t dicomSize) + { + DicomWebJsonVisitor visitor; + visitor.SetFormatter(formatter); + + { + ParsedDicomFile parsed(dicom, dicomSize); + parsed.Apply(visitor); + } + + std::string s; + + if (isJson) + { + s = visitor.GetResult().toStyledString(); + } + else + { + visitor.FormatXml(s); + } + + *target = CopyString(s); + } + + bool OrthancPlugins::InvokeSafeService(SharedLibrary& plugin, _OrthancPluginService service, const void* parameters) @@ -4196,27 +4254,24 @@ *reinterpret_cast<const _OrthancPluginEncodeDicomWeb*>(parameters); DicomWebBinaryFormatter formatter(p); - - DicomWebJsonVisitor visitor; - visitor.SetFormatter(formatter); - - { - ParsedDicomFile dicom(p.dicom, p.dicomSize); - dicom.Apply(visitor); - } - - std::string s; - - if (service == _OrthancPluginService_EncodeDicomWebJson) - { - s = visitor.GetResult().toStyledString(); - } - else - { - visitor.FormatXml(s); - } - - *p.target = CopyString(s); + + FormatDicomWeb(p.target, + (service == _OrthancPluginService_EncodeDicomWebJson), + formatter, p.dicom, p.dicomSize); + return true; + } + + case _OrthancPluginService_EncodeDicomWebJson2: + case _OrthancPluginService_EncodeDicomWebXml2: + { + const _OrthancPluginEncodeDicomWeb2& p = + *reinterpret_cast<const _OrthancPluginEncodeDicomWeb2*>(parameters); + + DicomWebBinaryFormatter formatter(p); + + FormatDicomWeb(p.target, + (service == _OrthancPluginService_EncodeDicomWebJson2), + formatter, p.dicom, p.dicomSize); return true; }