Mercurial > hg > orthanc
comparison Plugins/Engine/OrthancPlugins.cpp @ 3919:6f11b3233a06 transcoding
OrthancPluginTranscodeDicomInstance() and OrthancPluginSerializeDicomInstance()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 12 May 2020 12:38:27 +0200 |
parents | 0e3849268a55 |
children | 395c59208f10 |
comparison
equal
deleted
inserted
replaced
3917:04fb907dfc85 | 3919:6f11b3233a06 |
---|---|
1822 return instance_; | 1822 return instance_; |
1823 }; | 1823 }; |
1824 }; | 1824 }; |
1825 | 1825 |
1826 | 1826 |
1827 class OrthancPlugins::DicomInstanceFromTranscoded : public IDicomInstance | |
1828 { | |
1829 private: | |
1830 std::unique_ptr<ParsedDicomFile> parsed_; | |
1831 DicomInstanceToStore instance_; | |
1832 | |
1833 public: | |
1834 DicomInstanceFromTranscoded(IDicomTranscoder::TranscodedDicom& transcoded) : | |
1835 parsed_(ParsedDicomFile::AcquireDcmtkObject(transcoded.ReleaseDicom())) | |
1836 { | |
1837 instance_.SetParsedDicomFile(*parsed_); | |
1838 instance_.SetOrigin(DicomInstanceOrigin::FromPlugins()); | |
1839 } | |
1840 | |
1841 virtual bool CanBeFreed() const ORTHANC_OVERRIDE | |
1842 { | |
1843 return true; | |
1844 } | |
1845 | |
1846 virtual const DicomInstanceToStore& GetInstance() const ORTHANC_OVERRIDE | |
1847 { | |
1848 return instance_; | |
1849 }; | |
1850 }; | |
1851 | |
1852 | |
1827 void OrthancPlugins::SignalStoredInstance(const std::string& instanceId, | 1853 void OrthancPlugins::SignalStoredInstance(const std::string& instanceId, |
1828 const DicomInstanceToStore& instance, | 1854 const DicomInstanceToStore& instance, |
1829 const Json::Value& simplifiedTags) | 1855 const Json::Value& simplifiedTags) |
1830 { | 1856 { |
1831 DicomInstanceFromCallback wrapped(instance); | 1857 DicomInstanceFromCallback wrapped(instance); |
2743 { | 2769 { |
2744 decoded.reset(DicomImageDecoder::Decode(instance.GetParsedDicomFile(), p.frameIndex)); | 2770 decoded.reset(DicomImageDecoder::Decode(instance.GetParsedDicomFile(), p.frameIndex)); |
2745 } | 2771 } |
2746 | 2772 |
2747 *(p.targetImage) = ReturnImage(decoded); | 2773 *(p.targetImage) = ReturnImage(decoded); |
2774 return; | |
2775 } | |
2776 | |
2777 case _OrthancPluginService_SerializeDicomInstance: | |
2778 { | |
2779 if (p.targetBuffer == NULL) | |
2780 { | |
2781 throw OrthancException(ErrorCode_NullPointer); | |
2782 } | |
2783 | |
2784 p.targetBuffer->data = NULL; | |
2785 p.targetBuffer->size = 0; | |
2786 | |
2787 std::string serialized; | |
2788 instance.GetParsedDicomFile().SaveToMemoryBuffer(serialized); | |
2789 CopyToMemoryBuffer(*p.targetBuffer, serialized); | |
2748 return; | 2790 return; |
2749 } | 2791 } |
2750 | 2792 |
2751 default: | 2793 default: |
2752 throw OrthancException(ErrorCode_InternalError); | 2794 throw OrthancException(ErrorCode_InternalError); |
3630 return true; | 3672 return true; |
3631 | 3673 |
3632 case _OrthancPluginService_GetInstanceFramesCount: | 3674 case _OrthancPluginService_GetInstanceFramesCount: |
3633 case _OrthancPluginService_GetInstanceRawFrame: | 3675 case _OrthancPluginService_GetInstanceRawFrame: |
3634 case _OrthancPluginService_GetInstanceDecodedFrame: | 3676 case _OrthancPluginService_GetInstanceDecodedFrame: |
3677 case _OrthancPluginService_SerializeDicomInstance: | |
3635 AccessDicomInstance2(service, parameters); | 3678 AccessDicomInstance2(service, parameters); |
3636 return true; | 3679 return true; |
3637 | 3680 |
3638 case _OrthancPluginService_SetGlobalProperty: | 3681 case _OrthancPluginService_SetGlobalProperty: |
3639 { | 3682 { |
4210 } | 4253 } |
4211 | 4254 |
4212 return true; | 4255 return true; |
4213 } | 4256 } |
4214 | 4257 |
4258 case _OrthancPluginService_TranscodeDicomInstance: | |
4259 { | |
4260 const _OrthancPluginCreateDicomInstance& p = | |
4261 *reinterpret_cast<const _OrthancPluginCreateDicomInstance*>(parameters); | |
4262 | |
4263 DicomTransferSyntax transferSyntax; | |
4264 if (p.transferSyntax == NULL || | |
4265 !LookupTransferSyntax(transferSyntax, p.transferSyntax)) | |
4266 { | |
4267 throw OrthancException(ErrorCode_ParameterOutOfRange, "Unsupported transfer syntax: " + | |
4268 std::string(p.transferSyntax == NULL ? "(null)" : p.transferSyntax)); | |
4269 } | |
4270 else | |
4271 { | |
4272 ParsedDicomFile dicom(p.buffer, p.size); | |
4273 | |
4274 std::set<DicomTransferSyntax> syntaxes; | |
4275 syntaxes.insert(transferSyntax); | |
4276 | |
4277 std::unique_ptr<IDicomTranscoder::TranscodedDicom> transcoded; | |
4278 | |
4279 { | |
4280 PImpl::ServerContextLock lock(*pimpl_); | |
4281 transcoded.reset(lock.GetContext().GetTranscoder().TranscodeToParsed( | |
4282 dicom.GetDcmtkObject(), p.buffer, p.size, | |
4283 syntaxes, true /* allow new sop */)); | |
4284 } | |
4285 | |
4286 if (transcoded.get() == NULL) | |
4287 { | |
4288 throw OrthancException(ErrorCode_NotImplemented, "Cannot transcode image"); | |
4289 } | |
4290 else | |
4291 { | |
4292 *(p.target) = reinterpret_cast<OrthancPluginDicomInstance*>( | |
4293 new DicomInstanceFromTranscoded(*transcoded)); | |
4294 return true; | |
4295 } | |
4296 } | |
4297 } | |
4298 | |
4215 default: | 4299 default: |
4216 return false; | 4300 return false; |
4217 } | 4301 } |
4218 } | 4302 } |
4219 | 4303 |