Mercurial > hg > orthanc
annotate Core/DicomParsing/MemoryBufferTranscoder.cpp @ 3935:09262122934c transcoding
Moved the GDCM sample plugin out of the Orthanc repository as a separate plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 15 May 2020 15:48:15 +0200 |
parents | b99acc213937 |
children | aae045f802f4 |
rev | line source |
---|---|
3893 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "../PrecompiledHeaders.h" | |
35 #include "MemoryBufferTranscoder.h" | |
36 | |
37 #include "../OrthancException.h" | |
38 #include "FromDcmtkBridge.h" | |
39 | |
3929
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
40 #if !defined(NDEBUG) // For debugging |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
41 # include "ParsedDicomFile.h" |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
42 #endif |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
43 |
3893 | 44 namespace Orthanc |
45 { | |
3929
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
46 static void CheckTargetSyntax(const std::string& transcoded, |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
47 const std::set<DicomTransferSyntax>& allowedSyntaxes) |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
48 { |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
49 #if !defined(NDEBUG) |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
50 // Debug mode |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
51 ParsedDicomFile parsed(transcoded); |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
52 |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
53 std::string s; |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
54 DicomTransferSyntax a, b; |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
55 if (!parsed.LookupTransferSyntax(s) || |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
56 !FromDcmtkBridge::LookupOrthancTransferSyntax(a, parsed.GetDcmtkObject()) || |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
57 !LookupTransferSyntax(b, s) || |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
58 a != b || |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
59 allowedSyntaxes.find(a) == allowedSyntaxes.end()) |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
60 { |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
61 throw OrthancException( |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
62 ErrorCode_Plugin, |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
63 "DEBUG - The transcoding plugin has not written to one of the allowed transfer syntaxes"); |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
64 } |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
65 #endif |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
66 } |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
67 |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
68 |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
69 bool MemoryBufferTranscoder::TranscodeParsedToBuffer( |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
70 std::string& target /* out */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
71 bool& hasSopInstanceUidChanged /* out */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
72 DcmFileFormat& dicom /* in, possibly modified */, |
3910 | 73 DicomTransferSyntax targetSyntax, |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
74 bool allowNewSopInstanceUid) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
75 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
76 if (dicom.getDataset() == NULL) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
77 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
78 throw OrthancException(ErrorCode_InternalError); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
79 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
80 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
81 std::string source; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
82 FromDcmtkBridge::SaveToMemoryBuffer(source, *dicom.getDataset()); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
83 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
84 const void* data = source.empty() ? NULL : source.c_str(); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
85 |
3929
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
86 std::set<DicomTransferSyntax> allowedSyntaxes; |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
87 allowedSyntaxes.insert(targetSyntax); |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
88 |
3930
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3929
diff
changeset
|
89 if (Transcode(target, hasSopInstanceUidChanged, |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3929
diff
changeset
|
90 data, source.size(), allowedSyntaxes, allowNewSopInstanceUid)) |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
91 { |
3930
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3929
diff
changeset
|
92 CheckTargetSyntax(target, allowedSyntaxes); |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3929
diff
changeset
|
93 return true; |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
94 } |
3930
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3929
diff
changeset
|
95 else |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3929
diff
changeset
|
96 { |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3929
diff
changeset
|
97 return false; |
b99acc213937
transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3929
diff
changeset
|
98 } |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
99 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
100 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
101 |
3907
1555feda39e2
substituting IDicomTranscoder::TranscodeToParsed() by refactored implementation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3906
diff
changeset
|
102 IDicomTranscoder::TranscodedDicom* MemoryBufferTranscoder::TranscodeToParsed( |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
103 DcmFileFormat& dicom /* in, possibly modified */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
104 const void* buffer /* in, same DICOM file as "dicom" */, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
105 size_t size, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
106 const std::set<DicomTransferSyntax>& allowedSyntaxes, |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
107 bool allowNewSopInstanceUid) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
108 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
109 bool hasSopInstanceUidChanged; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
110 |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
111 std::string target; |
3929
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
112 if (Transcode(target, hasSopInstanceUidChanged, |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
113 buffer, size, allowedSyntaxes, allowNewSopInstanceUid)) |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
114 { |
3929
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
115 CheckTargetSyntax(target, allowedSyntaxes); |
7dc5e7e0045d
simplifying MemoryBufferTranscoder::Transcode() interface
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3910
diff
changeset
|
116 |
3906
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
117 const void* data = target.empty() ? NULL : target.c_str(); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
118 return IDicomTranscoder::TranscodedDicom::CreateFromInternal( |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
119 FromDcmtkBridge::LoadFromMemoryBuffer(data, target.size()), hasSopInstanceUidChanged); |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
120 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
121 else |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
122 { |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
123 return NULL; |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
124 } |
f0dd5ded8927
refactoring using IDicomTranscoder::TranscodedDicom
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3905
diff
changeset
|
125 } |
3893 | 126 } |